Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to input multiple beams at once #502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/run/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ Option: ``from_file``
Name of the beam to be read in. If an openPMD file contains multiple beams, the name of the beam
needs to be specified.

* ``beams.all_from_file`` (`string`)
Name of the input file for all beams. This macro then passes it down to all individual beams
without a specified `injection_type`. Additionally the input parameters `beams.iteration`,
`beams.plasma_density` and `beams.file_coordinates_xyz` are passed down if applicable.

Diagnostic parameters
---------------------

Expand Down
8 changes: 8 additions & 0 deletions src/particles/MultiBeam.H
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public:
* \param[in] ibeam index of the beam
*/
int getNRealParticles (int ibeam) const {return m_n_real_particles[ibeam];};

/** \brief Allows beams.all_from_file to specify the input file of all beams that have
* no injection_type. Also passes down beams.iteration, beams.plasma_density and
* beams.file_coordinates_xyz to the individual beams if applicable.
*
* \param[in] beam_names names of all beams.
*/
void MultiFromFileMacro (const amrex::Vector<std::string> beam_names);
private:

amrex::Vector<BeamParticleContainer> m_all_beams; /**< contains all beam containers */
Expand Down
40 changes: 40 additions & 0 deletions src/particles/MultiBeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MultiBeam::MultiBeam (amrex::AmrCore* /*amr_core*/)
pp.getarr("names", m_names);
if (m_names[0] == "no_beam") return;
m_nbeams = m_names.size();
MultiFromFileMacro(m_names);
for (int i = 0; i < m_nbeams; ++i) {
m_all_beams.emplace_back(BeamParticleContainer(m_names[i]));
}
Expand Down Expand Up @@ -173,3 +174,42 @@ MultiBeam::PackLocalGhostParticles (int it, const amrex::Vector<BoxSorter>& box_
);
}
}

void
MultiBeam::MultiFromFileMacro (const amrex::Vector<std::string> beam_names)
{
amrex::ParmParse pp("beams");
std::string all_input_file = "";
if(!pp.query("all_from_file", all_input_file)) {
return;
}

int iteration = 0;
const bool multi_iteration = pp.query("iteration", iteration);
amrex::Real plasma_density = 0;
const bool multi_plasma_density = pp.query("plasma_density", plasma_density);
std::vector<std::string> file_coordinates_xyz;
const bool multi_file_coordinates_xyz = pp.queryarr("file_coordinates_xyz",
file_coordinates_xyz);

for( std::string name : beam_names ) {
amrex::ParmParse pp_beam(name);
if(!pp_beam.contains("injection_type")) {
std::string str_from_file = "from_file";
pp_beam.add("injection_type", str_from_file);
pp_beam.add("input_file", all_input_file);

if(!pp_beam.contains("iteration") && multi_iteration) {
pp_beam.add("iteration", iteration);
}

if(!pp_beam.contains("plasma_density") && multi_plasma_density) {
pp_beam.add("plasma_density", plasma_density);
}

if(!pp_beam.contains("file_coordinates_xyz") && multi_file_coordinates_xyz) {
pp_beam.addarr("file_coordinates_xyz", file_coordinates_xyz);
}
}
}
}