aboutsummaryrefslogtreecommitdiff
path: root/Source/Particles/PhysicalParticleContainer.cpp
diff options
context:
space:
mode:
authorGravatar L. Diana Amorim <LDianaAmorim@lbl.gov> 2020-03-31 17:03:52 -0700
committerGravatar GitHub <noreply@github.com> 2020-03-31 17:03:52 -0700
commit6768fae9eea0a1e9243c94e30281767c24f89046 (patch)
tree7b5f2113a76002dc32ec70cb180cfd585f3e53e6 /Source/Particles/PhysicalParticleContainer.cpp
parent8a0b7dbf9f28a474955662c922cdc5a76c502196 (diff)
downloadWarpX-6768fae9eea0a1e9243c94e30281767c24f89046.tar.gz
WarpX-6768fae9eea0a1e9243c94e30281767c24f89046.tar.zst
WarpX-6768fae9eea0a1e9243c94e30281767c24f89046.zip
Read species distribution from OPMD - part 2 (#859)
* Added <species>.profile=external_file and .profile_file * Added description of input parameters to Docs * Changed from profile to injection option for external file * Fix typo in amrex abort message (due to copy paste) * Added the OpenPMD use amrex abort message * Minor fix - not sure how to remove EOL issue * Tried to add AddExternalFileBeam functon to PhysicalParticleContainer * Trued to fix EOL white space issue * Added read/print species name from OPMD file * Fixed OpenPMD charge and mass read * Added number of particles in species * Added nparts and converted charge/mass units to SI * Fix to nr of particles * Added q_tot parameter to determine part weight * Added macroparticle's weight * Fixed std::int typo - use only int * Update Source/Initialization/PlasmaInjector.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.H Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * No need to include openPMD header yet * Minor Fixes * Fix EOL according to @ax3l's recommendation in #845 * Remove commented out AbortMessage Co-Authored-By: MaxThevenet <mthevenet@lbl.gov> * Removed commented out part initialization (used only in branch for next PR) Co-Authored-By: MaxThevenet <mthevenet@lbl.gov> * Added warning that this is WIP Co-Authored-By: MaxThevenet <mthevenet@lbl.gov> * Changed function name to AddPlasmaFromFile * Removed AMReX warning from loop Co-Authored-By: MaxThevenet <mthevenet@lbl.gov> * Added fix suggested in PR# 847 * Changed to mevpc2_kg * Fix EOL again * Style fix adding spaces around ` = ` Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Style fix added spaces in definitions and between comma Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Style fix Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Added Assert Message for #iterations and TODO const mass/charge * Fix EOL again * Update Docs/source/running_cpp/parameters.rst Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Corrected division by int Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl <axel.huebl@plasma.ninja> * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja> Co-authored-by: MaxThevenet <mthevenet@lbl.gov>
Diffstat (limited to 'Source/Particles/PhysicalParticleContainer.cpp')
-rw-r--r--Source/Particles/PhysicalParticleContainer.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp
index e89d537b6..7010da425 100644
--- a/Source/Particles/PhysicalParticleContainer.cpp
+++ b/Source/Particles/PhysicalParticleContainer.cpp
@@ -307,17 +307,34 @@ PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m,
}
void
-PhysicalParticleContainer::AddPlasmaFromFile(const std::string s_f)
+PhysicalParticleContainer::AddPlasmaFromFile(const std::string s_f, amrex::Real q_tot)
{
#ifdef WARPX_USE_OPENPMD
openPMD::Series series = openPMD::Series(s_f, openPMD::AccessType::READ_ONLY);
amrex::Print() << "openPMD standard version " << series.openPMD() << "\n";
+ AMREX_ALWAYS_ASSERT_WITH_MESSAGE(series.iterations.size() == 1u, "External "
+ "file should contain only one iteration\n");
openPMD::Iteration& i = series.iterations[1];
- amrex::Print() << "File contains " << i.particles.size() << " specie(s):" << "\n";
- for( auto const& ps : i.particles ) {
- amrex::Print() << "\t" << ps.first << "\n";
- }
+
+ AMREX_ALWAYS_ASSERT_WITH_MESSAGE(i.particles.size() == 1u, "External file "
+ "should contain only one species\n");
+ std::pair<std::string,openPMD::ParticleSpecies> ps = *i.particles.begin();
+
+ //TODO: In future PRs will add AMREX_ALWAYS_ASSERT_WITH_MESSAGE to test if mass and charge are both const
+ amrex::Real p_m = ps.second["mass"][openPMD::RecordComponent::SCALAR].loadChunk<amrex::Real>().get()[0];
+ amrex::Real p_q = ps.second["charge"][openPMD::RecordComponent::SCALAR].loadChunk<amrex::Real>().get()[0];
+ int npart = ps.second["position"]["x"].getExtent()[0];
+ series.flush();
+
+ mass = p_m*PhysConst::mevpc2_kg;
+ charge = p_q*PhysConst::q_e;
+ Real const weight = q_tot/(charge*amrex::Real(npart));
+
+ amrex::Print() << npart << " parts of species " << ps.first << "\nWith"
+ << " mass = " << mass << " and charge = " << charge << "\nTo initialize "
+ << npart << " macroparticles with weight " << weight << "\n";
+
amrex::Print()<<"WARNING: this is WIP, no particle has been injected!!";
#endif
return;
@@ -380,7 +397,8 @@ PhysicalParticleContainer::AddParticles (int lev)
}
if (plasma_injector->external_file) {
- AddPlasmaFromFile(plasma_injector->str_injection_file);
+ AddPlasmaFromFile(plasma_injector->str_injection_file,
+ plasma_injector->q_tot);
return;
}