Many, many more comments

This commit is contained in:
2024-12-04 17:15:04 +01:00
parent 8696517336
commit 03854339ca
100 changed files with 1702 additions and 49 deletions
+4
View File
@@ -54,4 +54,8 @@ numpy, matplotlib, scipy and h5py.
An example of how to use the analysis scripts is provided in the file "analysis/plot_example.py".
NOTES:
Kommentare in den files: position_binning.*, current_collector.*, kinematic.*, sim_constants.h, mover.*, simulation_output.*, functions.*, injector_generator.h, ionization.h, recombination.cpp und species_generator überprüfen lassen
für interactions.cpp: mehr Kommentare zum source code (i.e. zur Berechnung?)
für cross_sections.h: Referenzen mit reinschreiben?
+10
View File
@@ -4,13 +4,23 @@
#include <string>
#include "blitz/array.h"
// class for reading data from a hdf5-file
class Hdf5Reader {
public:
// Constructor: taking a string with the path to the directory and
// a string with the name of the file to be read (without the ".h5", which is appended by default)
Hdf5Reader(std::string directory, std::string filename);
// Constructor: taking a string of the absolute path to the file (string is not changed)
Hdf5Reader(std::string absolute_filename);
// read a 3-dimensional array from the hdf5-file specified at construction of the reader
// object at the hdf5-path "path" and return it as a blitz::Array
blitz::Array<double, 3> readD3Double(std::string path);
// read a 2-dimensional array from the hdf5-file specified at construction of the reader
// object at the hdf5-path "path" and return it as a blitz::Array
blitz::Array<double, 2> readD2Double(std::string path);
// read a 1-dimensional array from the hdf5-file specified at construction of the reader
// object at the hdf5-path "path" and return it as a blitz::Array
blitz::Array<double, 1> readD1Double(std::string path);
private:
+6 -1
View File
@@ -5,11 +5,16 @@
#include <vector>
#include "blitz/array.h"
// Class to handle hdf5 output
class Hdf5Writer {
public:
// the ".h5" is appened to the filename by default
Hdf5Writer(std::string directory = "./output",
std::string filename = "output");
// writing functions to write data to a HDF dataset specified by the path
// variable (format: path = "/Group1/Group2/.../GroupN/NameOfDataset")
// into the file specified by directory and filename
void write(const blitz::Array<double, 1>& data, std::string path);
void write(const blitz::Array<double, 2>& data, std::string path);
void write(const blitz::Array<double, 3>& data, std::string path);
+69 -1
View File
@@ -7,36 +7,57 @@
#include <vector>
#include "IO/hdf5_writer.h"
// defined in "simulation/density_field.h"
class DynamicDensityField;
class CurrentBorder;
//class CurrentBorder;
// defined in "simulation/parameter.h"
class Parameter;
// defined in "simulation/current_collector.h"
class CurrentCollector;
// defined in "simulation/logger.h"
class DeletionLogger;
// defined in "simulation/species.h"
namespace species {
class TrackedSpecie;
enum class ImplementedSpecies;
}; // namespace species
// structure to store information about output types
struct OutputTask {
// name of the particle species that output should be performed for
std::string specie_name;
// if true earlier output is overwritten
bool overwrite_last;
// how many cpu synchronization steps are inbetween two output steps
int intervall;
// selector if each or only first cpu should write can be added here
};
// class to handle output from the simulation
class SimulationOutput {
public:
// Constructor: takes the name of the output directory and
// the name of the output file (".h5" appended by default)
// directory is created if it does not exist
SimulationOutput(const std::string& output_folder,
const std::string& output_filename);
// add OutputTask for the output of the (dynamic) density field
void addDensityFieldOutput(OutputTask task);
// add OutputTask for the output of the current collector
void addCurrentBorderOutput(OutputTask task);
// add OutputTask for the output of the deletion logger
void addDeletionLoggerOutput(OutputTask task);
// write data that is initialized once at the beginning of the simulation
// for all TrackedSpecies (mass (kg), charge (C), bin volumes, bin borders, number of bins
// bin areas)
void writeMetaData(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species);
// write data that changes during the simulation, output intervalls are defined
// wrt the number of cpu synchronization steps cpu_sync
void writeSimulationData(
int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species);
@@ -48,45 +69,92 @@ class SimulationOutput {
Hdf5Writer writer;
// function for writing simulated data in the dynamic density field
// takes the path to the hdf group of the specie the dynamic density field is defined for
// takes the number of cpu synchronization steps that have been performed
// takes whether earlier output should be overwritten
void writeSimulationData(DynamicDensityField* density_field,
std::string species_path,
int cpu_sync,
bool overwrite_last);
// write the 4d density array of the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeSpectrum(DynamicDensityField* density_field, std::string path);
// write the 3d density array of the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeDensity(DynamicDensityField* density_field, std::string path);
// write the 4d time in bin array (i.e. the raw data) of the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeTimeInBin(DynamicDensityField* density_field, std::string path);
// write the 4d density array of the deleted particles array
// in the hdf group defined by string (has to be a total hdf path)
void writeDeletedParticles(DynamicDensityField* density_field,
std::string path);
// write the time of the Timer member object
// in the hdf group defined by string (has to be a total hdf path)
void writePhysicalTime(DynamicDensityField* density_field, std::string path);
// function for writing simulated data in the current collector
// takes the path to the hdf group of the specie the dynamic density field is defined for
// takes the number of cpu synchronization steps that have been performed
// takes whether earlier output should be overwritten
void writeSimulationData(CurrentCollector* current_collector,
std::string species_path,
int cpu_sync,
bool overwrite_last);
// write all positive and negative crossing arrays (i.e. raw data)
// in the hdf group defined by string (has to be a total hdf path)
void writeCurrentCrossings(CurrentCollector* current_collector,
std::string path);
// write all physical particle current arrays (i.e. raw data)
// in the hdf group defined by string (has to be a total hdf path)
void writeCurrent(CurrentCollector* current_collector, std::string path);
// write the time of the Timer member object
// in the hdf group defined by string (has to be a total hdf path)
void writePhysicalTime(CurrentCollector* current_collector, std::string path);
// function for writing simulated data in the deletion logger
// takes the path to the hdf group of the specie the dynamic density field is defined for
// takes the number of cpu synchronization steps that have been performed
// takes whether earlier output should be overwritten
void writeSimulationData(DeletionLogger* logger,
std::string species_path,
int cpu_sync,
bool overwrite_last);
// write the deletion trakced by the DeletionLogger
// in the hdf group defined by string (has to be a total hdf path)
void writeNumDeletions(DeletionLogger* logger, std::string path);
// write the not simulated aspects of the TrackedSpecie
// (mass (kg), charge (C))
// in the hdf group defined by string (has to be a total hdf path)
void writeMetaData(species::TrackedSpecie* specie);
// write the not simulated aspects of the DynamicDensityField
// (bin volumes, bin borders)
// in the hdf group defined by string (has to be a total hdf path)
void writeMetaData(DynamicDensityField* density_field, std::string path);
// write the not simulated aspects of the CurrentCollector
// (bin areas)
// in the hdf group defined by string (has to be a total hdf path)
void writeMetaData(CurrentCollector* current_collector, std::string path);
// void writeParameterFile(Parameter* parameter);
// write the areas of the bins used by the current collector
// in the hdf group defined by string (has to be a total hdf path)
void writeCollectorAreas(CurrentCollector* current_collector,
std::string path);
// write the volumes of the bins used by the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeBinVolumes(DynamicDensityField* density_field,
std::string path_to_field);
// write the number of bins used by the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeNumBins(DynamicDensityField* density_field,
std::string path_to_field);
// write the borders of the bins used by the dynamic density field
// in the hdf group defined by string (has to be a total hdf path)
void writeBinBorders(DynamicDensityField* density_field,
std::string path_to_field);
};
+7 -3
View File
@@ -2,9 +2,13 @@
#define T2_BETA_DECAY_H
namespace T2BetaDecay {
static const double lambda_T2 = 1.78405E-9; // tritium decay constant (1/s)
static const double E0_T = 18.573e3; // Tritium endpoint energy (eV)
static const double spectrum_prefactor = 1.2072343416696292E-47; // beta decay constant
// tritium decay constant (1/s)
static const double lambda_T2 = 1.78405E-9;
// Tritium endpoint energy (eV)
static const double E0_T = 18.573e3;
// beta decay constant used in the fermi spectrum
static const double spectrum_prefactor = 1.2072343416696292E-47;
// maximum value of the fermi spectrum
static const double spectrum_maximum = 1.5E-28;
}
+2 -2
View File
@@ -1,7 +1,7 @@
#ifndef PHYSICAL_CONSTANTS_H
#define PHYSICAL_CONSTANTS_H
// The default is (Gaussian) CGS units
// Constants in CGS units
namespace CGS {
static const double me = 9.1094e-28; // Electron mass (g)
static const double mp = 1.6726231e-24; // Proton mass (g)
@@ -21,7 +21,7 @@ static const double G = 6.67428e-8; // Gravitational constant cm^3/(g sec^2)
}; // namespace CGS
// Constants in SI
// Constants in SI (default)
namespace SI {
static const double me = 9.1094e-31; // Electron mass (kg)
static const double mp = 1.6726e-27; // Proton mass (kg)
+5
View File
@@ -3,12 +3,17 @@
#include <limits>
// constants due to numercial accuracy
namespace SimConstants {
// minimal value for a cross section
static const double minimal_cross_section =
std::numeric_limits<double>::min() * 1E5;
// minimal value for a cross section scaled by density
static const double minimal_macroscopic_cross_section =
std::numeric_limits<double>::min() * 1E5;
// arbitrarily chosen value to serve as the lowest value possible (to exclude 0)
static const double random_lower_limit = 1E-15;
// double1 == double2 <=> abs(double1 - double2) <= compare_epsilon
static const double compare_epsilon = 1E-10;
} // namespace SimConstants
+13
View File
@@ -4,19 +4,32 @@
#include <functional>
#include <vector>
// R^1 -> R^1 mappings
namespace D1ToD1 {
// return a function defined at the vector positions with the vector values
// which interpolates linearly between those values
// both vectors have to be sorted according to the values in positions
std::function<double(double)> PiecewiseLinear(std::vector<double> positions,
std::vector<double> values);
// return a function, that always returns the constant value "constant"
std::function<double(double)> Constant(double constant);
// return a function returning the product of the values defined by the functions
// in the vector "functions"
std::function<double(double)> Product(
std::vector<std::function<double(double)>> functions);
}; // namespace D1ToD1
// R^3 -> R^1 mappings
namespace D3ToD1 {
// return a function, that always returns the constant value "constant"
std::function<double(double, double, double)> Constant(double value);
// return a function that returns the product of the values of the functions fi, fj and fk
// fi calculates its value from the first parameter the function "Product" returns gets,
// fj from the second parameter and
// fk from the third
std::function<double(double, double, double)> Product(
std::function<double(double)> fi,
std::function<double(double)> fj,
+51
View File
@@ -9,12 +9,63 @@
#include "simulation/position_binning.h"
namespace generator {
// return a CylinderBinning object as described in the json-object object
// object has to contain a json-object "CylinderBinning"
// "CylinderBinning" has to consist of:
// - json-object "Radial" consisting of a json-double (later cast to an integer) "NumberOfBins"
// and a json-object "MaxRadius", which has to follow the form described in "json_read_length"
// ("simulation/jansson_additionals.h")
// - json-object "Longitudinal" consisting of a json-double (later cast to an integer) "NumberOfBins"
// and a json-object "MaxLength", which has to follow the form described in "json_read_length"
// ("simulation/jansson_additionals.h")
// - json-object "Azimuthal" consisting of a json-double (later cast to an integer) "NumberOfBins"
// example:
// "object" : {
// "CylinderBinning": {
// "Radial": {"NumberOfBins": 1, "MaxRadius" : {...}},
// "Azimuthal": {"NumberOfBins": 1},
// "Longitudinal": {"NumberOfBins": 1, "MaxLength" : {...}}
// }
// }
CylinderBinning buildPositionBinning(json_t* object);
// return a CylinderBinning object described by the json-object in parameter at the
// path "path_to_binning"
// if a json-array called "CreateSameAs" exists: has to consist of the path to the PositionBinning
// json-object that should be used (e.g. ["Object1", "Object2", ..., "PositionBinning"],
// "Object1" has to be located in the root object)
// otherwise same specifications as "buildPositionBinning"
CylinderBinning buildPositionBinningIncludingRedirection(
Parameter& parameter,
json_path& path_to_binning);
// return a EnergyBinning object as defined in the json-object object
// object has to contain:
// - a json-string "Type", defining the type of the EnergyBinning (right now only "Logarithmic" is valid)
// - a json-double "NumberOfBins", defining the number of bins for the binning (will be cast to an int)
// - a json-object "MinEnergy" and a json-object "MaxEnergy", defining the lower and upper
// value for the binning. Both objects have to follow the structure described in
// "json_read_energy" ("simulation/jansson_additionals.h")
//
// example:
// "object": {
// "Type": "Logarithmic",
// "NumberOfBins": 3,
// "MinEnergy": {
// "value": 1,
// "unit": eV
// },
// "MaxEnergy": {
// "value": 1000,
// "unit": eV
// }
// }
EnergyBinning buildEnergyBinning(json_t* object);
// return a EnergyBinning object described by the json-object in parameter at the
// path "path_to_binning"
// if a json-array called "CreateSameAs" exists: has to consist of the path to the EnergyBinning
// json-object that should be used (e.g. ["Object1", "Object2", ..., "EnergyBinning"],
// "Object1" has to be located in the root object)
// otherwise same specifications as "buildEnergy"
EnergyBinning buildEnergyBinningIncludingRedirection(
Parameter& parameter,
json_path& path_to_binning);
@@ -9,6 +9,11 @@
#include "simulation/timer.h"
namespace generator {
// return a shared_ptr to a CurrentCollector object, defined by the json-object
// at "path_to_collector" in the Parameter file using the provied Timer object
// the json-object has to contain a json-object called "PositionBinning",
// wich has to follow the structure described in "buildPositionBinning"
// (in "generators/binning_generator.h")
std::shared_ptr<CurrentCollector> buildCurrentCollector(
Parameter& parameter,
const json_path& path_to_collector,
@@ -8,8 +8,16 @@
namespace generator {
// return a shared_ptr to a ConstantDensityField object described by the give json-object
// object has to contain a json-object "ScalarField", that has to follow the form
// described in "buildScalarField" (defined in "generators/scalar_field_generator.h")
std::shared_ptr<ConstantDensityField> buildConstantDensityField(json_t* object);
// return a shared_ptr to a DynamicDensityField object described by the json-object
// at the give path in the Parameter object which uses the given Timer object
// the json-object at path_to_field has to contain two json-objects called
// "PositionBinning" and "EnergyBinning", which are described in "buildPositionBinning"
// and "buildEnergyBinning" respectivley (both defined in "generators/binning_generator.h")
std::shared_ptr<DynamicDensityField> buildDynamicDensityField(
Parameter& parameter,
const json_path& path_to_field,
@@ -7,10 +7,21 @@
namespace generator {
// create a shared_ptr to a DriftVelocity object described by the json-object in parameter at the
// path "path_to_drift_velocity"
// has to consist of a json-object "VectorField" or "null"
// if "VectorField" is specified: has to follow the form described by "buildVectorField" (in "generators/vector_field_generator.h")
// if "null" is specified: nothing more has to be specified, simply returns a nullptr
// (examples in "simulation_config/drift_velocity_examples.json")
std::shared_ptr<DriftVelocity> buildDriftVelocity(
Parameter& parameter,
const json_path& path_to_drift_velocity);
// create a shared_ptr to a DriftVelocity object described by the json-object in parameter at the
// path "path_to_drift_velocity"
// if a json-array called "CreateSameAs" exists: has to consist of the path to the DriftVelocity
// json-object that should be used (e.g. ["Object1", "Object2", ..., "DriftVelocity"], has to start at the root)
// otherwise same specifications as "buildDriftVelocity"
std::shared_ptr<DriftVelocity> buildDriftVelocityIncludingRedirection(
Parameter& parameter, const json_path& path_to_drift_velocity);
};
@@ -6,8 +6,15 @@
namespace generator {
// create an ElectricField object from a json_t pointer to an json object
// defining the electric field
// has to consist of two json-objects "Background" and "Dynamic" defining the vector fields
// as described in "generators/vector_field_generator.h" (function: "buildVectorField")
std::shared_ptr<ElectricField> electricField(json_t* object);
// create an ElectricField object from the given Parameter object
// json file has to have a json object called "ElectricField" directly in the json root object
// of the parameter file
std::shared_ptr<ElectricField> electricField(Parameter& parameter);
}; // namespace generator
@@ -9,6 +9,22 @@
namespace generator {
// return a shared_ptr to an EnergyDistributionFunction object at the json-object
// with path "path_to_function" (from root) in the Parameter object
// has to consist of a json-object called either "TritiumBetaDecay", "MaxwellBoltzmann" or "Constant"
// if "TritiumBetaDecay" is specified:
// - does not have to contain anything (returns a TritiumBetaDecay object)
//
// if "MaxwellBoltzmann" is specified:
// - has to contain a json-object "Temperature", which has to contain a json-double "value"
// that specified the temperature (in K) for the Maxwell-Boltzmann distribution (returns a MaxwellBoltzmann object)
//
// if "Constant" is specified:
// - has to contain a json-object "constant", which has to contain a json-double "value", which
// specifies the constant energy in eV (returns a Constant object)
//
// (examples in "simulation_config_energy_distribution_function_examples.json"; definition of the
// objects in "simulatoin/energy_distribution.h")
std::shared_ptr<EnergyDistributionFunction> buildEnergyDistributionFunction(
Parameter& parameter,
const json_path& path_to_function);
+30 -1
View File
@@ -6,8 +6,37 @@
#include "jansson.h"
namespace generator {
// return a function1D specified by the json object "object"
// consists of a json-object called either "Constant", "PiecewiseLinear", "PiecewiseLinearFromFile" or an json-array called "Product"
// if "Constant" is specified:
// - has to contain a json-double called "constant" specifying the value of the constant the function should return
//
// if "PiecewiseLinear" is specified:
// - has to contain two json_arrays "xValues" and "yValues" specifying the point between which should be linearly interpolated
// - has to contain a json-double "prefactor", with which "yValues" will be scaled
//
// if "PiecewiseLinearFromFile" is specified:
// - has to contain a json-object "PathToH5" as described in "generators/vector_field_generator.h"
// - two json-strings "xValuesKey" and "yValuesKey" specifying the path of the x- and y-values in the hdf5 file
// - a json-double "prefactor" which scales the read y-values
//
// if "Product" is specified:
// - has to consist of an arbitrary number of json-objects following the format described for this function
//
// (examples can be found in "simulation_config/function_examples.json")
std::function<double(double)> function1D(json_t* object);
// return a function3D specified by the json object "object"
// has to consist of a json-object called either "Constant3D" or "Product"
//
// if "Constant3D" is specified:
// - has to contain a json-double "constant", defining the constant value that should be returned
//
// if "Product" is specified:
// - has to contain three json-objects called "fi", "fk" and "fj" defining the
// functional form in x,y and z direction; objects have to follow the description
// of "function1D"
//
// (examples can be found in "simulation_config/function_examples.json")
std::function<double(double, double, double)> function3D(json_t* object);
}; // namespace generator
+4
View File
@@ -9,6 +9,10 @@
namespace generator {
// return a shared_ptr to a Geometry object described by the json-object at the given path in the Parameter object
// the json-object at the path has to contain a json-object "Cylinder". This json-object has to contain:
// two json-objects "Radius" and "Height", which have to follow the form described in "json_read_length"
// ("simulation/jansson_additionals.h")
std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
const json_path& path_to_geometry);
+23
View File
@@ -10,6 +10,29 @@
namespace generator {
// return a shared_ptr to an Injector object described in the Parameter object
// the tracked_species should contain all TrackedSpecie objects that are considered in the simulation
// (background_species is not used)
// Parameter has to have a json-object "Injector" in the root object
// - in "Injector" a json-object "CreatedSpecies" has to exist, which
// consists of one more arbitrarily named json-objects
// these json-objects have to contain:
// - a json-string "TrackedSpecieName", which has to correspond to one
// of the strings used to describe the TrackedSpecies in the "Tracked" json-object of the same Paramter file
// - a json-object "CreationVelocityDistribution" following the description in "generators/velocity_distribution_generator.h"
// - a json-object "EventPositionDistribution" has to exit
// - therein a json-object "ScalarField" has to exist, which describes the distribution from which positions will be drawn (following the
// description in "generators/scalar_field_generator.h")
// - a json-object "DensityLimit", which has to contain
// - a json-double "min", which described the minimal density value of the used density distribution
// - a json-double "max", which described the maximal density value of the used density distribution
// - a json-object "PositionLimits" consisting of three json-object "rPosition", "phiPosition" and "zPosition", which
// all have the same sturcture:
// - a json-double "min", describing the minimum value that a drawn position should have
// - a json-double "max", describing the maximum value that a drawn position should have
// - a json-object "MotherDriftVelocity", which has a form as described in "generators/drift_velocity_generator.h"
//
// (example in "simulation_config/parameter_katrin_example.json")
std::shared_ptr<Injector> buildInjector(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species,
+103
View File
@@ -12,6 +12,61 @@
namespace generator {
// create the interactions specified at the "path_to_insteractions" in the Parameter
// and add them to the given TrackedSpecie specie
// the json-object at "path_to_interactions" has to consist of an arbitrary number
// of arbitrarily named json-objects describing the interaction. These objects have to contain:
// - a json-string "Type" with a value of either: "ElasticScattering", "FreeMovement", "ElectronIonization", "Excitation"
// "Clustering", "ChargeExchange" or "Recombination"
//
// if the Type "ElasticScattering" is specified (for elastic scattering interactions) the additional elements have to be present:
// - a json-object "CrossSection" (as described in "buildTotalCrossSection" function)
// - a json-object "ScatteringAngleDistribution" (as described in "buildScatteringAngleDistribution")
// - a json-string "Target", containing the interaction partner (has to be the name given in the json file
// of either a TrackedSpecie or a BackgroundSpecie)
//
// if the Type "FreeMovement" is specified (for a dummy interaction that does nothing) no additional elements have to be present
//
// if the Type is "ElectronIonization" the additional elements have to be provided:
// - a json-string "Target", containing the interaction partner (has to be the name given in the json file
// of either a TrackedSpecie or a BackgroundSpecie)
// - a json-string "OutgoingElectron", containing the name (given in the json parameter file) of
// a TrackedSpecie
// - a json-string "OutgoingIon", containing the name (given in the json parameter file) of
// a TrackedSpecie
// - a json-string "IonizationModel" with a value of either "JanevNonDiss", "JanevDissToGround" or "JanevDissToFirstExcited"
// - if the value is "IonizationModel": the "eT2_ionization_janev_non_diss" function for the cross section is used, "OutgoingElectron" has to be an electron ImplementedSpecies
// and "OutgoingIon" has to be a T2plus ImplementedSpecies, the scattering angle distribution is "IonizationScatteringAngleDistribution" and
// the energy distribution of the ionization electrons produced in the ionization is defined in "eT2_ionization_bed" (functions defined in "interations/cross_sections.h" and "interactions/ionization.h")
// - if the value is "JanevDissToGround": the "eT2_ionization_janev_diss_ground" function for the cross section is used, "OutgoingElectron" has to be an electron ImplementedSpecies
// and "OutgoingIon" has to be a Tplus ImplementedSpecies, the scattering angle distribution is "IonizationScatteringAngleDistribution" and
// the energy distribution of the ionization electrons produced in the ionization is defined in "eT2_ionization_bed" (functions defined in "interations/cross_sections.h" and "interactions/ionization.h")
// - if the value is "JanevDissToFirstExcited": the "eT2_ionization_janev_diss_first" function for the cross section is used, "OutgoingElectron" has to be an electron ImplementedSpecies
// and "OutgoingIon" has to be a Tplus ImplementedSpecies, the scattering angle distribution is "IonizationScatteringAngleDistribution" and
// the energy distribution of the ionization electrons produced in the ionization is defined in "eT2_ionization_bed" (functions defined in "interations/cross_sections.h" and "interactions/ionization.h")
//
// if the Type is "Excitation" the additiona elements have to be provided:
// - a json-string "Target", containing the interaction partner (has to be the name given in the json file
// of either a TrackedSpecie or a BackgroundSpecie)
// - a json-string "ExcitationState" being one of the names defined in "buildExcitationCrossSection"
//
// if the Type is "Clustering":
// - a json-string "Target", containing the interaction partner (has to be the name given in the json file
// of either a TrackedSpecie or a BackgroundSpecie)
// - a json-string "Product" (being a name of a tracked specie as defined in the json parameter file)
// - a json-object "CrossSection" (as described in the "buildTotalCrossSection" function)
//
// if the Type is "ChargeExchange" (right now only if the species for which it's defined is the target with a charge of +1):
// - a json-string "Target", containing the interaction partner (has to be the name given in the json file
// of either a TrackedSpecie or a BackgroundSpecie)
// - a json-object "CrossSection" (as described in the "buildTotalCrossSection" function)
//
// if the Type is "Recombination" the additional elements have to be present as well:
// - a json-string "Target", containing the interaction partner (has to be the name given in the json file
// of a TrackedSpecie)
// - a json-object "CrossSection" (as described in the "buildTotalCrossSection" function)
//
// examples for the usage in a json-file can be found in simulation_config/interactions_examples.json
void addInteractions(
std::shared_ptr<species::TrackedSpecie> specie,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
@@ -21,17 +76,62 @@ void addInteractions(
Parameter& parameter,
json_path& path_to_interactions);
// returns the cross section function defined in the given json-object
// the json-object has to either contain a json-string "PredefinedFunction", a json-object "1dFunction" or a json-object "ExcitationFunction"
// if the json-string "PredefinedFunction" is defined it has to have a value of one of the following strings:
// - "eT2_elastic_scattering_constant", "eT2_elastic_scattering", "TpT2_elastic_scattering_tabata", "T3pT2_elastic_scattering_tabata",
// "eT2_ionization_janev_diss_ground", "eT2_ionization_janev_diss_first", "TpT2_clustering_radiative_ascendion_pasil",
// "TpT2_clustering_tertiary_ascendion_pasil", "T2pT2_clustering_janev", "T2pT2_charge_exchange_janev", "eT2p_recombination_janev", "eT3p_recombination_janev"
// (further explanations can be found in "interactions/cross_sections.h"; the functions have the same name as the corresponding string listed above)
//
// if the json-object "1dFunction" exists, it has to follow the structure described in "generators/function_generator.h" for function1D
//
// if the json-object "ExcitationFunction" has to exist, this object has to contain a json-string called "ExcitationState",
// which has to be one of the strings defined in "buildExcitationCrossSection"
std::function<double(double)> buildTotalCrossSection(json_t* object);
// return a cross section function depending on two variables (e.g. in-going and out-going particle energies in an ionization)
// has to contain a json-string "PredefinedFunction" with a value of "eT2_ionization_bed"
// (right now the function is only defined but never used)
std::function<double(double, double)> build2DCrossSection(json_t* object);
// return a shared_ptr to a ScatteringAngleDistribution object that is defined by the given json-object
// has to contain a json-object called:
// "Isotropic". This object does not need any elements.
//
// "AngleDistributionFromFile". Has to contain a json-object "PathToH5" following the format as described in "readAbsoluteFilename"
// (defined in "generators/vector_field_generator.h")
//
// "CompositeAngleDistribution". Has to contain a
// - json-object "DeciderEnergy" following the description of "json_read_energy" (defined in "simulation/jansson_additionals.h")
// - two json-objects "LowerDistribution" and "HigherDisribuiton" as defined for this function
std::shared_ptr<ScatteringAngleDistribution> buildScatteringAngleDistribution(
json_t* object);
// return the value of the excitation energy for the given string defining the final excitation state of the target particle
// possible values for the excitation_state are (the numerical values can be found in the interaction_generatior.cpp file):
// - janev_singlet_B1, janev_singlet_B1prime, janev_singlet_B1primeprime, janev_singlet_C1, janev_singlet_D1,
// janev_singlet_D1prime, janev_singlet_symmetry_forbidden_EF1, janev_singlet_symmetry_forbidden_HHb,
// janev_singlet_symmetry_forbidden_GK1, janev_singlet_symmetry_forbidden_I1, janev_triplet_A3, janev_triplet_B3,
// janev_triplet_C3, janev_triplet_D3, janev_triplet_E3, janev_vibrational_first, janev_vibrational_second,
// england_rotational_j0_to_j2, england_rotational_j1_to_j3
double buildExcitationEnergy(std::string excitation_state);
// return the function for a predefined excitation cross section (see simulation/cross_sections.h)
// defined by the string "excitation_state"
// possible values for the excitation_state are:
// - janev_singlet_B1, janev_singlet_B1prime, janev_singlet_B1primeprime, janev_singlet_C1, janev_singlet_D1,
// janev_singlet_D1prime, janev_singlet_symmetry_forbidden_EF1, janev_singlet_symmetry_forbidden_HHb,
// janev_singlet_symmetry_forbidden_GK1, janev_singlet_symmetry_forbidden_I1, janev_triplet_A3, janev_triplet_B3,
// janev_triplet_C3, janev_triplet_D3, janev_triplet_E3, janev_vibrational_first, janev_vibrational_second,
// england_rotational_j0_to_j2, england_rotational_j1_to_j3
std::function<double(double)> buildExcitationCrossSection(
std::string excitation_state);
// if the string target_name is used as a key in either the map for the TrackedSpecies or
// the map for the BackgroundSpecies returns the corresponding Species
// (the keys in the map are defined by the name given in the json parameter file)
std::shared_ptr<species::Specie> findTarget(
std::string& target_name,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
@@ -39,6 +139,9 @@ std::shared_ptr<species::Specie> findTarget(
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>&
background_species);
// if the string target_name is used as a key in either the map for the TrackedSpecies
// returns the corresponding TrackedSpecie
// (the keys in the map are defined by the name given in the json parameter file)
std::shared_ptr<species::TrackedSpecie> findTracked(
std::string& target_name,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
+9
View File
@@ -7,7 +7,16 @@
namespace generator {
// return a shared_ptr to a DeletionLogger object described by the given json-object
// can contain a json-array or a json-string "Type"
// - if it's a json-array: list the DeletionTypes that should be counted
// during the simulation (json-strings: "wall", "recombination", "max_interactions", "max_time_alive" and "cluster_formation")
// - if it's a json-string: has to have the value "all" and then all DeletionTypes are tracked (see list above)
// - if not present: no DeletionTypes are tracked
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object);
// return a shared_ptr to a DeletionLogger object described at the given path
// in the Parameter object, this object has to contain a json-object "Deletion"
// following the structure in the overload of this function
std::shared_ptr<DeletionLogger> buildDeletionLogger(
Parameter& parameter,
const json_path& path_to_logger);
@@ -6,8 +6,15 @@
namespace generator {
// create an MagneticField object from a json_t pointer to an json object
// defining the magnetic field
// has to consist of a json-objects called "VectorField"
// as described in "generators/vector_field_generator.h" (function: "buildVectorField")
std::shared_ptr<MagneticField> magneticField(json_t* object);
// create an MagneticField object from the given Parameter object
// json file has to have a json object called "MagneticField" directly in the root object
// of the parameter file
std::shared_ptr<MagneticField> magneticField(Parameter& parameter);
}; // namespace generator
+7
View File
@@ -4,20 +4,27 @@
#include <map>
#include "jansson.h"
// defined in "simulation/species.h"
namespace species {
enum class ImplementedSpecies;
};
namespace generator {
// class containing a map of the masses (in kg) to the respective ImplementedSpecies
class SpeciesMasses {
public:
// return the mass of the ImplementedSpecies
static double mass(const species::ImplementedSpecies& species);
private:
static std::map<species::ImplementedSpecies, double> mass_;
};
// return the mass of the specie at the json-object
// has to contain either a json-string "FromParticleType" or a json-double "value"
// if "FromParticleType" is specified, it has to be one of the strings defined in the SpecieAlias class in "generators/species_generator.h"
// if "value" is specified, it has to be the value in (kg)
double buildMass(json_t* object);
}; // namespace generator
+16
View File
@@ -7,6 +7,22 @@
namespace generator {
// return a shared_ptr to a Mover object described at the given path in the Parameter file
// the json-object at path_to_mover has to consist of a json-object called either "Boris", "Drift" or "Euler"
// if "Boris" exists:
// - has to contain a json-object "MaximalTimestepLength", which has to contain
// a json-double called "value" giving the maximum allowed timestep for the BorisMover
// in seconds
//
// if "Drift" is specified:
// - has to contain a json-object "MaximalMovedDistance" which has to follow the form
// described in json_read_length ("simulation/jansson_additionals.h")
// specifies the maximal distance a particle is allowed to move in one timestep
//
// if "Euler" is specified:
// - has to contain a json-object "MaximalMovedDistance" which has to follow the form
// described in json_read_length ("simulation/jansson_additionals.h")
// specifies the maximal distance a particle is allowed to move in one timestep
std::shared_ptr<Mover> buildMover(Parameter& parameter,
const json_path& path_to_mover);
@@ -7,6 +7,10 @@
namespace generator {
// return a shared_ptr to a RandomNumbers object
// parameter has to have a json-object "RandomNumbers" in its root object
// "RandomNumbers" has to contain a json-double "Seed" which specifies the seed
// on mpi-process 0 (a different seed is calculated for all other mpi-processes)
std::shared_ptr<RandomNumbers> buildRandomNumbers(Parameter& parameter);
};
+6
View File
@@ -9,6 +9,12 @@
namespace generator {
// return a shared_ptr to a Reflector object described at the given path in the Parameter object
// the object at the path has to consist of a json-object called either "ReflectorDPS"
// or "NoReflector"
// if "ReflectorDPS" exists, a json-object "position_z" has to exist following the structure
// described in json_read_length ("simulation/jansson_additionals.h")
// if "NoReflector" is specified, it can be an empty object
std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
const json_path& path_to_reflector);
@@ -7,6 +7,10 @@
#include "simulation/scalar_field.h"
namespace generator {
// return a shared_ptr to a ScalarField object described in the json-object "object"
// has to contain a json-object "ScalarFieldFunctionInZ"
// - has to contain a json-object "zFunction" defined as in "function3D" (in "generators/function_generator.h")
// (example in "simulation_config/scalar_fields_examples.json")
std::shared_ptr<ScalarField> buildScalarField(json_t* object);
}
@@ -6,13 +6,33 @@
#include <string>
#include "jansson.h"
// defined in "IO/simulation_output.h"
class SimulationOutput;
// defined in "simulation/species.h"
namespace species {
class TrackedSpecie;
};
namespace generator {
// return a shared_ptr to a SimulationOutput object defined in the given json-object
// the json-object has to consist of:
// - a json-string "folder" containing the path to where the ouput file is supposed to be written
// (relative to where the program was started from)
// - a json-string "filename": with the name of the file (a ".h5" is always appended)
// - a json-object "DensityFields", which has to contain:
// - a json-double (interpreted as an int) or a json-string called "Intervall":
// - if it's a json_double it has to > 0
// - if it's a json_string it has to have the value "EachSync", which means that after each cpu-synchronization step
// the ouput is written
// - a json-string "OverwriteLast" with value either "true" or "false" (defaults to false)
// if "true" old data is overwritten each step
// - a json-array or a json-string "Species":
// - if its a json-string it has to have the value "all" (density information is written for each tracked specie)
// - if its a json-array has to be an array of the names used in the "Tracked" object for which
// density output should be written
// - two more json-objects "CurrentBorders" and "DeletionLogger", which follow the same structure
// as the "DensityFields" object
std::shared_ptr<SimulationOutput> buildSimulationOutput(
json_t* object,
const std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
+117
View File
@@ -11,10 +11,13 @@
#include "simulation/parameter.h"
#include "simulation/species.h"
// defined in "simulation/timer.h"
class Timer;
namespace generator {
// structure to store various variables neccessary for the creation
// of TrackedSpecies objects
struct TrackedSpeciesBuilderInfo {
public:
std::shared_ptr<Mover> mover;
@@ -32,6 +35,8 @@ struct TrackedSpeciesBuilderInfo {
json_path path_in_json;
};
// structure to store various variables neccessary for the creation
// of BackgroundSpecies objects
struct BackgroundSpeciesBuilderInfo {
public:
BackgroundSpeciesBuilderInfo()
@@ -49,33 +54,57 @@ struct BackgroundSpeciesBuilderInfo {
json_path path_in_json;
};
// class for mapping between certain strings and ImplementedSpecies enums
class SpeciesAlias {
public:
// return the ImplementedSpecies enum for the given string. If the
// name is not defined as an alias an error is thrown
static species::ImplementedSpecies alias(const std::string& name);
// return the string defined as an alias for the given ImplemetedSpecies enum
// if no alias has been defined returns an empty string
// (if it were to be defined multiple times return the first found instance)
static std::string name(species::ImplementedSpecies specie);
// check if the string name is defined as an alias
static bool isAlias(const std::string& name);
private:
// mapping between the string and enum
static std::map<std::string, species::ImplementedSpecies> specie_aliases;
};
// class mapping between ImplementedSpecies enum and the charge corresponding to
// the physical particle
class SpeciesCharges {
public:
// return the charge of the ImplementedSpecies enum
static double charge(species::ImplementedSpecies species);
private:
static std::map<species::ImplementedSpecies, double> charge_;
};
// class for creation of the TrackedSpecies map and the BackgroudSpecies map
class SpeciesBuilder {
public:
// Constructor: takes the Parameter object created by the input json file
SpeciesBuilder(Parameter& parameter);
// function to create a map of TrackedSpecies and an arbitrary string used to
// identify the TrackedSpecies within the map
// description for the json-object structure can be found in the private functions of
// this class (examples e.g. in "simulation_config/parameter_katrin_example")
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>
trackedSpecies();
// function to create a map of BackgroundSpecies and an arbitrary string used to
// identify the BackgroundSpecies within the map
// description for the json-object structure can be found in the private functions of
// this class (examples e.g. in "simulation_config/parameter_katrin_example")
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>
backgroundSpecies();
// function to create a shared_ptr to a Timer object
std::shared_ptr<Timer> timer();
// function to create a shared_ptr to a Timer object (to be used as a copy of the
// main timer object during cpu synchronization)
std::shared_ptr<Timer> lastSyncTimer();
private:
@@ -89,27 +118,115 @@ class SpeciesBuilder {
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>
background_species;
// checks all json-objects (with an aribtrary name used as the name of the corresponding
// BackgroundSpecie) in the json-object "Background", which is located in the json-object
// "Species" (which is in the root) and creates new entries in the background_species_info
// map (and sets the name and path_in_json members)
//
// example:
// {
// "Species":{
// "Background": {
// "background1": {...},
// ...
// }
// ...
// }
// }
// in this example the name is set to "background1" and path_in_json to ["Species", "Background", "background1"]
void initBackgroundSpecies(Parameter& parameter);
// checks all json-objects (with an aribtrary name used as the name of the corresponding
// BackgroundSpecie) in the json-object "Tracked", which is located in the json-object
// "Species" (which is in the root) and creates new entries in the background_species_info
// map (and sets the name and path_in_json members)
//
// example:
// {
// "Species":{
// "Tracked": {
// "tracked1": {...},
// ...
// }
// ...
// }
// }
// in this example the name is set to "tracked1" and path_in_json to ["Species", "Tracked", "tracked1"]
void initTrackedSpecies(Parameter& parameter);
// for each element of the background_species_info element and for each tracked_species_info element
// fill the velocity_distribution member with a VelocityDistribution object
// described in a json-object called "VelocityDistribution", that has to follow the
// format described in "buildVelocityDistribution" (generators/velocity_distribution_generator.h)
void fillVelocityDistribution(Parameter& parameter);
// for each element of the background_species_info element and for each tracked_species_info element
// fill the drift_velocity member with a DirftVelocity object
// described in a json-object called "DriftVelocity", that has to follow the
// format described in "buildDriftVelocity" (generators/drift_velocity_generator.h)
void fillDriftVelocity(Parameter& parameter);
// for each element of the background_species_info element and for each tracked_species_info element
// fill the mass_kg member with the value defined in the SpeciesMasses class (defined in
// "generators/mass_generator.h")
void fillMass();
// for each element of the background_species_info element and for each tracked_species_info element
// fill the charge_C member with the value defined in the SpeciesCharges class (defined here in
// "generators/species_generator.h")
void fillCharge();
// for all elements in the tracked_species map add the defined interactions
// in the path stored in the corresponding tracked_species_info element (i.e. ["Species", "Tracked", name of the tracked specie])
// a json-object "Interactions" has to exist, this object has to follow the
// format described for the "addInteractions" function (defined in "generators/interaction_generator.h")
void fillInteractions(Parameter& parameter);
// read the json-string "ParticleType" in the json-object at the path stored in
// path_in_json in the BackgroundSpeciesBuilderInfo map for all elements
// "ParticleType" has to be one of the strings defined as an alias in
// the SpeciesAlias class ("generators/species_generator.h")
void fillBackgroundSpecieType(Parameter& parameter);
// for all elements in the BackgroundSpeciesBuilderInfo map create the
// density member with the density field described in the json-object "ConstantDensityField"
// (in the json-object at path_in_json)
// "ConstantDensityField" has to follow the structure described in "buildConstantDensityField"
// (defined in "generators/density_field_generator.h")
void fillBackgroundDensity(Parameter& parameter);
// read the json-string "ParticleType" in the json-object at the path stored in
// path_in_json in the TrackedSpeciesBuilderInfo map for all elements
// "ParticleType" has to be one of the strings defined as an alias in
// the SpeciesAlias class ("generators/species_generator.h")
void fillTrackedSpecieType(Parameter& parameter);
// fill current_collector and last_sync_current_collector members of the
// TrackedSpecies map, created according to the json-object
// "CurrentCollector" (located in at the path_in_json member)
// has to follow the form described in "buildCurrentCollector" ("generators/current_collector_generator.h")
void fillCurrentCollector(Parameter& parameter);
// fill deletion_logger and last_sync_deletion_logger members of the
// TrackedSpecies map, created according to the json-object
// "Loggers" (located in at the path_in_json member)
// has to follow the form described in "buildDeletionLogger" ("generators/logger_generator.h")
void fillLoggers(Parameter& parameter);
// fill mover member of the TrackedSpeciesBuilderInfo map,
// created according to the json-object "Mover" (located in at the path_in_json member)
// has to follow the form described in "buildMover" ("generators/mover_generator.h")
void fillMover(Parameter& parameter);
// fill terminator member of the TrackedSpeciesBuilderInfo map,
// created according to the json-object "Terminator" (located in at the path_in_json member)
// has to follow the form described in "buildTerminator" ("generators/mover_generator.h")
void fillTerminator(Parameter& parameter);
// fill reflector member of the TrackedSpeciesBuilderInfo map,
// created according to the json-object "Reflector" (located in at the path_in_json member)
// has to follow the form described in "buildReflector" ("generators/mover_generator.h")
void fillReflector(Parameter& parameter);
// fill density_field and last_sync_density_field members of the
// TrackedSpeciesBuilderInfo map, created according to the json-object
// "DynamicDensityField" (located in at the path_in_json member)
// has to follow the form described in "buildDyamicDensityField"
void fillTrackedDensity(Parameter& parameter);
// fill timer_ and last_sync_timer_ objects (no json-specifications needed)
void initTimer();
// create the TrackedSpecies and BackgroundSpecies maps from the data contained in
// the corresponding entries of the TrackedSpeciesBuilderInfo and BackgroundSpeciesBuilderInfo
// maps
void buildSpecies();
};
@@ -7,6 +7,13 @@
namespace generator {
// return a shared_ptr to a Terminator object described by the given json-object in the Parameter object
// the object at the path has to contain:
// - a json-double (later cast to an integer) "MaximumInteractions"
// - a json-object "MaxTimeAlive", which has to contain a json-double "value", giving the
// maximum time a particle is allowed to live in seconds
// - a json-object "BoundaryGeometry", which has to follow the structure given in buildGeometry
// ("generators/geometry_generator.h")
std::shared_ptr<Terminator> buildTerminator(
Parameter& parameter,
const json_path& path_to_terminator);
@@ -8,9 +8,57 @@
#include "simulation/vector_field.h"
namespace generator {
// create an VectorField object from a json_t pointer to an json object
// defining the vector field:
// has to contain a json-object with key either: "VectorFieldConstant", "VectorFieldFunctionInZ" or "VectorFieldFromArray"
// if neither of those is specified an error is thrown
// if "VectorFieldConstant" is specified:
// - has to contain a json-object called "constant" containing a json-array of size 3 (r,phi and z component in this ordering)
// with an arbitrary key
// if "VectorFieldFunctionInZ" is specifid:
// - has to contain a json-object with key "zFunction", that defines a function3D (see "generators/function_generator.h")
// if "VectorFieldFromArray" is specified:
// - has to contain a json-object called "ReadArrayFromFile" (see readComponentFromFile)
// - a json-double "Radius" specifying the radial extent for which the read in vector field is defined
// - a json-double "Length" specifying the longitudinal extent for which the read in vector field is defined
// examples for the look in a json file can be found in "simulation_config/vector_field_examples.json"
std::shared_ptr<VectorField> buildVectorField(json_t* object);
// read a path to a file from a json-object consisting of three json-string objects:
// - "Type": acceptable value either "AbsolutePath" or "RelativeToHomebase", if neither is specified throw an error
// - if "Type" is "AbsolutePath", the json-string with key "AbsoluteFolderPath" has to be defined, containing
// the absolute path to the directory the file that should be read is located in
// - if "Type" is "RelativeToHomebase", the json-string with key "RelativePath" has to be defined, containing
// the path relative (wrt the shell variable "HOMEBASE") to the directory the file that should be read is located in
// - the json-string with key "Filename", containing the name of the file to be read
//
// "key_of_object": {
// "Type": "RelativeToHomebase" or "AbsolutePath",
// "RelativePath" or "AbsoluteFolderPath": path to directory
// "Filename": name of file in the path to the directory
// }
std::string readAbsoluteFilename(json_t* object);
// read a single component (radial, azimuthal or longitudinal) into a blitz::Array
// has to consist of:
// - a json_object called "PathToH5" in the format described for the function "readAbsoluteFilename"
// - a json_array "Keys" consisting of the keys of the absolute path to groups that should be read from the given hdf5 file
//
// "key_to_object": {
// "PathToH5" : { ... },
// "Keys": [path to component of vector field in r-dir, path to component of vector field in phi-dir, path to component of vector field in z-dir]
// }
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component);
// read a single 3d array into a blitz::Array
// has to consist of:
// - a json_object called "PathToH5" in the format described for the function "readAbsoluteFilename"
// - a json_string "Key" specifying the path to the array within the hdf5 file
//
// "key_to_object": {
// "PathToH5" : { ... },
// "Key": path within hdf5 file
// }
blitz::Array<double, 3> readFromFile(json_t* object);
} // namespace generator
@@ -8,6 +8,21 @@
namespace generator {
// return a shared_ptr to a VelocityDistributionFunction object described by the json-object
// at the given json_path in the Parameter object
// has to contain a json-object called either "IsotropicDistribution" or "DirectedDistribution"
// if "IsotropicDistribution" is specified:
// - has to include a json-object "EnergyDistributionFunction" as defined in "generators/energy_distribtion_function_generator.h"
// - has to include a json-object "Mass" as defined in "generators/mass_generator.h"
// - returns a IsotropicDistribution object (see simulation/energy_distribtion.h)
//
// if "DirectedDistribution" is specified:
// - has to include a json-object "EnergyDistributionFunction" as defined in "generators/energy_distribtion_function_generator.h"
// - has to include a json-object "Mass" as defined in "generators/mass_generator.h"
// - has to include a json-array of size 3, defining the direction in cartesian coordinates (x,y,z)
// - returns a DirectedDistribution object (see simulation/energy_distribtion.h)
//
// (example in "simulation_config/velocity_distribution_function_examples.json")
std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
Parameter& parameter,
const json_path& path_to_distribution);
@@ -8,6 +8,25 @@
namespace generator {
// return a shared_ptr to a VelocityDistribution object described by the json-object
// at the path "path_to_distribution" (from root object) in the Parameter object
// consisting of a json-object either called "VelocityDistributionFromFunction" or "null"
// if "VelocityDistributionFromFunction" is specified:
// - has to consist of a json-object "VelocityDistributionFunction", as defined in "generators/velocity_distribution_function_generator.h"
//
// if "null" is specified:
// - no further information has to be specified
//
// example:
// "path_to_distribution" : {
// "VelocityDistributionFromFunction": {
// "VelocityDistributionFunction" : { ... }
// }
// }
// or
// "path_to_distribution" : {
// "null": {}
// }
std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
Parameter& parameter,
const json_path& path_to_distribution);
+6
View File
@@ -4,17 +4,23 @@
#include <functional>
#include "simulation/interaction.h"
// defined in "simulation/species.h"
namespace species {
class Specie;
};
namespace interaction {
// class for charge exchange interactions e.g. T2+ + T2 --> T2 + T2+
// only for symmetric charge exchange processes (i.e. A+ + A --> A + A+)
class ChargeExchange : public Interaction {
public:
// Constructor: takes the function describing the cross section (dependent on the energy of the incident particle)
// and a shared_ptr to the Species that is the target in the interaction
ChargeExchange(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target);
// return the result of the interaction as an InteractionOutput object
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
};
+6
View File
@@ -4,17 +4,23 @@
#include <functional>
#include "simulation/interaction.h"
// defined in "simulation/species.h"
namespace species {
class Specie;
};
namespace interaction {
// class for cluster formation interactions (A + B --> AB)
class ClusterFormation : public Interaction {
public:
// Constructor: takes the function describing the cross section (dependent on the energy of the incident particle)
// and a shared_ptr to the Species that is the target in the interaction
// and a shared_ptr to the TrackedSpecie that is the product of the interaction
ClusterFormation(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target,
std::shared_ptr<species::TrackedSpecie> product);
// return an InteractionOutput object with the results of the interaction
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
+56
View File
@@ -7,43 +7,99 @@
namespace interaction {
namespace d2CrossSection {
// returns a function dependent on the initial energy of the electron ionization
// of T2 and the final energy of (one of) the resulting electrons
// function defines the energy distribution of the energy distribution of
// the secondary electron
// (functional form from Kim and Rudd 1994)
std::function<double(double, double)> eT2_ionization_bed();
}
// ? mention how data was obtained ?
namespace totalCrossSection {
// returns function that returns a constant value of 1.4e-19 m²
std::function<double(double)> eT2_elastic_scattering_constant();
// returns a function that linearly interpolates between the values
// defined in the file "data/crossSections/eT2_elastic_scattering/eT2_elastic_cross_section_total.h5"
// (relative to the HOMEBASE variable)
// data for e + T2 elastic scattering
std::function<double(double)> eT2_elastic_scattering();
// return function that describes the total elastic scattering cross section
// for T⁺ + T₂
std::function<double(double)> TpT2_elastic_scattering_tabata();
// return function that describes the total elastic scattering cross section
// for T₃⁺ + T₂
std::function<double(double)> T3pT2_elastic_scattering_tabata();
// return a function that describes the cross section for charge exchange
// T₂⁺ + T₂ --> T₂ + T₂⁺
std::function<double(double)> T2pT2_charge_exchange_janev();
// return a function describing the cross section for electron ionization of
// T₂: T₂ + e¯ --> T₂⁺ + 2e¯ (?)
std::function<double(double)> eT2_ionization_bed();
// return a function describing the non-dissociative cross section for electron ionization of
// T₂: T₂ + e¯ --> T₂⁺ + 2e¯
std::function<double(double)> eT2_ionization_janev_non_diss();
// return a function describing the cross section for dissociative electron ionization of
// T₂, where the products are in the ground state: T₂ + e¯ --> T⁺ + T + 2e¯ (?)
std::function<double(double)> eT2_ionization_janev_diss_ground();
// return a function describing the cross section for dissociative electron ionization of
// T₂, where the products are in the first excited state: T₂ + e¯ --> T⁺ + T* + 2e¯ (?)
std::function<double(double)> eT2_ionization_janev_diss_first();
// return a function describing the cross section for radiative clustering of T⁺ and T₂:
// T⁺ + T₂ --> T₃⁺ + h\nu
std::function<double(double)> TpT2_clustering_radiative_ascendion_pasil();
// return a function describing the cross section for tertiary clustering of T⁺ and T₂:
// T⁺ + 2T₂ --> T₃⁺ + T₂
std::function<double(double)> TpT2_clustering_tertiary_ascendion_pasil();
// return a function describing the cross section for clustering of T₂⁺ and T₂:
// T₂⁺ + T₂ --> T₃⁺ + T
std::function<double(double)> T2pT2_clustering_janev();
// return a function describing the cross section for electronic excitation of T₂ by
// the impact of an electron from the singlet ground state to the final state
// specified in the string "final_state". final_state has to have one of the following
// values: "B1", "B1prime", "B1primeprime", "C1", "D1", "D1prime"
std::function<double(double)>
eT2_excitation_electric_janev_from_singlet_ground_state(
std::string final_state);
// return a function describing the cross section for electronic excitation of T₂ by
// the impact of an electron from the singlet ground state to the final state that is
// forbidden by the symmetry of the system specified in the string "final_state".
// final_state has to have one of the following values:
// "EF1", "HHb", "GK1", "I1"
std::function<double(double)>
eT2_excitation_electric_janev_from_singlet_ground_state_symmetry_forbidden(
std::string final_state);
// return a function describing the cross section for electronic excitation of T₂ by
// the impact of an electron from the triplet ground state to the final state
// specified in the string "final_state". final_state has to have one of the following
// values: "A3", "B3", "C3", "D3", "E3"
std::function<double(double)>
eT2_excitation_electric_janev_from_triplet_ground_state(
std::string final_state);
// return a function describing the cross section for vibrational excitation of T₂
// from ground to first excited state by electron impact.
std::function<double(double)> eT2_excitation_vibrational_janev_first();
// return a function describing the cross section for vibrational excitation of T₂
// from ground to second excited state by electron impact.
std::function<double(double)> eT2_excitation_vibrational_janev_second();
// return a function describing the cross section for rotational excitation of T₂
// from ground to second excited state by electron impact.
std::function<double(double)> eT2_excitation_rotational_j0_to_j2_england();
// return a function describing the cross section for rotational excitation of T₂
// from first to third excited state by electron impact.
std::function<double(double)> eT2_excitation_rotational_j1_to_j3_england();
// return a function describing the cross section for recombination of T₂⁺ with an
// electron: T₂⁺ + e⁼ --> T₂
std::function<double(double)> eT2p_recombination_janev();
// return a function describing the cross section for recombination of T₃⁺ with an
// electron: T₃⁺ + e⁼ --> T₂ + T
std::function<double(double)> eT3p_recombination_janev();
}; // namespace totalCrossSection
@@ -7,12 +7,16 @@ class ScatteringAngleDistribution;
namespace interaction {
// class for handling elastic scattering interactions (A + B --> A + B)
class ElasticScattering : public Interaction {
public:
// Constructor: takes a function for the cross section, a shared_ptr with the Specie of the target of the interaction
// and a shared_ptr to a scatteringAngleDistribution object
ElasticScattering(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target,
std::shared_ptr<ScatteringAngleDistribution> theta_distrib);
// return the interaction outcome as an InteractionOutput object
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
+6
View File
@@ -6,18 +6,24 @@
#include "simulation/particle.h"
#include "simulation/random_numbers.h"
// defined in "simulation/species.h"
namespace species {
class Specie;
};
namespace interaction {
// class for handling processes consisting of the excitation (rotational, vibrational or
// electronic) of the target particle (e.g. A + B --> A + B*)
class Excitation : public Interaction {
public:
// Constructor: takes the function for the cross section, a shared_ptr to the Specie of the
// the threshold energy of the specific excitation type
Excitation(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target,
double excitation_energy_eV);
// return the output of the interaction as an InteractionOutput object
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
+6
View File
@@ -7,13 +7,19 @@
namespace interaction {
// class for dummy interaction "free movement" (i.e. no interaction)
class FreeMovement : public Interaction {
public:
// Constructor: does not need anything
FreeMovement();
// return the result of the interaction as an InteractionOutput object
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
// return the value of the cross section at the given energy (eV) (units: m^2)
double microscopicCrossSection(double energy_eV);
// return the density scaled cross section value for the energy of the
// Particle (units m^{-1})
double macroscopicCrossSection(particle::Particle& particle);
};
+26
View File
@@ -5,11 +5,18 @@
namespace interaction {
// class for drawing the energy of the outgoing electron (i.e. the slower one of the
// two electrons that exist after the interaction)
class IonizationEnergyDistribution {
public:
// Constructor: takes a function dependent on the energy of the incident particle
// and the energy of the ejected electron. Function should describe
// the energy distribution of the ejected electron.
// takes the ionization threshold energy in eV
IonizationEnergyDistribution(
std::function<double(double, double)> d2_cross_section,
double ionization_energy_eV);
// draw the energy (always < (impact_energy - ionization_energy)/2) of the ejected particle
double rollImpactParticleEnergyAfterCollision(double impact_energy,
RandomNumbers* generator);
@@ -18,20 +25,37 @@ class IonizationEnergyDistribution {
const double ionization_energy_eV_;
};
// function handling the azimuthal angle distribution for
// electron ionization
class IonizationScatteringAngleDistribution {
public:
// draw the azimuthal angle of the faster electron after collision
// impact_energy is the kinetic energy of the particle in the rest frame of the target in eV before the collision
// impact_energy is the kinetic energy of the particle (the faster of the two electrons) in the rest frame of the target in eV after the collision
double rollAzimuthImpactParticleAfterCollision(
double impact_energy,
double energy_impact_particle_new,
RandomNumbers* generator);
// draw the azimuthal angle of the slower electron after collision
// impact_energy is the kinetic energy of the particle in the rest frame of the target in eV before the collision
// impact_energy is the kinetic energy of the particle (the slower of the two electrons) in the rest frame of the target in eV after the collision
double rollAzimuthEjectedParticleAfterCollision(
double impact_energy,
double energy_impactParticle_new,
RandomNumbers* generator);
};
// class for handling electron impact ionization
class ElectronIonization : public Interaction {
public:
// Constructor: takes a function describing the cross section for the interaction
// a shared_ptr to the Specie of the target particle
// a shared_ptr to the TrackedSpecie electron describing the incident electron
// a shared_ptr to the TrackedSpecie ion describing the positive ion type that is created
// a shared_ptr to the IonizationEnergyDistribution, descibing the energy distribution of either
// of the two electrons after the interaction
// a shared_ptr to the IonizationScatterinAngleDistribution, which describes the
// azimuthal angle distribution of both final electrons
ElectronIonization(
std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target,
@@ -41,6 +65,8 @@ class ElectronIonization : public Interaction {
std::shared_ptr<IonizationScatteringAngleDistribution> angle_distribution,
double ionization_energy_eV);
// perform the interaction and return an InteractionOutput object
// containing the corresponding information (new particles)
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
+6 -1
View File
@@ -5,14 +5,19 @@
namespace interaction {
// class for handling recombination between two simulated species (TrackedSpecies)
class Recombination : public Interaction {
public:
// Constructor: takes a function describing the energy dependent cross section
// and a shared_ptr to the TrackedSpecie that is the target in the interaction
Recombination(std::function<double(double)> cross_section,
std::shared_ptr<species::TrackedSpecie> target);
// return the result of the interaction as an InteractionOutput object
InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator);
// return the cross section scaled by the density of the target at the position
// of the incident particle (units: m^{-1})
double macroscopicCrossSection(particle::Particle& particle);
private:
+2
View File
@@ -3,6 +3,8 @@
#include "constants/sim_constants.h"
// check if a and b are the same up to an accuracy eps defined in constants/sim_constants.h
// isEqual(a,b) = true <=> abs(a - b) < eps
bool isEqual(double a, double b) {
return std::abs(a - b) < SimConstants::compare_epsilon;
}
+64 -1
View File
@@ -3,41 +3,62 @@
#include "blitz/array.h"
// Note: seems to be deprecated
// structure to store a coordinate wrt the binning of the simulation domain
struct BinCoordinate {
// Constructor using a blitz::TinyVector<int,3> containing the values defining a bin
// and the position frac within that bin
BinCoordinate(const blitz::TinyVector<int, 3>& bin,
const blitz::TinyVector<double, 3>& frac);
// Constructor using a blitz::TinyVector<double,3> containing the position and the spacing
// to calculate the bin and frac values
BinCoordinate(blitz::TinyVector<double, 3> position,
blitz::TinyVector<double, 3> spacing);
blitz::TinyVector<int, 3> bin;
blitz::TinyVector<double, 3> frac;
// return the blitz::TinyVector<int, 3> containing the bin of the variable
// position using the specified "spacing"
static blitz::TinyVector<int, 3> binValue(
blitz::TinyVector<double, 3> position,
blitz::TinyVector<double, 3> spacing);
// return the blitz::TinyVector<int, 3> containing the fractional value within a bin
// of the variable position using the specified "spacing"
static blitz::TinyVector<double, 3> binFrac(
blitz::TinyVector<double, 3> position,
blitz::TinyVector<double, 3> spacing);
};
// parent class for different Coordinate types (cartesian, cylinder)
// cannot be instantiated
class Coordinate {
public:
// return the value of the stored coordinate transformed to Cartesian space
virtual blitz::TinyVector<double, 3> cartesianEntries() const = 0;
// return the value of the stored coordinate transformed to Cylinder space
virtual blitz::TinyVector<double, 3> cylinderEntries() const = 0;
// add the values of the parameter coordinate to the value stored in this variable
virtual void add(const Coordinate& coordinate) = 0;
};
// class for storing and handling of coordinates in cartesian space
class CartesianCoordinate : public Coordinate {
public:
// Constructor using a blitz::TinyVector that holds the values of a cartesian coordinate (x,y,z)
CartesianCoordinate(const blitz::TinyVector<double, 3>& cartesian_position);
// Constructor using an arbitrary Coordinate object
CartesianCoordinate(const Coordinate& coordinate);
// return the value of the stored coordinate transformed to Cartesian space
blitz::TinyVector<double, 3> cartesianEntries() const;
// return the value of the stored coordinate transformed to Cylider space
blitz::TinyVector<double, 3> cylinderEntries() const;
// add the values of the parameter coordinate to the value stored in this variable
void add(const Coordinate& coordinate);
private:
@@ -46,62 +67,104 @@ class CartesianCoordinate : public Coordinate {
class CylinderCoordinate : public Coordinate {
public:
// Constructor using a blitz::TinyVector that holds the values of a cylinder coordinate (r,phi,z)
CylinderCoordinate(const blitz::TinyVector<double, 3>& cylinder_position);
// Constructor using an arbitrary Coordinate object
CylinderCoordinate(const Coordinate& coordinate);
// return the value of the stored coordinate transformed to Cartesian space
blitz::TinyVector<double, 3> cartesianEntries() const;
// return the value of the stored coordinate transformed to Cylinder space
blitz::TinyVector<double, 3> cylinderEntries() const;
// add the values of the parameter coordinate to the value stored in this variable
void add(const Coordinate& coordinate);
private:
// transform phi to be in the interval [0, 2pi]
void limitPhi();
blitz::TinyVector<double, 3> cylinder_position;
};
// parent class for different types of vectors (cartesian vector, cylinder vector)
class Vector {
public:
// return the stored value as a cartesian vector, the transformation depends on
// the Coordinate, where the Vector is defined
virtual blitz::TinyVector<double, 3> cartesianEntries(
const Coordinate& coordinate) const = 0;
// return the stored value as a cylinder vector, the transformation depends on
// the Coordinate, where the Vector is defined
virtual blitz::TinyVector<double, 3> cylinderEntries(
const Coordinate& coordinate) const = 0;
// Add the Vector vector to the value stored in this object; for the addition both
// Vectors have to be in the same space (i.e. Cartesian or Cylinder) therefore
// the Coordinate is necessary for potential transformations
virtual void add(const Vector& vector, const Coordinate& coordinate) = 0;
};
// class for storing and handling of Cylinder Vectors (v_r, v_phi, v_z)
class CylinderVector : public Vector {
public:
// copy constructor
CylinderVector(const CylinderVector& vector);
// constructor using a blitz::TinyVector containing the cylinder vector components
// of a vector
CylinderVector(const blitz::TinyVector<double, 3> cylinder_vector);
// constructor using an arbitrary vector, needs the Coordinate of the vector
// to transform into cylinder space
CylinderVector(const Vector& vector, const Coordinate& coordinate);
// overwrite the "+"-Operator for the addtion of two CylinderVector objects
CylinderVector operator+(const CylinderVector& coordinate);
// return the stored value as a cartesian vector, the transformation depends on
// the Coordinate, where the CylinderVector is defined
blitz::TinyVector<double, 3> cartesianEntries(
const Coordinate& coordinate) const;
// return the stored values as a cylinder vector; overwrite of the pure virtual
// function in the Vector class
blitz::TinyVector<double, 3> cylinderEntries(
const Coordinate& coordinate) const;
// returns the entries of the CylinderVector without the need for the Coordinate
blitz::TinyVector<double, 3> cylinderEntries() const;
// Add the Vector vector to the value stored in this object; for the addition both
// Vectors have to be in the same space (i.e. Cartesian or Cylinder) therefore
// the Coordinate is necessary for potential transformations
void add(const Vector& vector, const Coordinate& coordinate);
private:
blitz::TinyVector<double, 3> cylinder_vector;
};
// class for storing and handling of Cylinder Vectors (v_x, v_y, v_z)
class CartesianVector : public Vector {
public:
// constructor using a blitz::TinyVector containing the cartesian vector components
// of a vector
CartesianVector(const blitz::TinyVector<double, 3> cartesian_vector);
// copy constructor
CartesianVector(const CartesianVector& vector);
// constructor using an arbitrary vector, needs the Coordinate of the vector
// to transform into cartesian space
CartesianVector(const Vector& vector, const Coordinate& coordinate);
// return the stored values as a cartesian vector; overwrite of the pure virtual
// function in the Vector class
blitz::TinyVector<double, 3> cartesianEntries(
const Coordinate& coordinate) const;
// returns the entries of the CartesianVector without the need for the Coordinate
blitz::TinyVector<double, 3> cartesianEntries() const;
// return the stored value as a cylinder vector, the transformation depends on
// the Coordinate, where the CartesianVector is defined
blitz::TinyVector<double, 3> cylinderEntries(
const Coordinate& coordinate) const;
// Add the Vector vector to the value stored in this object; for the addition both
// Vectors have to be in the same space (i.e. Cartesian or Cylinder) therefore
// the Coordinate is necessary for potential transformations
void add(const Vector& vector, const Coordinate& coordinate);
private:
+46 -3
View File
@@ -6,42 +6,85 @@
#include <string>
#include "blitz/array.h"
// defined in "simulation/density_field.h"
class DynamicDensityField;
// defined in "simulation/timer.h"
class Timer;
// defined in "simulation/current_collector.h"
class CurrentCollector;
// defined in "simulation/logger.h"
class DeletionLogger;
// defined in "simulation/species.h"
namespace species {
class TrackedSpecie;
};
// class to synchronize states between mpi-processes
class CpuSynchronizer {
public:
// CpuSynchronizer();
// function to handle synchronization of the map of TrackedSpecie
// synchronizes the timer, all CurrentCollectors, DynamicDensityFields and DeletionLoggers
void synchronize(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
tracked_species);
// function to synchronize a DynamicDensityField;
// last_sync_field includes the state of the DynamicDensityField after the last
// synchronization, neccessary to calculate changes that have to be communicated
// after the synchronization both field and last_sync_field contain the same data
// but are different objects
void synchronize(DynamicDensityField* field,
DynamicDensityField* last_sync_field);
// function to synchronize a CurrentCollector;
// last_sync_collector includes the state of the CurrentCollector after the last
// synchronization, neccessary to calculate changes that have to be communicated
// after the synchronization both collector and last_sync_collector contain the same data
// but are different objects
void synchronize(CurrentCollector* collector,
CurrentCollector* last_sync_collector);
// function to synchronize a DeletionLogger;
// last_sync_logger includes the state of the DeletionLogger after the last
// synchronization, neccessary to calculate changes that have to be communicated
// after the synchronization both logger and last_sync_logger contain the same data
// but are different objects
void synchronize(DeletionLogger* logger,
DeletionLogger* last_sync_logger);
// function to synchronize a Timer;
// last_sync_timer includes the state of the Timer after the last
// synchronization, neccessary to calculate changes that have to be communicated
// after the synchronization both timer and last_sync_timer contain the same data
// but are different objects
void synchronize(Timer* timer, Timer* last_sync_timer);
/*
sums delta = * - last_sync_* to last_sync_* over all CPUs
*/
// calculates delta = array - last_sync_array, then collects all deltas of all
// mpi-processes and adds them to last_sync_array (i.e. array does not get modified)
void sumToAll(blitz::Array<double, 4>& array,
blitz::Array<double, 4>& last_sync_array);
// calculates delta = array - last_sync_array, then collects all deltas of all
// mpi-processes and adds them to last_sync_array so that
// afterwards last_sync_array has the same values on each mpi-process
// (i.e. array does not get modified)
void sumToAll(blitz::Array<double, 3>& array,
blitz::Array<double, 3>& last_sync_array);
// calculates delta = array - last_sync_array, then collects all deltas of all
// mpi-processes and adds them to last_sync_array so that
// afterwards last_sync_array has the same values on each mpi-process
// (i.e. array does not get modified)
void sumToAll(blitz::Array<long int, 4>& array,
blitz::Array<long int, 4>& last_sync_array);
// calculates delta = value - last_sync_value, then collects all deltas of all
// mpi-processes and adds them to last_sync_value so that
// afterwards last_sync_value has the same value on each mpi-process
// (i.e. array does not get modified)
void sumToAll(double& value, double& last_sync_value);
// calculates delta = array - last_sync_array, then collects all deltas of all
// mpi-processes and adds them to last_sync_value so that
// afterwards last_sync_value has the same value on each mpi-process
// (i.e. array does not get modified)
void sumToAll(long int& value, long int& last_sync_value);
};
+63
View File
@@ -7,55 +7,117 @@
#include "simulation/position_binning.h"
#include "simulation/timer.h"
// class to store and calculate particle currents
class CurrentCollector {
public:
// Constructor: takes a CylinderBinning object to create the crossing and area arrays
// a shared_ptr of a timer object (object be shared between all
// CurrentCollectors and DensityFields regardless of specie)
CurrentCollector(const CylinderBinning& position_binning,
std::shared_ptr<Timer> timer);
// from the pointer to the particle and the Coordinate of an old position (e.g. before movement)
// crossings over bin boundaries are determined and stored
void collect(particle::Particle* particle, const Coordinate& old_position);
// returns the blitz::Array containing the crossings out of the bins in radial direction
blitz::Array<double, 3> negativeCrossingsInR() const;
// returns the blitz::Array containing the crossins into the bins in radial direction
blitz::Array<double, 3> positiveCrossingsInR() const;
// return a blitz::Array with the areas of the bin borders in radial direction
blitz::Array<double, 3> areaInR() const;
// return a blitz::Array with the particle current in radial direction (in m^-2s^-1)
blitz::Array<double, 3> currentInR() const;
// returns the blitz::Array containing the crossings out of the bins in azimuthal direction
blitz::Array<double, 3> negativeCrossingsInPhi() const;
// returns the blitz::Array containing the crossins into the bins in azimuthal direction
blitz::Array<double, 3> positiveCrossingsInPhi() const;
// return a blitz::Array with the areas of the bin borders in azimuthal direction
blitz::Array<double, 3> areaInPhi() const;
// return a blitz::Array with the particle current in azimuthal direction (in m^-2s^-1)
blitz::Array<double, 3> currentInPhi() const;
// returns the blitz::Array containing the crossings out of the bins in longitudinal direction
blitz::Array<double, 3> negativeCrossingsInZ() const;
// returns the blitz::Array containing the crossins into the bins in longitudinal direction
blitz::Array<double, 3> positiveCrossingsInZ() const;
// return a blitz::Array with the areas of the bin borders in longitudinal direction
blitz::Array<double, 3> areaInZ() const;
// return a blitz::Array with the particle current in longitudinal direction (in m^-2s^-1)
blitz::Array<double, 3> currentInZ() const;
// return the time from the Timer object
double physicalTime() const;
// give the CpuSynchronizer class access to the private member variables to
// make synchronization between processes simpler
friend class CpuSynchronizer;
private:
// determine whether the particle moves out of or into a bin in radial direction from two TinyVectors containing
// the indices of two bins of the CylinderBinning, the corresponding crossings member array
// is then updated at the closest boundary position of the new bin; if multiple bins would
// be crossed only the boundary described above will receive an update
void collectRadialMovement(const blitz::TinyVector<int, 3>& bin_old,
const blitz::TinyVector<int, 3>& bin_new);
// determine whether the particle moves out of or into a bin in longitudinal direction from two TinyVectors containing
// the indices of two bins of the CylinderBinning, the corresponding crossings member array
// is then updated at the closest boundary position of the new bin; if multiple bins would
// be crossed only the boundary described above will receive an update
void collectLongitudinalMovement(const blitz::TinyVector<int, 3>& bin_old,
const blitz::TinyVector<int, 3>& bin_new);
// determine whether the particle moves out of or into a bin in azimuthal direction from two TinyVectors containing
// the indices of two bins of the CylinderBinning, the corresponding crossings member array
// is then updated at the closest boundary position of the new bin (periodic nature is accouted for); if multiple bins would
// be crossed only the boundary described above will receive an update
void collectAzimuthalMovement(const blitz::TinyVector<int, 3>& bin_old,
const blitz::TinyVector<int, 3>& bin_new);
/*
schematics for the numbering of the bins and the corresponding borders
longitudinal:
underflow bin 0 bin 1 bin 2 ... bin N-1 overflow
---------|------------|------------|------------| ... |------------|--------
border_0 border_1 border_2 border_3 ... border_N-1 border_N
radial:
bin 0 bin 1 bin 2 ... bin N-1 overflow
----------|------------|------------| ... |------------|--------
border_0 border_1 border_2 ... border_N-2 border_N-1
azimuthal:
bin N-1 bin 0 bin 1 bin 2 ... bin N-1 bin 0
---------|------------|------------|------------| ... |------------|--------
border_0 border_1 border_2 border_3 ... border_N-1 border_0
*/
// create the array containing the areas of the different boundary sections between bins in longitudinal direction
// uses the provided CylinderBinning for the spacings of the bins
blitz::Array<double, 3> createAreaLongitudinal(
const CylinderBinning& position_binning);
// return an array for the counting of crossings across the bin borders in longitudinal direction
blitz::Array<double, 3> createCrossingsLongitudinal(
const CylinderBinning& position_binning);
// return an array containing the areas of the different boundary sections between bins in radial direction
// uses the provided CylinderBinning for the spacings of the bins
blitz::Array<double, 3> createAreaRadial(
const CylinderBinning& position_binning);
// return an array for the counting of crossings across the bin borders in radial direction
blitz::Array<double, 3> createCrossingsRadial(
const CylinderBinning& position_binning);
// create the array containing the areas of the different boundary sections between bins in azimuthal direction
// uses the provided CylinderBinning for the spacings of the bins
blitz::Array<double, 3> createAreaAzimuthal(
const CylinderBinning& position_binning);
// return an array for the counting of crossings across the bin borders in azimuthal direction
blitz::Array<double, 3> createCrossingsAzimuthal(
const CylinderBinning& position_binning);
// Arrays for the storage of boundary crossings
blitz::Array<double, 3> z_negative_crossings;
blitz::Array<double, 3> z_positive_crossings;
@@ -65,6 +127,7 @@ class CurrentCollector {
blitz::Array<double, 3> r_negative_crossings;
blitz::Array<double, 3> r_positive_crossings;
// Arrays with the size area of the boundary segments
blitz::Array<double, 3> collector_areas_r;
blitz::Array<double, 3> collector_areas_phi;
blitz::Array<double, 3> collector_areas_z;
+44
View File
@@ -9,46 +9,79 @@
#include "simulation/position_binning.h"
#include "simulation/timer.h"
// defined in "simulation/scalar_field.h"
class ScalarField;
// defined in "simulation/event_position_dirstribution.h"
class EventPositionDistribution;
// class for a generic density field, specifying the minimum requirements
class DensityField {
public:
// pure virtual function requiring that a function to obtain the density (m^-3) at
// the Coordinate position is returned
virtual double density(const Coordinate& position) = 0;
// pure virtual function requiring that a function to obtain the density (m^-3) at
// the Coordinate position and energy energy_eV is returned
virtual double density(const Coordinate& position, double energy_eV) = 0;
};
// class for the density field for TrackedSpecies, i.e. simulated species
class DynamicDensityField : public DensityField {
public:
// Constructor: create the necessary array storing the time particles (4d r,phi,z,E) have spent in a bin,
// a corresponding array that stores the number of deletions (4d r,phi,z,E) in a bin
// as well as the 4d array for the actual density (in m^-3) and the
// array with the volumes of the individual bins from the CylinderBinning and EnergyBinnig
DynamicDensityField(const CylinderBinning& position_binning,
const EnergyBinning& energy_binning,
std::shared_ptr<Timer> timer);
// returns true if the bin of the old_position Coordinate and the bin of the
// new_position Coordinate are different otherwise returns false
bool changedPositionBin(const Coordinate& old_position,
const Coordinate& new_position) const;
// returns true if the bin of old_energy_eV is different than the bin of new_energy_eV
// otherwise returns false
bool changedEnergyBin(double old_energy_eV, double new_energy_eV) const;
// increases the value of the time_in_bin array by time_in_bin_s at the bin index
// determined by the Coordinate position and energy_eV
void logMovement(const Coordinate& position,
double energy_eV,
double time_in_bin_s);
// increases the value of the deleted_particles array by 1 at the bin index determined
// by position and energy_eV
void logDeletion(const Coordinate& position, double energy_eV);
// return the value of the density_per_m3 array at the bin index
// determined by the Coordinate position summed over all energy bins
double density(const Coordinate& position);
// return the value of the density_per_m3 array at the bin index
// determined by the Coordinate position and energy_eV
double density(const Coordinate& position, double energy_eV);
// calculate and return the 3d density array (m^-3), no resolution in the energy direction
blitz::Array<double, 3> densityArray();
// calculate and return the 4d density array (m^-3), with a resolution in energy direction
blitz::Array<double, 4> spectrumArray();
// getter for the time_in_bin array
blitz::Array<double, 4> timeInBinArray() const;
// getter for the deleted_particles array
blitz::Array<long int, 4> deletedParticlesArray() const;
// getter for the bin_volume_m3 array
blitz::Array<double, 3> binVolumeArray() const;
// return a raw pointer to the EnergyBinning member object
const EnergyBinning* energyBinning() const;
// return a raw pointer to the CylinderBinning member object
const CylinderBinning* positionBinning() const;
// return the time from the timer member
double physicalTime() const;
// make the private member variables accessable by the CpuSynchronizer
friend class CpuSynchronizer;
private:
@@ -66,11 +99,17 @@ class DynamicDensityField : public DensityField {
// 0, ..., num_bin_z-1: 0 <= z < z_max
// num_bin_z: z >= z_max
BinCoordinate densityBin(const CylinderCoordinate& position) const;
// uses time_in_bin, deleted_particles (4d), bin_volume_m3 (3d) and the timer to
// recalculate the density_per_m3 array (4d)
void recalculateDensityArray();
// array storing the cumulative time particles of a species have spent in certain bins
blitz::Array<double, 4> time_in_bin_s_;
// array storing the cumulative time particles of a species have been deleted due to recombination
blitz::Array<long int, 4> deleted_particles_;
// array storing the physical density (units: m^-3), histogram in energy dimension
blitz::Array<double, 4> density_per_m3_;
// arrya storing the volumes of the individual bins of the time_in_bin array (or rather the CylinderBinning object)
blitz::Array<double, 3> bin_volume_m3_;
const CylinderBinning position_binning_;
@@ -79,11 +118,16 @@ class DynamicDensityField : public DensityField {
std::shared_ptr<Timer> timer_;
};
// class for the density field for BackgroundSpecies, i.e. non-simulated species
class ConstantDensityField : public DensityField {
public:
// Constructor: making the shared_ptr density a member variable
ConstantDensityField(std::shared_ptr<ScalarField> density);
// return the value of the of the ScalarField density at the position Coordinate position
double density(const Coordinate& position);
// return the value of the of the ScalarField density at the position Coordinate position
// (energy_eV is ignored, since ScalarField does not have an energy resolution)
double density(const Coordinate& position, double energy_eV);
private:
+3
View File
@@ -6,10 +6,13 @@
#include "simulation/coordinates.h"
#include "simulation/vector_field.h"
// class to handle the drift veloctiy
class DriftVelocity {
public:
// Constructor: takes a VectorField that describes the direction of the drift velocity
DriftVelocity(std::shared_ptr<VectorField> drift_velocity);
// returns the drift velocity value at the Coordinate position as a CartesianVector
CartesianVector driftVelocity(const Coordinate& position);
private:
@@ -7,13 +7,20 @@
#include "simulation/scalar_field.h"
#include "simulation/vector_field.h"
// class for an electric field; consists of two VectorField objects
// one for the dynamic electric field, i.e. calculated during the simulation (not yet implemented, right now behaves the same as the background field)
// one for the background field, i.e. a field read in from an input file
class ElectricField {
public:
// Constructor: setting the background and dynamic field to the provided VectorFields
ElectricField(std::shared_ptr<VectorField> background,
std::shared_ptr<VectorField> dynamic);
// return the value of the electric field at the Coordinate position (sum of the background and dynamic field values)
// as a CylinderVector
CylinderVector value(const Coordinate& position) const;
// set the dynamic field to the provided field
void updateDynamicField(std::shared_ptr<VectorField> field);
private:
@@ -21,10 +28,13 @@ class ElectricField {
std::shared_ptr<VectorField> dynamic_;
};
// class for a magnetic field
class MagneticField {
public:
// Constructor: takes the VectorField describing the magnetic field
MagneticField(std::shared_ptr<VectorField> field);
// return the value of the magnetic field at Coordinate position as a CylinderVector
CylinderVector value(const Coordinate& position) const;
private:
+16
View File
@@ -3,18 +3,34 @@
#include <vector>
// class defining the grid for the energy-direction (includes an over- and underflow bin)
class EnergyBinning {
public:
// Constructor: create the EnergyBinning by using the minimal_energy (has to be positive and in eV units)
// as the lower boundary and the maximal_energy (in eV) as the upper boundary with num_bins bins
// the bin borders are created using a log10-spacing
EnergyBinning(double minimal_energy, double maximal_energy, int num_bins);
// Constructor: create an EnergyBinning with the bin borders being defined in the
// vector energy_bin_borders (has to contain the values of the edges of the energy-bins;
// for the lowest energy bin the left boundary has to be given as well, similar for the
// highest energy bin the upper boundary value has to be given as well)
EnergyBinning(std::vector<double> energy_bin_borders);
// return the index of the energy bin that contains the given energy_eV (in eV)
// if energy_eV < minimal_energy then -1 is returned (underflow bin)
// if energy_eV > maximal_energy then numBins is returned (overflow bin)
int bin(double energy_eV) const;
// returns the number of bins (not the number of bin borders!)
int numBins() const;
// returns the vector containing the energy bin borders
std::vector<double> binBorders() const;
// return the index of the underflow bin
int binIndexMin() const;
// return the index of the overflow bin
int binIndexMax() const;
private:
// vector containing the values of the bin edges
const std::vector<double> energy_bin_borders_;
};
+15 -3
View File
@@ -4,14 +4,20 @@
#include <functional>
#include <random>
// class defining the minimum requirements of an EnergyDistributionFunction child class
class EnergyDistributionFunction {
public:
virtual double rollEnergy(std::mt19937* engine) = 0; // eV
// draw an energy value using the provided engine in eV
virtual double rollEnergy(std::mt19937* engine) = 0;
};
// class for drawing an energy value from the Fermi spectrum of the Tritium beta decay
// using the rejection method
class TritiumBetaDecay : public EnergyDistributionFunction {
public:
// Constructor: initializes the random distributions
TritiumBetaDecay();
// draw an energy (eV) from the Fermi spectrum of the Tritium beta decay
double rollEnergy(std::mt19937* engine);
private:
@@ -20,18 +26,24 @@ class TritiumBetaDecay : public EnergyDistributionFunction {
std::uniform_real_distribution<double> y_distribution_;
};
// class for drawing an energy value from the Maxwell Boltzmann energy distribution
class MaxwellBoltzmann : public EnergyDistributionFunction {
public:
// initialize the distribution with the temperature (in K)
MaxwellBoltzmann(double temperature_K);
double rollEnergy(std::mt19937* engine); // eV
// draw an energy (in eV) from the Maxwell Boltzmann energy distribtion
double rollEnergy(std::mt19937* engine);
private:
std::gamma_distribution<double> distribution_;
};
// class for returnig a constant energy value
class Constant : public EnergyDistributionFunction {
public:
// Constructor: takes the energy value (in eV) that will be returned later
Constant(double constant_eV);
double rollEnergy(std::mt19937* engine); // eV
// return the energy (in eV) set at construction of the object
double rollEnergy(std::mt19937* engine);
private:
const double constant_eV_;
};
+50
View File
@@ -9,6 +9,7 @@
#include "simulation/mpi_communication.h"
// if any debug is defined, define the main function to print the debugging message
#if defined debug_level3 || defined debug_level2 || defined debug_level1 || \
defined debug_level0
inline void DEBUG(const std::string& message) {
@@ -16,45 +17,78 @@ inline void DEBUG(const std::string& message) {
<< std::endl;
}
// depending on the debug level, activate the corresponding debugging function
#if defined debug_level0
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 0
inline void DEBUG_LEVEL_0(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 1
inline void DEBUG_LEVEL_1(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 2
inline void DEBUG_LEVEL_2(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 3
inline void DEBUG_LEVEL_3(const std::string& message) {}
#elif defined debug_level1
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 0
inline void DEBUG_LEVEL_0(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 1
inline void DEBUG_LEVEL_1(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 2
inline void DEBUG_LEVEL_2(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 3
inline void DEBUG_LEVEL_3(const std::string& message) {}
#elif defined debug_level2
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 0
inline void DEBUG_LEVEL_0(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 1
inline void DEBUG_LEVEL_1(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 2
inline void DEBUG_LEVEL_2(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 3
inline void DEBUG_LEVEL_3(const std::string& message) {}
#else
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 0
inline void DEBUG_LEVEL_0(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 1
inline void DEBUG_LEVEL_1(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 2
inline void DEBUG_LEVEL_2(const std::string& message) {
DEBUG(message);
}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 3
inline void DEBUG_LEVEL_3(const std::string& message) {
DEBUG(message);
}
@@ -62,18 +96,28 @@ inline void DEBUG_LEVEL_3(const std::string& message) {
#else
inline void DEBUG(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 0
inline void DEBUG_LEVEL_0(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 1
inline void DEBUG_LEVEL_1(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 2
inline void DEBUG_LEVEL_2(const std::string& message) {}
// prints the message string to stdout if the code has been compiled with a
// DEBUG_LEVEL > 3
inline void DEBUG_LEVEL_3(const std::string& message) {}
#endif
// for MPI process 0 print the message string to stdout
inline void SIM_INFO(const std::string& message) {
if (MpiCommunication::mpi_rank == 0) {
std::cout << "#INFO: " << message << std::endl;
}
}
// writes message string to stderr and exits the program with an EXIT_FAILURE
inline void ERROR(const std::string& message) {
fprintf(stderr, "ERROR <%d> %s\n", MpiCommunication::mpi_rank,
message.c_str());
@@ -81,6 +125,7 @@ inline void ERROR(const std::string& message) {
// throw std::runtime_error(message);
}
// assert if value is positive otherwise exit the program and print the message to stderr
template <class T>
void ASSERT_POSITIVE(T* value, const std::string& message) {
if (!(*value > 0)) {
@@ -88,6 +133,7 @@ void ASSERT_POSITIVE(T* value, const std::string& message) {
}
}
// assert if value is not negative otherwise exit the program and print the message to stderr
template <class T>
void ASSERT_NOTNEGATIVE(T* value, const std::string& message) {
if (!(*value >= 0)) {
@@ -95,6 +141,7 @@ void ASSERT_NOTNEGATIVE(T* value, const std::string& message) {
}
}
// assert if value exists otherwise exit the program and print the message to stderr
template <class T>
void ASSERT_EXISTS(T* value, const std::string& message) {
if (!value) {
@@ -102,12 +149,15 @@ void ASSERT_EXISTS(T* value, const std::string& message) {
}
}
// assert if value is finite otherwise exit the program and print the message to stderr
inline void ASSERT_FINITE(double value, const std::string& message) {
if (!std::isfinite(value)) {
ERROR(message);
}
}
// assert if the blitz::TinyVector is finite otherwise
// exit the program and print the message to stderr
inline void ASSERT_FINITE(const blitz::TinyVector<double, 3>& value,
const std::string& message) {
if (!std::isfinite(value(0)) || !std::isfinite(value(1)) ||
@@ -7,6 +7,7 @@
#include "simulation/coordinates.h"
#include "simulation/scalar_field.h"
// structure for storing a minimum and maximum value
struct Limit {
Limit() : min(0), max(0){};
Limit(double min, double max) : min(min), max(max){};
@@ -14,19 +15,28 @@ struct Limit {
double max;
};
// class for drawing positions
class EventPositionDistribution {
public:
// Constructor: takes a shared_ptr to a ScalarField used as the distribution to be drawn from
// a Limit density containing the maximum value of the mother_density within the position limits (used for rejection method)
// a Limit r_position defining the region in r-direction, where positions are drawn from
// a Limit z_position defining the region in z-direction, where positions are drawn from
// a Limit phi_position defining the region in phi-direction, where positions are drawn from
EventPositionDistribution(std::shared_ptr<ScalarField> mother_density,
Limit density,
Limit r_position,
Limit phi_position,
Limit z_position);
// draw a position from the ScalarField using the given mt19937 engine pointer as a CylinderCoordinate
// using the rejection method
CylinderCoordinate rollPosition(std::mt19937* engine);
private:
// ScalarField defining the distribution
std::shared_ptr<ScalarField> mother_density_;
// for Rejection method
// distribution functions drawn to be drawn from in the rejection method
std::uniform_real_distribution<double> r_values;
std::uniform_real_distribution<double> z_values;
std::uniform_real_distribution<double> phi_values;
+7
View File
@@ -3,14 +3,21 @@
#include "simulation/coordinates.h"
// class defining the miminmum requirement of a Geometry class
class Geometry {
public:
// check if Coordinate position is contained in the Geometry
virtual bool isInside(const Coordinate& position) const = 0;
};
// Geometry class for a cylinder
class Cylinder : public Geometry {
public:
// Constructor: takes the radius and height of the cylinder
// z always starts at 0
Cylinder(double radius, double height);
// check whether Coordinate position lies within the Cylinder
// i.e. z in (0,height), r in (0,radius)
bool isInside(const Coordinate& position) const;
private:
+1
View File
@@ -1,6 +1,7 @@
#ifndef HOMEBASE_H
#define HOMEBASE_H
// BUILD_HOMEBASE_STRING returns the string of the path stored in the HOMEBASE shell variable
#define STRINGIZER(arg) #arg
#define STR_VALUE(arg) STRINGIZER(arg)
#define BUILD_HOMEBASE_STRING STR_VALUE(HOMEBASE)
+16
View File
@@ -8,34 +8,48 @@
#include "simulation/coordinates.h"
// defined in "simulation/drift_velocity.h"
class DriftVelocity;
// defined in "simulation/veloctiy_distribution.h"
class VelocityDistribution;
// defined in "simulation/particle.h"
namespace particle {
class Particle;
}
// defined in "simulation/species.h"
namespace species {
class Specie;
class TrackedSpecie;
} // namespace species
// defined in "simulation/event_position_distribution.h"
class EventPositionDistribution;
// structure storing information about particles that are injected by the injector
// conains the TrackedSpecie of the particle and its veloctiy distribution
struct InjectorInfo {
public:
std::shared_ptr<species::TrackedSpecie> created_specie;
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
};
// class handling injection of event particles (i.e. particles from the tritium beta decay)
class Injector {
public:
// Constructor: takes a vector of InjectorInfo objects defining the particles that are supposed to be injected at invocation of the Injector object
// the activity of the simulation volume (units 1/s) defines the "timestep" (i.e. 1/activity)
// an EventPositionDistribution defining the valid space of the simulation domain where particles can be created
// a DriftVelocity object defining the bulk motion the injected particles are created with (regardless of specie), can be null
Injector(std::vector<InjectorInfo>& injector_info,
double activity,
std::shared_ptr<EventPositionDistribution> position_distribution,
std::shared_ptr<DriftVelocity> mother_drift_velocity);
// return a vector with the particles defined in the InjectorInfo vector using the random engine object
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine);
// return average time between events (1/activity)
double timePassed() const;
private:
@@ -44,6 +58,8 @@ class Injector {
std::shared_ptr<EventPositionDistribution> position_distribution_;
std::shared_ptr<DriftVelocity> mother_drift_velocity_;
// draw a single particle of species created_specie with a velocity distribution creation_velocity_distribution
// at the Coordinate position using the random engine engine
particle::Particle rollNewParticle(
std::mt19937* engine,
const Coordinate& position,
+18
View File
@@ -11,28 +11,46 @@
namespace interaction {
// class to define the output of an interaction
class InteractionOutput {
public:
// Constructor: incident particle is not flagged for deletion
InteractionOutput();
// if new_decider is true then the incident particle of the interaction is
// flagged for deletion
void deleteCurrentParticle(bool new_decider);
// return if the incident particle is flagged for deletion
bool deleteCurrentParticle();
// add particles that are created (not the incident) particles to the InteractionOutput
void add(const particle::Particle& new_particle);
// return the vector of particles that have been created by an interactoin
std::vector<particle::Particle> newParticles();
private:
// flag if the incident particle should be deleted
bool delete_current_particle_;
// vector for the interaction products (no including the incident particle even if it's not
// destroyed by the interaction)
std::vector<particle::Particle> new_particles_;
};
// parent class for all interactions (cannot be instantiated)
class Interaction {
public:
// Constructor: takes a function describing the cross section of used for the interaction as a function of energy (in eV)
// a shared_ptr to the Specie of the target species
Interaction(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target);
// return the value of the cross section at the energy (in eV) energy_eV in m^2
virtual double microscopicCrossSection(double energy_eV);
// calculate the density scaled cross section for the Particle particle
// interacting with the defined target Specie (returns cross section * target density) (units: m^-1)
// assumes that v_particle >> v_target
virtual double macroscopicCrossSection(particle::Particle& particle);
// pure virtual function defining the specifics of the actual interaction
virtual InteractionOutput performInteraction(particle::Particle& particle,
RandomNumbers* generator) = 0;
+31
View File
@@ -10,8 +10,12 @@
#include "simulation/errors.h"
#include "simulation/unit_converter.h"
// define the json_path type; contains the keys of the nested json-objects
// as the elements in the vector e.g. ["Root", "Group1", "Group2", ..., "GroupN"]
typedef std::vector<std::string> json_path;
// return the value specified by "path" as a json_t pointer
// (can point to a json-object, json-array, etc.)
inline json_t* json_object_by_path(json_t* object, const json_path& path) {
json_t* j_obj = object;
for (auto str : path) {
@@ -20,6 +24,7 @@ inline json_t* json_object_by_path(json_t* object, const json_path& path) {
return j_obj;
}
// return the value of the json_t pointer "object" as an double; defaults "default value"
inline double json_double(json_t* object, double default_value = 0.) {
if (object) {
return json_real_value(object);
@@ -28,6 +33,8 @@ inline double json_double(json_t* object, double default_value = 0.) {
}
}
// return the value of the json_t pointer "object" as an int; defaults to "default value"
// if the pointer is not a json-real value
inline int json_int(json_t* object, int default_value = 0) {
if (object) {
return std::floor(json_real_value(object));
@@ -36,6 +43,8 @@ inline int json_int(json_t* object, int default_value = 0) {
}
}
// return the value of the json_t pointer "object" as a string; defaults "default value"
// if the pointer is not a json-string
inline std::string json_string(json_t* object, std::string default_value = "") {
if (object) {
return std::string(json_string_value(object));
@@ -44,6 +53,8 @@ inline std::string json_string(json_t* object, std::string default_value = "") {
}
}
// return the value of the json_t pointer "object" as a bool; defaults to default_value
// if the pointer is not a json-string or the string has a value different from "true" or "false"
inline bool json_bool(json_t* object, bool default_value = false) {
if (object) {
return (json_string(object) == "true");
@@ -52,6 +63,9 @@ inline bool json_bool(json_t* object, bool default_value = false) {
}
}
// returns a blitz::TinyVector<double, s> with the values from a json_t pointer which points to
// a json-array; if the json_t pointer is not an array or the array has a different size than
// the specified template parameter s an error is thrown and the execution of the program terminated
template <int s>
blitz::TinyVector<double, s> json_blitz_vector(json_t* object) {
blitz::TinyVector<double, s> vector;
@@ -73,6 +87,8 @@ blitz::TinyVector<double, s> json_blitz_vector(json_t* object) {
return vector;
}
// returns a vector<double> containing the values of a json-array pointed to by
// json_t* object; if json_t* object is not a json-array returns an empty vector
inline std::vector<double> json_vector(json_t* object) {
std::vector<double> vector;
size_t index;
@@ -83,6 +99,7 @@ inline std::vector<double> json_vector(json_t* object) {
return vector;
}
// return the json-array in "object" as a json_path variable
inline json_path json_path_get(json_t* object) {
json_path path;
@@ -94,6 +111,8 @@ inline json_path json_path_get(json_t* object) {
return path;
}
// returns a json_path variable, that consists of the path appended by the
// json_path append
inline json_path json_path_append(const json_path& path,
const json_path& append) {
json_path result = path;
@@ -103,12 +122,24 @@ inline json_path json_path_append(const json_path& path,
return result;
}
// returns the value of a json-object, which should consist of a json-real with the key
// "value" and a json-string with the key "unit" transformed to the specified length
// "output_unit" (supported units: "mm", "cm", "m"). If the key "unit" does not exist or is not
// a json-string an error will be thrown and the program will terminate. If the key "value"
// does not exist or not a json-real it will default to 0.0
inline double json_read_length(json_t* object, std::string output_unit = "m") {
double value = json_double(json_object_by_path(object, {"value"}));
std::string unit = json_string(json_object_by_path(object, {"unit"}));
return unitConvertion::length(value, unit, output_unit);
}
/*
returns the value of a json-object, which should consist of a json-real with the key
"value" and a json-string with the key "unit" transformed to the specified energy
"output_unit" (supported units: "eV", "J"). If the key "unit" does not exist or is not
a json-string an error will be thrown and the program will terminate. If the key "value"
does not exist or not a json-real it will default to 0.0
*/
inline double json_read_energy(json_t* object, std::string output_unit = "eV") {
double value = json_double(json_object_by_path(object, {"value"}));
std::string unit = json_string(json_object_by_path(object, {"unit"}));
+50
View File
@@ -4,22 +4,38 @@
#include "simulation/coordinates.h"
namespace kinematic {
// calculate the velocity of the center off mass, where velocity_1 (cartesian vector, m/s) and
// mass_1 (kg) belong to the same particle and velocity_2 (cartesian vector, m/s) and mass_2 (kg) belong
// to the same particle
blitz::TinyVector<double, 3> velocityOfCenterOfMass(
const blitz::TinyVector<double, 3>& velocity_1,
const blitz::TinyVector<double, 3>& velocity_2,
double mass_1,
double mass_2);
// Galileo transformation to the rest frame of the second particle
// both velocities are in m/s and both masses in kg
blitz::TinyVector<double, 3> velocityTargetFixed(
const blitz::TinyVector<double, 3>& velocity_1,
const blitz::TinyVector<double, 3>& velocity_2,
double mass_1,
double mass_2);
// rotates the vector (cartesian) v by the polar angle theta and the azimuthal angle phi
// in the frame where v is aligned with the z-axis
// returns the rotated vector as a blitz::TinyVector in cartesian coordinates in the
// original frame where v is not (not neccessarily) aligned with the z-axis (all in SI units)
blitz::TinyVector<double, 3> rotateVector(const blitz::TinyVector<double, 3>& v,
double theta,
double phi);
// transform velocity_1 into the center of mass frame defined by
// velocity_1, mass_1 and velocity_2 and mass_2 (vectors are cartesian)
// velocity_1_centerOfMass is then rotated by the polar angle theta and the
// azimuthal angle phi in the frame in which velocity_1_centerOfMass is aligned with
// the z-axis
// returns the rotated velocity_1 vector in the original non-center of mass frame (cartesian coordinates)
// (all in SI units)
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
const blitz::TinyVector<double, 3>& velocity_1,
const blitz::TinyVector<double, 3>& velocity_2,
@@ -28,38 +44,72 @@ blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
double theta,
double phi);
// return the non-relativistic kinetic energy (J) defined by the cartesian velocity (m/s)
// and the mass (kg)
double kineticEnergy(const blitz::TinyVector<double, 3>& velocity, double mass);
// transform the temperature (K) into an energy in eV
double thermalEnergy(double temperature_K);
// returns the modulus of the velocity (m/s) of the kinetic energy (eV)
// and the mass (kg) (non-relativistic)
double velocity(double energy_eV, double mass_kg);
// transform the cartesian velocity v2 in the frame moving with cartesian velocity v1
// into the laboratory frame (both velocities in m/s)
// returns the boosted vector in cartesian coordinates
blitz::TinyVector<double, 3> relativisticBoost(
const blitz::TinyVector<double, 3>& v1,
const blitz::TinyVector<double, 3>& v2);
// calculate gamma from velocity from the given cartesian velocity (in SI units)
// where the velocity is the realtivistic 3 momentum divided by the rest mass of the particle
double relativisticGamma(const blitz::TinyVector<double, 3>& velocity);
// calculates the Lorentz factor given the kinetic energy in eV and the
// rest mass of the particle transformed to eV
double relativisticGamma(double kin_energy_eV, double mass_eV);
// return the cartesian velocity (m/s) devided by the speed of light
double relativisticBeta(double velocity_ms);
// calculates the relativistic beta (velocity/speed of light) given the kinetic energy in eV and the
// rest mass of the particle transformed to eV
double relativisticBeta(double kin_energy_eV, double mass_eV);
// Note: what units does the relativisitvMomentum function "return"?
// calculate the modulus of the realtivistic momentum from the kinetic energy in eV
// and the mass in eV
double relativisticMomentum(double energy_eV, double mass_eV);
// returns the norm of the vector
double norm(const blitz::TinyVector<double, 3>& vector);
// calculates the distance between the two points position_1 and position_2
// which are both in cylinder coordinates (r, phi, z)
double distanceInCylinder(const blitz::TinyVector<double, 3>& position_1,
const blitz::TinyVector<double, 3>& position_2);
// calculate v_perp, s.t. vector = v_perp + v_parallel, with
// v_perp perpendicular to the vector direction and v_parallel parallel to the vector direction
// (both vectors cartesian)
blitz::TinyVector<double, 3> perpendicularVector(
const blitz::TinyVector<double, 3>& vector,
const blitz::TinyVector<double, 3>& direction);
// calculate v_parallel, s.t. vector = v_perp + v_parallel, with
// v_perp perpendicular to the vector direction and v_parallel parallel to the vector direction
// (both vectors cartesian)
blitz::TinyVector<double, 3> parallelVector(
const blitz::TinyVector<double, 3>& vector,
const blitz::TinyVector<double, 3>& direction);
// rotate vector around rotation_axis about the angle angle
// (vectors cartesian)
blitz::TinyVector<double, 3> rotateVector(
const blitz::TinyVector<double, 3>& vector,
const blitz::TinyVector<double, 3>& rotation_axis,
double angle);
// return the random_unit_vector scaled by the modulus of the non-relativistic velocity
// defined by the kinetic energy energy_eV (eV) and mass mass_kg (kg)
blitz::TinyVector<double, 3> velocityVector(
double energy_eV,
const blitz::TinyVector<double, 3>& random_unit_vector,
+17
View File
@@ -5,6 +5,7 @@
#include <vector>
#include "simulation/coordinates.h"
// enum that defines the different types of deletions that can be counted
enum class DeletionType {
wall,
recombination,
@@ -13,19 +14,35 @@ enum class DeletionType {
cluster_formation
};
// class that keeps track of the DeletionType that caused a particle to be deleted
class DeletionLogger {
public:
// Constructor: vector used_types defines for which DeletionType elements the
// deletion is supposed to be tracked (i.e. if recombination is not
// specified in the used_types vector, then particles that are
// removed due to recombination are not counted)
DeletionLogger(std::vector<DeletionType> used_types);
// increase the count corresponding to DeletionType by 1
// Coordinate coordinate is not used (i.e. can be chosen arbitrarily)
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
// returns the map with the keys being the tracked DeletionTypes and the
// value the long int count of how many particles have been logged by the
// corresponding key
std::map<DeletionType, long int> numDeletions() const;
// set the count for DeletionType type to new_value
void numDeletions(long int new_value, DeletionType type);
// return the count for DeletionType type; if the type was not specified
// as used in the creation of the object return 0
long int numDeletions(DeletionType type) const;
// make private member variable accessable for the cpu synchronization
friend class CpuSynchronizer;
private:
// map with keys being the used DeletionTypes and the value being the count
// of how many particles have been deleted due to the DeletionType of the key
std::map<DeletionType, long int> num_deletions;
};
+25 -1
View File
@@ -4,6 +4,7 @@
#include "simulation/electromagnetic_field.h"
#include "simulation/particle.h"
// class defining the minimum requirements of a mover class
class Mover {
public:
virtual void move(particle::Particle* particle,
@@ -12,10 +13,18 @@ class Mover {
MagneticField* magnetic_field) = 0;
};
// Mover class using the Boris push algorithm for propagation
class BorisMover : public Mover {
public:
// Constructor: sets the maximal timestep acceptable for the Boris puhs algorithm
// (should at the very least resolve the gyro timescale of the particle)
BorisMover(double maximal_time_step_s);
// propagate the Particle particle using the electric and magnetic fields
// until the particle has moved a distance of mfp_m or until it changes
// either its energy or position bin or it reaches the maximal time the
// particle is allowed to live
// also updates the density, deletion logger and current collector of the particle species
void move(particle::Particle* particle,
double mfp_m,
ElectricField* electric_field,
@@ -24,16 +33,26 @@ class BorisMover : public Mover {
private:
const double maximal_time_step_s_;
// single update step of the Boris push algorithm
// updates moved_distance by the distance the particle moved during the update step
void movementStep(particle::Particle* particle,
const blitz::TinyVector<double, 3>& electric_field,
const blitz::TinyVector<double, 3>& magnetic_field,
double& moved_distance) const;
};
// Mover class using the drift approximation for propagation
class DriftMover : public Mover {
public:
// Constructor: takes the maximal distance the particle is allowed to move during one step
// (should be smaller than the length scale defined by the gradient of the modulus of the magnetic field)
DriftMover(double maximal_distance);
// propagate the Particle particle using the electric and magnetic fields
// until the particle has moved a distance of mfp_m or until it changes
// either its energy or position bin or it reaches the maximal time the
// particle is allowed to live
// also updates the density, deletion logger and current collector of the particle species
void move(particle::Particle* particle,
double mfp_m,
ElectricField* electric_field,
@@ -42,15 +61,20 @@ class DriftMover : public Mover {
private:
const double maximal_distance_m_;
// single update step using the drift approximation
// updates moved_distance by the distance the particle moved during the update step
blitz::TinyVector<double, 3> driftVelocity(
const blitz::TinyVector<double, 3>& magnetic_field,
const blitz::TinyVector<double, 3>& electric_field) const;
};
// Mover for the case of 0 magnetic field. Simply ignores electric and magnetic field
// Mover for the case of no magnetic field. Simply ignores electric and magnetic field
// for the movement step, i.e. velocity doesn't change.
class EulerMover : public Mover {
public:
// Constructor: takes the maxium distance the particle is allowed to move during
// one update step (used to limit the distance a particle can move
// into a neighboring bin before the check can be performed if the bin has been changed)
EulerMover(double maximal_distance);
void move(particle::Particle* particle,
+5
View File
@@ -1,15 +1,20 @@
#ifndef MPI_COMMUNICATION_H
#define MPI_COMMUNICATION_H
// class to handle MPI communication
class MpiCommunication {
public:
static int mpi_rank;
static int mpi_size;
// returns the MPI-rank of the process
static int mpiRank();
// returns the number of MPI processes
static int mpiSize();
// initialize the two member variables
static void init(int argc, char* argv[]);
// wrapper for MPI_Finalize()
static void finalize();
};
+14
View File
@@ -7,23 +7,37 @@
#include "jansson.h"
#include "simulation/jansson_additionals.h"
// class to handle the json-parameter file and read it's data
class Parameter {
public:
Parameter(std::string filename);
~Parameter();
// read the value at the json path and return it as a double; defaults to 0.0
double doubleValue(const json_path& path) const;
// read the value at the json path and return it as a double; defaults to the default value
double doubleValue(const json_path& path, double default_value) const;
// read the value at the json path and return it as a int; defaults to 0
int intValue(const json_path& path) const;
// read the value at the json path and return it as a int; defaults to default value
int intValue(const json_path& path, int default_value) const;
// read the value at the json path and return it as a string; defaults to the empty string
std::string stringValue(const json_path& path) const;
// read the value at the json path and return it as a string; defaults to the default value
std::string stringValue(const json_path& path,
const std::string& default_value) const;
// read the value at the json path and return it as a string;
// the string "true" in the json file results in true, everything else in false
bool boolValue(const json_path& path) const;
// read the value at the json path and return it as a string;
// the string "true" in the json file results in true, everything else in the default value
bool boolValue(const json_path& path, bool default_value) const;
// check if "path" exists in the json-parameter file
bool pathExists(const json_path& path) const;
// return a pointer to the json_t object of the json-parameter_file
json_t* jsonFile() const;
// return a pointer to the json_t object of the group specified by "path"
json_t* jsonObjectFromBase(const json_path& path) const;
private:
+32 -1
View File
@@ -7,40 +7,71 @@
namespace particle {
// class for the simulated particles
class Particle {
public:
// Constructor: takes shared_ptr to the TrackedSpecies object that describes the particle
// the Coordinate containing the position the particle should be created at
// the Vector containing the velocity the particle should be created with
Particle(std::shared_ptr<species::TrackedSpecie> specie,
const Coordinate& position,
const Vector& velocity);
// set the position of the particle to the provided Coordinate new_position
void position(const Coordinate& new_position);
// return the position of the particle as a CartesianVector
CartesianCoordinate position() const;
// set the velocity of the particle to the provided CartesianVector new_velocity
void velocity(const CartesianVector& new_velocity);
// return the velocity of the particle as a CartesianVector
CartesianVector velocity() const;
// ads the Coordinate distance to the position of the particle
// x_new = x_old + distance
void move(const Coordinate& distance);
// return the kinetic energy of the particle in eV
double kineticEnergy_eV() const;
// return the modulus of the particle velocity in m/s
double absoluteVelocity() const;
// return the squared modulus of the particle velocity in (m/s)^2
double absoluteVelocitySquared() const;
// return the mass of the particle in kg (i.e. the mass of the particles specie)
double mass_kg() const;
// return the charge of the particle in C (i.e. the charge of the particles specie)
double charge_C() const;
// get a raw pointer to the TrackedSpecie object of the particle
species::TrackedSpecie* specie() const;
// set the static variable (only local to the mpi process) from which
// the particle ids are generated
static void lastId(long int id);
static long int lastId(); // only local on this cpu
// get the static variable (only local to the mpi process) from which
// the particle ids are generated
static long int lastId();
// increase member variable that counts the number of interactions performed
// by the particle by 1
void increaseInteractionCounter();
// return the value of the number of interactions performed by the particle
long int interactionCounter() const;
// increase member variable counting the total time (in s) that the
// particle has been alive
void increaseTimeAlive(double time_s);
// return the time the particle has been alive (in s)
double timeAlive() const;
// increase member variable counting the time the particle has bin alive
// without chaingin any bin (i.e. spatial or energy) by the given time (in s).
// equivalent to the time the particle has spent in its current bin
void increaseTimeInBin(double time_s);
// reset the time in bin variable (i.e. set to 0)
void resetTimeInBin();
// return the time the particle has not changed any bin
double timeInBin() const;
private:
+56
View File
@@ -4,15 +4,25 @@
#include <vector>
#include "blitz/array.h"
// class for a linear binning without under- or overflow bins
class LowerAndUpperBoundBinning {
public:
// Constructor: create binning with num_bins bins and
// an upper boundary of maximum (the lower boundary is always chosen as 0)
// the spacing between bins is always linear
LowerAndUpperBoundBinning(int num_bins, double maximum);
// return the bin index, that includes the value position
int bin(double position) const;
// return the spacing between the bin borders
double stepsize() const;
// getter for the number of bins
int numBins() const;
// returns the index for the first bin (0)
int binIndexMin() const;
// returns the index for the last bin (num_bins - 1)
int binIndexMax() const;
// return a vector containing the edges of the bins
std::vector<double> binBorders() const;
private:
@@ -20,17 +30,27 @@ class LowerAndUpperBoundBinning {
double stepsize_;
};
// class for a linear binning with an overflow but no underflow bin
class LowerBoundBinningWithOverflow {
public:
// Constructor: creates a linear binning between 0 and maximum with num_bins_excluding_overflow
// (number of bins without the overflow bin)
LowerBoundBinningWithOverflow(int num_bins_excluding_overflow,
double maximum);
// return the bin index, that includes the value position
int bin(double position) const;
// return the spacing between the bin borders
double stepsize() const;
// returns the number of bins including the overflow bin
int numBinsWithOverflow() const;
// returns the number of bins excluding the overflow bin
int numBinsWithoutOverflow() const;
// returns the index for the first bin (0)
int binIndexMin() const;
// returns the index for the last bin (i.e. the overflow bin)
int binIndexMax() const;
// return the values of the borders of the bins (the overflow bin does not have an upper boundary)
std::vector<double> binBorders() const;
private:
@@ -38,17 +58,28 @@ class LowerBoundBinningWithOverflow {
double stepsize_;
};
// class for a linear binning with an under- and overflow bin
class BinningWithOverAndUnderflow {
public:
// Constructor: creates a linear binning between 0 and maximum with num_bins_excluding_overflow
// (number of bins without the overflow and underflow bin)
BinningWithOverAndUnderflow(int num_bins_excluding_overunderflow,
double maximum);
// return the bin index, that includes the value position
int bin(double position) const;
// return the spacing between the bin borders
double stepsize() const;
// returns the number of bins including both the overflow and underflow bin
int numBinsWithOverUnderflow() const;
// returns the number of bins excluding both the overflow and underflow bin
int numBinsWithoutOverUnderflow() const;
// returns the index for the first (underflow) bin (-1)
int binIndexMin() const;
// returns the index for the last bin (i.e. the overflow bin)
int binIndexMax() const;
// return the values of the borders of the bins (the overflow bin does not have an upper
// and the underflow bin does not have a lower boundary)
std::vector<double> binBorders() const;
private:
@@ -56,23 +87,48 @@ class BinningWithOverAndUnderflow {
double stepsize_;
};
// class for handling the segmentation of a cylindrical domain
class CylinderBinning {
public:
// Constructor: takes the number of bins for the radial direction,
// the radius of the cylinder,
// the number of bins in azimuthal direction,
// the number of bins in longitudinal (i.e. z) direction,
// the height of the cylinder
// creates a LowerBoundBinninigWithOverflow for the radial direction (no boundary at r=0),
// a LowerAndUpperBoundBinning for the azimuthal direction (no boundary at all),
// and a BinningWithOverAndUnderflow in longitudinal direction
CylinderBinning(int num_bins_radial,
double radius,
int num_bins_azimuthal,
int num_bins_longitudinal,
double height);
// return a blitz::TinyVector containing the indeces for each of the three binnings
// (bin_r, bin_azimuthal, bin_longitudinal), in which the blitz::TinyVector cylinder_position
// (containing (r, phi,z)) is contained in
blitz::TinyVector<int, 3> bin(
const blitz::TinyVector<double, 3>& cylinder_position) const;
// return a blitz::TinyVector with the spacings of the three binnings
// (spacing_radial, spacing_azimuthal, spacing_longitudinal)
blitz::TinyVector<double, 3> stepsize() const;
// return a blitz::TinyVector with the number of bins of each binning (excludes all over- and underflow bins)
// (numBins_radial, numBins_azimuthal, numBins_longitudinal)
blitz::TinyVector<int, 3> numBins() const;
// return a blitz::TinyVector with the number of bins of each binning (includes all over- and underflow bins)
// (numBins_radial, numBins_azimuthal, numBins_longitudinal)
blitz::TinyVector<int, 3> numBinsIncludingOverUnderflow() const;
// return a blitz::TinyVector with the indices of the first bins of each binning
// (binIndexMin_radial, binIndexMin_azimuthal, binIndexMin_longitudinal)
// includes the underflow bin in longitudinal direction
blitz::TinyVector<int, 3> binIndexMin() const;
// return a blitz::TinyVector with the indices of the last bins of each binning
// (binIndexMin_radial, binIndexMin_azimuthal, binIndexMin_longitudinal)
// includes the overflow bin in radial and longitudinal direction
blitz::TinyVector<int, 3> binIndexMax() const;
// binnings for each of the three directions (radial, azimuthal, longitudinal)
const LowerBoundBinningWithOverflow radial_binning;
const LowerAndUpperBoundBinning azimuth_binning;
const BinningWithOverAndUnderflow longitudinal_binning;
+5
View File
@@ -5,13 +5,18 @@
#include <memory>
#include <random>
// class to handle a random generator object
class RandomNumbers {
public:
// Constructor: takes the seed for the random engine
RandomNumbers(int seed);
// draw a uniformly distributed integer number between min, max
int rollUniform(int min, int max);
// draw a uniformly distributed double number between min, max
double rollUniform(double min, double max);
// getter for the pointer to the mersenne twister 19937 engine
std::mt19937* engine();
private:
+10
View File
@@ -3,6 +3,7 @@
#include "simulation/particle.h"
// class defining the minimum requirements of a Reflector class
class Reflector {
public:
virtual bool needsReflectionBackToDomain(
@@ -10,18 +11,27 @@ class Reflector {
virtual void reflectBackToDomain(particle::Particle* particle) const = 0;
};
// class for Reflectrion at the DPS section of KATRIN
// (i.e. reflection at the z=L end of the cylinder)
class ReflectorDPS : public Reflector {
public:
// Constructor: takes the position in longitudinal direction where particles should
// be reflected at (reflects particles back to lower z values)
ReflectorDPS(double z_position_dps);
// check if Particle particle needs to be reflected
bool needsReflectionBackToDomain(const particle::Particle* particle) const;
// perform the reflection of the particle back to the left
void reflectBackToDomain(particle::Particle* particle) const;
private:
const double z_position_dps_;
};
// class for particles that are not reflected anywhere
class NoReflector : public Reflector {
// always returns false
bool needsReflectionBackToDomain(const particle::Particle* particle) const;
// does nothing
void reflectBackToDomain(particle::Particle* particle) const;
};
+7
View File
@@ -6,15 +6,22 @@
#include "simulation/coordinates.h"
// class for a scalar field
class ScalarField {
public:
// returns the value of the scalar field at the Coordinate coordinate
virtual double value(const Coordinate& coordinate) const = 0;
};
// class for a scalar field that has an arbitrary form in longitudinal direction
// and is constant in radial in azimuthal directoin
class ScalarFieldFunctionInZ : public ScalarField {
public:
// Constructor: gets the function F_z defining the form of the scalar field
// in longitudinal direction
ScalarFieldFunctionInZ(std::function<double(double, double, double)> F_z);
// return the value of the scalar field at Coordinate coordinate
double value(const Coordinate& coordinate) const;
private:
@@ -9,23 +9,33 @@
#include "simulation/energy_binning.h"
// class defining the minimum requirements of a scattering angle distribution
class ScatteringAngleDistribution {
public:
// draw a value for the scattering angle depending on the energy (in eV) and
// the random engine
virtual double roll(std::mt19937* engine, double energy_eV) = 0;
};
// class for an isotropic scattering angle distribution
class IsotropicAngleDistribution : public ScatteringAngleDistribution {
public:
// Constructor: initializes a uniform distribution between (o,2pi)
IsotropicAngleDistribution();
// draw from a uniform distribution
double roll(std::mt19937* engine, double energy_eV = 0.);
private:
std::uniform_real_distribution<double> distribution_;
};
// class for drawing from a piecewise linear scattering angle distribution
class AngleDistributionFromFile : public ScatteringAngleDistribution {
public:
// Constructor: takes string containing the absolute path (including the file)
// that contains the data of the scattering angle distribution
AngleDistributionFromFile(std::string absolute_filepath);
// draw a value from the distribution
double roll(std::mt19937* engine, double energy_eV);
private:
@@ -33,12 +43,17 @@ class AngleDistributionFromFile : public ScatteringAngleDistribution {
std::vector<std::piecewise_linear_distribution<double>> angle_distributions_;
};
// class for a composition of two scattering angle distibutions
class CompositeAngleDistribution : public ScatteringAngleDistribution {
public:
// Constructor: takes two ScatteringAngleDistributions and a decider energy (eV)
// if energy_eV < decider energy use lower_distribution
// otherwise use the higher_distribution
CompositeAngleDistribution(
std::shared_ptr<ScatteringAngleDistribution> lower_distribution,
std::shared_ptr<ScatteringAngleDistribution> higher_distribution,
double decider_energy);
// draw a value from the distribution
double roll(std::mt19937* engine, double energy_eV);
private:
+29
View File
@@ -8,41 +8,70 @@
#include "simulation/parameter.h"
#include "simulation/particle.h"
// defined in "simulation/random_numbers.h"
class RandomNumbers;
// defined in "simulation/interaction.h"
class InteractionOutput;
// defined in "simulation/electromagnetic_field.h"
class MagneticField;
class ElectricField;
// defined in "simulation/timer.h"
class Timer;
// defined in "simulation/injector.h"
class Injector;
// defined in "IO/simulation_output.h"
class SimulationOutput;
// defined in "simulation/cpu_synchronizer.h"
class CpuSynchronizer;
// defined in "simulation/species.h"
namespace species {
class Specie;
};
// defined in "simulation/interaction.h"
namespace interaction {
class InteractionOutput;
};
class Simulation {
public:
// Constructor: initialize everything using the json file at the path in parameter_filename
Simulation(std::string parameter_filename);
// function for initialization from Parameter object
void init(Parameter& parameter);
// function for main simulation loop
void start();
// function to finalize simulation
void finalize();
// process events until "events" number of beta decay chains have been
// simulated until completion
void processEvents(int events);
// process the Particle particle until it is terminated
// any interaction product created during the interactions during the propagation of
// particle are appened to the vector particle_queue
void processUntilTermination(particle::Particle& particle,
std::vector<particle::Particle>& particle_queue);
private:
// function to create particles from the injector (i.e. the event particles)
// also increases the time in the Timer object
std::vector<particle::Particle> determineInjectedParticles(
RandomNumbers* random);
// calculate the mean free path for the Particle particle
// the calculated target density scaled cross sections are then
// appened to the vector macroscopic_cross_sections_m to be used
// later in the interact function (to avoid an unneccessary recalculation)
double meanFreePath(particle::Particle& particle, RandomNumbers* random,
std::vector<double>& macroscopic_cross_sections_m);
// randomly chooses the interaction the particle will experience by
// using the values in the macroscopic_cross_sections_m vector (does NOT have to be normalized)
// as the relative weight for the corresponding interaction to occur
// afterwards perform the interaction and return the
// output of the as an InteractionOutput object
interaction::InteractionOutput interact(particle::Particle& particle,
RandomNumbers* random,
std::vector<double>& macroscopic_cross_sections_m);
+75 -3
View File
@@ -7,51 +7,91 @@
#include "simulation/parameter.h"
// defined in "simulation/mover.h"
class Mover;
// defined in "simulation/terminator.h"
class Terminator;
// defined in "simulation/reflector.h"
class Reflector;
// defined in "simulation/injector.h"
class Injector;
// defined in "simulation/density_field.h"
class DensityField;
class DynamicDensityField;
class ConstantDensityField;
// defined in "simulation/logger.h"
class DeletionLogger;
// defined in "simulation/current_collector.h"
class CurrentCollector;
// defined in "simulation/velocity_distribution.h"
class VelocityDistribution;
// defined in "simulation/drift_velocity.h"
class DriftVelocity;
// defined in "simulation/interaction.h"
namespace interaction {
class Interaction;
};
namespace species {
// enum that lists all implemented specie types (Tritium molecule T2, electron,
// Tritium ion T+, Tritium molecule ion T2+ and Trtitium cluster ion T3+)
enum class ImplementedSpecies { T2, electron, Tplus, T2plus, T3plus };
// general specie, defining the minimum requirements for all other specie classes
class Specie {
public:
// Constructor, taking one of the implemented speices in the ImplementedSpecies enum,
// an arbitrary string defining the name of the species (e.g. if multiple electron species
// are required), the mass of the particle type in kg and it's charge in Coulomb
Specie(ImplementedSpecies type,
std::string name,
double mass_kg,
double charge_C);
// getter for the mass of the species (in kg)
double mass_kg() const;
// getter for the charge of the species (in Coulomb)
double charge_C() const;
// getter for the type of the species (ImplementedSpecies enum)
ImplementedSpecies type() const;
// getter for the name of the species
std::string name() const;
// getter for the DensityField pointer
virtual DensityField* densityField() = 0;
// getter for the VelocityDistribution pointer
virtual VelocityDistribution* velocityDistibution() = 0;
// getter for the DriftVelocity pointer
virtual DriftVelocity* driftVelocity() = 0;
protected:
// mass of species in kg
const double mass_kg_;
// charge of species in C
const double charge_C_;
// type of species defined by ImplementedSpecies enum
const ImplementedSpecies type_;
// arbitrary name of the species
const std::string name_;
};
// class for particle species that are simulated
class TrackedSpecie : public Specie {
public:
// Constructor; takes an ImplemetedSpecies enum to define the type of the species,
// an arbitrary string to name the species,
// the mass of the particles of the species in kg,
// the charge of the particles of the species in C,
// a shared_ptr of a Mover object (defines the propagation algorithm),
// a shared_ptr of a Terminator object (defines when a particle is deleted),
// a shared_ptr of a Reflector object (defines if, where and how a particle of the specie is reflected),
// a shared_ptr of a DynamicDensityField object (collects the density of the species),
// a shared_ptr of a DriftVelocity object (can be a nullptr but only if no interactions between simulated species are present),
// a shared_ptr of a second DynamicDensityField object (essentially a copy of the first DynamicDensityField; necessary for cpu-synchronization)
// the deletion logger and the current collector (as well as their synchronization equivalents) are initialized
// with a null pointer
TrackedSpecie(ImplementedSpecies type,
std::string name,
double mass_kg,
@@ -64,30 +104,50 @@ class TrackedSpecie : public Specie {
std::shared_ptr<DriftVelocity> drift_velocity,
std::shared_ptr<DynamicDensityField> last_sync_density_field);
// getter for a raw pointer to the DynamicDensityField member as its parent class DensityField
DensityField* densityField();
// getter for a raw pointer to the VelocityDistribution member
VelocityDistribution* velocityDistibution();
// getter for a raw pointer to the driftVelocity member
DriftVelocity* driftVelocity();
// getter for a raw pointer to the DynamicDensityField member
DynamicDensityField* dynamicDensityField();
// getter for a raw pointer to the DynamicDensityField member used for the synchronization between processes
DynamicDensityField* lastSyncDensityField();
// getter for a raw pointer to the Mover member
Mover* mover();
// getter for a raw pointer to the Terminator member
Terminator* terminator();
// getter for a raw pointer to the Reflector member
Reflector* reflector();
// getter for a raw pointer to the DeletionLogger member
DeletionLogger* deletionLogger();
// setter for the DeletionLogger member
void deletionLogger(std::shared_ptr<DeletionLogger> new_logger);
// getter for a raw pointer to the DeletionLogger member used for cpu-synchronization
DeletionLogger* lastSyncDeletionLogger();
// setter for the DeletionLogger member used for cpu-synchronization
void lastSyncDeletionLogger(std::shared_ptr<DeletionLogger> new_logger);
// getter for a raw pointer to the CurrentCollector member
CurrentCollector* currentCollector();
// setter for the CurrentCollector member
void currentCollector(std::shared_ptr<CurrentCollector> new_collector);
// getter for a raw pointer to the CurrentCollector member used for cpu-synchronization
CurrentCollector* lastSyncCurrentCollector();
// setter for the CurrentCollector member used for cpu-synchronization
void lastSyncCurrentCollector(
std::shared_ptr<CurrentCollector> new_collector);
// vector of shared_ptr to Interaction objects, defines the different types
// of interactions that the specie can take part in
std::vector<std::shared_ptr<interaction::Interaction>> interactions();
// adds the shared_ptr of the Interaction object "interaction" to the vector
// of possible interactions
void addInteraction(std::shared_ptr<interaction::Interaction> interaction);
private:
@@ -99,20 +159,29 @@ class TrackedSpecie : public Specie {
std::shared_ptr<Terminator> terminator_;
std::shared_ptr<Reflector> reflector_;
// object to keep track of how particles of the specie are removed from the simulation
std::shared_ptr<DeletionLogger> deletion_logger_;
std::shared_ptr<CurrentCollector> current_collector_;
std::vector<std::shared_ptr<interaction::Interaction>> interactions_;
// fields to store the date of the last synchronization
// (after a synchronization the last_sync field and the non-last_sync field
// fields to store the data of the last synchronization
// (immediately after a synchronization the last_sync field and the non-last_sync field
// contain the same data)
std::shared_ptr<DynamicDensityField> last_sync_density_field_;
std::shared_ptr<DeletionLogger> last_sync_deletion_logger_;
std::shared_ptr<CurrentCollector> last_sync_current_collector_;
};
// class for particle types that are not simulated
class BackgroundSpecie : public Specie {
public:
// Constructor: takes the type of the species as one of the implemented species defined in the ImplementedSpecies enum,
// an arbirtary name for the species,
// the mass of the particles of the species in kg,
// the charge of the particles of the species in C,
// a shared_ptr to a ConstantDensityField object,
// a shared_ptr to a VelocityDistribution object (defines the velocity distribution of the particles realtive to their drift veloctiy)
// a shared_ptr to a DriftVelocity object (defines the drift velocity of the particles)
BackgroundSpecie(ImplementedSpecies type,
std::string name,
double mass_kg,
@@ -121,8 +190,11 @@ class BackgroundSpecie : public Specie {
std::shared_ptr<VelocityDistribution> velocity_distribution,
std::shared_ptr<DriftVelocity> drift_velocity);
// getter for a raw pointer to the ConstantDensityField member as its parent type
DensityField* densityField();
// getter for a raw pointer to the VelocityDistribution member
VelocityDistribution* velocityDistibution();
// getter for a raw pointer to the driftVelocity member
DriftVelocity* driftVelocity();
private:
+12
View File
@@ -3,18 +3,30 @@
#include "simulation/particle.h"
// defined in "simulation/geometry.h"
class Geometry;
// class for checking if a paricle has to be terminated due to
// any reason except interaction effects
class Terminator {
public:
// Constructor: takes the maximum number of interactions a particle is allowed to perform
// the maximum amount of time a paticle is allowed to live
// a Geometry object defining the boundaries of the volume particles are allowed to exist in
Terminator(long int max_interactions,
double max_time_alive,
std::shared_ptr<Geometry> geometry);
// check if particle has not reached the maximum interaction count, the maximal time its allowed to live
// and that it has not reached a geometry boundary
bool isAlive(const particle::Particle* particle) const;
// check if particle has crossed any boundary of the Geometry
bool leftSimulationDomain(const particle::Particle* particle) const;
// check if particle has reached the maximum interaction count
bool reachedMaxInteractions(const particle::Particle* particle) const;
// check if the particle has reached its maximum lifetime
bool reachedMaxTimeAlive(const particle::Particle* particle) const;
// return the maximum lifetime
double maxTimeAlive() const;
private:
+5
View File
@@ -3,12 +3,17 @@
#include <iostream>
// class to keep track of the "simulation time" (i.e. number of processed events * Activity)
class Timer {
public:
// Constructor; initializes time to 0
Timer();
// getter for the time
double time() const;
// increase the time by time_s (time in s)
void increaseTimestep(double time_s);
// set time to time_s
void setTime(double time_s);
private:
+1
View File
@@ -3,6 +3,7 @@
#include <functional>
// return a function calculating the fermi distribution with the given prefactor
std::function<double(double)> tritiumDecayEnergySpectrum(double prefactor);
+11
View File
@@ -5,15 +5,26 @@
namespace unitConvertion {
// transforms the value from current lenght unit "unit_from" to "unit_to"
// possible values for both "unit_from" and "unit_to": "mm", "cm", "m" otherwise
// an error is thrown and the program terminates
double length(double value,
const std::string& unit_from,
const std::string& unit_to);
// returns the value of unit/meter, supports "mm", "cm", "m" for any other value
// an error is thrown and the program terminates
double lengthPrefactor(const std::string& unit);
// transforms the value from current energy unit "unit_from" to "unit_to"
// possible values for both "unit_from" and "unit_to": "eV", "J" otherwise
// an error is thrown and the program terminates
double energy(double value,
const std::string& unit_from,
const std::string& unit_to);
// returns the value of unit/eV, supports "eV", "J" for any other value
// an error is thrown and the program terminates
double energyPrefactor(const std::string& unit);
}; // namespace unitConvertion
+19
View File
@@ -7,19 +7,28 @@
#include "simulation/coordinates.h"
#include "simulation/position_binning.h"
// class for vector fields
class VectorField {
public:
// return the value of the vector field at the Coordinate coordinate as a
// CylinderVector object
virtual CylinderVector value(const Coordinate& coordinate) const = 0;
};
// class for vector fields that are defined by an array (e.g. from data that was used as input)
class VectorFieldFromArray : public VectorField {
public:
// Constructor: takes the radial, azimuthal and longitudinal component of the vector field
// as 3d arrays; all three arrays have to have the same size (not checked)
// also takes the radius and length of the domain, where the vector field is defined
VectorFieldFromArray(const blitz::Array<double, 3>& radial_component,
const blitz::Array<double, 3>& azimuthal_component,
const blitz::Array<double, 3>& longitudial_component,
double radius,
double length);
// return the value at the Coordinate coordinate, if the coordinate does not fall into
// the region where the vector field is defined in return (0,0,0)
CylinderVector value(const Coordinate& coordinate) const;
private:
@@ -27,22 +36,32 @@ class VectorFieldFromArray : public VectorField {
const blitz::Array<double, 3> Fphi_;
const blitz::Array<double, 3> Fz_;
// used to determine which array element is neccessary in the value() function
CylinderBinning binning_;
CylinderVector value(const blitz::TinyVector<int, 3>& bin) const;
};
// class for spatially constant vector fields
class VectorFieldConstant : public VectorField {
public:
// Constructor: takes the value of the constant cylinder vector for the vector field
VectorFieldConstant(const CylinderVector& constant);
// return the value of the vector field at the Coordinate coordinate as a CylinderVector
CylinderVector value(const Coordinate& coordinate) const;
private:
const CylinderVector constant_;
};
// class for a vector field that has a z-dependence that can be described by an
// analytic function and is 0 for the radial and azimuthal component
class VectorFieldFunctionInZ : public VectorField {
public:
// Constructor: takes a function that describes the value of the longitudinal
// component as a function of r,phi,z
VectorFieldFunctionInZ(std::function<double(double, double, double)> v_z);
// return the value of the vector field at the Coordinate coordinate as a CylinderVector
CylinderVector value(const Coordinate& coordinate) const;
private:
@@ -5,19 +5,30 @@
#include <random>
#include "simulation/coordinates.h"
// defined in "velocity_distribution_function.h"
class VelocityDistributionFunction;
// class to define the minimum requirements of a velocity distribution function
// (in the frame center of mass frame)
class VelocityDistribution {
public:
// draw a randomly oriented Cartesian velocity vector at the Coordinate position
// using the random engine
virtual CartesianVector rollVelocity(const Coordinate& position,
std::mt19937* engine) = 0;
};
// class that defines a velocity distribution by the usage of a VelocityDistributionFunction
// object
class VelocityDistributionFromFunction : public VelocityDistribution {
public:
// Constructor: takes a shared_ptr to the VelocityDistributionFunction, that defines the
// distribution to be drawn from
VelocityDistributionFromFunction(
std::shared_ptr<VelocityDistributionFunction> fv);
// returns a radnomly oriented CartesianVector drawn from the VelocityDistribution
// given at creation of the object
CartesianVector rollVelocity(const Coordinate& position,
std::mt19937* engine);
@@ -6,17 +6,27 @@
#include "simulation/coordinates.h"
// defined in "simulation/energy_distribution.h"
class EnergyDistributionFunction;
// class to define minimum requirements for a VelocityDistributionFunction child class
class VelocityDistributionFunction {
public:
virtual CartesianVector rollVelocity(std::mt19937* engine) = 0;
};
// class for a velocity distribution, that has a isotropically distributed
// direction of the velocity vector and an modulus that is inferred from
// an energy distribution
class IsotropicDistribution : public VelocityDistributionFunction {
public:
// Constructor: takes a shared_ptr to an EnergyDistributionFunction that describes
// the distribution of the energy and the mass of the particle
// to transform the drawn energy to the corresponding velocity
IsotropicDistribution(std::shared_ptr<EnergyDistributionFunction> f_E,
double mass_kg);
// draw an isotropically directed velocity vector with a modulus determined by the
// EnergyDistributionFunction given at construction of the object
CartesianVector rollVelocity(std::mt19937* engine);
private:
@@ -24,11 +34,19 @@ class IsotropicDistribution : public VelocityDistributionFunction {
const double mass_kg_;
};
// class for a velocity distribution, that has a fixed direction of the velocity vector
// and an modulus that is inferred from an energy distribution
class DirectedDistribution : public VelocityDistributionFunction {
public:
// Constructor: takes a shared_ptr to an EnergyDistributionFunction that describes
// the distribution of the energy and the mass of the particle
// to transform the drawn energy to the corresponding velocity
// and the direction of the velocity vector
DirectedDistribution(std::shared_ptr<EnergyDistributionFunction> f_E,
double mass_kg,
const CartesianVector& direction);
// draw a directed velocity vector with a modulus determined by the
// EnergyDistributionFunction given at construction of the object
CartesianVector rollVelocity(std::mt19937* engine);
private:
+11
View File
@@ -5,19 +5,30 @@
#include <map>
#include <string>
// structure to measure a timing (stores begin and endpoint and the corresponding timespan)
struct TimerEvent {
std::chrono::time_point<std::chrono::high_resolution_clock> start;
std::chrono::time_point<std::chrono::high_resolution_clock> stop;
std::chrono::duration<double, std::nano> total_timespan;
};
// class to time between a start and endpoint if the code has been compiled with
// USE_TIMER = true, otherwise does nothing
class SimulationTimer {
public:
// if first invocation of eventStartPoint with a specific event_name, adds a
// TimerEvent at the time it was called; otherwise sets the value to
// the time it has been invoked
static void eventStartPoint(std::string event_name);
// sets the endpoint in the TimerEvent struct to the time the function was called
// the event_name has to match with an eventStartPoint invocation (not checked)
// calculates the timedifference
static void eventStopPoint(std::string event_name);
// print a formatted string containing all event_names and their respective timing to stdout
static void printDurations();
private:
// map to store all event_names with their TimerEvent structs
static std::map<std::string, TimerEvent> timed_events_;
};
+1 -1
View File
@@ -1,7 +1,7 @@
{
"VectorfieldExample1": {
"VectorFieldConstant": {
"Constant": {
"constant": {
"vector": [ 1, 2, 3]
}
}
+1 -1
View File
@@ -17,7 +17,7 @@ std::function<double(double)> PiecewiseLinear(std::vector<double> positions,
return [=](double x) {
const auto lb = coordinates.lower_bound(x);
const auto ub = coordinates.upper_bound(x);
const auto ub = coordinates.upper_bound(x); // i think superfluous
if (lb == coordinates.end()) {
return coordinates.rbegin()->second;
+7 -7
View File
@@ -312,8 +312,8 @@ double buildExcitationEnergy(std::string excitation_state) {
} else if (excitation_state == "england_rotational_j1_to_j3") {
return 0.0727;
} else {
ERROR(
"This type of cross section ExcitationState is not implemented in "
ERROR( excitation_state +
": This type of cross section ExcitationState is not implemented in "
"buildExcitationEnergy.");
return 0.;
}
@@ -383,8 +383,8 @@ std::function<double(double)> buildExcitationCrossSection(
return interaction::totalCrossSection::
eT2_excitation_rotational_j1_to_j3_england();
} else {
ERROR(
"This type of cross section ExcitationState is not implemented in "
ERROR( excitation_state +
": This type of cross section ExcitationState is not implemented in "
"buildExcitationCrossSection.");
return nullptr;
}
@@ -397,7 +397,7 @@ std::function<double(double, double)> build2DCrossSection(json_t* object) {
if (function_name == "eT2_ionization_bed") {
return interaction::d2CrossSection::eT2_ionization_bed();
} else {
ERROR("This predefined function does not exist");
ERROR(function_name + ": This predefined function does not exist");
return nullptr;
}
} else {
@@ -452,7 +452,7 @@ std::shared_ptr<species::Specie> findTarget(
} else if (tracked_species.count(target_name)) {
return tracked_species.at(target_name);
} else {
ERROR("The specified target does not exist.");
ERROR(target_name + ": The specified target does not exist.");
return nullptr;
}
};
@@ -464,7 +464,7 @@ std::shared_ptr<species::TrackedSpecie> findTracked(
if (tracked_species.count(target_name)) {
return tracked_species.at(target_name);
} else {
ERROR("The specified target does not exist.");
ERROR(target_name + ": The specified target does not exist.");
return nullptr;
}
}
+1
View File
@@ -8,6 +8,7 @@
namespace generator {
// map for the implemented species to their masses in kg
std::map<species::ImplementedSpecies, double> SpeciesMasses::mass_ = {
{species::ImplementedSpecies::electron, SI::me},
{species::ImplementedSpecies::T2, 6 * SI::mp + 2 * SI::me},
+1 -1
View File
@@ -2,7 +2,7 @@
#include <functional>
#include "IO/hdf5_reader.h"
#include "generators/binning_generator.h"
// #include "generators/binning_generator.h"
#include "generators/function_generator.h"
#include "simulation/errors.h"
#include "simulation/homebase.h"
+1
View File
@@ -16,6 +16,7 @@ InteractionOutput ChargeExchange::performInteraction(
DEBUG_LEVEL_3("Perform charge exchange.");
const auto x_impact = particle.position();
// draw velocity of the target specie
const blitz::TinyVector<double, 3> v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
target_->velocityDistibution()
+4
View File
@@ -24,12 +24,16 @@ InteractionOutput ClusterFormation::performInteraction(
target_->velocityDistibution()
->rollVelocity(x_impact, generator->engine())
.cartesianEntries();
// kinetic energy of the target particle
const double energy_eV =
kinematic::kineticEnergy(v_target, target_->mass_kg()) *
UnitConversion::JouleToeV;
// interaction product has the same energy as the target cluster
// and the same direction as well
const blitz::TinyVector<double, 3> v_cluster =
kinematic::velocity(energy_eV, product_->mass_kg()) * v_target /
kinematic::norm(v_target);
// create the product particle
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster));
InteractionOutput output;
+10
View File
@@ -19,26 +19,35 @@ InteractionOutput ElasticScattering::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
DEBUG_LEVEL_3("Perform elastic scattering.");
// get the information of the incident particle
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
const auto x_impact = particle.position();
// draw the velocity of the target particle
const blitz::TinyVector<double, 3> v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
target_->velocityDistibution()
->rollVelocity(x_impact, generator->engine())
.cartesianEntries();
// transform the velocity of the incident particle into the rest frame of the
// target particle
const blitz::TinyVector<double, 3> v_laboratory =
kinematic::velocityTargetFixed(v_impact, v_target, particle.mass_kg(),
target_->mass_kg());
// calculate the energy in the rest frame of the target particle
const double E_kin =
kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
UnitConversion::JouleToeV;
// draw the direction of the incident particle after the scattering in the
// center of mass frame
const double theta = theta_distrib_->roll(generator->engine(), E_kin);
const double phi = generator->rollUniform(0., 2 * M_PI);
// rotate the velocity of the incident particle in the center of mass frame
// and transform it back to the original frame
const blitz::TinyVector<double, 3> v_impact_new =
kinematic::rotateVelocityInCenterOfMassFrame(
v_impact, v_target, particle.mass_kg(), target_->mass_kg(), theta,
@@ -46,6 +55,7 @@ InteractionOutput ElasticScattering::performInteraction(
particle.velocity(CartesianVector(v_impact_new));
// no new particles were created and the incident particle is not destroyed by the interaction
return InteractionOutput();
}
+4 -1
View File
@@ -13,7 +13,7 @@ Excitation::Excitation(std::function<double(double)> cross_section,
: Interaction(cross_section, target),
excitation_energy_eV_(excitation_energy_eV) {
ASSERT_POSITIVE(&excitation_energy_eV_,
"The exitationenergy must be positive.");
"The exitation energy must be positive.");
}
InteractionOutput Excitation::performInteraction(particle::Particle& particle,
@@ -26,8 +26,11 @@ InteractionOutput Excitation::performInteraction(particle::Particle& particle,
const double E_kin = kinematic::kineticEnergy(v_impact, particle.mass_kg()) *
UnitConversion::JouleToeV;
// since the target is (usually) not tracked, only the energy of the energy of the
// electron changes
const double E_kin_new = E_kin - excitation_energy_eV_;
// the direction of the velocity is not changed
const blitz::TinyVector<double, 3> v_impact_new =
kinematic::velocityVector(E_kin_new, n_impact, particle.mass_kg());
particle.velocity(CartesianVector(v_impact_new));
+2 -1
View File
@@ -20,7 +20,8 @@ double FreeMovement::microscopicCrossSection(double energy_eV) {
return SimConstants::minimal_cross_section;
}
double FreeMovement::macroscopicCrossSection(particle::Particle& particle) {
// returns a very small number, so the interaction will only be
// returns a very small number, so the interaction will be very unlikely compared
// to the other interactions
return SimConstants::minimal_macroscopic_cross_section;
}
}; // namespace interaction
+14 -1
View File
@@ -37,6 +37,11 @@ InteractionOutput ElectronIonization::performInteraction(
blitz::TinyVector<double, 3> v_target;
blitz::TinyVector<double, 3> v_laboratory;
// repeatedly draw the velocity of the target specie until the energy
// of the incident electron in the rest frame of the target
// is higher than the ionization threshold energy
// (otherwise the interaction could not happen)
double E_impact;
do {
v_target =
@@ -52,14 +57,18 @@ InteractionOutput ElectronIonization::performInteraction(
UnitConversion::JouleToeV;
} while (E_impact <= ionization_energy_eV_);
// draw the impact energy of the slower of the two electrons after the interaction
const double E_impact_new =
energy_distribution_->rollImpactParticleEnergyAfterCollision(E_impact,
generator);
// calculate the energy of the second electron
const double E_ejected =
std::max(0., E_impact - E_impact_new - ionization_energy_eV_);
// draw the polar angle of the slower electron
const double polar_angle_impact_new = generator->rollUniform(0., 2 * M_PI);
// calculate the polar angle of the faster electron
const double polar_angle_ejected = (polar_angle_impact_new - M_PI) < 0.
? (polar_angle_impact_new + M_PI)
: (polar_angle_impact_new - M_PI);
@@ -79,6 +88,8 @@ InteractionOutput ElectronIonization::performInteraction(
const blitz::TinyVector<double, 3> v_lab_norm =
v_laboratory / kinematic::norm(v_laboratory);
// rotate the normal vector in the target rest frame and transform back
// into the original referenceframe
const blitz::TinyVector<double, 3> v_impact_new =
kinematic::rotateVector(v_lab_norm, azimuth_angle_impact_new,
polar_angle_impact_new) *
@@ -93,6 +104,7 @@ InteractionOutput ElectronIonization::performInteraction(
particle.velocity(v_impact_new);
// add the new particles to the InteractionOutput
InteractionOutput output;
output.add(
particle::Particle(electron_, x_impact, CartesianVector(v_ejected)));
@@ -124,7 +136,8 @@ double IonizationEnergyDistribution::rollImpactParticleEnergyAfterCollision(
cross_section =
generator->rollUniform(cross_section_min, cross_section_max);
} while (cross_section > d2_cross_section_(impact_energy, energy_after));
// outgoing particles are indistiquishable
// outgoing particles are indistiquishable, therefore always return the lower of the
// two possible energies
energy_after = energy_after > (impact_energy - ionization_energy_eV_) / 2.
? energy_after
: (impact_energy - ionization_energy_eV_) - energy_after;
+18 -5
View File
@@ -24,6 +24,7 @@ InteractionOutput Recombination::performInteraction(
std::vector<double> energyBinBorders = recombination_target_->
dynamicDensityField()->energyBinning()->binBorders();
// calculate the density scaled cross section for each energy bin
if(recombination_target_->type() == species::ImplementedSpecies::electron) {
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
macroscopic_bin_cross_sections_m.push_back(
@@ -33,14 +34,18 @@ InteractionOutput Recombination::performInteraction(
const blitz::TinyVector<double, 3> v_particle =
particle.velocity().cartesianEntries();
// ion targets need to have a drift velocity defined in the json file
// (a determination is not yet part of the simulation itself)
if(!recombination_target_->driftVelocity()) {
ERROR(recombination_target_->name() + ": does not have a drift velocity!");
}
// drift velocity of the target particle
const blitz::TinyVector<double, 3> v_partner =
recombination_target_->driftVelocity()
->driftVelocity(particle.position()).cartesianEntries();
// velocity of incident particle in the drift frame of the target species
const blitz::TinyVector<double, 3> velocity_target_fixed =
kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
recombination_target_->mass_kg());
@@ -49,7 +54,9 @@ InteractionOutput Recombination::performInteraction(
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) *
UnitConversion::JouleToeV;
// velocity distribution in the drift frame assumed to be isotropic -> averages out
// so that the density scaled cross section only depends on the kinetic energy
// of the electrons in the drift frame
double energy_eV_bin_center;
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
@@ -69,18 +76,23 @@ InteractionOutput Recombination::performInteraction(
". But recombination was chosen.");
}
// distribution to choose the energy (bin) of the actual target particle that will
// perform the interaction
std::discrete_distribution<int> energy_bin_decider(
macroscopic_bin_cross_sections_m.begin(),
macroscopic_bin_cross_sections_m.end());
const int energy_bin = energy_bin_decider(*(generator->engine()));
// calculate the energy of the chosen energy bin
const double energy_eV = (energyBinBorders[energy_bin] +
energyBinBorders[energy_bin+1]) / 2.;
// log the deletion in the dynamic density field of the target specie
recombination_target_->dynamicDensityField()->logDeletion(particle.position(),
energy_eV);
InteractionOutput output;
// incident particle is lost
output.deleteCurrentParticle(true);
if (particle.specie()->deletionLogger()) {
@@ -102,13 +114,14 @@ double Recombination::macroscopicCrossSection(particle::Particle& particle) {
}
return macroscopic_cross_section;
}
// if target is not an electron -> cross section independent of Energy of
// the target
// if target is not an electron -> cross section independent of energy of
// the target (electrons are much faster than the ions)
return Interaction::macroscopicCrossSection(particle);
}
// implicitly assumes that the bin index > 0 and < maxBinIndex
// calculates ∫dE_t σ(E_t) dn_t/dE_t (i.e. only applicable if
// cross section is independent of E_i); i: incident, t: target
// calculates ∫dE_t σ(E_t) dn_t/dE_t (only applicable if
// cross section is effectively independent of E_i)
// over the given energy bin; i: incident, t: target
double Recombination::macroscopicCrossSection(const Coordinate& position,
const int energy_bin_index) {
if (energy_bin_index > recombination_target_->dynamicDensityField()
+5
View File
@@ -11,6 +11,7 @@
#include "tools/simulation_time.h"
int main(int argc, char* argv[]) {
// timing of the whole simulation, adds the beginning time when the simulation began
SimulationTimer::eventStartPoint(std::string("Simulation"));
MpiCommunication::init(argc, argv);
@@ -18,6 +19,8 @@ int main(int argc, char* argv[]) {
std::string parameter_filename;
std::string homebase_folder;
// The name of the json-parameter file is given by the commandline
// variable "--parameter_file"
for (int arg = 1; arg < argc; arg++) {
if (std::string(argv[arg]) == "--parameter_file") {
parameter_filename = std::string(argv[arg + 1]);
@@ -33,8 +36,10 @@ int main(int argc, char* argv[]) {
simulation.start();
simulation.finalize();
// adds the time the simulation ended
SimulationTimer::eventStopPoint(std::string("Simulation"));
if (MpiCommunication::mpiRank() == 0) {
// calculate and output the measured timings to stdout
SimulationTimer::printDurations();
}
+6
View File
@@ -5,6 +5,9 @@
#include "simulation/event_position_distribution.h"
#include "simulation/scalar_field.h"
// function to create a zero initialized 4 dimensional blitz::Array
// defined by the given Range objects (ordering of dimensions: radial, phi, longitudinal, energy)
template <class T>
blitz::Array<T, 4> initiate4DArray(blitz::Range radial,
blitz::Range phi,
@@ -15,6 +18,9 @@ blitz::Array<T, 4> initiate4DArray(blitz::Range radial,
return data.copy();
}
// creates and returns a 3d blitz::Array containing the volumes of the bins defined
// by the Range objects and a blitz::TinyVector containing the spacings of the
// three spatial dimension (ordering: radial, azimuthal, longitudinal)
blitz::Array<double, 3> initiateVolumeArray(
blitz::Range radial,
blitz::Range phi,
+3
View File
@@ -2,6 +2,9 @@
#include <math.h>
#include <algorithm>
// create a logarithmic spacing of edge-values for num_bins bins,
// where bin_min is the first bin border value (i.e. lowest value)
// and bin_max is the last bin border value (i.e. the highest value)
std::vector<double> generateBinBorders(double bin_min,
double bin_max,
int num_bins) {
+1
View File
@@ -19,6 +19,7 @@ double TritiumBetaDecay::rollEnergy(std::mt19937* engine) {
double random_number_x;
double random_number_y;
double return_value;
// Rejection Method
do {
random_number_x = x_distribution_(*engine);
random_number_y = y_distribution_(*engine);
@@ -7,6 +7,8 @@ EventPositionDistribution::EventPositionDistribution(
Limit phi_position,
Limit z_position)
: mother_density_(mother_density),
// draw r^2 uniformly in order to account for the volume of the segment, that
// increases linear in r. (this drawing method would recreate a uniform density)
r_values(std::uniform_real_distribution<double>(r_position.min*r_position.min,
r_position.max*r_position.max)),
phi_values(std::uniform_real_distribution<double>(phi_position.min,
+4
View File
@@ -30,6 +30,7 @@ particle::Particle Injector::rollNewParticle(
blitz::TinyVector<double, 3> velocity =
creation_velocity_distribution->rollVelocity(position, engine)
.cartesianEntries();
// if mother_drift_velocity is not null boost the drawn velocity by that vector
if (mother_drift_velocity_) {
velocity = kinematic::relativisticBoost(
velocity,
@@ -41,10 +42,13 @@ particle::Particle Injector::rollNewParticle(
std::vector<particle::Particle> Injector::rollNewParticles(
std::mt19937* engine) {
// particles are assumed to be created by a decay process
// therefore the resulting particles all start out at the same position
CylinderCoordinate position = position_distribution_->rollPosition(engine);
DEBUG_LEVEL_3("Injected z position: " +
std::to_string(position.cylinderEntries()(2)));
std::vector<particle::Particle> new_particles;
// draw the velocity of all particles to be injected an append them to the new_particles vector
for (auto& injector_info : injector_infos_) {
new_particles.push_back(
rollNewParticle(engine, position, injector_info.created_specie,
-1
View File
@@ -31,7 +31,6 @@ Interaction::Interaction(std::function<double(double)> cross_section,
std::shared_ptr<species::Specie> target)
: cross_section_(cross_section), target_(target) {}
// assumes that v_particle >> v_target
double Interaction::macroscopicCrossSection(particle::Particle& particle) {
const auto x_particle = particle.position();
const blitz::TinyVector<double, 3> v_particle =
+9 -2
View File
@@ -29,7 +29,7 @@ void BorisMover::move(particle::Particle* particle,
double old_kinetic_energy = particle->kineticEnergy_eV();
if (old_kinetic_energy < 1E-9) {
// Guard against small enegies taking up much time without contributing to
// Guard against small energies taking up much time without contributing to
// density
return;
}
@@ -185,20 +185,23 @@ void DriftMover::move(particle::Particle* particle,
magnetic_field->value(old_position).cartesianEntries(old_position);
const double B_norm = kinematic::norm(B);
// calculate component of the velocity parallel to the magnetic field
const blitz::TinyVector<double, 3> v_parallel =
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
const double v_parallel_norm = kinematic::norm(v_parallel);
// calculate component of the velocity perpendicular to the magnetic field
const blitz::TinyVector<double, 3> v_perp =
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
const double v_perp_norm = kinematic::norm(v_perp);
// calculate E cross B drift velocity
const blitz::TinyVector<double, 3> v_drift = driftVelocity(B, E);
const double v_drift_norm = kinematic::norm(v_drift);
const double stepsize = std::min(leftover_distance, maximal_distance_m_);
// guard against very large timesteps i.e. v ~ 0 -> timestep = Inf
// should be a very rare case (but has happend)
// should be a very rare case
const double timestep = std::min(
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
max_time_alive);
@@ -207,11 +210,13 @@ void DriftMover::move(particle::Particle* particle,
v_parallel * timestep;
const blitz::TinyVector<double, 3> movement_drift = v_drift * timestep;
// calculate component of electric field parallel to the magnetic field
const blitz::TinyVector<double, 3> E_parallel =
kinematic::parallelVector(E, B);
const blitz::TinyVector<double, 3> dv_electric =
timestep * particle->charge_C() * E_parallel / particle->mass_kg();
// check if the particle has a gyroradius > 0
if (v_perp_norm > SimConstants::compare_epsilon) {
const double gyro_radius = particle->mass_kg() * v_perp_norm /
(B_norm * particle->charge_C());
@@ -219,12 +224,14 @@ void DriftMover::move(particle::Particle* particle,
const blitz::TinyVector<double, 3> velocity_normal =
(-1) * blitz::cross(B, v_perp);
// calculate the vector pointing from the gyro center to the particle position
const blitz::TinyVector<double, 3> offset_to_gyro_center =
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
const double gyro_frequency =
particle->charge_C() * B_norm / particle->mass_kg();
const double total_rotation_angle = gyro_frequency * timestep;
// move the particle around the gyro center
const blitz::TinyVector<double, 3> movement_around_gyro_center =
kinematic::rotateVector(offset_to_gyro_center, B,
total_rotation_angle) -
@@ -5,11 +5,14 @@
IsotropicAngleDistribution::IsotropicAngleDistribution()
: distribution_(std::uniform_real_distribution<double>(0, M_PI)) {}
double IsotropicAngleDistribution::roll(std::mt19937* engine,
double energy_eV) {
return distribution_(*engine);
}
// calculate the borders of the array energies, that defines the position
// of the bins
std::vector<double> energyBinBorders(const blitz::Array<double, 1>& energies) {
std::vector<double> energy_bin_borders;
+7 -4
View File
@@ -99,6 +99,7 @@ void Simulation::start() {
int num_cpu_syncs = 0;
// special case for unbalanced cpu loads to prevent a deadlock
bool empty_loop = false;
if(total_simulated_events % MpiCommunication::mpiSize() != 0) {
if((events_this_cpu % event_stride == 0) &&
@@ -117,13 +118,13 @@ void Simulation::start() {
empty_loop = false;
}
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events);
int evenst_of_cycle = eventsOfCycle(event_stride, leftover_events);
SIM_INFO("Leftover events on first cpu: " +
std::to_string(leftover_events));
processEvents(events_of_cylcle);
processEvents(evenst_of_cycle);
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
leftover_events -= events_of_cylcle;
leftover_events -= evenst_of_cycle;
SIM_INFO("Cpu sync.");
SimulationTimer::eventStartPoint(std::string("CpuSync"));
@@ -153,11 +154,12 @@ void Simulation::processEvents(int events) {
int current_event = 0;
while ((current_event < events) || (!particle_queue.empty())) {
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
// if the particle queue is empty a new beta decay event is started
if (particle_queue.empty()) {
current_event += 1;
DEBUG_LEVEL_2("Inject particles to queue.");
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
// draw new beta decay particles
std::vector<particle::Particle> new_particles =
determineInjectedParticles(random_.get());
SimulationTimer::eventStopPoint(std::string("ParticleInjection"));
@@ -167,6 +169,7 @@ void Simulation::processEvents(int events) {
new_particles.end());
}
DEBUG_LEVEL_2("Particles in queue: " + std::to_string(particle_queue.size()));
// choose a random particle from the particle queue to be processed
const int particle_number =
particleNumberFromQueue(particle_queue.size(), random_.get());
+2
View File
@@ -10,6 +10,8 @@ std::function<double(double)> tritiumDecayEnergySpectrum(double prefactor) {
ERROR("Prefactor must be positive");
}
// defines the function to be returned using a lambda expression
// (standard return type of lambdas is double)
return [=](double energy_eV) {
if (energy_eV < 0.) {
ERROR("Beta decay spectrum not defined for negative energies.");
+2 -2
View File
@@ -12,7 +12,7 @@ double lengthPrefactor(const std::string& unit) {
} else if (unit == "mm") {
return 1E-3;
} else {
ERROR("I dont know this length unit.");
ERROR("I dont know this length unit: " + unit);
return 0;
}
}
@@ -32,7 +32,7 @@ double energyPrefactor(const std::string& unit) {
} else if (unit == "J") {
return 1 / SI::e;
} else {
ERROR("I dont know this energy unit.");
ERROR("I dont know this energy unit: " + unit);
return 0;
}
}