Version 2, position dependent E/B, kinetic ions, boris mover, terminator
This commit is contained in:
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#ifndef COMPARE_H
|
||||
#define COMPARE_H
|
||||
|
||||
#include "constants/sim_constants.h"
|
||||
|
||||
bool isEqual(double a, double b) {
|
||||
return std::abs(a - b) < SimConstants::compare_epsilon;
|
||||
}
|
||||
|
||||
#endif /* COMPARE_H */
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
#ifndef COORDINATES_H
|
||||
#define COORDINATES_H
|
||||
|
||||
#include "blitz/array.h"
|
||||
|
||||
struct BinCoordinate {
|
||||
BinCoordinate(const blitz::TinyVector<int, 3>& bin,
|
||||
const blitz::TinyVector<double, 3>& frac);
|
||||
|
||||
BinCoordinate(blitz::TinyVector<double, 3> position,
|
||||
blitz::TinyVector<double, 3> spacing);
|
||||
|
||||
blitz::TinyVector<int, 3> bin;
|
||||
blitz::TinyVector<double, 3> frac;
|
||||
|
||||
static blitz::TinyVector<int, 3> binValue(
|
||||
blitz::TinyVector<double, 3> position,
|
||||
blitz::TinyVector<double, 3> spacing);
|
||||
|
||||
static blitz::TinyVector<double, 3> binFrac(
|
||||
blitz::TinyVector<double, 3> position,
|
||||
blitz::TinyVector<double, 3> spacing);
|
||||
};
|
||||
|
||||
class Coordinate {
|
||||
public:
|
||||
virtual blitz::TinyVector<double, 3> cartesianEntries() const = 0;
|
||||
virtual blitz::TinyVector<double, 3> cylinderEntries() const = 0;
|
||||
|
||||
virtual void add(const Coordinate& coordinate) = 0;
|
||||
};
|
||||
|
||||
class CartesianCoordinate : public Coordinate {
|
||||
public:
|
||||
CartesianCoordinate(const blitz::TinyVector<double, 3>& cartesian_position);
|
||||
CartesianCoordinate(const Coordinate& coordinate);
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
void add(const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
blitz::TinyVector<double, 3> cartesian_position;
|
||||
};
|
||||
|
||||
class CylinderCoordinate : public Coordinate {
|
||||
public:
|
||||
CylinderCoordinate(const blitz::TinyVector<double, 3>& cylinder_position);
|
||||
CylinderCoordinate(const Coordinate& coordinate);
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
void add(const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
void limitPhi();
|
||||
blitz::TinyVector<double, 3> cylinder_position;
|
||||
};
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
virtual blitz::TinyVector<double, 3> cartesianEntries(
|
||||
const Coordinate& coordinate) const = 0;
|
||||
virtual blitz::TinyVector<double, 3> cylinderEntries(
|
||||
const Coordinate& coordinate) const = 0;
|
||||
|
||||
virtual void add(const Vector& vector, const Coordinate& coordinate) = 0;
|
||||
};
|
||||
|
||||
class CylinderVector : public Vector {
|
||||
public:
|
||||
CylinderVector(const CylinderVector& vector);
|
||||
CylinderVector(const blitz::TinyVector<double, 3> cylinder_vector);
|
||||
CylinderVector(const Vector& vector, const Coordinate& coordinate);
|
||||
|
||||
CylinderVector operator+(const CylinderVector& coordinate);
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianEntries(
|
||||
const Coordinate& coordinate) const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries(
|
||||
const Coordinate& coordinate) const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
void add(const Vector& vector, const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
blitz::TinyVector<double, 3> cylinder_vector;
|
||||
};
|
||||
|
||||
class CartesianVector : public Vector {
|
||||
public:
|
||||
CartesianVector(const blitz::TinyVector<double, 3> cartesian_vector);
|
||||
CartesianVector(const CartesianVector& vector);
|
||||
|
||||
CartesianVector(const Vector& vector, const Coordinate& coordinate);
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianEntries(
|
||||
const Coordinate& coordinate) const;
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries(
|
||||
const Coordinate& coordinate) const;
|
||||
|
||||
void add(const Vector& vector, const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
blitz::TinyVector<double, 3> cartesian_vector;
|
||||
};
|
||||
|
||||
#endif /* COORDINATES_H */
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#ifndef CPU_SYNCHRONIZER_H
|
||||
#define CPU_SYNCHRONIZER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "blitz/array.h"
|
||||
|
||||
class DynamicDensityField;
|
||||
class Timer;
|
||||
class CurrentCollector;
|
||||
class DeletionLogger;
|
||||
|
||||
namespace species {
|
||||
class TrackedSpecie;
|
||||
};
|
||||
|
||||
class CpuSynchronizer {
|
||||
public:
|
||||
// CpuSynchronizer();
|
||||
|
||||
void synchronize(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
||||
tracked_species);
|
||||
|
||||
void synchronize(DynamicDensityField* field);
|
||||
void synchronize(CurrentCollector* collector);
|
||||
void synchronize(DeletionLogger* logger);
|
||||
void synchronize(Timer* timer);
|
||||
|
||||
void sumToAll(blitz::Array<double, 4>& array);
|
||||
void sumToAll(blitz::Array<double, 3>& array);
|
||||
void sumToAll(blitz::Array<long int, 4>& array);
|
||||
void sumToAll(double& value);
|
||||
void sumToAll(long int& value);
|
||||
};
|
||||
|
||||
#endif /* CPU_SYNCHRONIZER_H */
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#ifndef CURRENT_COLLECTOR_H
|
||||
#define CURRENT_COLLECTOR_H
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/energy_binning.h"
|
||||
#include "simulation/particle.h"
|
||||
#include "simulation/position_binning.h"
|
||||
#include "simulation/timer.h"
|
||||
|
||||
class CurrentCollector {
|
||||
public:
|
||||
CurrentCollector(const CylinderBinning& position_binning,
|
||||
std::shared_ptr<Timer> timer);
|
||||
|
||||
void collect(particle::Particle* particle, const Coordinate& old_position);
|
||||
|
||||
blitz::Array<double, 3> negativeCrossingsInR() const;
|
||||
blitz::Array<double, 3> positiveCrossingsInR() const;
|
||||
blitz::Array<double, 3> areaInR() const;
|
||||
blitz::Array<double, 3> currentInR() const;
|
||||
|
||||
blitz::Array<double, 3> negativeCrossingsInPhi() const;
|
||||
blitz::Array<double, 3> positiveCrossingsInPhi() const;
|
||||
blitz::Array<double, 3> areaInPhi() const;
|
||||
blitz::Array<double, 3> currentInPhi() const;
|
||||
|
||||
blitz::Array<double, 3> negativeCrossingsInZ() const;
|
||||
blitz::Array<double, 3> positiveCrossingsInZ() const;
|
||||
blitz::Array<double, 3> areaInZ() const;
|
||||
blitz::Array<double, 3> currentInZ() const;
|
||||
|
||||
double physicalTime() const;
|
||||
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
private:
|
||||
void collectRadialMovement(const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new);
|
||||
void collectLongitudinalMovement(const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new);
|
||||
void collectAzimuthalMovement(const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new);
|
||||
|
||||
blitz::Array<double, 3> createAreaLongitudinal(
|
||||
const CylinderBinning& position_binning);
|
||||
blitz::Array<double, 3> createCrossingsLongitudinal(
|
||||
const CylinderBinning& position_binning);
|
||||
|
||||
blitz::Array<double, 3> createAreaRadial(
|
||||
const CylinderBinning& position_binning);
|
||||
blitz::Array<double, 3> createCrossingsRadial(
|
||||
const CylinderBinning& position_binning);
|
||||
|
||||
blitz::Array<double, 3> createAreaAzimuthal(
|
||||
const CylinderBinning& position_binning);
|
||||
blitz::Array<double, 3> createCrossingsAzimuthal(
|
||||
const CylinderBinning& position_binning);
|
||||
|
||||
blitz::Array<double, 3> z_negative_crossings;
|
||||
blitz::Array<double, 3> z_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> phi_negative_crossings;
|
||||
blitz::Array<double, 3> phi_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> r_negative_crossings;
|
||||
blitz::Array<double, 3> r_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> collector_areas_r;
|
||||
blitz::Array<double, 3> collector_areas_phi;
|
||||
blitz::Array<double, 3> collector_areas_z;
|
||||
|
||||
CylinderBinning position_binning_;
|
||||
std::shared_ptr<Timer> timer_;
|
||||
};
|
||||
|
||||
#endif /* CURRENT_COLLECTOR_H */
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
#ifndef DENSITY_FIELD_H
|
||||
#define DENSITY_FIELD_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/cpu_synchronizer.h"
|
||||
#include "simulation/energy_binning.h"
|
||||
#include "simulation/position_binning.h"
|
||||
#include "simulation/timer.h"
|
||||
|
||||
class ScalarField;
|
||||
class EventPositionDistribution;
|
||||
|
||||
class DensityField {
|
||||
public:
|
||||
virtual double density(const Coordinate& position) = 0;
|
||||
virtual double density(const Coordinate& position, double energy_eV) = 0;
|
||||
};
|
||||
|
||||
class DynamicDensityField : public DensityField {
|
||||
public:
|
||||
DynamicDensityField(const CylinderBinning& position_binning,
|
||||
const EnergyBinning& energy_binning,
|
||||
std::shared_ptr<Timer> timer);
|
||||
|
||||
bool changedPositionBin(const Coordinate& old_position,
|
||||
const Coordinate& new_position) const;
|
||||
|
||||
bool changedEnergyBin(double old_energy_eV, double new_energy_eV) const;
|
||||
|
||||
void logMovement(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double time_in_bin_s);
|
||||
|
||||
void logDeletion(const Coordinate& position, double energy_eV);
|
||||
|
||||
double density(const Coordinate& position);
|
||||
double density(const Coordinate& position, double energy_eV);
|
||||
|
||||
blitz::Array<double, 3> densityArray();
|
||||
blitz::Array<double, 4> spectrumArray();
|
||||
blitz::Array<double, 4> timeInBinArray() const;
|
||||
blitz::Array<long int, 4> deletedParticlesArray() const;
|
||||
blitz::Array<double, 3> binVolumeArray() const;
|
||||
|
||||
const EnergyBinning* energyBinning() const;
|
||||
const CylinderBinning* positionBinning() const;
|
||||
|
||||
double physicalTime() const;
|
||||
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
private:
|
||||
// coordinate ordering: r, phi, z, E
|
||||
// bin numbering
|
||||
// radial:
|
||||
// 0, ..., num_bin_r-1: r < r_max
|
||||
// num_bin_r: r >= r_max
|
||||
//
|
||||
// azimuthal:
|
||||
// 0, ..., num_bin_phi: all
|
||||
//
|
||||
// longitudinal:
|
||||
// -1: z < 0
|
||||
// 0, ..., num_bin_z-1: 0 <= z < z_max
|
||||
// num_bin_z: z >= z_max
|
||||
BinCoordinate densityBin(const CylinderCoordinate& position) const;
|
||||
void recalculateDensityArray();
|
||||
|
||||
blitz::Array<double, 4> time_in_bin_s_;
|
||||
blitz::Array<long int, 4> deleted_particles_;
|
||||
blitz::Array<double, 4> density_per_m3_;
|
||||
blitz::Array<double, 3> bin_volume_m3_;
|
||||
|
||||
const CylinderBinning position_binning_;
|
||||
const EnergyBinning energy_binning_;
|
||||
|
||||
std::shared_ptr<Timer> timer_;
|
||||
};
|
||||
|
||||
class ConstantDensityField : public DensityField {
|
||||
public:
|
||||
ConstantDensityField(std::shared_ptr<ScalarField> density);
|
||||
|
||||
double density(const Coordinate& position);
|
||||
double density(const Coordinate& position, double energy_eV);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ScalarField> density_;
|
||||
};
|
||||
|
||||
#endif /* DENSITY_FIELD_H */
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#ifndef DRIFT_VELOCITY_H
|
||||
#define DRIFT_VELOCITY_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/vector_field.h"
|
||||
|
||||
class DriftVelocity {
|
||||
public:
|
||||
DriftVelocity(std::shared_ptr<VectorField> drift_velocity);
|
||||
|
||||
CartesianVector driftVelocity(const Coordinate& position);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VectorField> drift_velocity_;
|
||||
};
|
||||
|
||||
#endif /* DRIFT_VELOCITY_H */
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#ifndef ELECTROMAGNETIC_FIELD_H
|
||||
#define ELECTROMAGNETIC_FIELD_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/scalar_field.h"
|
||||
#include "simulation/vector_field.h"
|
||||
|
||||
class ElectricField {
|
||||
public:
|
||||
ElectricField(std::shared_ptr<VectorField> background,
|
||||
std::shared_ptr<VectorField> dynamic);
|
||||
|
||||
CylinderVector value(const Coordinate& position) const;
|
||||
|
||||
void updateDynamicField(std::shared_ptr<VectorField> field);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VectorField> background_;
|
||||
std::shared_ptr<VectorField> dynamic_;
|
||||
};
|
||||
|
||||
class MagneticField {
|
||||
public:
|
||||
MagneticField(std::shared_ptr<VectorField> field);
|
||||
|
||||
CylinderVector value(const Coordinate& position) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VectorField> field_;
|
||||
};
|
||||
|
||||
#endif /* ELECTROMAGNETIC_FIELD_H */
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#ifndef ENERGY_BINNING_H
|
||||
#define ENERGY_BINNING_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
class EnergyBinning {
|
||||
public:
|
||||
EnergyBinning(double minimal_energy, double maximal_energy, int num_bins);
|
||||
EnergyBinning(std::vector<double> energy_bin_borders);
|
||||
|
||||
int bin(double energy_eV) const;
|
||||
int numBins() const;
|
||||
std::vector<double> binBorders() const;
|
||||
int binIndexMin() const;
|
||||
int binIndexMax() const;
|
||||
|
||||
private:
|
||||
const std::vector<double> energy_bin_borders_;
|
||||
};
|
||||
|
||||
#endif /* ENERGY_BINNING_H */
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#ifndef ENERGY_DISTRIBUTION_H
|
||||
#define ENERGY_DISTRIBUTION_H
|
||||
|
||||
#include <functional>
|
||||
#include <random>
|
||||
|
||||
class EnergyDistributionFunction {
|
||||
public:
|
||||
virtual double rollEnergy(std::mt19937* engine) = 0; // eV
|
||||
};
|
||||
|
||||
class TritiumBetaDecay : public EnergyDistributionFunction {
|
||||
public:
|
||||
TritiumBetaDecay();
|
||||
double rollEnergy(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
const std::function<double(double)> tritium_spectrum_;
|
||||
std::uniform_real_distribution<double> x_distribution_;
|
||||
std::uniform_real_distribution<double> y_distribution_;
|
||||
};
|
||||
|
||||
class MaxwellBoltzmann : public EnergyDistributionFunction {
|
||||
public:
|
||||
MaxwellBoltzmann(double temperature_K);
|
||||
double rollEnergy(std::mt19937* engine); // eV
|
||||
private:
|
||||
std::gamma_distribution<double> distribution_;
|
||||
};
|
||||
|
||||
class Constant : public EnergyDistributionFunction {
|
||||
public:
|
||||
Constant(double constant_eV);
|
||||
double rollEnergy(std::mt19937* engine); // eV
|
||||
private:
|
||||
const double constant_eV_;
|
||||
};
|
||||
|
||||
#endif /* ENERGY_DISTRIBUTION_H */
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#ifndef ERRORS_H
|
||||
#define ERRORS_H
|
||||
|
||||
#include <math.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "blitz/array.h"
|
||||
|
||||
#include "simulation/mpi_communication.h"
|
||||
|
||||
#if defined debug_level3 || defined debug_level2 || defined debug_level1 || \
|
||||
defined debug_level0
|
||||
inline void DEBUG(const std::string& message) {
|
||||
std::cout << "#DEBUG<" << MpiCommunication::mpi_rank << ">: " << message
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
#if defined debug_level0
|
||||
inline void DEBUG_LEVEL_0(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_1(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_2(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
||||
#elif defined debug_level1
|
||||
inline void DEBUG_LEVEL_0(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_1(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_2(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
||||
|
||||
#elif defined debug_level2
|
||||
inline void DEBUG_LEVEL_0(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_1(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_2(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
||||
|
||||
#else
|
||||
inline void DEBUG_LEVEL_0(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_1(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_2(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
inline void DEBUG_LEVEL_3(const std::string& message) {
|
||||
DEBUG(message);
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
inline void DEBUG(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_0(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_1(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_2(const std::string& message) {}
|
||||
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
||||
#endif
|
||||
|
||||
inline void SIM_INFO(const std::string& message) {
|
||||
if (MpiCommunication::mpi_rank == 0) {
|
||||
std::cout << "#INFO: " << message << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
inline void ERROR(const std::string& message) {
|
||||
fprintf(stderr, "ERROR <%d> %s\n", MpiCommunication::mpi_rank,
|
||||
message.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
// throw std::runtime_error(message);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ASSERT_POSITIVE(T* value, const std::string& message) {
|
||||
if (!(*value > 0)) {
|
||||
ERROR(message);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ASSERT_NOTNEGATIVE(T* value, const std::string& message) {
|
||||
if (!(*value >= 0)) {
|
||||
ERROR(message);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void ASSERT_EXISTS(T* value, const std::string& message) {
|
||||
if (!value) {
|
||||
ERROR(message);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ASSERT_FINITE(double value, const std::string& message) {
|
||||
if (!std::isfinite(value)) {
|
||||
ERROR(message);
|
||||
}
|
||||
}
|
||||
|
||||
inline void ASSERT_FINITE(const blitz::TinyVector<double, 3>& value,
|
||||
const std::string& message) {
|
||||
if (!std::isfinite(value(0)) || !std::isfinite(value(1)) ||
|
||||
!std::isfinite(value(2))) {
|
||||
ERROR(message);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ERRORS_H */
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
#ifndef EVENT_POSITION_DISTRIBUTION_H
|
||||
#define EVENT_POSITION_DISTRIBUTION_H
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/scalar_field.h"
|
||||
|
||||
struct Limit {
|
||||
Limit() : min(0), max(0){};
|
||||
Limit(double min, double max) : min(min), max(max){};
|
||||
double min;
|
||||
double max;
|
||||
};
|
||||
|
||||
class EventPositionDistribution {
|
||||
public:
|
||||
EventPositionDistribution(std::shared_ptr<ScalarField> mother_density,
|
||||
Limit density,
|
||||
Limit r_position,
|
||||
Limit phi_position,
|
||||
Limit z_position);
|
||||
CylinderCoordinate rollPosition(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ScalarField> mother_density_;
|
||||
|
||||
// for Rejection method
|
||||
std::uniform_real_distribution<double> r_values;
|
||||
std::uniform_real_distribution<double> z_values;
|
||||
std::uniform_real_distribution<double> phi_values;
|
||||
std::uniform_real_distribution<double> density_values;
|
||||
};
|
||||
|
||||
#endif /* EVENT_POSITION_DISTRIBUTION_H */
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#ifndef GEOMETRY_H
|
||||
#define GEOMETRY_H
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
class Geometry {
|
||||
public:
|
||||
virtual bool isInside(const Coordinate& position) const = 0;
|
||||
};
|
||||
|
||||
class Cylinder : public Geometry {
|
||||
public:
|
||||
Cylinder(double radius, double height);
|
||||
bool isInside(const Coordinate& position) const;
|
||||
|
||||
private:
|
||||
const double radius_;
|
||||
const double height_;
|
||||
};
|
||||
|
||||
#endif /* GEOMETRY_H */
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#ifndef HOMEBASE_H
|
||||
#define HOMEBASE_H
|
||||
|
||||
#define STRINGIZER(arg) #arg
|
||||
#define STR_VALUE(arg) STRINGIZER(arg)
|
||||
#define BUILD_HOMEBASE_STRING STR_VALUE(HOMEBASE)
|
||||
|
||||
#endif /* HOMEBASE_H */
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#ifndef INJECTOR_H
|
||||
#define INJECTOR_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
class DriftVelocity;
|
||||
class VelocityDistribution;
|
||||
|
||||
namespace particle {
|
||||
class Particle;
|
||||
}
|
||||
|
||||
namespace species {
|
||||
class Specie;
|
||||
class TrackedSpecie;
|
||||
} // namespace species
|
||||
|
||||
class EventPositionDistribution;
|
||||
|
||||
struct InjectorInfo {
|
||||
public:
|
||||
std::shared_ptr<species::TrackedSpecie> created_specie;
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
|
||||
};
|
||||
|
||||
class Injector {
|
||||
public:
|
||||
Injector(std::vector<InjectorInfo>& injector_info,
|
||||
double activity,
|
||||
std::shared_ptr<EventPositionDistribution> position_distribution,
|
||||
std::shared_ptr<DriftVelocity> mother_drift_velocity);
|
||||
|
||||
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine);
|
||||
double timePassed() const;
|
||||
|
||||
private:
|
||||
std::vector<InjectorInfo> injector_infos_;
|
||||
const double activity_;
|
||||
std::shared_ptr<EventPositionDistribution> position_distribution_;
|
||||
std::shared_ptr<DriftVelocity> mother_drift_velocity_;
|
||||
|
||||
particle::Particle rollNewParticle(
|
||||
std::mt19937* engine,
|
||||
const Coordinate& position,
|
||||
std::shared_ptr<species::TrackedSpecie> created_specie,
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution);
|
||||
};
|
||||
|
||||
#endif /* INJECTOR_H */
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#ifndef INTERACTION_H
|
||||
#define INTERACTION_H
|
||||
|
||||
#include "simulation/particle.h"
|
||||
#include "simulation/random_numbers.h"
|
||||
#include "simulation/species.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace interaction {
|
||||
|
||||
class InteractionOutput {
|
||||
public:
|
||||
InteractionOutput();
|
||||
|
||||
void deleteCurrentParticle(bool new_decider);
|
||||
bool deleteCurrentParticle();
|
||||
void add(const particle::Particle& new_particle);
|
||||
std::vector<particle::Particle> newParticles();
|
||||
|
||||
private:
|
||||
bool delete_current_particle_;
|
||||
std::vector<particle::Particle> new_particles_;
|
||||
};
|
||||
|
||||
class Interaction {
|
||||
public:
|
||||
Interaction(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target);
|
||||
|
||||
virtual double microscopicCrossSection(double energy_eV);
|
||||
virtual double macroscopicCrossSection(particle::Particle& particle);
|
||||
|
||||
virtual InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) = 0;
|
||||
|
||||
protected:
|
||||
std::function<double(double)> cross_section_;
|
||||
std::shared_ptr<species::Specie> target_;
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
#endif /* INTERACTION_H */
|
||||
Executable
+118
@@ -0,0 +1,118 @@
|
||||
#ifndef JANSSON_ADDITIONALS_H
|
||||
#define JANSSON_ADDITIONALS_H
|
||||
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "blitz/array.h"
|
||||
#include "jansson.h"
|
||||
#include "simulation/errors.h"
|
||||
#include "simulation/unit_converter.h"
|
||||
|
||||
typedef std::vector<std::string> json_path;
|
||||
|
||||
inline json_t* json_object_by_path(json_t* object, const json_path& path) {
|
||||
json_t* j_obj = object;
|
||||
for (auto str : path) {
|
||||
j_obj = json_object_get(j_obj, str.c_str());
|
||||
}
|
||||
return j_obj;
|
||||
}
|
||||
|
||||
inline double json_double(json_t* object, double default_value = 0.) {
|
||||
if (object) {
|
||||
return json_real_value(object);
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
inline int json_int(json_t* object, int default_value = 0) {
|
||||
if (object) {
|
||||
return std::floor(json_real_value(object));
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string json_string(json_t* object, std::string default_value = "") {
|
||||
if (object) {
|
||||
return std::string(json_string_value(object));
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool json_bool(json_t* object, bool default_value = false) {
|
||||
if (object) {
|
||||
return (json_string(object) == "true");
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
template <int s>
|
||||
blitz::TinyVector<double, s> json_blitz_vector(json_t* object) {
|
||||
blitz::TinyVector<double, s> vector;
|
||||
size_t index;
|
||||
json_t* value;
|
||||
json_t* array = json_object_by_path(object, {"vector"});
|
||||
size_t size = json_array_size(array);
|
||||
if (size != s) {
|
||||
std::stringstream error_message;
|
||||
error_message << "The provided vector has size: " << size
|
||||
<< ", but is stated as size " << s;
|
||||
ERROR(error_message.str());
|
||||
}
|
||||
|
||||
json_array_foreach(array, index, value) {
|
||||
vector(index) = json_double(value);
|
||||
}
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
inline std::vector<double> json_vector(json_t* object) {
|
||||
std::vector<double> vector;
|
||||
size_t index;
|
||||
json_t* value;
|
||||
json_array_foreach(object, index, value) {
|
||||
vector.push_back(json_double(value));
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
inline json_path json_path_get(json_t* object) {
|
||||
json_path path;
|
||||
|
||||
json_t* value;
|
||||
size_t index;
|
||||
json_array_foreach(object, index, value) {
|
||||
path.push_back(json_string(value));
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
inline json_path json_path_append(const json_path& path,
|
||||
const json_path& append) {
|
||||
json_path result = path;
|
||||
for (auto a : append) {
|
||||
result.push_back(a);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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"}));
|
||||
return unitConvertion::energy(value, unit, output_unit);
|
||||
}
|
||||
|
||||
#endif /* JANSSON_ADDITIONALS_H */
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
#ifndef KINEMATIC_H
|
||||
#define KINEMATIC_H
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
namespace kinematic {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVector(const blitz::TinyVector<double, 3>& v,
|
||||
double theta,
|
||||
double phi);
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||
const blitz::TinyVector<double, 3>& velocity_1,
|
||||
const blitz::TinyVector<double, 3>& velocity_2,
|
||||
double mass_1,
|
||||
double mass_2,
|
||||
double theta,
|
||||
double phi);
|
||||
|
||||
double kineticEnergy(const blitz::TinyVector<double, 3>& velocity, double mass);
|
||||
double thermalEnergy(double temperature_K);
|
||||
|
||||
double velocity(double energy_eV, double mass_kg);
|
||||
|
||||
blitz::TinyVector<double, 3> relativisticBoost(
|
||||
const blitz::TinyVector<double, 3>& v1,
|
||||
const blitz::TinyVector<double, 3>& v2);
|
||||
|
||||
double relativisticGamma(const blitz::TinyVector<double, 3>& velocity);
|
||||
double relativisticGamma(double kin_energy_eV, double mass_eV);
|
||||
double relativisticBeta(double velocity_ms);
|
||||
double relativisticBeta(double kin_energy_eV, double mass_eV);
|
||||
double relativisticMomentum(double energy_eV, double mass_eV);
|
||||
|
||||
double norm(const blitz::TinyVector<double, 3>& vector);
|
||||
|
||||
double distanceInCylinder(const blitz::TinyVector<double, 3>& position_1,
|
||||
const blitz::TinyVector<double, 3>& position_2);
|
||||
|
||||
blitz::TinyVector<double, 3> perpendicularVector(
|
||||
const blitz::TinyVector<double, 3>& vector,
|
||||
const blitz::TinyVector<double, 3>& direction);
|
||||
blitz::TinyVector<double, 3> parallelVector(
|
||||
const blitz::TinyVector<double, 3>& vector,
|
||||
const blitz::TinyVector<double, 3>& direction);
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVector(
|
||||
const blitz::TinyVector<double, 3>& vector,
|
||||
const blitz::TinyVector<double, 3>& rotation_axis,
|
||||
double angle);
|
||||
|
||||
blitz::TinyVector<double, 3> velocityVector(
|
||||
double energy_eV,
|
||||
const blitz::TinyVector<double, 3>& random_unit_vector,
|
||||
double mass_kg);
|
||||
|
||||
}; // namespace kinematic
|
||||
|
||||
#endif /* KINEMATIC_H */
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
enum class DeletionType {
|
||||
wall,
|
||||
recombination,
|
||||
max_interactions,
|
||||
max_time_alive,
|
||||
cluster_formation
|
||||
};
|
||||
|
||||
class DeletionLogger {
|
||||
public:
|
||||
DeletionLogger(std::vector<DeletionType> used_types);
|
||||
|
||||
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
|
||||
|
||||
std::map<DeletionType, long int> numDeletions() const;
|
||||
void numDeletions(long int new_value, DeletionType type);
|
||||
long int numDeletions(DeletionType type) const;
|
||||
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
private:
|
||||
std::map<DeletionType, long int> num_deletions;
|
||||
};
|
||||
|
||||
#endif /* LOGGER_H */
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#ifndef MOVER_H
|
||||
#define MOVER_H
|
||||
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
class Mover {
|
||||
public:
|
||||
virtual void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field) = 0;
|
||||
};
|
||||
|
||||
class BorisMover : public Mover {
|
||||
public:
|
||||
BorisMover(double maximal_time_step_s);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field);
|
||||
|
||||
private:
|
||||
const double maximal_time_step_s_;
|
||||
|
||||
void movementStep(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
double& moved_distance) const;
|
||||
};
|
||||
|
||||
class DriftMover : public Mover {
|
||||
public:
|
||||
DriftMover(double maximal_distance);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field);
|
||||
|
||||
private:
|
||||
const double maximal_distance_m_;
|
||||
|
||||
blitz::TinyVector<double, 3> driftVelocity(
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& electric_field) const;
|
||||
};
|
||||
|
||||
#endif /* MOVER_H */
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#ifndef MPI_COMMUNICATION_H
|
||||
#define MPI_COMMUNICATION_H
|
||||
|
||||
class MpiCommunication {
|
||||
public:
|
||||
static int mpi_rank;
|
||||
static int mpi_size;
|
||||
|
||||
static int mpiRank();
|
||||
static int mpiSize();
|
||||
|
||||
static void init(int argc, char* argv[]);
|
||||
static void finalize();
|
||||
};
|
||||
|
||||
#endif /* MPI_COMMUNICATION_H */
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#ifndef NEUTRAL_GAS_H
|
||||
#define NEUTRAL_GAS_H
|
||||
|
||||
|
||||
#endif /* NEUTRAL_GAS_H */
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#ifndef PARAMETER_H
|
||||
#define PARAMETER_H
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "jansson.h"
|
||||
#include "simulation/jansson_additionals.h"
|
||||
|
||||
class Parameter {
|
||||
public:
|
||||
Parameter(std::string filename);
|
||||
~Parameter();
|
||||
|
||||
double doubleValue(const json_path& path) const;
|
||||
double doubleValue(const json_path& path, double default_value) const;
|
||||
int intValue(const json_path& path) const;
|
||||
int intValue(const json_path& path, int default_value) const;
|
||||
std::string stringValue(const json_path& path) const;
|
||||
std::string stringValue(const json_path& path,
|
||||
const std::string& default_value) const;
|
||||
bool boolValue(const json_path& path) const;
|
||||
bool boolValue(const json_path& path, bool default_value) const;
|
||||
|
||||
bool pathExists(const json_path& path) const;
|
||||
json_t* jsonFile() const;
|
||||
json_t* jsonObjectFromBase(const json_path& path) const;
|
||||
|
||||
private:
|
||||
json_error_t* j_error_;
|
||||
json_t* j_file_;
|
||||
|
||||
json_t* openParameterFile(const std::string& filename) const;
|
||||
};
|
||||
|
||||
#endif /* PARAMETER_H */
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#ifndef PARTICLE_H
|
||||
#define PARTICLE_H
|
||||
|
||||
#include "blitz/array.h"
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/species.h"
|
||||
|
||||
namespace particle {
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
// Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
// Coordinate* position,
|
||||
// Vector* velocity);
|
||||
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const Coordinate& position,
|
||||
const Vector& velocity);
|
||||
|
||||
void position(const Coordinate& new_position);
|
||||
CartesianCoordinate position() const;
|
||||
|
||||
void velocity(const CartesianVector& new_velocity);
|
||||
CartesianVector velocity() const;
|
||||
|
||||
void move(const Coordinate& distance);
|
||||
|
||||
double kineticEnergy_eV() const;
|
||||
double absoluteVelocity() const;
|
||||
double absoluteVelocitySquared() const;
|
||||
|
||||
double mass_kg() const;
|
||||
double charge_C() const;
|
||||
|
||||
species::TrackedSpecie* specie() const;
|
||||
|
||||
static void lastId(long int id);
|
||||
static long int lastId(); // only local on this cpu
|
||||
|
||||
void increaseInteractionCounter();
|
||||
long int interactionCounter() const;
|
||||
|
||||
void increaseTimeAlive(double time_s);
|
||||
double timeAlive() const;
|
||||
|
||||
void increaseTimeInBin(double time_s);
|
||||
void resetTimeInBin();
|
||||
double timeInBin() const;
|
||||
|
||||
private:
|
||||
CartesianVector velocity_;
|
||||
CartesianCoordinate position_;
|
||||
|
||||
double time_alive_s_;
|
||||
double time_in_bin_s_;
|
||||
long int interaction_counter_;
|
||||
|
||||
std::shared_ptr<species::TrackedSpecie> specie_;
|
||||
long int id_;
|
||||
|
||||
static long int last_id_; // only local on this cpu
|
||||
};
|
||||
|
||||
}; // namespace particle
|
||||
|
||||
#endif /* PARTICLE_H */
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#ifndef POSITION_BINNING_H
|
||||
#define POSITION_BINNING_H
|
||||
|
||||
#include <vector>
|
||||
#include "blitz/array.h"
|
||||
|
||||
class LowerAndUpperBoundBinning {
|
||||
public:
|
||||
LowerAndUpperBoundBinning(int num_bins, double maximum);
|
||||
|
||||
int bin(double position) const;
|
||||
double stepsize() const;
|
||||
int numBins() const;
|
||||
int binIndexMin() const;
|
||||
int binIndexMax() const;
|
||||
std::vector<double> binBorders() const;
|
||||
|
||||
private:
|
||||
int num_bins_;
|
||||
double stepsize_;
|
||||
};
|
||||
|
||||
class LowerBoundBinningWithOverflow {
|
||||
public:
|
||||
LowerBoundBinningWithOverflow(int num_bins_excluding_overflow,
|
||||
double maximum);
|
||||
|
||||
int bin(double position) const;
|
||||
double stepsize() const;
|
||||
int numBinsWithOverflow() const;
|
||||
int numBinsWithoutOverflow() const;
|
||||
int binIndexMin() const;
|
||||
int binIndexMax() const;
|
||||
std::vector<double> binBorders() const;
|
||||
|
||||
private:
|
||||
int num_bins_;
|
||||
double stepsize_;
|
||||
};
|
||||
|
||||
class BinningWithOverAndUnderflow {
|
||||
public:
|
||||
BinningWithOverAndUnderflow(int num_bins_excluding_overunderflow,
|
||||
double maximum);
|
||||
|
||||
int bin(double position) const;
|
||||
double stepsize() const;
|
||||
int numBinsWithOverUnderflow() const;
|
||||
int numBinsWithoutOverUnderflow() const;
|
||||
int binIndexMin() const;
|
||||
int binIndexMax() const;
|
||||
std::vector<double> binBorders() const;
|
||||
|
||||
private:
|
||||
int num_bins_;
|
||||
double stepsize_;
|
||||
};
|
||||
|
||||
class CylinderBinning {
|
||||
public:
|
||||
CylinderBinning(int num_bins_radial,
|
||||
double radius,
|
||||
int num_bins_azimuthal,
|
||||
int num_bins_longitudinal,
|
||||
double height);
|
||||
|
||||
blitz::TinyVector<int, 3> bin(
|
||||
const blitz::TinyVector<double, 3>& cylinder_position) const;
|
||||
blitz::TinyVector<double, 3> stepsize() const;
|
||||
|
||||
blitz::TinyVector<int, 3> numBins() const;
|
||||
blitz::TinyVector<int, 3> numBinsIncludingOverUnderflow() const;
|
||||
blitz::TinyVector<int, 3> binIndexMin() const;
|
||||
blitz::TinyVector<int, 3> binIndexMax() const;
|
||||
|
||||
const LowerBoundBinningWithOverflow radial_binning;
|
||||
const LowerAndUpperBoundBinning azimuth_binning;
|
||||
const BinningWithOverAndUnderflow longitudinal_binning;
|
||||
};
|
||||
|
||||
#endif /* POSITION_BINNING_H */
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#ifndef RANDOM_NUMBERS_H
|
||||
#define RANDOM_NUMBERS_H
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
class RandomNumbers {
|
||||
public:
|
||||
RandomNumbers(int seed);
|
||||
|
||||
int rollUniform(int min, int max);
|
||||
double rollUniform(double min, double max);
|
||||
|
||||
std::mt19937* engine();
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::mt19937> engine_;
|
||||
std::uniform_real_distribution<double> real_distribution_;
|
||||
};
|
||||
|
||||
#endif /* RANDOM_NUMBERS_H */
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#ifndef REFLECTOR_H
|
||||
#define REFLECTOR_H
|
||||
|
||||
#include "simulation/particle.h"
|
||||
|
||||
class Reflector {
|
||||
public:
|
||||
virtual bool needsReflectionBackToDomain(
|
||||
const particle::Particle* particle) const = 0;
|
||||
virtual void reflectBackToDomain(particle::Particle* particle) const = 0;
|
||||
};
|
||||
|
||||
class ReflectorDPS : public Reflector {
|
||||
public:
|
||||
ReflectorDPS(double z_position_dps);
|
||||
bool needsReflectionBackToDomain(const particle::Particle* particle) const;
|
||||
void reflectBackToDomain(particle::Particle* particle) const;
|
||||
|
||||
private:
|
||||
const double z_position_dps_;
|
||||
};
|
||||
|
||||
class NoReflector : public Reflector {
|
||||
bool needsReflectionBackToDomain(const particle::Particle* particle) const;
|
||||
void reflectBackToDomain(particle::Particle* particle) const;
|
||||
};
|
||||
|
||||
#endif /* REFLECTOR_H */
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#ifndef SCALAR_FIELD_H
|
||||
#define SCALAR_FIELD_H
|
||||
|
||||
#include <functional>
|
||||
#include "blitz/array.h"
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
class ScalarField {
|
||||
public:
|
||||
virtual double value(const Coordinate& coordinate) const = 0;
|
||||
};
|
||||
|
||||
class ScalarFieldFunctionInZ : public ScalarField {
|
||||
public:
|
||||
ScalarFieldFunctionInZ(std::function<double(double, double, double)> F_z);
|
||||
|
||||
double value(const Coordinate& coordinate) const;
|
||||
|
||||
private:
|
||||
std::function<double(double, double, double)> F_z_;
|
||||
};
|
||||
|
||||
#endif /* SCALAR_FIELD_H */
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#ifndef SCATTERING_ANGLE_DISTRIBUTION_H
|
||||
#define SCATTERING_ANGLE_DISTRIBUTION_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "simulation/energy_binning.h"
|
||||
|
||||
class ScatteringAngleDistribution {
|
||||
public:
|
||||
virtual double roll(std::mt19937* engine, double energy_eV) = 0;
|
||||
};
|
||||
|
||||
class IsotropicAngleDistribution : public ScatteringAngleDistribution {
|
||||
public:
|
||||
IsotropicAngleDistribution();
|
||||
double roll(std::mt19937* engine, double energy_eV = 0.);
|
||||
|
||||
private:
|
||||
std::uniform_real_distribution<double> distribution_;
|
||||
};
|
||||
|
||||
class AngleDistributionFromFile : public ScatteringAngleDistribution {
|
||||
public:
|
||||
AngleDistributionFromFile(std::string absolute_filepath);
|
||||
double roll(std::mt19937* engine, double energy_eV);
|
||||
|
||||
private:
|
||||
std::shared_ptr<EnergyBinning> energy_binning_;
|
||||
std::vector<std::piecewise_linear_distribution<double>> angle_distributions_;
|
||||
};
|
||||
|
||||
class CompositeAngleDistribution : public ScatteringAngleDistribution {
|
||||
public:
|
||||
CompositeAngleDistribution(
|
||||
std::shared_ptr<ScatteringAngleDistribution> lower_distribution,
|
||||
std::shared_ptr<ScatteringAngleDistribution> higher_distribution,
|
||||
double decider_energy);
|
||||
double roll(std::mt19937* engine, double energy_eV);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ScatteringAngleDistribution> lower_distribution_;
|
||||
std::shared_ptr<ScatteringAngleDistribution> higher_distribution_;
|
||||
const double decider_energy_;
|
||||
};
|
||||
|
||||
#endif /* SCATTERING_ANGLE_DISTRIBUTION_H */
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#ifndef SIMULATION_H
|
||||
#define SIMULATION_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "simulation/parameter.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
class RandomNumbers;
|
||||
class InteractionOutput;
|
||||
class MagneticField;
|
||||
class ElectricField;
|
||||
class Timer;
|
||||
class Injector;
|
||||
class SimulationOutput;
|
||||
class CpuSynchronizer;
|
||||
|
||||
namespace species {
|
||||
class Specie;
|
||||
};
|
||||
|
||||
namespace interaction {
|
||||
class InteractionOutput;
|
||||
};
|
||||
|
||||
class Simulation {
|
||||
public:
|
||||
Simulation(std::string parameter_filename);
|
||||
|
||||
void init(Parameter& parameter);
|
||||
void start();
|
||||
void finalize();
|
||||
void processEvents(int events);
|
||||
void processUntilTermination(particle::Particle& particle,
|
||||
std::vector<particle::Particle>& particle_queue);
|
||||
|
||||
private:
|
||||
std::vector<particle::Particle> determineInjectedParticles(
|
||||
RandomNumbers* random);
|
||||
|
||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random);
|
||||
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random);
|
||||
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>
|
||||
tracked_species_;
|
||||
std::map<std::string, std::shared_ptr<species::BackgroundSpecie>>
|
||||
background_species_;
|
||||
|
||||
std::shared_ptr<Injector> injector_;
|
||||
|
||||
std::shared_ptr<MagneticField> magnetic_field_;
|
||||
std::shared_ptr<ElectricField> electric_field_;
|
||||
|
||||
Parameter parameter_;
|
||||
std::shared_ptr<RandomNumbers> random_;
|
||||
|
||||
std::shared_ptr<Timer> timer_;
|
||||
|
||||
std::shared_ptr<SimulationOutput> output_;
|
||||
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
||||
};
|
||||
|
||||
#endif /* SIMULATION_H */
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
#ifndef SPECIES_H
|
||||
#define SPECIES_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "simulation/parameter.h"
|
||||
|
||||
class Mover;
|
||||
class Terminator;
|
||||
class Reflector;
|
||||
class Injector;
|
||||
class DensityField;
|
||||
class DynamicDensityField;
|
||||
class ConstantDensityField;
|
||||
class DeletionLogger;
|
||||
class CurrentCollector;
|
||||
class VelocityDistribution;
|
||||
class DriftVelocity;
|
||||
|
||||
namespace interaction {
|
||||
class Interaction;
|
||||
};
|
||||
|
||||
namespace species {
|
||||
|
||||
enum class ImplementedSpecies { T2, electron, Tplus, T2plus, T3plus };
|
||||
|
||||
class Specie {
|
||||
public:
|
||||
Specie(ImplementedSpecies type,
|
||||
std::string name,
|
||||
double mass_kg,
|
||||
double charge_C);
|
||||
|
||||
double mass_kg() const;
|
||||
double charge_C() const;
|
||||
ImplementedSpecies type() const;
|
||||
std::string name() const;
|
||||
|
||||
virtual DensityField* densityField() = 0;
|
||||
virtual VelocityDistribution* velocityDistibution() = 0;
|
||||
virtual DriftVelocity* driftVelocity() = 0;
|
||||
|
||||
protected:
|
||||
const double mass_kg_;
|
||||
const double charge_C_;
|
||||
const ImplementedSpecies type_;
|
||||
const std::string name_;
|
||||
};
|
||||
|
||||
class TrackedSpecie : public Specie {
|
||||
public:
|
||||
TrackedSpecie(ImplementedSpecies type,
|
||||
std::string name,
|
||||
double mass_kg,
|
||||
double charge_C,
|
||||
std::shared_ptr<Mover> mover,
|
||||
std::shared_ptr<Terminator> terminator,
|
||||
std::shared_ptr<Reflector> reflector,
|
||||
std::shared_ptr<DynamicDensityField> density_field,
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
||||
std::shared_ptr<DriftVelocity> drift_velocity);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
DynamicDensityField* dynamicDensityField();
|
||||
Mover* mover();
|
||||
Terminator* terminator();
|
||||
Reflector* reflector();
|
||||
|
||||
DeletionLogger* deletionLogger();
|
||||
void deletionLogger(std::shared_ptr<DeletionLogger> new_logger);
|
||||
|
||||
CurrentCollector* currentCollector();
|
||||
void currentCollector(std::shared_ptr<CurrentCollector> new_collector);
|
||||
|
||||
std::vector<std::shared_ptr<interaction::Interaction>> interactions();
|
||||
void addInteraction(std::shared_ptr<interaction::Interaction> interaction);
|
||||
|
||||
private:
|
||||
std::shared_ptr<DynamicDensityField> density_field_;
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
||||
std::shared_ptr<DriftVelocity> drift_velocity_;
|
||||
|
||||
std::shared_ptr<Mover> mover_;
|
||||
std::shared_ptr<Terminator> terminator_;
|
||||
std::shared_ptr<Reflector> reflector_;
|
||||
|
||||
std::shared_ptr<DeletionLogger> deletion_logger_;
|
||||
std::shared_ptr<CurrentCollector> current_collector_;
|
||||
std::vector<std::shared_ptr<interaction::Interaction>> interactions_;
|
||||
};
|
||||
|
||||
class BackgroundSpecie : public Specie {
|
||||
public:
|
||||
BackgroundSpecie(ImplementedSpecies type,
|
||||
std::string name,
|
||||
double mass_kg,
|
||||
double charge_C,
|
||||
std::shared_ptr<ConstantDensityField> density_field,
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
||||
std::shared_ptr<DriftVelocity> drift_velocity);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ConstantDensityField> density_field_;
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
||||
std::shared_ptr<DriftVelocity> drift_velocity_;
|
||||
};
|
||||
|
||||
}; // namespace species
|
||||
|
||||
#endif /* SPECIES_H */
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#ifndef TERMINATOR_H
|
||||
#define TERMINATOR_H
|
||||
|
||||
#include "simulation/particle.h"
|
||||
|
||||
class Geometry;
|
||||
|
||||
class Terminator {
|
||||
public:
|
||||
Terminator(long int max_interactions,
|
||||
double max_time_alive,
|
||||
std::shared_ptr<Geometry> geometry);
|
||||
|
||||
bool isAlive(const particle::Particle* particle) const;
|
||||
bool leftSimulationDomain(const particle::Particle* particle) const;
|
||||
bool reachedMaxInteractions(const particle::Particle* particle) const;
|
||||
bool reachedMaxTimeAlive(const particle::Particle* particle) const;
|
||||
|
||||
private:
|
||||
const long int max_interactions_;
|
||||
const double max_time_alive_;
|
||||
std::shared_ptr<Geometry> geometry_;
|
||||
};
|
||||
|
||||
#endif /* TERMINATOR_H */
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
|
||||
double time() const;
|
||||
void increaseTimestep(double time_s);
|
||||
void setTime(double time_s);
|
||||
|
||||
private:
|
||||
double current_time_s_;
|
||||
};
|
||||
|
||||
#endif /* TIMER_H */
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#ifndef TRITIUM_SPECTRUM_H
|
||||
#define TRITIUM_SPECTRUM_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
std::function<double(double)> tritiumDecayEnergySpectrum(double prefactor);
|
||||
|
||||
|
||||
#endif /* TRITIUM_SPECTRUM_H */
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#ifndef UNIT_CONVERTER_H
|
||||
#define UNIT_CONVERTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace unitConvertion {
|
||||
|
||||
double length(double value,
|
||||
const std::string& unit_from,
|
||||
const std::string& unit_to);
|
||||
|
||||
double lengthPrefactor(const std::string& unit);
|
||||
|
||||
double energy(double value,
|
||||
const std::string& unit_from,
|
||||
const std::string& unit_to);
|
||||
double energyPrefactor(const std::string& unit);
|
||||
|
||||
}; // namespace unitConvertion
|
||||
|
||||
#endif /* UNIT_CONVERTER_H */
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
#ifndef VECTOR_FIELD_H
|
||||
#define VECTOR_FIELD_H
|
||||
|
||||
#include <functional>
|
||||
#include "blitz/array.h"
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/position_binning.h"
|
||||
|
||||
class VectorField {
|
||||
public:
|
||||
virtual CylinderVector value(const Coordinate& coordinate) const = 0;
|
||||
};
|
||||
|
||||
class VectorFieldFromArray : public VectorField {
|
||||
public:
|
||||
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);
|
||||
|
||||
CylinderVector value(const Coordinate& coordinate) const;
|
||||
|
||||
private:
|
||||
// todo: make sure we use fast axis on z to reduce acess time
|
||||
const blitz::Array<double, 3> Fr_;
|
||||
const blitz::Array<double, 3> Fphi_;
|
||||
const blitz::Array<double, 3> Fz_;
|
||||
|
||||
CylinderBinning binning_;
|
||||
CylinderVector value(const blitz::TinyVector<int, 3>& bin) const;
|
||||
};
|
||||
|
||||
class VectorFieldConstant : public VectorField {
|
||||
public:
|
||||
VectorFieldConstant(const CylinderVector& constant);
|
||||
CylinderVector value(const Coordinate& coordinate) const;
|
||||
|
||||
private:
|
||||
const CylinderVector constant_;
|
||||
};
|
||||
|
||||
class VectorFieldFunctionInZ : public VectorField {
|
||||
public:
|
||||
VectorFieldFunctionInZ(std::function<double(double, double, double)> v_z);
|
||||
CylinderVector value(const Coordinate& coordinate) const;
|
||||
|
||||
private:
|
||||
std::function<double(double, double, double)> F_z_;
|
||||
};
|
||||
|
||||
#endif /* VECTOR_FIELD_H */
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#ifndef VELOCITY_DISTRIBUTION_H
|
||||
#define VELOCITY_DISTRIBUTION_H
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
class VelocityDistributionFunction;
|
||||
|
||||
class VelocityDistribution {
|
||||
public:
|
||||
virtual CartesianVector rollVelocity(const Coordinate& position,
|
||||
std::mt19937* engine) = 0;
|
||||
};
|
||||
|
||||
class VelocityDistributionFromFunction : public VelocityDistribution {
|
||||
public:
|
||||
VelocityDistributionFromFunction(
|
||||
std::shared_ptr<VelocityDistributionFunction> fv);
|
||||
|
||||
CartesianVector rollVelocity(const Coordinate& position,
|
||||
std::mt19937* engine);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VelocityDistributionFunction> fv_;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
todo: implement this for direct interactions of simulated particles
|
||||
|
||||
class DensityField;
|
||||
|
||||
class VelocityDistributionFromDensityField : public VelocityDistribution {
|
||||
public:
|
||||
VelocityDistributionFromDensityField(
|
||||
std::shared_ptr<DensityField> density_field);
|
||||
CartesianVector driftVelocity_ms(const CylinderVector& position);
|
||||
CartesianVector rollVelocity_ms(
|
||||
const CylinderVector& position, std::mt19937* engine);
|
||||
private:
|
||||
std::shared_ptr<DensityField> density_field_;
|
||||
};
|
||||
*/
|
||||
|
||||
#endif /* VELOCITY_DISTRIBUTION_H */
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#ifndef VELOCITY_DISTRIBUTION_FUNCTION_H
|
||||
#define VELOCITY_DISTRIBUTION_FUNCTION_H
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
class EnergyDistributionFunction;
|
||||
|
||||
class VelocityDistributionFunction {
|
||||
public:
|
||||
virtual CartesianVector rollVelocity(std::mt19937* engine) = 0;
|
||||
};
|
||||
|
||||
class IsotropicDistribution : public VelocityDistributionFunction {
|
||||
public:
|
||||
IsotropicDistribution(std::shared_ptr<EnergyDistributionFunction> f_E,
|
||||
double mass_kg);
|
||||
CartesianVector rollVelocity(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
std::shared_ptr<EnergyDistributionFunction> f_E_;
|
||||
const double mass_kg_;
|
||||
};
|
||||
|
||||
class DirectedDistribution : public VelocityDistributionFunction {
|
||||
public:
|
||||
DirectedDistribution(std::shared_ptr<EnergyDistributionFunction> f_E,
|
||||
double mass_kg,
|
||||
const CartesianVector& direction);
|
||||
CartesianVector rollVelocity(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
std::shared_ptr<EnergyDistributionFunction> f_E_;
|
||||
const blitz::TinyVector<double, 3> direction_normal_;
|
||||
const double mass_kg_;
|
||||
};
|
||||
|
||||
#endif /* VELOCITY_DISTRIBUTION_FUNCTION_H */
|
||||
Reference in New Issue
Block a user