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
+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: