Version 2, position dependent E/B, kinetic ions, boris mover, terminator

This commit is contained in:
Jonas Kellerer
2022-10-21 10:09:19 +02:00
parent acc55cf003
commit 83fd2e5d7e
869 changed files with 1033204 additions and 3634436 deletions
+121
View File
@@ -0,0 +1,121 @@
#include "generators/binning_generator.h"
#include <sstream>
#include <string>
#include "simulation/errors.h"
#include "simulation/jansson_additionals.h"
#include "simulation/unit_converter.h"
namespace generator {
CylinderBinning buildPositionBinning(json_t* object) {
if (json_object_by_path(object, {"CylinderBinning"})) {
DEBUG_LEVEL_2("Creating position binning: cylinder binning.");
object = json_object_by_path(object, {"CylinderBinning"});
json_t* radial = json_object_by_path(object, {"Radial"});
int number_of_bins_radial =
json_int(json_object_by_path(radial, {"NumberOfBins"}));
ASSERT_POSITIVE(&number_of_bins_radial, "Number of Bins must be positive");
double max_radius =
json_read_length(json_object_by_path(radial, {"MaxRadius"}), "m");
ASSERT_POSITIVE(&max_radius, "Radius must be positive");
json_t* azimuthal = json_object_by_path(object, {"Azimuthal"});
int number_of_bins_azimuthal =
json_int(json_object_by_path(azimuthal, {"NumberOfBins"}));
ASSERT_POSITIVE(&number_of_bins_azimuthal,
"Number of Bins must be positive");
json_t* longitudinal = json_object_by_path(object, {"Longitudinal"});
int number_of_bins_longitudinal =
json_int(json_object_by_path(longitudinal, {"NumberOfBins"}));
ASSERT_POSITIVE(&number_of_bins_longitudinal,
"Number of Bins must be positive");
double max_length =
json_read_length(json_object_by_path(longitudinal, {"MaxLength"}), "m");
ASSERT_POSITIVE(&max_length, "Radius must be positive");
DEBUG_LEVEL_3("with number of bins radial: " +
std::to_string(number_of_bins_radial));
DEBUG_LEVEL_3("with number of bins azimuthal: " +
std::to_string(number_of_bins_azimuthal));
DEBUG_LEVEL_3("with number of bins longitudinal: " +
std::to_string(number_of_bins_longitudinal));
DEBUG_LEVEL_3("with radius: " + std::to_string(max_radius));
DEBUG_LEVEL_3("with height: " + std::to_string(max_length));
return CylinderBinning(number_of_bins_radial, max_radius,
number_of_bins_azimuthal,
number_of_bins_longitudinal, max_length);
} else {
ERROR("This position binning is not implemented.");
return CylinderBinning(0, 0, 0, 0, 0);
}
}
CylinderBinning buildPositionBinningIncludingRedirection(
Parameter& parameter,
json_path& path_to_binning) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"}))) {
DEBUG_LEVEL_2("Creating position binning: CreateSameAs.");
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 << " ";
}
DEBUG_LEVEL_3("From path: " + path.str());
return buildPositionBinningIncludingRedirection(parameter, path_to_same);
} else {
return buildPositionBinning(parameter.jsonObjectFromBase(path_to_binning));
}
}
EnergyBinning buildEnergyBinning(json_t* object) {
std::string energy_type = json_string(json_object_by_path(object, {"Type"}));
if (energy_type == "Logarithmic") {
DEBUG_LEVEL_2("Creating energy binning: logarithmic.");
int number_of_bins =
json_int(json_object_by_path(object, {"NumberOfBins"}));
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
double min_energy =
json_read_energy(json_object_by_path(object, {"MinEnergy"}), "eV");
ASSERT_POSITIVE(&min_energy, "Min Energy must be positive");
double max_energy =
json_read_energy(json_object_by_path(object, {"MaxEnergy"}), "eV");
ASSERT_POSITIVE(&max_energy, "Min Energy must be positive");
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));
return EnergyBinning(min_energy, max_energy, number_of_bins);
} else {
ERROR("This energy binning is not implemented.");
return EnergyBinning(0, 0, 0);
}
}
EnergyBinning buildEnergyBinningIncludingRedirection(
Parameter& parameter,
json_path& path_to_binning) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_binning, {"CreateSameAs"}))) {
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
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 << " ";
}
DEBUG_LEVEL_3("From path: " + path.str());
return buildEnergyBinningIncludingRedirection(parameter, path_to_same);
} else {
return buildEnergyBinning(parameter.jsonObjectFromBase(path_to_binning));
}
}
}; // namespace generator
+21
View File
@@ -0,0 +1,21 @@
#include "generators/current_collector_generator.h"
#include "generators/binning_generator.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<CurrentCollector> buildCurrentCollector(
Parameter& parameter,
const json_path& path_to_collector,
std::shared_ptr<Timer>& timer) {
DEBUG_LEVEL_2("Creating current collector.");
json_path path_binning =
json_path_append(path_to_collector, {"PositionBinning"});
CylinderBinning position_binning =
buildPositionBinningIncludingRedirection(parameter, path_binning);
return std::make_shared<CurrentCollector>(position_binning, timer);
}
}; // namespace generator
+36
View File
@@ -0,0 +1,36 @@
#include "generators/density_field_generator.h"
#include "generators/binning_generator.h"
#include "generators/scalar_field_generator.h"
#include "simulation/position_binning.h"
#include "simulation/scalar_field.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<ConstantDensityField> buildConstantDensityField(
json_t* object) {
DEBUG_LEVEL_2("Creating constant density field.");
json_path path = {"ScalarField"};
std::shared_ptr<ScalarField> field =
buildScalarField(json_object_by_path(object, path));
return std::shared_ptr<ConstantDensityField>(new ConstantDensityField(field));
}
std::shared_ptr<DynamicDensityField> buildDynamicDensityField(
Parameter& parameter,
const json_path& path_to_field,
std::shared_ptr<Timer>& timer) {
DEBUG_LEVEL_2("Creating dynamic density field.");
json_path path_binning = json_path_append(path_to_field, {"PositionBinning"});
CylinderBinning position_binning =
buildPositionBinningIncludingRedirection(parameter, path_binning);
json_path path_energy_binning =
json_path_append(path_to_field, {"EnergyBinning"});
EnergyBinning energy_binning =
buildEnergyBinningIncludingRedirection(parameter, path_energy_binning);
return std::shared_ptr<DynamicDensityField>(
new DynamicDensityField(position_binning, energy_binning, timer));
}
}; // namespace generator
+26
View File
@@ -0,0 +1,26 @@
#include "generators/drift_velocity_generator.h"
#include "generators/vector_field_generator.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<DriftVelocity> buildDriftVelocity(
Parameter& parameter,
const json_path& path_to_drift_velocity) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_drift_velocity, {"VectorField"}))) {
DEBUG_LEVEL_2("Creating drift velocity: Vector field.");
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"}))) {
DEBUG_LEVEL_2("Creating drift velocity: null.");
return nullptr;
} else {
ERROR("No drift velocity given.");
return nullptr;
}
}
}; // namespace generator
+37
View File
@@ -0,0 +1,37 @@
#include "generators/electric_field_generator.h"
#include "generators/vector_field_generator.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<ElectricField> electricField(json_t* object) {
DEBUG_LEVEL_2("Generating electric field.");
std::shared_ptr<VectorField> background;
std::shared_ptr<VectorField> dynamic;
if (json_object_by_path(object, {"Background"})) {
DEBUG_LEVEL_2("Generating background electric field.");
background = buildVectorField(
json_object_by_path(object, {"Background", "VectorField"}));
} else {
ERROR("Can not find background for electric field");
}
if (json_object_by_path(object, {"Dynamic"})) {
DEBUG_LEVEL_2("Generating dynamic electric field.");
dynamic = buildVectorField(
json_object_by_path(object, {"Dynamic", "VectorField"}));
} else {
ERROR("Can not find dynamic for electric field");
}
return std::shared_ptr<ElectricField>(new ElectricField(background, dynamic));
}
std::shared_ptr<ElectricField> electricField(Parameter& parameter) {
return electricField(
json_object_by_path(parameter.jsonFile(), {"ElectricField"}));
}
}; // namespace generator
+36
View File
@@ -0,0 +1,36 @@
#include "generators/energy_distribution_function_generator.h"
#include <string>
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<EnergyDistributionFunction> buildEnergyDistributionFunction(
Parameter& parameter,
const json_path& path_to_function) {
json_t* object = parameter.jsonObjectFromBase(path_to_function);
if (json_object_by_path(object, {"TritiumBetaDecay"})) {
DEBUG_LEVEL_2("Creating energy distribution function: tritium beta decay.");
return std::shared_ptr<EnergyDistributionFunction>(new TritiumBetaDecay());
} else if (json_object_by_path(object, {"MaxwellBoltzmann"})) {
DEBUG_LEVEL_2("Creating energy distribution function: Maxwell Boltzmann.");
double temperature_K = json_double(json_object_by_path(
object, {"MaxwellBoltzmann", "Temperature", "value"}));
DEBUG_LEVEL_3("with temperature: " + std::to_string(temperature_K) + " K");
return std::shared_ptr<EnergyDistributionFunction>(
new MaxwellBoltzmann(temperature_K));
} else if (json_object_by_path(object, {"Constant"})) {
DEBUG_LEVEL_2("Creating energy distribution function: Constant.");
double constant_eV = json_double(
json_object_by_path(object, {"Constant", "constant", "value"}));
DEBUG_LEVEL_3("with constant: " + std::to_string(constant_eV) + " eV");
return std::shared_ptr<EnergyDistributionFunction>(
new Constant(constant_eV));
}
ERROR("This Energy Distribution is not implemented");
return nullptr;
}
}; // namespace generator
+101
View File
@@ -0,0 +1,101 @@
#include "generators/function_generator.h"
#include <string>
#include "IO/hdf5_reader.h"
#include "functions/functions.h"
#include "generators/vector_field_generator.h"
#include "simulation/errors.h"
#include "simulation/jansson_additionals.h"
namespace generator {
std::function<double(double)> function1D(json_t* object) {
if (json_object_by_path(object, {"Constant"})) {
DEBUG_LEVEL_2("Creating function1d: constant.");
double constant =
json_double(json_object_by_path(object, {"Constant", "constant"}));
DEBUG_LEVEL_3("with constant: " + std::to_string(constant));
return D1ToD1::Constant(constant);
} else if (json_object_by_path(object, {"PiecewiseLinear"})) {
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear.");
std::vector<double> x_values = json_vector(
json_object_by_path(object, {"PiecewiseLinear", {"xValues"}}));
std::vector<double> y_values = json_vector(
json_object_by_path(object, {"PiecewiseLinear", {"yValues"}}));
double prefactor = json_double(
json_object_by_path(object, {"PiecewiseLinear", {"prefactor"}}));
for (int i = 0; i < y_values.size(); ++i) {
y_values[i] = y_values[i] * prefactor;
}
return D1ToD1::PiecewiseLinear(x_values, y_values);
} else if (json_object_by_path(object, {"PiecewiseLinearFromFile"})) {
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear from file.");
std::string absolute_filename = readAbsoluteFilename(
json_object_by_path(object, {"PiecewiseLinearFromFile", "PathToH5"}));
DEBUG_LEVEL_3("with filename: " + absolute_filename);
Hdf5Reader reader(absolute_filename);
std::string x_values_key = json_string(
json_object_by_path(object, {"PiecewiseLinearFromFile", "xValuesKey"}));
blitz::Array<double, 1> x_values_array = reader.readD1Double(x_values_key);
// DEBUG_LEVEL_3("with x values: " + x_values_array);
std::string y_values_key = json_string(
json_object_by_path(object, {"PiecewiseLinearFromFile", "yValuesKey"}));
blitz::Array<double, 1> y_values_array = reader.readD1Double(y_values_key);
// DEBUG_LEVEL_3("with y values: " + y_values_array);
std::vector<double> x_values(x_values_array.begin(), x_values_array.end());
std::vector<double> y_values(y_values_array.begin(), y_values_array.end());
double prefactor = json_double(json_object_by_path(
object, {"PiecewiseLinearFromFile", {"prefactor"}}));
DEBUG_LEVEL_3("with prefactor: " + std::to_string(prefactor));
for (int i = 0; i < y_values.size(); ++i) {
y_values[i] = y_values[i] * prefactor;
}
return D1ToD1::PiecewiseLinear(x_values, y_values);
} else if (json_object_by_path(object, {"Product"})) {
DEBUG_LEVEL_2("Creating function1d: Product.");
json_t* function_array = json_object_by_path(object, {"Product"});
std::vector<std::function<double(double)>> functions;
size_t index;
json_t* value;
json_array_foreach(function_array, index, value) {
functions.push_back(function1D(value));
}
return D1ToD1::Product(functions);
} else {
ERROR("This 1d to 1d function is not implemented.");
return nullptr;
}
}
std::function<double(double, double, double)> function3D(json_t* object) {
if (json_object_by_path(object, {"Constant3D"})) {
DEBUG_LEVEL_2("Creating function3d: Constant3D.");
double constant =
json_double(json_object_by_path(object, {"Constant3D", "constant"}));
return D3ToD1::Constant(constant);
} else if (json_object_by_path(object, {"Product"})) {
DEBUG_LEVEL_2("Creating function3d: Product.");
std::function<double(double)> fi =
function1D(json_object_by_path(object, {"Product", "fi"}));
std::function<double(double)> fj =
function1D(json_object_by_path(object, {"Product", "fj"}));
std::function<double(double)> fk =
function1D(json_object_by_path(object, {"Product", "fk"}));
return D3ToD1::Product(fi, fj, fk);
} else {
ERROR("This 3d to 1d function is not implemented.");
return nullptr;
}
}
}; // namespace generator
+28
View File
@@ -0,0 +1,28 @@
#include "generators/geometry_generator.h"
#include <string>
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
const json_path& path_to_geometry) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_geometry, {"Cylinder"}))) {
DEBUG_LEVEL_2("Creating geometry: cylinder.");
double radius =
json_read_length(parameter.jsonObjectFromBase(json_path_append(
path_to_geometry, {"Cylinder", "Radius"})),
"m");
double height =
json_read_length(parameter.jsonObjectFromBase(json_path_append(
path_to_geometry, {"Cylinder", "Height"})),
"m");
DEBUG_LEVEL_3("with radius: " + std::to_string(radius) + " m");
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
} else {
ERROR("This geometry is not implemented.");
return nullptr;
}
}
}; // namespace generator
+91
View File
@@ -0,0 +1,91 @@
#include "generators/injector_generator.h"
#include "generators/drift_velocity_generator.h"
#include "generators/scalar_field_generator.h"
#include "generators/velocity_distribution_generator.h"
#include "simulation/event_position_distribution.h"
#include "simulation/velocity_distribution.h"
namespace generator {
std::shared_ptr<Injector> buildInjector(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species,
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>&
background_species,
Parameter& parameter) {
json_path path_to_injector = {"Injector"};
json_t* object = parameter.jsonObjectFromBase(path_to_injector);
// InjectorInfos
std::vector<InjectorInfo> injector_infos;
const char* key;
json_t* value;
json_t* array = json_object_by_path(object, {"CreatedSpecies"});
json_object_foreach(array, key, value) {
std::string specie_name =
json_string(json_object_by_path(value, {"TrackedSpecieName"}));
DEBUG_LEVEL_3("Injected specie: " + specie_name);
InjectorInfo info;
info.created_specie = tracked_species[specie_name];
info.creation_velocity_distribution = buildVelocityDistribution(
parameter,
json_path_append(path_to_injector, {"CreatedSpecies", std::string(key),
"CreationVelocityDistribution"}));
injector_infos.push_back(info);
}
// EventPositionDistribution
DEBUG_LEVEL_2("Creating event distribution");
std::shared_ptr<ScalarField> field = buildScalarField(json_object_by_path(
object, {"EventPositionDistribution", "ScalarField"}));
Limit position_limit_r;
position_limit_r.min = json_double(json_object_by_path(
object,
{"EventPositionDistribution", "PositionLimits", "rPosition", "min"}));
position_limit_r.max = json_double(json_object_by_path(
object,
{"EventPositionDistribution", "PositionLimits", "rPosition", "max"}));
Limit position_limit_phi;
position_limit_phi.min = json_double(json_object_by_path(
object,
{"EventPositionDistribution", "PositionLimits", "phiPosition", "min"}));
position_limit_phi.max = json_double(json_object_by_path(
object,
{"EventPositionDistribution", "PositionLimits", "phiPosition", "max"}));
Limit position_limit_z;
position_limit_z.min = json_double(json_object_by_path(
object,
{"EventPositionDistribution", "PositionLimits", "zPosition", "min"}));
position_limit_z.max = json_double(json_object_by_path(
object,
{"EventPositionDistribution", "PositionLimits", "zPosition", "max"}));
Limit density_limit;
density_limit.min = json_double(json_object_by_path(
object, {"EventPositionDistribution", "DensityLimit", "min"}));
density_limit.max = json_double(json_object_by_path(
object, {"EventPositionDistribution", "DensityLimit", "max"}));
std::shared_ptr<EventPositionDistribution> event_distribution(
new EventPositionDistribution(field, density_limit, position_limit_r,
position_limit_phi, position_limit_z));
// MotherDriftVelocity
DEBUG_LEVEL_2("Creating mother drift velocity");
std::shared_ptr<DriftVelocity> drift_velocity = buildDriftVelocity(
parameter, json_path_append(path_to_injector, {"MotherDriftVelocity"}));
// Activity
double activity =
json_double(json_object_by_path(object, {"Activity", "value"}));
return std::shared_ptr<Injector>(new Injector(
injector_infos, activity, event_distribution, drift_velocity));
}
}; // namespace generator
+472
View File
@@ -0,0 +1,472 @@
#include "generators/interaction_generator.h"
#include "constants/ionization_constants.h"
#include "generators/function_generator.h"
#include "generators/vector_field_generator.h"
#include "interactions/charge_exchange.h"
#include "interactions/cluster_formation.h"
#include "interactions/cross_sections.h"
#include "interactions/elastic_scattering.h"
#include "interactions/excitation.h"
#include "interactions/free_movement.h"
#include "interactions/ionization.h"
#include "interactions/recombination.h"
#include "simulation/errors.h"
#include "simulation/homebase.h"
#include "simulation/scattering_angle_distribution.h"
#include "simulation/species.h"
namespace generator {
void addInteractions(
std::shared_ptr<species::TrackedSpecie> specie,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species,
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>&
background_species,
Parameter& parameter,
json_path& path_to_interactions) {
const char* key;
json_t* value;
json_t* array = parameter.jsonObjectFromBase(path_to_interactions);
json_object_foreach(array, key, value) {
std::string type = json_string(json_object_by_path(value, {"Type"}));
if (type == "ElasticScattering") {
DEBUG_LEVEL_2("Adding interactions: ElasticScattering");
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
std::shared_ptr<ScatteringAngleDistribution>
scattering_angle_distribution = buildScatteringAngleDistribution(
json_object_by_path(value, {"ScatteringAngleDistribution"}));
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
DEBUG_LEVEL_3("with target" + target_name);
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ElasticScattering(cross_section, target,
scattering_angle_distribution)));
} else if (type == "FreeMovement") {
DEBUG_LEVEL_2("Adding interactions: FreeMovement");
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::FreeMovement()));
} else if (type == "ElectronIonization") {
DEBUG_LEVEL_2("Adding interactions: Ionization");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::string outgoing_electron_name =
json_string(json_object_by_path(value, {"OutgoingElectron"}));
std::shared_ptr<species::TrackedSpecie> electron =
findTracked(outgoing_electron_name, tracked_species);
std::string outgoing_ion_name =
json_string(json_object_by_path(value, {"OutgoingIon"}));
std::shared_ptr<species::TrackedSpecie> ion =
findTracked(outgoing_ion_name, tracked_species);
std::string ionization_model =
json_string(json_object_by_path(value, {"IonizationModel"}));
if (ionization_model == "JanevNonDiss") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT2_ionization_janev_non_diss();
const double ionization_energy_eV =
ionization::ionization_energy_janev_non_diss;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT2_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR(
"The JanevNonDiss needs electron species as outgoing electrons.");
}
if (ion->type() != species::ImplementedSpecies::T2plus) {
std::cout << ion->name() << std::endl;
ERROR("The JanevNonDiss needs T2+ species as outgoing ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else if (ionization_model == "JanevDissToGround") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT2_ionization_janev_diss_ground();
const double ionization_energy_eV =
ionization::ionization_energy_janev_diss_ground;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT2_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR(
"The JanevDissToGround needs electron species as outgoing "
"electrons.");
}
if (ion->type() != species::ImplementedSpecies::Tplus) {
ERROR("The JanevDissToGround needs T+ species as outgoing ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else if (ionization_model == "JanevDissToFirstExcited") {
std::function<double(double)> cross_section =
interaction::totalCrossSection::eT2_ionization_janev_diss_first();
const double ionization_energy_eV =
ionization::ionization_energy_janev_diss_first;
auto ionization_energy_distribution =
std::make_shared<interaction::IonizationEnergyDistribution>(
interaction::d2CrossSection::eT2_ionization_bed(),
ionization_energy_eV);
auto scattering_angle_distribution = std::make_shared<
interaction::IonizationScatteringAngleDistribution>();
if (electron->type() != species::ImplementedSpecies::electron) {
ERROR(
"The JanevDissToFirstExcited needs electron species as outgoing "
"electrons.");
}
if (ion->type() != species::ImplementedSpecies::Tplus) {
ERROR(
"The JanevDissToFirstExcited needs T+ species as outgoing "
"ions.");
}
specie->addInteraction(
std::make_shared<interaction::ElectronIonization>(
cross_section, target, electron, ion,
ionization_energy_distribution, scattering_angle_distribution,
ionization_energy_eV));
} else {
ERROR("This ionization model is not implemented.");
}
} else if (type == "Excitation") {
DEBUG_LEVEL_2("Adding interactions: Excitation");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::string excitation_state =
json_string(json_object_by_path(value, {"ExcitationState"}));
std::function<double(double)> cross_section =
buildExcitationCrossSection(excitation_state);
double excitation_energy = buildExcitationEnergy(excitation_state);
specie->addInteraction(
std::shared_ptr<interaction::Interaction>(new interaction::Excitation(
cross_section, target, excitation_energy)));
} else if (type == "Clustering") {
DEBUG_LEVEL_2("Adding interactions: Clustering");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::string product_name =
json_string(json_object_by_path(value, {"Product"}));
std::shared_ptr<species::TrackedSpecie> product =
findTracked(product_name, tracked_species);
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ClusterFormation(cross_section, target, product)));
} else if (type == "ChargeExchange") {
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::Specie> target =
findTarget(target_name, tracked_species, background_species);
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ChargeExchange(cross_section, target)));
} else if (type == "Recombination") {
std::string target_name =
json_string(json_object_by_path(value, {"Target"}));
std::shared_ptr<species::TrackedSpecie> target =
findTracked(target_name, tracked_species);
std::function<double(double)> cross_section =
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::Recombination(cross_section, target)));
}
else {
ERROR("This interaction type is not implemented: " + type);
}
}
}
std::function<double(double)> buildTotalCrossSection(json_t* object) {
if (json_object_by_path(object, {"PredefinedFunction"})) {
std::string function_name =
json_string(json_object_by_path(object, {"PredefinedFunction"}));
if (function_name == "eT2_elastic_scattering_constant") {
return interaction::totalCrossSection::eT2_elastic_scattering_constant();
} else if (function_name == "eT2_elastic_scattering") {
return interaction::totalCrossSection::eT2_elastic_scattering();
} else if (function_name == "eT2_elastic_scattering") {
return interaction::totalCrossSection::eT2_elastic_scattering();
} else if (function_name == "TpT2_elasitc_scattering_tabata") {
return interaction::totalCrossSection::TpT2_elasitc_scattering_tabata();
} else if (function_name == "T3pT2_elasitc_scattering_tabata") {
return interaction::totalCrossSection::T3pT2_elasitc_scattering_tabata();
} else if (function_name == "eT2_ionization_janev_diss_ground") {
return interaction::totalCrossSection::eT2_ionization_janev_diss_ground();
} else if (function_name == "eT2_ionization_janev_diss_first") {
return interaction::totalCrossSection::eT2_ionization_janev_diss_first();
} else if (function_name == "TpT2_clustering_radiative_ascendion_pasil") {
return interaction::totalCrossSection::
TpT2_clustering_radiative_ascendion_pasil();
} else if (function_name == "TpT2_clustering_tertiary_ascendion_pasil") {
return interaction::totalCrossSection::
TpT2_clustering_tertiary_ascendion_pasil();
} else if (function_name == "T2pT2_clustering_janev") {
return interaction::totalCrossSection::T2pT2_clustering_janev();
} else if (function_name == "T2pT2_charge_exchange_janev") {
return interaction::totalCrossSection::T2pT2_charge_exchange_janev();
} else if (function_name == "eT2p_recombination_janev") {
return interaction::totalCrossSection::eT2p_recombination_janev();
} else if (function_name == "eT3p_recombination_janev") {
return interaction::totalCrossSection::eT3p_recombination_janev();
}
else {
ERROR("This predefined function does not exist: " + function_name);
return nullptr;
}
} else if (json_object_by_path(object, {"1dFunction"})) {
return function1D(json_object_by_path(object, {"1dFunction"}));
} else if (json_object_by_path(object, {"ExcitationFunction"})) {
std::string excitation_state = json_string(
json_object_by_path(object, {"ExcitationFunction", "ExcitationState"}));
return buildExcitationCrossSection(excitation_state);
} else {
ERROR("This type of cross section is not implemented");
return nullptr;
}
}
double buildExcitationEnergy(std::string excitation_state) {
if (excitation_state == "janev_singlet_B1") {
return 12.754;
} else if (excitation_state == "janev_singlet_B1prime") {
return 14.85;
} else if (excitation_state == "janev_singlet_B1primeprime") {
return 15.47;
} else if (excitation_state == "janev_singlet_C1") {
return 13.29;
} else if (excitation_state == "janev_singlet_D1") {
return 14.996;
} else if (excitation_state == "janev_singlet_D1prime") {
return 15.555;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_EF1") {
return 13.13;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_HHb") {
return 14.98;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_GK1") {
return 14.816;
} else if (excitation_state == "janev_singlet_symmetry_forbidden_I1") {
return 14.824;
} else if (excitation_state == "janev_triplet_A3") {
return 11.71;
} else if (excitation_state == "janev_triplet_B3") {
return 7.93;
} else if (excitation_state == "janev_triplet_C3") {
return 11.71;
} else if (excitation_state == "janev_triplet_E3") {
return 13.0;
} else if (excitation_state == "janev_triplet_D3") {
return 13.6;
} else if (excitation_state == "janev_vibrational_first") {
return 0.516;
} else if (excitation_state == "janev_vibrational_second") {
return 1.003;
} else if (excitation_state == "england_rotational_j0_to_j2") {
return 0.0439;
} else if (excitation_state == "england_rotational_j1_to_j3") {
return 0.0727;
} else {
ERROR(
"This type of cross section ExcitationState is not implemented in "
"buildExcitationEnergy.");
return 0.;
}
}
std::function<double(double)> buildExcitationCrossSection(
std::string excitation_state) {
if (excitation_state == "janev_singlet_B1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("B1");
} else if (excitation_state == "janev_singlet_B1prime") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("B1prime");
} else if (excitation_state == "janev_singlet_B1primeprime") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("B1primeprime");
} else if (excitation_state == "janev_singlet_C1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("C1");
} else if (excitation_state == "janev_singlet_D1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("D1");
} else if (excitation_state == "janev_singlet_D1prime") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state("D1prime");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_EF1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"EF1");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_HHb") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"HHb");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_GK1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"GK1");
} else if (excitation_state == "janev_singlet_symmetry_forbidden_I1") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
"I1");
} else if (excitation_state == "janev_triplet_A3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("A3");
} else if (excitation_state == "janev_triplet_B3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("B3");
} else if (excitation_state == "janev_triplet_C3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("C3");
} else if (excitation_state == "janev_triplet_E3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("E3");
} else if (excitation_state == "janev_triplet_D3") {
return interaction::totalCrossSection::
eT2_excitation_electric_janev_from_triplet_ground_state("D3");
} else if (excitation_state == "janev_vibrational_first") {
return interaction::totalCrossSection::
eT2_excitation_vibrational_janev_first();
} else if (excitation_state == "janev_vibrational_second") {
return interaction::totalCrossSection::
eT2_excitation_vibrational_janev_second();
} else if (excitation_state == "england_rotational_j0_to_j2") {
return interaction::totalCrossSection::
eT2_excitation_rotational_j0_to_j2_england();
} else if (excitation_state == "england_rotational_j1_to_j3") {
return interaction::totalCrossSection::
eT2_excitation_rotational_j1_to_j3_england();
} else {
ERROR(
"This type of cross section ExcitationState is not implemented in "
"buildExcitationCrossSection.");
return nullptr;
}
}
std::function<double(double, double)> build2DCrossSection(json_t* object) {
if (json_object_by_path(object, {"PredefinedFunction"})) {
std::string function_name =
json_string(json_object_by_path(object, {"PredefinedFunction"}));
if (function_name == "eT2_ionization_bed") {
return interaction::d2CrossSection::eT2_ionization_bed();
} else {
ERROR("This predefined function does not exist");
return nullptr;
}
} else {
ERROR("This type of cross section is not implemented.");
return nullptr;
}
}
std::shared_ptr<ScatteringAngleDistribution> buildScatteringAngleDistribution(
json_t* object) {
if (json_object_by_path(object, {"Isotropic"})) {
DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic");
return std::shared_ptr<ScatteringAngleDistribution>(
new IsotropicAngleDistribution());
} else if (json_object_by_path(object, {"AngleDistributionFromFile"})) {
DEBUG_LEVEL_2(
"Adding ScatteringAngleDistribution: AngleDistributionFromFile");
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"})) {
DEBUG_LEVEL_2(
"Adding ScatteringAngleDistribution: CompositeAngleDistribution");
json_t* object_composite =
json_object_by_path(object, {"CompositeAngleDistribution"});
const double decider_energy = json_read_energy(
json_object_by_path(object_composite, {"DeciderEnergy"}));
std::shared_ptr<ScatteringAngleDistribution> lower_distribution =
buildScatteringAngleDistribution(
json_object_by_path(object_composite, {"LowerDistribution"}));
std::shared_ptr<ScatteringAngleDistribution> higher_distribution =
buildScatteringAngleDistribution(
json_object_by_path(object_composite, {"HigherDistribution"}));
return std::make_shared<CompositeAngleDistribution>(
lower_distribution, higher_distribution, decider_energy);
} else {
ERROR("This scattering angle distribution is not implemented.");
return nullptr;
}
}
std::shared_ptr<species::Specie> findTarget(
std::string& target_name,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species,
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>&
background_species) {
if (background_species.count(target_name)) {
return background_species.at(target_name);
} else if (tracked_species.count(target_name)) {
return tracked_species.at(target_name);
} else {
ERROR("The specified target does not exist.");
return nullptr;
}
};
std::shared_ptr<species::TrackedSpecie> findTracked(
std::string& target_name,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species) {
if (tracked_species.count(target_name)) {
return tracked_species.at(target_name);
} else {
ERROR("The specified target does not exist.");
return nullptr;
}
}
}; // namespace generator
+51
View File
@@ -0,0 +1,51 @@
#include "generators/logger_generator.h"
#include "simulation/errors.h"
#include "simulation/logger.h"
namespace generator {
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
std::vector<DeletionType> used_types;
json_t* type = json_object_by_path(object, {"Type"});
if (json_is_array(type)) {
size_t index;
json_t* value;
json_array_foreach(type, index, value) {
std::string type_alias = json_string(value);
if (type_alias == "wall") {
used_types.push_back(DeletionType::wall);
} else if (type_alias == "recombination") {
used_types.push_back(DeletionType::recombination);
} else if (type_alias == "max_interactions") {
used_types.push_back(DeletionType::max_interactions);
} else if (type_alias == "max_time_alive") {
used_types.push_back(DeletionType::max_time_alive);
} else {
ERROR("This deletion type is not known");
}
}
} else {
if (json_string(type) == "all") {
used_types.push_back(DeletionType::wall);
used_types.push_back(DeletionType::recombination);
used_types.push_back(DeletionType::max_interactions);
used_types.push_back(DeletionType::max_time_alive);
}
}
return std::make_shared<DeletionLogger>(used_types);
}
std::shared_ptr<DeletionLogger> buildDeletionLogger(
Parameter& parameter,
const json_path& path_to_loggers) {
DEBUG_LEVEL_2("Creating deletion logger.");
json_path path_logger = json_path_append(path_to_loggers, {"Deletion"});
json_t* object = parameter.jsonObjectFromBase(path_logger);
return buildDeletionLogger(object);
}
} // namespace generator
+18
View File
@@ -0,0 +1,18 @@
#include "generators/magnetic_field_generator.h"
#include "generators/vector_field_generator.h"
namespace generator {
std::shared_ptr<MagneticField> magneticField(json_t* object) {
DEBUG_LEVEL_2("Generating magnetic field.");
return std::shared_ptr<MagneticField>(new MagneticField(
buildVectorField(json_object_by_path(object, {"VectorField"}))));
}
std::shared_ptr<MagneticField> magneticField(Parameter& parameter) {
return magneticField(
json_object_by_path(parameter.jsonFile(), {"MagneticField"}));
}
}; // namespace generator
+40
View File
@@ -0,0 +1,40 @@
#include "generators/mass_generator.h"
#include "constants/physical_constants.h"
#include "generators/species_generator.h"
#include "simulation/errors.h"
#include "simulation/jansson_additionals.h"
#include "simulation/species.h"
namespace generator {
std::map<species::ImplementedSpecies, double> SpeciesMasses::mass_ = {
{species::ImplementedSpecies::electron, SI::me},
{species::ImplementedSpecies::T2, 6 * SI::mp + 2 * SI::me},
{species::ImplementedSpecies::Tplus, 3 * SI::mp},
{species::ImplementedSpecies::T2plus, 6 * SI::mp + SI::me},
{species::ImplementedSpecies::T3plus, 9 * SI::mp + 2 * SI::me}};
double SpeciesMasses::mass(const species::ImplementedSpecies& species) {
return mass_.at(species);
}
double buildMass(json_t* object) {
if (json_object_by_path(object, {"FromParticleType"})) {
std::string name =
json_string(json_object_by_path(object, {"FromParticleType"}));
if (SpeciesAlias::isAlias(name)) {
return SpeciesMasses::mass(SpeciesAlias::alias(name));
} else {
ERROR("This specie type is not known.");
return 0.;
}
} else if (json_object_by_path(object, {"value"})) {
return json_double(json_object_by_path(object, {"value"}));
} else {
ERROR("The mass is not given correcty.");
return 0.;
}
}
}; // namespace generator
+27
View File
@@ -0,0 +1,27 @@
#include "generators/mover_generator.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<Mover> buildMover(Parameter& parameter,
const json_path& path_to_mover) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_mover, {"Boris"}))) {
DEBUG_LEVEL_2("Creating mover: Boris.");
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"}))) {
DEBUG_LEVEL_2("Creating mover: Drift.");
double maximal_moved_distance =
json_read_length(parameter.jsonObjectFromBase(json_path_append(
path_to_mover, {"Drift", "MaximalMovedDistance"})));
return std::make_shared<DriftMover>(maximal_moved_distance);
} else {
ERROR("This mover is not implemented");
return nullptr;
}
}
}; // namespace generator
+23
View File
@@ -0,0 +1,23 @@
#include "generators/random_numbers_generator.h"
#include "simulation/errors.h"
#include "simulation/jansson_additionals.h"
#include "simulation/mpi_communication.h"
namespace generator {
std::shared_ptr<RandomNumbers> buildRandomNumbers(Parameter& parameter) {
if (parameter.jsonObjectFromBase({"RandomNumbers"})) {
int seed =
json_int(parameter.jsonObjectFromBase({"RandomNumbers", "Seed"}));
int local_seed = seed + MpiCommunication::mpi_rank;
return std::shared_ptr<RandomNumbers>(new RandomNumbers(local_seed));
} else {
ERROR("No information given for random numbers.");
return nullptr;
}
}
}; // namespace generator
+27
View File
@@ -0,0 +1,27 @@
#include "generators/reflector_generator.h"
#include "simulation/errors.h"
namespace generator {
std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
const json_path& path_to_reflector) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_reflector, {"ReflectorDPS"}))) {
DEBUG_LEVEL_2("Create reflector: ReflectorDPS");
double position_z = json_read_length(
parameter.jsonObjectFromBase(json_path_append(
path_to_reflector, {"ReflectorDPS", "position_z"})),
"m");
return std::shared_ptr<Reflector>(new ReflectorDPS(position_z));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_reflector, {"NoReflector"}))) {
DEBUG_LEVEL_2("Create reflector: NoReflector");
return std::shared_ptr<Reflector>(new NoReflector());
} else {
ERROR("This reflector is not implemented");
return nullptr;
}
}
}; // namespace generator
+20
View File
@@ -0,0 +1,20 @@
#include "generators/scalar_field_generator.h"
#include "functions/functions.h"
#include "generators/function_generator.h"
#include "simulation/errors.h"
#include "simulation/jansson_additionals.h"
namespace generator {
std::shared_ptr<ScalarField> buildScalarField(json_t* object) {
if (json_object_by_path(object, {"ScalarFieldFunctionInZ"})) {
std::function<double(double, double, double)> z_function = function3D(
json_object_by_path(object, {"ScalarFieldFunctionInZ", "zFunction"}));
return std::shared_ptr<ScalarField>(new ScalarFieldFunctionInZ(z_function));
} else {
ERROR("This scalar field is not implemented");
return nullptr;
}
return nullptr;
}
}; // namespace generator
+135
View File
@@ -0,0 +1,135 @@
#include "generators/simulation_output_generator.h"
#include "IO/simulation_output.h"
#include "simulation/jansson_additionals.h"
#include "simulation/species.h"
namespace generator {
std::shared_ptr<SimulationOutput> buildSimulationOutput(
json_t* object,
const std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species) {
std::string output_folder =
json_string(json_object_by_path(object, {"folder"}));
std::string filename = json_string(json_object_by_path(object, {"filename"}));
auto output = std::make_shared<SimulationOutput>(output_folder, filename);
// DensityFields
{
int intervall =
json_int(json_object_by_path(object, {"DensityFields", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"DensityFields", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(&intervall,
"The intervall for density field output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"DensityFields", "OverwriteLast"}));
json_t* species = json_object_by_path(object, {"DensityFields", "Species"});
if (json_is_array(species)) {
size_t index;
json_t* value;
json_array_foreach(species, index, value) {
std::string specie_alias = json_string(value);
OutputTask task = {specie_alias, overwrite_last, intervall};
output->addDensityFieldOutput(task);
}
} else {
std::string all = json_string(species);
if (all == "all") {
for (const auto& pairs : tracked_species) {
OutputTask task = {pairs.first, overwrite_last, intervall};
output->addDensityFieldOutput(task);
}
} else {
ERROR("This species can not be outputted.");
}
}
}
// CurrentBorders
{
int intervall =
json_int(json_object_by_path(object, {"CurrentBorders", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"CurrentBorders", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(&intervall,
"The intervall for current border output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"CurrentBorders", "OverwriteLast"}));
json_t* species =
json_object_by_path(object, {"CurrentBorders", "Species"});
if (json_is_array(species)) {
size_t index;
json_t* value;
json_array_foreach(species, index, value) {
std::string specie_alias = json_string(value);
OutputTask task = {specie_alias, overwrite_last, intervall};
output->addCurrentBorderOutput(task);
}
} else {
std::string all = json_string(species);
if (all == "all") {
for (const auto& pairs : tracked_species) {
OutputTask task = {pairs.first, overwrite_last, intervall};
output->addCurrentBorderOutput(task);
}
} else {
ERROR("This species can not be outputted.");
}
}
}
// DeletionLogger
{
int intervall =
json_int(json_object_by_path(object, {"DeletionLogger", "Intervall"}));
if (intervall == 0 &&
json_string(json_object_by_path(
object, {"DeletionLogger", "Intervall"})) == "EachSync") {
intervall = 1;
}
ASSERT_POSITIVE(
&intervall,
"The intervall for deletion logger output must be positive");
bool overwrite_last = json_bool(
json_object_by_path(object, {"DeletionLogger", "OverwriteLast"}));
json_t* species =
json_object_by_path(object, {"DeletionLogger", "Species"});
if (json_is_array(species)) {
size_t index;
json_t* value;
json_array_foreach(species, index, value) {
std::string specie_alias = json_string(value);
OutputTask task = {specie_alias, overwrite_last, intervall};
output->addDeletionLoggerOutput(task);
}
} else {
std::string all = json_string(species);
if (all == "all") {
for (const auto& pairs : tracked_species) {
OutputTask task = {pairs.first, overwrite_last, intervall};
output->addDeletionLoggerOutput(task);
}
} else {
ERROR("This species can not be outputted.");
}
}
}
return output;
}
}; // namespace generator
+310
View File
@@ -0,0 +1,310 @@
#include "generators/species_generator.h"
#include "constants/physical_constants.h"
#include "generators/current_collector_generator.h"
#include "generators/density_field_generator.h"
#include "generators/drift_velocity_generator.h"
#include "generators/logger_generator.h"
#include "generators/mass_generator.h"
#include "generators/mover_generator.h"
#include "generators/reflector_generator.h"
#include "generators/terminator_generator.h"
#include "generators/velocity_distribution_generator.h"
#include "simulation/errors.h"
#include "simulation/timer.h"
namespace generator {
std::map<std::string, species::ImplementedSpecies>
SpeciesAlias::specie_aliases = {
{"electron", species::ImplementedSpecies::electron},
{"T2+", species::ImplementedSpecies::T2plus},
{"T3+", species::ImplementedSpecies::T3plus},
{"T+", species::ImplementedSpecies::Tplus},
{"T2", species::ImplementedSpecies::T2}};
species::ImplementedSpecies SpeciesAlias::alias(const std::string& name) {
if (isAlias(name)) {
return specie_aliases.at(name);
} else {
ERROR("This specie has no alias." + name);
return specie_aliases.at(name);
}
}
std::string SpeciesAlias::name(species::ImplementedSpecies specie) {
for (auto& pair : specie_aliases) {
if (pair.second == specie) {
return pair.first;
}
}
return std::string("");
}
bool SpeciesAlias::isAlias(const std::string& name) {
return static_cast<bool>(specie_aliases.count(name));
}
std::map<species::ImplementedSpecies, double> SpeciesCharges::charge_ = {
{species::ImplementedSpecies::electron, -SI::e},
{species::ImplementedSpecies::T2, 0.},
{species::ImplementedSpecies::Tplus, SI::e},
{species::ImplementedSpecies::T2plus, SI::e},
{species::ImplementedSpecies::T3plus, SI::e}};
double SpeciesCharges::charge(species::ImplementedSpecies species) {
return charge_.at(species);
}
SpeciesBuilder::SpeciesBuilder(Parameter& parameter) {
initTimer();
initBackgroundSpecies(parameter);
initTrackedSpecies(parameter);
fillBackgroundSpecieType(parameter);
fillTrackedSpecieType(parameter);
// same for all
fillMass();
fillCharge();
fillVelocityDistribution(parameter);
fillDriftVelocity(parameter);
// only background
fillBackgroundDensity(parameter);
// only trackable
fillMover(parameter);
fillTerminator(parameter);
fillReflector(parameter);
fillTrackedDensity(parameter);
buildSpecies();
fillInteractions(parameter);
fillCurrentCollector(parameter);
fillLoggers(parameter);
};
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>
SpeciesBuilder::trackedSpecies() {
return tracked_species;
}
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>
SpeciesBuilder::backgroundSpecies() {
return background_species;
}
std::shared_ptr<Timer> SpeciesBuilder::timer() {
return timer_;
}
void SpeciesBuilder::initTimer() {
DEBUG_LEVEL_2("Init timer.");
timer_ = std::shared_ptr<Timer>(new Timer());
}
void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
DEBUG_LEVEL_2("Init background species info.");
const char* key;
json_t* value;
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Background"}),
key, value) {
background_species_info[std::string(key)] = BackgroundSpeciesBuilderInfo();
background_species_info[std::string(key)].name = std::string(key);
background_species_info[std::string(key)].path_in_json = {
"Species", "Background", std::string(key)};
}
}
void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
DEBUG_LEVEL_2("Init tracked species info.");
const char* key;
json_t* value;
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key,
value) {
tracked_species_info[std::string(key)] = TrackedSpeciesBuilderInfo();
tracked_species_info[std::string(key)].name = std::string(key);
tracked_species_info[std::string(key)].path_in_json = {"Species", "Tracked",
std::string(key)};
}
}
void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
DEBUG_LEVEL_2("Fill background species type.");
for (auto& b : background_species_info) {
std::string type = json_string(parameter.jsonObjectFromBase(
json_path_append(b.second.path_in_json, {"ParticleType"})));
DEBUG_LEVEL_3("Type: " + type);
if (SpeciesAlias::isAlias(type)) {
b.second.type = SpeciesAlias::alias(type);
} else {
ERROR("This specie type is not implemented: " + type);
}
}
}
void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
DEBUG_LEVEL_2("Fill tracked species type.");
for (auto& b : tracked_species_info) {
std::string type = json_string(parameter.jsonObjectFromBase(
json_path_append(b.second.path_in_json, {"ParticleType"})));
DEBUG_LEVEL_3("Type: " + type);
if (SpeciesAlias::isAlias(type)) {
b.second.type = SpeciesAlias::alias(type);
} else {
ERROR("This specie type is not implemented: " + type);
}
}
}
void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
DEBUG_LEVEL_2("Fill background density.");
for (auto& b : background_species_info) {
b.second.density = buildConstantDensityField(parameter.jsonObjectFromBase(
json_path_append(b.second.path_in_json, {"ConstantDensityField"})));
}
}
void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
DEBUG_LEVEL_2("Fill velocity distributions.");
for (auto& b : background_species_info) {
b.second.velocity_distribution = buildVelocityDistribution(
parameter,
json_path_append(b.second.path_in_json, {"VelocityDistribution"}));
}
for (auto& b : tracked_species_info) {
b.second.velocity_distribution = buildVelocityDistribution(
parameter,
json_path_append(b.second.path_in_json, {"VelocityDistribution"}));
}
}
void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
DEBUG_LEVEL_2("Fill drift velocity.");
for (auto& b : background_species_info) {
b.second.drift_velocity = buildDriftVelocity(
parameter, json_path_append(b.second.path_in_json, {"DriftVelocity"}));
}
for (auto& b : tracked_species_info) {
b.second.drift_velocity = buildDriftVelocity(
parameter, json_path_append(b.second.path_in_json, {"DriftVelocity"}));
}
}
void SpeciesBuilder::fillMass() {
DEBUG_LEVEL_2("Fill masses.");
for (auto& b : background_species_info) {
b.second.mass_kg = SpeciesMasses::mass(b.second.type);
}
for (auto& b : tracked_species_info) {
b.second.mass_kg = SpeciesMasses::mass(b.second.type);
}
}
void SpeciesBuilder::fillCharge() {
DEBUG_LEVEL_2("Fill charges");
for (auto& b : background_species_info) {
b.second.charge_C = SpeciesCharges::charge(b.second.type);
}
for (auto& b : tracked_species_info) {
b.second.charge_C = SpeciesCharges::charge(b.second.type);
}
}
void SpeciesBuilder::fillMover(Parameter& parameter) {
DEBUG_LEVEL_2("Fill movers.");
for (auto& b : tracked_species_info) {
if ((b.second.mover == nullptr)) {
b.second.mover = buildMover(
parameter, json_path_append(b.second.path_in_json, {"Mover"}));
}
}
}
void SpeciesBuilder::fillTerminator(Parameter& parameter) {
DEBUG_LEVEL_2("Fill terminators.");
for (auto& b : tracked_species_info) {
if ((b.second.terminator == nullptr)) {
b.second.terminator = buildTerminator(
parameter, json_path_append(b.second.path_in_json, {"Terminator"}));
}
}
}
void SpeciesBuilder::fillReflector(Parameter& parameter) {
DEBUG_LEVEL_2("Fill reflectors.");
for (auto& b : tracked_species_info) {
if ((b.second.reflector == nullptr)) {
b.second.reflector = buildReflector(
parameter, json_path_append(b.second.path_in_json, {"Reflector"}));
}
}
}
void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
DEBUG_LEVEL_2("Fill tracked density.");
for (auto& b : tracked_species_info) {
b.second.density_field = buildDynamicDensityField(
parameter,
json_path_append(b.second.path_in_json,
{"DensityField", "DynamicDensityField"}),
timer_);
}
}
void SpeciesBuilder::buildSpecies() {
DEBUG_LEVEL_2("Build species from info.");
for (auto& b : background_species_info) {
background_species[b.first] = std::shared_ptr<species::BackgroundSpecie>(
new species::BackgroundSpecie(
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
b.second.density, b.second.velocity_distribution,
b.second.drift_velocity));
}
for (auto& b : tracked_species_info) {
tracked_species[b.first] =
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
b.second.mover, b.second.terminator, b.second.reflector,
b.second.density_field, b.second.velocity_distribution,
b.second.drift_velocity));
}
}
void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
DEBUG_LEVEL_2("Fill current collectors.");
for (auto& b : tracked_species) {
auto current_collector = buildCurrentCollector(
parameter,
json_path_append(tracked_species_info.at(b.first).path_in_json,
{"CurrentCollector"}),
timer_);
b.second->currentCollector(current_collector);
}
}
void SpeciesBuilder::fillLoggers(Parameter& parameter) {
DEBUG_LEVEL_2("Fill loggers.");
for (auto& b : tracked_species) {
auto deletion_logger = buildDeletionLogger(
parameter,
json_path_append(tracked_species_info.at(b.first).path_in_json,
{"Loggers"}));
b.second->deletionLogger(deletion_logger);
}
}
void SpeciesBuilder::fillInteractions(Parameter& parameter) {
DEBUG_LEVEL_2("Fill interactions.");
for (auto& b : tracked_species) {
json_path path = tracked_species_info[b.first].path_in_json;
path = json_path_append(path, {"Interactions"});
addInteractions(b.second, tracked_species, background_species, parameter,
path);
}
}
}; // namespace generator
+25
View File
@@ -0,0 +1,25 @@
#include "generators/terminator_generator.h"
#include "generators/geometry_generator.h"
namespace generator {
std::shared_ptr<Terminator> buildTerminator(
Parameter& parameter,
const json_path& path_to_terminator) {
DEBUG_LEVEL_2("Creating terminator.");
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"}));
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
std::shared_ptr<Geometry> geometry = buildGeometry(
parameter, json_path_append(path_to_terminator, {"BoundaryGeometry"}));
return std::shared_ptr<Terminator>(
new Terminator(max_interactions, max_time_alive, geometry));
}
}; // namespace generator
+99
View File
@@ -0,0 +1,99 @@
#include "generators/vector_field_generator.h"
#include <functional>
#include "IO/hdf5_reader.h"
#include "generators/binning_generator.h"
#include "generators/function_generator.h"
#include "simulation/errors.h"
#include "simulation/homebase.h"
#include "simulation/jansson_additionals.h"
namespace generator {
std::string readAbsoluteFilename(json_t* object) {
std::string path_type = json_string(json_object_by_path(object, {"Type"}));
if (path_type == "RelativeToHomebase") {
std::string homebase = BUILD_HOMEBASE_STRING;
std::string relative_path_to_homebase =
json_string(json_object_by_path(object, {"RelativePath"}));
std::string filename =
json_string(json_object_by_path(object, {"Filename"}));
return homebase + "/" + relative_path_to_homebase + "/" + filename;
} else if (path_type == "AbsolutPath") {
std::string absolute_path =
json_string(json_object_by_path(object, {"AbsoluteFolderPath"}));
std::string filename =
json_string(json_object_by_path(object, {"Filename"}));
return absolute_path + "/" + filename;
} else {
ERROR("This path type is not supported: " + path_type);
return "";
}
}
blitz::Array<double, 3> readFromFile(json_t* object) {
std::string absolute_filename =
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
std::string key = json_string(json_object_by_path(object, {"Key"}));
Hdf5Reader reader(absolute_filename);
return reader.readD3Double(key);
}
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
std::string absolute_filename =
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
std::string key = json_string(
json_array_get(json_object_by_path(object, {"PathToH5"}), component));
Hdf5Reader reader(absolute_filename);
return reader.readD3Double(key);
}
std::shared_ptr<VectorField> buildVectorField(json_t* object) {
if (json_object_by_path(object, {"VectorFieldConstant"})) {
DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant");
blitz::TinyVector<double, 3> constant = json_blitz_vector<3>(
json_object_by_path(object, {"VectorFieldConstant", "constant"}));
return std::shared_ptr<VectorField>(
new VectorFieldConstant(CylinderVector(constant)));
} else if (json_object_by_path(object, {"VectorFieldFunctionInZ"})) {
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ");
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"})) {
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray");
blitz::Array<double, 3> v_radial = readComponentFromFile(
json_object_by_path(object,
{"VectorFieldFromArray", "ReadArrayFromFile"}),
0);
blitz::Array<double, 3> v_azimuthal = readComponentFromFile(
json_object_by_path(object,
{"VectorFieldFromArray", "ReadArrayFromFile"}),
1);
blitz::Array<double, 3> v_longitudinal = readComponentFromFile(
json_object_by_path(object,
{"VectorFieldFromArray", "ReadArrayFromFile"}),
2);
double radius = json_double(
json_object_by_path(object, {"VectorFieldFromArray", "Radius"}));
double length = json_double(
json_object_by_path(object, {"VectorFieldFromArray", "Length"}));
return std::make_shared<VectorFieldFromArray>(
v_radial, v_azimuthal, v_longitudinal, radius, length);
} else {
ERROR("This vector field is not implemented");
return nullptr;
}
return nullptr;
}
} // namespace generator
@@ -0,0 +1,52 @@
#include "generators/velocity_distribution_function_generator.h"
#include "generators/energy_distribution_function_generator.h"
#include "generators/mass_generator.h"
#include "simulation/energy_distribution.h"
namespace generator {
std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
Parameter& parameter,
const json_path& path_to_distribution) {
if (parameter.jsonObjectFromBase(
json_path_append(path_to_distribution, {"IsotropicDistribution"}))) {
DEBUG_LEVEL_2(
"Creating velocity distribution function: IsotropicDistribution");
std::shared_ptr<EnergyDistributionFunction> fE =
buildEnergyDistributionFunction(
parameter, json_path_append(path_to_distribution,
{"IsotropicDistribution",
"EnergyDistributionFunction"}));
double mass_kg = buildMass(parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"IsotropicDistribution", "Mass"})));
return std::shared_ptr<VelocityDistributionFunction>(
new IsotropicDistribution(fE, mass_kg));
} else if (parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"DirectedDistribution"}))) {
DEBUG_LEVEL_2(
"Creating velocity distribution function: DirectedDistribution");
std::shared_ptr<EnergyDistributionFunction> fE =
buildEnergyDistributionFunction(
parameter, json_path_append(path_to_distribution,
{"DirectedDistribution",
"EnergyDistributionFunction"}));
double mass_kg = buildMass(parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"DirectedDistribution", "Mass"})));
blitz::TinyVector<double, 3> cartesian_direction =
json_blitz_vector<3>(parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"DirectedDistribution", "Direction"})));
return std::shared_ptr<VelocityDistributionFunction>(
new DirectedDistribution(fE, mass_kg,
CartesianVector(cartesian_direction)));
}
ERROR("This velocity distribution function is not implemented.");
return nullptr;
}
}; // namespace generator
+31
View File
@@ -0,0 +1,31 @@
#include "generators/velocity_distribution_generator.h"
#include "generators/velocity_distribution_function_generator.h"
#include "simulation/errors.h"
#include "simulation/velocity_distribution_function.h"
namespace generator {
std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
Parameter& parameter,
const json_path& path_to_distribution) {
if (parameter.jsonObjectFromBase(json_path_append(
path_to_distribution, {"VelocityDistributionFromFunction"}))) {
DEBUG_LEVEL_2(
"Creating velocity distribution: VelocityDistributionFromFunction");
std::shared_ptr<VelocityDistributionFunction> v =
buildVelocityDistributionFunction(
parameter, json_path_append(path_to_distribution,
{"VelocityDistributionFromFunction",
"VelocityDistributionFunction"}));
return std::shared_ptr<VelocityDistribution>(
new VelocityDistributionFromFunction(v));
} else if (parameter.jsonObjectFromBase(
json_path_append(path_to_distribution, {"null"}))) {
DEBUG_LEVEL_2("Creating velocity distribution: null");
return nullptr;
} else {
ERROR("This velocity distribution is not implemented.");
return nullptr;
}
}
}; // namespace generator