preprocessor now filters debug output

This commit is contained in:
2025-05-28 15:27:00 +02:00
parent e2167fb75b
commit f510d0a39a
39 changed files with 375 additions and 14 deletions
+33
View File
@@ -10,7 +10,9 @@ namespace generator {
CylinderBinning buildPositionBinning(json_t* object) {
if (json_object_by_path(object, {"CylinderBinning"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating position binning: cylinder binning.");
#endif
object = json_object_by_path(object, {"CylinderBinning"});
json_t* radial = json_object_by_path(object, {"Radial"});
@@ -36,6 +38,7 @@ CylinderBinning buildPositionBinning(json_t* object) {
json_read_length(json_object_by_path(longitudinal, {"MaxLength"}), "m");
ASSERT_POSITIVE(&max_length, "Radius must be positive");
#ifdef debug_level3
DEBUG_LEVEL_3("with number of bins radial: " +
std::to_string(number_of_bins_radial));
DEBUG_LEVEL_3("with number of bins azimuthal: " +
@@ -44,6 +47,7 @@ CylinderBinning buildPositionBinning(json_t* object) {
std::to_string(number_of_bins_longitudinal));
DEBUG_LEVEL_3("with radius: " + std::to_string(max_radius) + " m");
DEBUG_LEVEL_3("with height: " + std::to_string(max_length) + " m");
#endif
return CylinderBinning(number_of_bins_radial, max_radius,
number_of_bins_azimuthal,
@@ -59,14 +63,18 @@ CylinderBinning buildPositionBinningIncludingRedirection(
json_path& path_to_binning) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating position binning: CreateSameAs.");
#endif
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"})));
std::stringstream path;
for (auto& p : path_to_same) {
path << p << " ";
}
#ifdef debug_level3
DEBUG_LEVEL_3("From path: " + path.str());
#endif
return buildPositionBinningIncludingRedirection(parameter, path_to_same);
} else {
return buildPositionBinning(parameter.jsonObjectFromBase(path_to_binning));
@@ -76,7 +84,9 @@ CylinderBinning buildPositionBinningIncludingRedirection(
EnergyBinning buildEnergyBinning(json_t* object) {
std::string energy_type = json_string(json_object_by_path(object, {"Type"}));
if (energy_type == "Logarithmic") {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating energy binning: logarithmic.");
#endif
int number_of_bins =
json_int(json_object_by_path(object, {"NumberOfBins"}));
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
@@ -87,9 +97,11 @@ EnergyBinning buildEnergyBinning(json_t* object) {
json_read_energy(json_object_by_path(object, {"MaxEnergy"}), "eV");
ASSERT_POSITIVE(&max_energy, "Max Energy must be positive");
#ifdef debug_level3
DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins));
DEBUG_LEVEL_3("with min energy: " + std::to_string(min_energy));
DEBUG_LEVEL_3("with max energy: " + std::to_string(max_energy));
#endif
return EnergyBinning(min_energy, max_energy, number_of_bins);
@@ -104,14 +116,22 @@ EnergyBinning buildEnergyBinningIncludingRedirection(
json_path& path_to_binning) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
#endif
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"})));
#ifdef debug_level3
std::stringstream path;
for (auto& p : path_to_same) {
path << p << " ";
}
DEBUG_LEVEL_3("From path: " + path.str());
#endif
return buildEnergyBinningIncludingRedirection(parameter, path_to_same);
} else {
return buildEnergyBinning(parameter.jsonObjectFromBase(path_to_binning));
@@ -121,12 +141,18 @@ EnergyBinning buildEnergyBinningIncludingRedirection(
PitchAngleBinning buildPitchAngleBinning(json_t* object) {
std::string pitch_angle_type = json_string(json_object_by_path(object, {"Type"}));
if (pitch_angle_type == "Linear") {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating pitch angle binning: linear.");
#endif
int number_of_bins =
json_int(json_object_by_path(object, {"NumberOfBins"}));
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
#ifdef debug_level3
DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins));
#endif
return PitchAngleBinning(number_of_bins);
} else {
@@ -140,14 +166,21 @@ PitchAngleBinning buildPitchAngleBinningIncludingRedirection(
json_path& path_to_binning) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
#endif
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"})));
#ifdef debug_level3
std::stringstream path;
for (auto& p : path_to_same) {
path << p << " ";
}
DEBUG_LEVEL_3("From path: " + path.str());
#endif
return buildPitchAngleBinningIncludingRedirection(parameter, path_to_same);
} else {
return buildPitchAngleBinning(parameter.jsonObjectFromBase(path_to_binning));
@@ -9,7 +9,9 @@ std::shared_ptr<CurrentCollector> buildCurrentCollector(
Parameter& parameter,
const json_path& path_to_collector,
std::shared_ptr<Timer>& timer) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating current collector.");
#endif
json_path path_binning =
json_path_append(path_to_collector, {"PositionBinning"});
CylinderBinning position_binning =
@@ -10,7 +10,9 @@ namespace generator {
std::shared_ptr<ConstantDensityField> buildConstantDensityField(
json_t* object) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating constant density field.");
#endif
json_path path = {"ScalarField"};
std::shared_ptr<ScalarField> field =
buildScalarField(json_object_by_path(object, path));
@@ -22,7 +24,9 @@ std::shared_ptr<DynamicDensityField> buildDynamicDensityField(
const json_path& path_to_field,
std::shared_ptr<Timer>& timer) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating dynamic density field with pitch angle.");
#endif
json_path path_binning = json_path_append(path_to_field, {"PositionBinning"});
CylinderBinning position_binning =
buildPositionBinningIncludingRedirection(parameter, path_binning);
@@ -9,14 +9,18 @@ std::shared_ptr<DriftVelocity> buildDriftVelocity(
const json_path& path_to_drift_velocity) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"VectorField"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating drift velocity: Vector field.");
#endif
std::shared_ptr<VectorField> field =
buildVectorField(parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"VectorField"})));
return std::shared_ptr<DriftVelocity>(new DriftVelocity(field));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"null"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating drift velocity: null.");
#endif
return nullptr;
} else {
ERROR("No drift velocity given.");
@@ -29,14 +33,18 @@ std::shared_ptr<DriftVelocity> buildDriftVelocityIncludingRedirection(
std::stringstream cpath;
if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"CreateSameAs"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating drift velocity: CreateSameAs.");
#endif
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"CreateSameAs"})));
#ifdef debug_level3
std::stringstream path;
for (auto& p : path_to_same) {
path << p << " ";
}
DEBUG_LEVEL_3("From path: " + path.str());
#endif
return buildDriftVelocityIncludingRedirection(parameter, path_to_same);
} else {
return buildDriftVelocity(parameter, path_to_drift_velocity);
@@ -6,12 +6,16 @@
namespace generator {
std::shared_ptr<ElectricField> electricField(json_t* object) {
#ifdef debug_level2
DEBUG_LEVEL_2("Generating electric field.");
#endif
std::shared_ptr<VectorField> background;
std::shared_ptr<VectorField> dynamic;
if (json_object_by_path(object, {"Background"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Generating background electric field.");
#endif
background = buildVectorField(
json_object_by_path(object, {"Background", "VectorField"}));
} else {
@@ -19,7 +23,9 @@ std::shared_ptr<ElectricField> electricField(json_t* object) {
}
if (json_object_by_path(object, {"Dynamic"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Generating dynamic electric field.");
#endif
dynamic = buildVectorField(
json_object_by_path(object, {"Dynamic", "VectorField"}));
} else {
@@ -11,21 +11,31 @@ std::shared_ptr<EnergyDistributionFunction> buildEnergyDistributionFunction(
json_t* object = parameter.jsonObjectFromBase(path_to_function);
if (json_object_by_path(object, {"TritiumBetaDecay"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating energy distribution function: tritium beta decay.");
#endif
return std::shared_ptr<EnergyDistributionFunction>(new TritiumBetaDecay());
} else if (json_object_by_path(object, {"MaxwellBoltzmann"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating energy distribution function: Maxwell Boltzmann.");
#endif
double temperature_K = json_double(json_object_by_path(
object, {"MaxwellBoltzmann", "Temperature", "value"}));
#ifdef debug_level3
DEBUG_LEVEL_3("with temperature: " + std::to_string(temperature_K) + " K");
#endif
return std::shared_ptr<EnergyDistributionFunction>(
new MaxwellBoltzmann(temperature_K));
} else if (json_object_by_path(object, {"Constant"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating energy distribution function: Constant.");
#endif
double constant_eV = json_double(
json_object_by_path(object, {"Constant", "constant", "value"}));
#ifdef debug_level3
DEBUG_LEVEL_3("with constant: " + std::to_string(constant_eV) + " eV");
#endif
return std::shared_ptr<EnergyDistributionFunction>(
new Constant(constant_eV));
}
+20
View File
@@ -11,14 +11,20 @@ namespace generator {
std::function<double(double)> function1D(json_t* object) {
if (json_object_by_path(object, {"Constant"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function1d: constant.");
#endif
double constant =
json_double(json_object_by_path(object, {"Constant", "constant"}));
#ifdef debug_level3
DEBUG_LEVEL_3("with constant: " + std::to_string(constant));
#endif
return D1ToD1::Constant(constant);
} else if (json_object_by_path(object, {"PiecewiseLinear"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear.");
#endif
std::vector<double> x_values = json_vector(
json_object_by_path(object, {"PiecewiseLinear", {"xValues"}}));
std::vector<double> y_values = json_vector(
@@ -31,11 +37,15 @@ std::function<double(double)> function1D(json_t* object) {
return D1ToD1::PiecewiseLinear(x_values, y_values);
} else if (json_object_by_path(object, {"PiecewiseLinearFromFile"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear from file.");
#endif
std::string absolute_filename = readAbsoluteFilename(
json_object_by_path(object, {"PiecewiseLinearFromFile", "PathToH5"}));
#ifdef debug_level3
DEBUG_LEVEL_3("with filename: " + absolute_filename);
#endif
Hdf5Reader reader(absolute_filename);
std::string x_values_key = json_string(
@@ -53,7 +63,9 @@ std::function<double(double)> function1D(json_t* object) {
double prefactor = json_double(json_object_by_path(
object, {"PiecewiseLinearFromFile", {"prefactor"}}));
#ifdef debug_level3
DEBUG_LEVEL_3("with prefactor: " + std::to_string(prefactor));
#endif
for (int i = 0; i < y_values.size(); ++i) {
y_values[i] = y_values[i] * prefactor;
@@ -61,7 +73,9 @@ std::function<double(double)> function1D(json_t* object) {
return D1ToD1::PiecewiseLinear(x_values, y_values);
} else if (json_object_by_path(object, {"Product"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function1d: Product.");
#endif
json_t* function_array = json_object_by_path(object, {"Product"});
std::vector<std::function<double(double)>> functions;
size_t index;
@@ -72,7 +86,9 @@ std::function<double(double)> function1D(json_t* object) {
return D1ToD1::Product(functions);
} else if (json_object_by_path(object, {"Exponential"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function1d: Exponential.");
#endif
double prefactor = json_double(json_object_by_path(
object, {"Exponential", {"prefactor"}}));
double scale = json_double(json_object_by_path(
@@ -86,12 +102,16 @@ std::function<double(double)> function1D(json_t* object) {
std::function<double(double, double, double)> function3D(json_t* object) {
if (json_object_by_path(object, {"Constant3D"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function3d: Constant3D.");
#endif
double constant =
json_double(json_object_by_path(object, {"Constant3D", "constant"}));
return D3ToD1::Constant(constant);
} else if (json_object_by_path(object, {"Product"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating function3d: Product.");
#endif
std::function<double(double)> fi =
function1D(json_object_by_path(object, {"Product", "fi"}));
std::function<double(double)> fj =
+8
View File
@@ -7,7 +7,9 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
const json_path& path_to_geometry) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_geometry, {"Cylinder"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating geometry: cylinder.");
#endif
double radius =
json_read_length(parameter.jsonObjectFromBase(json_path_append(
path_to_geometry, {"Cylinder", "Radius"})),
@@ -16,8 +18,10 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
json_read_length(parameter.jsonObjectFromBase(json_path_append(
path_to_geometry, {"Cylinder", "Height"})),
"m");
#ifdef debug_level3
DEBUG_LEVEL_3("with radius: " + std::to_string(radius) + " m");
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
#endif
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
} else {
ERROR("This geometry is not implemented.");
@@ -29,14 +33,18 @@ std::shared_ptr<Geometry> buildGeometryIncludingRedirection(
Parameter& parameter, const json_path& path_to_geometry) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_geometry, {"CreateSameAs"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating geometry: CreateSameAs.");
#endif
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
json_path_append(path_to_geometry, {"CreateSameAs"})));
std::stringstream path;
for (auto& p : path_to_same) {
path << p << " ";
}
#ifdef debug_level3
DEBUG_LEVEL_3("From path: " + path.str());
#endif
return buildGeometryIncludingRedirection(parameter, path_to_same);
} else {
return buildGeometry(parameter, path_to_geometry);
@@ -5,7 +5,9 @@
namespace generator {
std::shared_ptr<GravityField> gravityField(json_t* object) {
#ifdef debug_level2
DEBUG_LEVEL_2("Generating gravity field.");
#endif
return std::shared_ptr<GravityField>(new GravityField(
buildVectorField(json_object_by_path(object, {"VectorField"}))));
}
+6
View File
@@ -25,7 +25,9 @@ std::shared_ptr<Injector> buildInjector(
json_object_foreach(array, key, value) {
std::string specie_name =
json_string(json_object_by_path(value, {"TrackedSpecieName"}));
#ifdef debug_level3
DEBUG_LEVEL_3("Injected specie: " + specie_name);
#endif
InjectorInfo info;
info.created_specie = tracked_species[specie_name];
@@ -41,7 +43,9 @@ std::shared_ptr<Injector> buildInjector(
}
// EventPositionDistribution
#ifdef debug_level2
DEBUG_LEVEL_2("Creating event distribution.");
#endif
std::shared_ptr<ScalarField> field = buildScalarField(json_object_by_path(
object, {"EventPositionDistribution", "ScalarField"}));
@@ -80,7 +84,9 @@ std::shared_ptr<Injector> buildInjector(
position_limit_phi, position_limit_z));
// MotherDriftVelocity
#ifdef debug_level2
DEBUG_LEVEL_2("Creating mother drift velocity.");
#endif
std::shared_ptr<DriftVelocity> drift_velocity = buildDriftVelocity(
parameter, json_path_append(path_to_injector, {"MotherDriftVelocity"}));
+22
View File
@@ -33,7 +33,9 @@ void addInteractions(
std::string type = json_string(json_object_by_path(value, {"Type"}));
if (type == "ElasticScattering") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: ElasticScattering");
#endif
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
@@ -43,7 +45,9 @@ void addInteractions(
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
#ifdef debug_level3
DEBUG_LEVEL_3("with target " + target_name);
#endif
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
@@ -53,11 +57,15 @@ void addInteractions(
scattering_angle_distribution)));
} else if (type == "FreeMovement") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: FreeMovement");
#endif
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::FreeMovement()));
} else if (type == "ElectronIonization") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: Ionization");
#endif
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
@@ -183,7 +191,9 @@ void addInteractions(
ERROR("This ionization model is not implemented: " + ionization_model);
}
} else if (type == "Excitation") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: Excitation");
#endif
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
@@ -201,7 +211,9 @@ void addInteractions(
cross_section, target, excitation_energy)));
} else if (type == "Clustering") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: Clustering");
#endif
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
@@ -217,7 +229,9 @@ void addInteractions(
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ClusterFormation(cross_section, target, product)));
} else if (type == "ChargeExchange") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
#endif
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
@@ -228,7 +242,9 @@ void addInteractions(
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ChargeExchange(cross_section, target)));
} else if (type == "Recombination") {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding interactions: Recombination");
#endif
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::TrackedSpecie> target =
@@ -471,18 +487,24 @@ std::function<double(double, double)> build2DCrossSection(json_t* object) {
std::shared_ptr<ScatteringAngleDistribution> buildScatteringAngleDistribution(
json_t* object) {
if (json_object_by_path(object, {"Isotropic"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic");
#endif
return std::shared_ptr<ScatteringAngleDistribution>(
new IsotropicAngleDistribution());
} else if (json_object_by_path(object, {"AngleDistributionFromFile"})) {
#ifdef debug_level2
DEBUG_LEVEL_2(
"Adding ScatteringAngleDistribution: AngleDistributionFromFile");
#endif
std::string absolute_filepath = readAbsoluteFilename(
json_object_by_path(object, {"AngleDistributionFromFile", "PathToH5"}));
return std::make_shared<AngleDistributionFromFile>(absolute_filepath);
} else if (json_object_by_path(object, {"CompositeAngleDistribution"})) {
#ifdef debug_level2
DEBUG_LEVEL_2(
"Adding ScatteringAngleDistribution: CompositeAngleDistribution");
#endif
json_t* object_composite =
json_object_by_path(object, {"CompositeAngleDistribution"});
const double decider_energy = json_read_energy(
+2
View File
@@ -43,7 +43,9 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
std::shared_ptr<DeletionLogger> buildDeletionLogger(
Parameter& parameter,
const json_path& path_to_loggers) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating deletion logger.");
#endif
json_path path_logger = json_path_append(path_to_loggers, {"Deletion"});
json_t* object = parameter.jsonObjectFromBase(path_logger);
@@ -5,7 +5,9 @@
namespace generator {
std::shared_ptr<MagneticField> magneticField(json_t* object) {
#ifdef debug_level2
DEBUG_LEVEL_2("Generating magnetic field.");
#endif
return std::shared_ptr<MagneticField>(new MagneticField(
buildVectorField(json_object_by_path(object, {"VectorField"})),
buildVectorField(json_object_by_path(object, {"GradientField"}))));
+4
View File
@@ -7,13 +7,17 @@ std::shared_ptr<Mover> buildMover(Parameter& parameter,
const json_path& path_to_mover) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_mover, {"Boris"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating mover: Boris.");
#endif
double max_timestep_length = parameter.doubleValue(json_path_append(
path_to_mover, {"Boris", "MaximalTimestepLength", "value"}));
return std::shared_ptr<Mover>(new BorisMover(max_timestep_length));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_mover, {"Drift"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating mover: Drift.");
#endif
double maximal_moved_distance =
json_read_length(parameter.jsonObjectFromBase(json_path_append(
path_to_mover, {"Drift", "MaximalMovedDistance"})));
@@ -10,7 +10,9 @@ namespace generator {
std::shared_ptr<PoissonSolver> buildPoissonSolver(
Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Generating Poisson solver.");
#endif
std::shared_ptr<Geometry> geometry;
json_t* object = json_object_by_path(
@@ -48,7 +50,9 @@ namespace generator {
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
const json_path& path_to_boundaries) {
#ifdef debug_level3
DEBUG_LEVEL_3("Creating Boundaries.");
#endif
std::map<std::string, GlobalBoundary> boundary_map {
{"Bottom", {0., BoundaryType::dirichlet}},
{"Top", {0., BoundaryType::dirichlet}},
@@ -63,7 +67,9 @@ namespace generator {
json_t* value;
json_object_foreach(parameter.jsonObjectFromBase(path_to_boundaries),
key, value) {
#ifdef debug_level3
DEBUG_LEVEL_3("Creating " + std::string(key) + ": ");
#endif
if(!(boundary_map.find(std::string(key)) == boundary_map.end())) {
double boundary_value =
json_double(json_object_by_path(value, {"value"}));
@@ -82,8 +88,10 @@ namespace generator {
". Using default boundary (dirichtlet, value 0)");
continue;
}
#ifdef debug_level3
DEBUG_LEVEL_3("with type: " + boundary_type);
DEBUG_LEVEL_3("with value: " + std::to_string(boundary_value));
#endif
} else {
SIM_INFO(std::string(key) + ": unknown location. Is ignored.");
+4
View File
@@ -8,7 +8,9 @@ std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
const json_path& path_to_reflector) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_reflector, {"ReflectorDPS"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Create reflector: ReflectorDPS");
#endif
double position_z = json_read_length(
parameter.jsonObjectFromBase(json_path_append(
path_to_reflector, {"ReflectorDPS", "position_z"})),
@@ -16,7 +18,9 @@ std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
return std::shared_ptr<Reflector>(new ReflectorDPS(position_z));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_reflector, {"NoReflector"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Create reflector: NoReflector");
#endif
return std::shared_ptr<Reflector>(new NoReflector());
} else {
ERROR("This reflector is not implemented.");
+6
View File
@@ -7,13 +7,17 @@ namespace generator {
DEBUG_LEVEL_3("Build Restart.");
bool do_restart = json_bool(json_object_by_path(object, {"Do"}));
if (!do_restart) {
#ifdef debug
DEBUG_LEVEL_0("No Restart desired.");
#endif
return Restart(false, "", "");
}
std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}))
+ ".h5";
#ifdef debug_level3
DEBUG_LEVEL_3("Restart: file path:" + filepath);
#endif
std::string identifier;
int sync_period = json_int(json_object_by_path(object, {"SyncPeriod"}));
@@ -27,7 +31,9 @@ namespace generator {
identifier = "SyncPeriod_" + std::to_string(sync_period);
}
#ifdef debug_level3
DEBUG_LEVEL_3("Restart: SyncPeriod to be started from: " + identifier);
#endif
return Restart(do_restart, filepath, identifier);
}
@@ -166,7 +166,9 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
}
ASSERT_NOTNEGATIVE(&intervall, "The intervall for RestartInfo has to be either 0"
",if no output is required or positive otherwise");
#ifdef debug_level3
DEBUG_LEVEL_3("Restart output interval: " + std::to_string(intervall));
#endif
bool overwrite_last = json_bool(
json_object_by_path(object, {"RestartInfo", "OverwriteLast"}));
+40
View File
@@ -107,13 +107,17 @@ std::shared_ptr<Timer> SpeciesBuilder::lastSyncTimer() {
}
void SpeciesBuilder::initTimer() {
#ifdef debug_level2
DEBUG_LEVEL_2("Init timer.");
#endif
timer_ = std::shared_ptr<Timer>(new Timer());
last_sync_timer_ = std::shared_ptr<Timer>(new Timer());
}
void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Init background species info.");
#endif
const char* key;
json_t* value;
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Background"}),
@@ -126,7 +130,9 @@ void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
}
void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Init tracked species info.");
#endif
const char* key;
json_t* value;
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key,
@@ -139,11 +145,15 @@ void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
}
void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill background species type.");
#endif
for (auto& b : background_species_info) {
std::string type = json_string(parameter.jsonObjectFromBase(
json_path_append(b.second.path_in_json, {"ParticleType"})));
#ifdef debug_level3
DEBUG_LEVEL_3("Type: " + type);
#endif
if (SpeciesAlias::isAlias(type)) {
b.second.type = SpeciesAlias::alias(type);
} else {
@@ -153,11 +163,15 @@ void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
}
void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill tracked species type.");
#endif
for (auto& b : tracked_species_info) {
std::string type = json_string(parameter.jsonObjectFromBase(
json_path_append(b.second.path_in_json, {"ParticleType"})));
#ifdef debug_level3
DEBUG_LEVEL_3("Type: " + type);
#endif
if (SpeciesAlias::isAlias(type)) {
b.second.type = SpeciesAlias::alias(type);
} else {
@@ -167,7 +181,9 @@ void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
}
void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill background density.");
#endif
for (auto& b : background_species_info) {
b.second.density = buildConstantDensityField(parameter.jsonObjectFromBase(
json_path_append(b.second.path_in_json, {"ConstantDensityField"})));
@@ -175,7 +191,9 @@ void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
}
void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill velocity distributions.");
#endif
for (auto& b : background_species_info) {
b.second.velocity_distribution = buildVelocityDistribution(
parameter,
@@ -189,7 +207,9 @@ void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
}
void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill drift velocity.");
#endif
for (auto& b : background_species_info) {
b.second.drift_velocity = buildDriftVelocityIncludingRedirection(
parameter, json_path_append(b.second.path_in_json, {"DriftVelocity"}));
@@ -201,7 +221,9 @@ void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
}
void SpeciesBuilder::fillMass() {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill masses.");
#endif
for (auto& b : background_species_info) {
b.second.mass_kg = SpeciesMasses::mass(b.second.type);
}
@@ -211,7 +233,9 @@ void SpeciesBuilder::fillMass() {
}
void SpeciesBuilder::fillCharge() {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill charges.");
#endif
for (auto& b : background_species_info) {
b.second.charge_C = SpeciesCharges::charge(b.second.type);
}
@@ -221,7 +245,9 @@ void SpeciesBuilder::fillCharge() {
}
void SpeciesBuilder::fillMover(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill movers.");
#endif
for (auto& b : tracked_species_info) {
if ((b.second.mover == nullptr)) {
b.second.mover = buildMover(
@@ -231,7 +257,9 @@ void SpeciesBuilder::fillMover(Parameter& parameter) {
}
void SpeciesBuilder::fillTerminator(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill terminators.");
#endif
for (auto& b : tracked_species_info) {
if ((b.second.terminator == nullptr)) {
b.second.terminator = buildTerminator(
@@ -241,7 +269,9 @@ void SpeciesBuilder::fillTerminator(Parameter& parameter) {
}
void SpeciesBuilder::fillReflector(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill reflectors.");
#endif
for (auto& b : tracked_species_info) {
if ((b.second.reflector == nullptr)) {
b.second.reflector = buildReflector(
@@ -252,7 +282,9 @@ void SpeciesBuilder::fillReflector(Parameter& parameter) {
// TBD: Fill and create dynamic density fields with pitch angle distribution
void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill tracked density.");
#endif
for (auto& b : tracked_species_info) {
b.second.density_field = buildDynamicDensityField(
parameter,
@@ -270,7 +302,9 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
}
void SpeciesBuilder::buildSpecies() {
#ifdef debug_level2
DEBUG_LEVEL_2("Build species from info.");
#endif
for (auto& b : background_species_info) {
background_species[b.first] = std::shared_ptr<species::BackgroundSpecie>(
new species::BackgroundSpecie(
@@ -290,7 +324,9 @@ void SpeciesBuilder::buildSpecies() {
}
void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill current collectors.");
#endif
for (auto& b : tracked_species) {
auto current_collector = buildCurrentCollector(
parameter,
@@ -302,7 +338,9 @@ void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
}
void SpeciesBuilder::fillLoggers(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill loggers.");
#endif
for (auto& b : tracked_species) {
auto deletion_logger = buildDeletionLogger(
parameter,
@@ -313,7 +351,9 @@ void SpeciesBuilder::fillLoggers(Parameter& parameter) {
}
void SpeciesBuilder::fillInteractions(Parameter& parameter) {
#ifdef debug_level2
DEBUG_LEVEL_2("Fill interactions.");
#endif
for (auto& b : tracked_species) {
json_path path = tracked_species_info[b.first].path_in_json;
path = json_path_append(path, {"Interactions"});
+4
View File
@@ -7,13 +7,17 @@ namespace generator {
std::shared_ptr<Terminator> buildTerminator(
Parameter& parameter,
const json_path& path_to_terminator) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating terminator.");
#endif
long int max_interactions = static_cast<long int>(parameter.doubleValue(
json_path_append(path_to_terminator, {"MaximumInteractions"})));
double max_time_alive = parameter.doubleValue(
json_path_append(path_to_terminator, {"MaxTimeAlive", "value"}));
#ifdef debug_level3
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
#endif
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
parameter, json_path_append(path_to_terminator, {"BoundaryGeometry"}));
@@ -53,7 +53,9 @@ blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
std::shared_ptr<VectorField> buildVectorField(json_t* object) {
if (json_object_by_path(object, {"VectorFieldConstant"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant");
#endif
blitz::TinyVector<double, 3> constant = json_blitz_vector<3>(
json_object_by_path(object, {"VectorFieldConstant", "constant"}));
@@ -61,13 +63,17 @@ std::shared_ptr<VectorField> buildVectorField(json_t* object) {
new VectorFieldConstant(CylinderVector(constant)));
} else if (json_object_by_path(object, {"VectorFieldFunctionInZ"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ");
#endif
std::function<double(double, double, double)> z_function = function3D(
json_object_by_path(object, {"VectorFieldFunctionInZ", "zFunction"}));
return std::shared_ptr<VectorField>(new VectorFieldFunctionInZ(z_function));
} else if (json_object_by_path(object, {"VectorFieldFromArray"})) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray");
#endif
blitz::Array<double, 3> v_radial = readComponentFromFile(
json_object_by_path(object,
@@ -11,8 +11,10 @@ std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
const json_path& path_to_distribution) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_distribution, {"IsotropicDistribution"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2(
"Creating velocity distribution function: IsotropicDistribution");
#endif
std::shared_ptr<EnergyDistributionFunction> fE =
buildEnergyDistributionFunction(
parameter, json_path_append(path_to_distribution,
@@ -26,8 +28,10 @@ std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
} else if (parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"DirectedDistribution"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2(
"Creating velocity distribution function: DirectedDistribution");
#endif
std::shared_ptr<EnergyDistributionFunction> fE =
buildEnergyDistributionFunction(
parameter, json_path_append(path_to_distribution,
@@ -10,8 +10,10 @@ std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
const json_path& path_to_distribution) {
if (parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"VelocityDistributionFromFunction"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2(
"Creating velocity distribution: VelocityDistributionFromFunction");
#endif
std::shared_ptr<VelocityDistributionFunction> v =
buildVelocityDistributionFunction(
parameter, json_path_append(path_to_distribution,
@@ -21,7 +23,9 @@ std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
new VelocityDistributionFromFunction(v));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_distribution, {"null"}))) {
#ifdef debug_level2
DEBUG_LEVEL_2("Creating velocity distribution: null");
#endif
return nullptr;
} else {
ERROR("This velocity distribution is not implemented.");