From 6768fae9eea0a1e9243c94e30281767c24f89046 Mon Sep 17 00:00:00 2001 From: "L. Diana Amorim" Date: Tue, 31 Mar 2020 17:03:52 -0700 Subject: Read species distribution from OPMD - part 2 (#859) * Added .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 * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl * Update Source/Particles/PhysicalParticleContainer.H Co-Authored-By: Axel Huebl * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl * 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 * Removed commented out part initialization (used only in branch for next PR) Co-Authored-By: MaxThevenet * Added warning that this is WIP Co-Authored-By: MaxThevenet * Changed function name to AddPlasmaFromFile * Removed AMReX warning from loop Co-Authored-By: MaxThevenet * Added fix suggested in PR# 847 * Changed to mevpc2_kg * Fix EOL again * Style fix adding spaces around ` = ` Co-Authored-By: Axel Huebl * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl * Style fix added spaces in definitions and between comma Co-Authored-By: Axel Huebl * Style fix Co-Authored-By: Axel Huebl * 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 * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl * Corrected division by int Co-Authored-By: Axel Huebl * Update Source/Particles/PhysicalParticleContainer.cpp Co-Authored-By: Axel Huebl * Update Source/Particles/PhysicalParticleContainer.cpp Co-authored-by: Axel Huebl Co-authored-by: MaxThevenet --- Source/Particles/PhysicalParticleContainer.cpp | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') 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 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().get()[0]; + amrex::Real p_q = ps.second["charge"][openPMD::RecordComponent::SCALAR].loadChunk().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; } -- cgit v1.2.3