Skip to content

Commit

Permalink
Merge pull request #5896 from MFraters/move_particle_plugin_declarations
Browse files Browse the repository at this point in the history
Move particle plugin declarations to relative path instead of absolulte path.
  • Loading branch information
gassmoeller authored Jun 15, 2024
2 parents bb315cc + 5167918 commit adb0b58
Show file tree
Hide file tree
Showing 24 changed files with 883 additions and 1,019 deletions.
48 changes: 20 additions & 28 deletions source/particle/generator/ascii_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,49 +61,41 @@ namespace aspect
void
AsciiFile<dim>::declare_parameters (ParameterHandler &prm)
{
prm.enter_subsection("Particles");
prm.enter_subsection("Generator");
{
prm.enter_subsection("Generator");
prm.enter_subsection("Ascii file");
{
prm.enter_subsection("Ascii file");
{
prm.declare_entry ("Data directory",
"$ASPECT_SOURCE_DIR/data/particle/generator/ascii/",
Patterns::DirectoryName (),
"The name of a directory that contains the particle data. This path "
"may either be absolute (if starting with a '/') or relative to "
"the current directory. The path may also include the special "
"text '$ASPECT_SOURCE_DIR' which will be interpreted as the path "
"in which the ASPECT source files were located when ASPECT was "
"compiled. This interpretation allows, for example, to reference "
"files located in the `data/' subdirectory of ASPECT. ");
prm.declare_entry ("Data file name", "particle.dat",
Patterns::Anything (),
"The name of the particle file.");
prm.leave_subsection();
}
prm.leave_subsection();
prm.declare_entry ("Data directory",
"$ASPECT_SOURCE_DIR/data/particle/generator/ascii/",
Patterns::DirectoryName (),
"The name of a directory that contains the particle data. This path "
"may either be absolute (if starting with a '/') or relative to "
"the current directory. The path may also include the special "
"text '$ASPECT_SOURCE_DIR' which will be interpreted as the path "
"in which the ASPECT source files were located when ASPECT was "
"compiled. This interpretation allows, for example, to reference "
"files located in the `data/' subdirectory of ASPECT. ");
prm.declare_entry ("Data file name", "particle.dat",
Patterns::Anything (),
"The name of the particle file.");
}
prm.leave_subsection();
}
prm.leave_subsection();
}


template <int dim>
void
AsciiFile<dim>::parse_parameters (ParameterHandler &prm)
{
prm.enter_subsection("Particles");
prm.enter_subsection("Generator");
{
prm.enter_subsection("Generator");
prm.enter_subsection("Ascii file");
{
prm.enter_subsection("Ascii file");
{
data_directory = Utilities::expand_ASPECT_SOURCE_DIR(prm.get ("Data directory"));
data_directory = Utilities::expand_ASPECT_SOURCE_DIR(prm.get ("Data directory"));

data_filename = prm.get ("Data file name");
}
prm.leave_subsection();
data_filename = prm.get ("Data file name");
}
prm.leave_subsection();
}
Expand Down
26 changes: 9 additions & 17 deletions source/particle/generator/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,7 @@ namespace aspect
create_particle_generator (ParameterHandler &prm)
{
std::string name;
prm.enter_subsection ("Particles");
{
name = prm.get ("Particle generator name");
}
prm.leave_subsection ();
name = prm.get ("Particle generator name");

return std::get<dim>(registered_plugins).create_plugin (name,
"Particle::Generator name");
Expand All @@ -235,18 +231,14 @@ namespace aspect
declare_parameters (ParameterHandler &prm)
{
// declare the entry in the parameter file
prm.enter_subsection ("Particles");
{
const std::string pattern_of_names
= std::get<dim>(registered_plugins).get_pattern_of_names ();

prm.declare_entry ("Particle generator name", "random uniform",
Patterns::Selection (pattern_of_names),
"Select one of the following models:\n\n"
+
std::get<dim>(registered_plugins).get_description_string());
}
prm.leave_subsection ();
const std::string pattern_of_names
= std::get<dim>(registered_plugins).get_pattern_of_names ();

prm.declare_entry ("Particle generator name", "random uniform",
Patterns::Selection (pattern_of_names),
"Select one of the following models:\n\n"
+
std::get<dim>(registered_plugins).get_description_string());

std::get<dim>(registered_plugins).declare_parameters (prm);
}
Expand Down
108 changes: 50 additions & 58 deletions source/particle/generator/probability_density_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,40 @@ namespace aspect
void
ProbabilityDensityFunction<dim>::declare_parameters (ParameterHandler &prm)
{
prm.enter_subsection("Particles");
prm.enter_subsection("Generator");
{
prm.enter_subsection("Generator");
prm.enter_subsection("Probability density function");
{
prm.enter_subsection("Probability density function");
{
Functions::ParsedFunction<dim>::declare_parameters (prm, 1);

prm.declare_entry ("Number of particles", "1000",
Patterns::Double (0.),
"Total number of particles to create (not per processor or per element). "
"The number is parsed as a floating point number (so that one can "
"specify, for example, '1e4' particles) but it is interpreted as "
"an integer, of course.");

prm.declare_entry ("Random cell selection", "true",
Patterns::Bool(),
"If true, particle numbers per cell are calculated randomly "
"according to their respective probability density. "
"This means particle numbers per cell can deviate statistically from "
"the integral of the probability density. If false, "
"first determine how many particles each cell should have "
"based on the integral of the density over each of the cells, "
"and then once we know how many particles we want on each cell, "
"choose their locations randomly within each cell.");

prm.declare_entry ("Random number seed", "5432",
Patterns::Integer(0),
"The seed for the random number generator that controls "
"the particle generation. Keep constant to generate "
"identical particle distributions in subsequent model "
"runs. Change to get a different distribution. In parallel "
"computations the seed is further modified on each process "
"to ensure different particle patterns on different "
"processes. Note that the number of particles per processor "
"is not affected by the seed.");
}
prm.leave_subsection();
Functions::ParsedFunction<dim>::declare_parameters (prm, 1);

prm.declare_entry ("Number of particles", "1000",
Patterns::Double (0.),
"Total number of particles to create (not per processor or per element). "
"The number is parsed as a floating point number (so that one can "
"specify, for example, '1e4' particles) but it is interpreted as "
"an integer, of course.");

prm.declare_entry ("Random cell selection", "true",
Patterns::Bool(),
"If true, particle numbers per cell are calculated randomly "
"according to their respective probability density. "
"This means particle numbers per cell can deviate statistically from "
"the integral of the probability density. If false, "
"first determine how many particles each cell should have "
"based on the integral of the density over each of the cells, "
"and then once we know how many particles we want on each cell, "
"choose their locations randomly within each cell.");

prm.declare_entry ("Random number seed", "5432",
Patterns::Integer(0),
"The seed for the random number generator that controls "
"the particle generation. Keep constant to generate "
"identical particle distributions in subsequent model "
"runs. Change to get a different distribution. In parallel "
"computations the seed is further modified on each process "
"to ensure different particle patterns on different "
"processes. Note that the number of particles per processor "
"is not affected by the seed.");
}
prm.leave_subsection();
}
Expand All @@ -98,30 +94,26 @@ namespace aspect
void
ProbabilityDensityFunction<dim>::parse_parameters (ParameterHandler &prm)
{
prm.enter_subsection("Particles");
prm.enter_subsection("Generator");
{
prm.enter_subsection("Generator");
prm.enter_subsection("Probability density function");
{
prm.enter_subsection("Probability density function");
{
n_particles = static_cast<types::particle_index>(prm.get_double ("Number of particles"));
random_cell_selection = prm.get_bool("Random cell selection");
random_number_seed = prm.get_integer("Random number seed");

try
{
function.parse_parameters (prm);
}
catch (...)
{
std::cerr << "ERROR: FunctionParser failed to parse\n"
<< "\t'Particle.Generator.Probability density function'\n"
<< "with expression\n"
<< "\t'" << prm.get("Function expression") << "'";
throw;
}
}
prm.leave_subsection();
n_particles = static_cast<types::particle_index>(prm.get_double ("Number of particles"));
random_cell_selection = prm.get_bool("Random cell selection");
random_number_seed = prm.get_integer("Random number seed");

try
{
function.parse_parameters (prm);
}
catch (...)
{
std::cerr << "ERROR: FunctionParser failed to parse\n"
<< "\t'Particle.Generator.Probability density function'\n"
<< "with expression\n"
<< "\t'" << prm.get("Function expression") << "'";
throw;
}
}
prm.leave_subsection();
}
Expand Down
78 changes: 35 additions & 43 deletions source/particle/generator/random_uniform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,38 @@ namespace aspect
void
RandomUniform<dim>::declare_parameters (ParameterHandler &prm)
{
prm.enter_subsection("Particles");
prm.enter_subsection("Generator");
{
prm.enter_subsection("Generator");
prm.enter_subsection("Probability density function");
{
prm.enter_subsection("Probability density function");
{
prm.declare_entry ("Number of particles", "1000",
Patterns::Double (0.),
"Total number of particles to create (not per processor or per element). "
"The number is parsed as a floating point number (so that one can "
"specify, for example, '1e4' particles) but it is interpreted as "
"an integer, of course.");

prm.declare_entry ("Random cell selection", "true",
Patterns::Bool(),
"If true, particle numbers per cell are calculated randomly "
"according to their respective probability density. "
"This means particle numbers per cell can deviate statistically from "
"the integral of the probability density. If false, "
"first determine how many particles each cell should have "
"based on the integral of the density over each of the cells, "
"and then once we know how many particles we want on each cell, "
"choose their locations randomly within each cell.");

prm.declare_entry ("Random number seed", "5432",
Patterns::Integer(0),
"The seed for the random number generator that controls "
"the particle generation. Keep constant to generate "
"identical particle distributions in subsequent model "
"runs. Change to get a different distribution. In parallel "
"computations the seed is further modified on each process "
"to ensure different particle patterns on different "
"processes. Note that the number of particles per processor "
"is not affected by the seed.");
}
prm.leave_subsection();
prm.declare_entry ("Number of particles", "1000",
Patterns::Double (0.),
"Total number of particles to create (not per processor or per element). "
"The number is parsed as a floating point number (so that one can "
"specify, for example, '1e4' particles) but it is interpreted as "
"an integer, of course.");

prm.declare_entry ("Random cell selection", "true",
Patterns::Bool(),
"If true, particle numbers per cell are calculated randomly "
"according to their respective probability density. "
"This means particle numbers per cell can deviate statistically from "
"the integral of the probability density. If false, "
"first determine how many particles each cell should have "
"based on the integral of the density over each of the cells, "
"and then once we know how many particles we want on each cell, "
"choose their locations randomly within each cell.");

prm.declare_entry ("Random number seed", "5432",
Patterns::Integer(0),
"The seed for the random number generator that controls "
"the particle generation. Keep constant to generate "
"identical particle distributions in subsequent model "
"runs. Change to get a different distribution. In parallel "
"computations the seed is further modified on each process "
"to ensure different particle patterns on different "
"processes. Note that the number of particles per processor "
"is not affected by the seed.");
}
prm.leave_subsection();
}
Expand All @@ -94,17 +90,13 @@ namespace aspect
void
RandomUniform<dim>::parse_parameters (ParameterHandler &prm)
{
prm.enter_subsection("Particles");
prm.enter_subsection("Generator");
{
prm.enter_subsection("Generator");
prm.enter_subsection("Probability density function");
{
prm.enter_subsection("Probability density function");
{
n_particles = static_cast<types::particle_index>(prm.get_double ("Number of particles"));
random_cell_selection = prm.get_bool("Random cell selection");
random_number_seed = prm.get_integer("Random number seed");
}
prm.leave_subsection();
n_particles = static_cast<types::particle_index>(prm.get_double ("Number of particles"));
random_cell_selection = prm.get_bool("Random cell selection");
random_number_seed = prm.get_integer("Random number seed");
}
prm.leave_subsection();
}
Expand Down
Loading

0 comments on commit adb0b58

Please sign in to comment.