Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88dcafee03 | ||
|
|
51877687b1 |
@@ -64,8 +64,8 @@ class SimulationOutput {
|
||||
void writeSpectrum(DynamicDensityField* density_field, std::string path);
|
||||
void writeDensity(DynamicDensityField* density_field, std::string path);
|
||||
void writeTimeInBin(DynamicDensityField* density_field, std::string path);
|
||||
// void writeDeletedParticles(DynamicDensityField* density_field,
|
||||
// std::string path);
|
||||
void writeDeletedParticles(DynamicDensityField* density_field,
|
||||
std::string path);
|
||||
void writePhysicalTime(DynamicDensityField* density_field, std::string path);
|
||||
|
||||
void writeSimulationData(CurrentCollector* current_collector,
|
||||
|
||||
@@ -15,8 +15,7 @@ class ElasticScattering : public Interaction {
|
||||
|
||||
InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
virtual double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ScatteringAngleDistribution> theta_distrib_;
|
||||
};
|
||||
|
||||
@@ -15,8 +15,6 @@ class FreeMovement : public Interaction {
|
||||
|
||||
double microscopicCrossSection(double energy_eV);
|
||||
double macroscopicCrossSection(particle::Particle& particle);
|
||||
double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
@@ -27,9 +27,6 @@ class Coordinate {
|
||||
virtual blitz::TinyVector<double, 3> cartesianEntries() const = 0;
|
||||
virtual blitz::TinyVector<double, 3> cylinderEntries() const = 0;
|
||||
|
||||
virtual double cosAzimuth() const = 0;
|
||||
virtual double sinAzimuth() const = 0;
|
||||
|
||||
virtual void add(const Coordinate& coordinate) = 0;
|
||||
};
|
||||
|
||||
@@ -41,9 +38,6 @@ class CartesianCoordinate : public Coordinate {
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
double cosAzimuth() const;
|
||||
double sinAzimuth() const;
|
||||
|
||||
void add(const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
@@ -58,9 +52,6 @@ class CylinderCoordinate : public Coordinate {
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
double cosAzimuth() const;
|
||||
double sinAzimuth() const;
|
||||
|
||||
void add(const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
|
||||
@@ -31,6 +31,7 @@ class DynamicDensityField : public DensityField {
|
||||
|
||||
double density(const Coordinate& position);
|
||||
double density(const Coordinate& position, double energy_eV);
|
||||
double density(const Coordinate& position, double energy_split, bool above);
|
||||
|
||||
bool changedPositionBin(const Coordinate& old_position,
|
||||
const Coordinate& new_position) const;
|
||||
@@ -39,17 +40,20 @@ class DynamicDensityField : public DensityField {
|
||||
|
||||
void logMovement(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle,
|
||||
double weight);
|
||||
double pitch_angle,
|
||||
double time_in_bin_s);
|
||||
|
||||
// void logDeletion(const Coordinate& position,
|
||||
// double energy_eV,
|
||||
// double pitch_angle);
|
||||
void logDeletion(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle);
|
||||
|
||||
// return the particle number stored in the density of this object
|
||||
double particleNumber();
|
||||
// return the particle number at the given index
|
||||
double particleNumber(blitz::TinyVector<int, 5> index);
|
||||
// return the particle number stored for energies higher than E_thresh
|
||||
// (above = true) or for energies below (above = false)
|
||||
// The energy bin, in which E_thresh is located, will be included in the
|
||||
// 'above=true' case (and excluded in the other case)
|
||||
double particleNumber(double E_thresh, bool above);
|
||||
|
||||
// returns true if the old pitch angle and the new pitch angle are in different bins
|
||||
// of the pitch angle binning
|
||||
@@ -58,12 +62,13 @@ class DynamicDensityField : public DensityField {
|
||||
blitz::Array<double, 3> densityArray();
|
||||
blitz::Array<double, 4> spectrumArray();
|
||||
blitz::Array<double, 5> timeInBinArray() const;
|
||||
// blitz::Array<long int, 5> deletedParticlesArray() const;
|
||||
blitz::Array<long int, 5> deletedParticlesArray() const;
|
||||
blitz::Array<double, 3> binVolumeArray() const;
|
||||
|
||||
blitz::Array<double, 3> densityArray(double energy_split, bool above);
|
||||
|
||||
// return an array of the density values at the Coordinate position (only energy
|
||||
// direction left); over and underflow bin are removed
|
||||
// (might not be good, since then the underflow particles are lost...)
|
||||
// direction left); overbin is removed
|
||||
blitz::Array<double, 1> sliceSpectrumArray(const Coordinate& position) const;
|
||||
|
||||
// return an array of the time in bin at the Coordinate position and the energy
|
||||
@@ -84,21 +89,18 @@ class DynamicDensityField : public DensityField {
|
||||
|
||||
void restartTimer(double time, double delta_t);
|
||||
void restartTimeInBin(blitz::Array<double, 5> time_in_bin);
|
||||
// void restartDeletedParticlesArray(blitz::Array<long int, 5> deleted_particles);
|
||||
void restartDeletedParticlesArray(blitz::Array<long int, 5> deleted_particles);
|
||||
|
||||
private:
|
||||
|
||||
void recalculateDensityArray();
|
||||
|
||||
// use ordering r, phi, z, pitch_angle, E
|
||||
// time in bin now contains the physical particle number per bin
|
||||
// (not renamed, since that would require many, many changes due to
|
||||
// renaming of the functions)
|
||||
blitz::Array<double, 5> time_in_bin_s_;
|
||||
// blitz::Array<long int, 5> deleted_particles_;
|
||||
blitz::Array<long int, 5> deleted_particles_;
|
||||
|
||||
blitz::Array<double, 5> sync_time_in_bin_s_;
|
||||
// blitz::Array<long int, 5> sync_deleted_particles_;
|
||||
blitz::Array<long int, 5> sync_deleted_particles_;
|
||||
|
||||
blitz::Array<double, 4> density_per_m3_;
|
||||
blitz::Array<double, 3> bin_volume_m3_;
|
||||
|
||||
@@ -11,8 +11,6 @@ class DriftVelocity {
|
||||
DriftVelocity(std::shared_ptr<VectorField> drift_velocity);
|
||||
|
||||
CartesianVector driftVelocity(const Coordinate& position);
|
||||
CartesianVector driftVelocity(const CartesianCoordinate& cartCoord,
|
||||
const CylinderCoordinate& cylCoord);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VectorField> drift_velocity_;
|
||||
|
||||
@@ -47,20 +47,20 @@ class PositionDistributionFromDensity {
|
||||
// draw a position from the density provided at construction using the rejection method
|
||||
CylinderCoordinate drawPosition(std::mt19937* engine);
|
||||
|
||||
// draw a position uniformly distributed within the bin of the given index
|
||||
// (note that the r-dependence of the particle number in a uniform density distribution
|
||||
// is not incorporated)
|
||||
CylinderCoordinate drawPosition(std::mt19937* engine, int r_idx, int phi_idx,
|
||||
int z_idx);
|
||||
CylinderCoordinate drawPosition(std::mt19937* engine, double energy_split, bool above);
|
||||
// sets the maximum density value needed for the rejection method
|
||||
// should not be called frequently, since during each call the density field is
|
||||
// recalculated from scratch by the DynamicDensityField object
|
||||
void setMaximumDensity();
|
||||
void setMaximumDensityAboveAndBelow(double energy_split);
|
||||
|
||||
private:
|
||||
// variable storing the maximum value of the density
|
||||
double maximum_density_ = 1.;
|
||||
|
||||
double maximum_density_below_ = 1.;
|
||||
double maximum_density_above_ = 1.;
|
||||
|
||||
std::shared_ptr<DynamicDensityField> density_;
|
||||
|
||||
// distributions for the spatial directions and for the density
|
||||
|
||||
@@ -46,23 +46,29 @@ class Injector {
|
||||
// the new particles are then appened to the vector queue
|
||||
// the magnetic field is necessary for the determination of the direction of the
|
||||
// injected particles
|
||||
// the weight_factor scales the time a particle contributes to a certain bin
|
||||
// the weight scales the time a particle contributes to a certain bin
|
||||
// and the injection time specifies the time the particle is injected (has to be
|
||||
// between T, T+\DeltaT)
|
||||
void drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
std::shared_ptr<MagneticField> field,
|
||||
const double weight_factor,
|
||||
const double weight,
|
||||
const double injection_time);
|
||||
|
||||
void initInjectionTimeDistribution(double delta_t);
|
||||
|
||||
double timePassed() const;
|
||||
|
||||
void fillParticleNumbers(std::shared_ptr<species::TrackedSpecie> specie);
|
||||
|
||||
double energySplit() const;
|
||||
|
||||
private:
|
||||
std::vector<InjectorInfo> injector_infos_;
|
||||
const double activity_;
|
||||
double energySplit_;
|
||||
std::map<std::string, std::vector<double>> particleNumbersMap_;
|
||||
std::shared_ptr<EventPositionDistribution> position_distribution_;
|
||||
std::shared_ptr<DriftVelocity> mother_drift_velocity_;
|
||||
std::uniform_real_distribution<double> injection_time_distribution_;
|
||||
@@ -74,6 +80,13 @@ class Injector {
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution,
|
||||
const double time_birth,
|
||||
const double weight);
|
||||
|
||||
particle::Particle drawNewDensityParticleAboveOrBelow(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::shared_ptr<MagneticField> field,
|
||||
const double weight,
|
||||
const double injection_time,
|
||||
const bool above);
|
||||
};
|
||||
|
||||
#endif /* INJECTOR_H */
|
||||
|
||||
@@ -33,19 +33,12 @@ class Interaction {
|
||||
virtual double microscopicCrossSection(double energy_eV);
|
||||
virtual double macroscopicCrossSection(particle::Particle& particle);
|
||||
|
||||
// return the time the given particle can travel in the laboratory frame
|
||||
// before this specific interaction occurs (also stores the velocity of the
|
||||
// target particle)
|
||||
virtual double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
virtual InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) = 0;
|
||||
|
||||
protected:
|
||||
std::function<double(double)> cross_section_;
|
||||
std::shared_ptr<species::Specie> target_;
|
||||
CartesianVector target_velocity_;
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "simulation/particle.h"
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
// to count numerical particle deletions
|
||||
enum class DeletionType {
|
||||
wall,
|
||||
recombination,
|
||||
@@ -14,23 +13,13 @@ enum class DeletionType {
|
||||
cluster_formation
|
||||
};
|
||||
|
||||
// to count physical particle deletion
|
||||
enum class PhysicalDeletionType {
|
||||
wall
|
||||
};
|
||||
class Coordinate;
|
||||
|
||||
class DeletionLogger {
|
||||
public:
|
||||
DeletionLogger(std::vector<DeletionType> used_types,
|
||||
std::vector<PhysicalDeletionType> used_phys_types);
|
||||
DeletionLogger(std::vector<DeletionType> used_types);
|
||||
// why a coordinate as a parameter -> not used in implementation
|
||||
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
|
||||
virtual void logDeletion(const particle::Particle& particle,
|
||||
PhysicalDeletionType type);
|
||||
|
||||
std::map<DeletionType, long int> numDeletions() const;
|
||||
std::map<PhysicalDeletionType, double> numPhysDeletions() const;
|
||||
void numDeletions(long int new_value, DeletionType type);
|
||||
long int numDeletions(DeletionType type) const;
|
||||
|
||||
@@ -41,10 +30,6 @@ class DeletionLogger {
|
||||
private:
|
||||
std::map<DeletionType, long int> num_deletions;
|
||||
std::map<DeletionType, long int> sync_num_deletions;
|
||||
|
||||
std::map<PhysicalDeletionType, double> num_phys_deletions;
|
||||
std::map<PhysicalDeletionType, double> sync_num_phys_deletions;
|
||||
|
||||
};
|
||||
|
||||
#endif /* LOGGER_H */
|
||||
|
||||
@@ -4,15 +4,10 @@
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
|
||||
/*
|
||||
change the mfp_m variable to a time_s variable!
|
||||
*/
|
||||
|
||||
class Mover {
|
||||
public:
|
||||
virtual void move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) = 0;
|
||||
@@ -23,7 +18,7 @@ class BorisMover : public Mover {
|
||||
BorisMover(double maximal_time_step_s);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field);
|
||||
@@ -35,7 +30,7 @@ class BorisMover : public Mover {
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& gravity_field,
|
||||
// double& moved_distance,
|
||||
double& moved_distance,
|
||||
double timestep) const;
|
||||
};
|
||||
|
||||
@@ -44,7 +39,7 @@ class DriftMover : public Mover {
|
||||
DriftMover(double maximal_distance);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field);
|
||||
|
||||
@@ -19,8 +19,7 @@ class Particle {
|
||||
const double weight);
|
||||
|
||||
void position(const Coordinate& new_position);
|
||||
CartesianCoordinate cartesianPosition() const;
|
||||
CylinderCoordinate cylinderPosition() const;
|
||||
CartesianCoordinate position() const;
|
||||
|
||||
void velocity(const CartesianVector& new_velocity);
|
||||
CartesianVector velocity() const;
|
||||
@@ -45,31 +44,24 @@ class Particle {
|
||||
void increaseTimeAlive(double time_s);
|
||||
double timeAlive() const;
|
||||
|
||||
void increaseTimeInBin(double time_s);
|
||||
void resetTimeInBin();
|
||||
double timeInBin() const;
|
||||
|
||||
long int ID() const;
|
||||
|
||||
double weight() const;
|
||||
|
||||
void indexNextInteration(const int index) { index_next_interaction_ = index; };
|
||||
int indexNextInteraction() { return index_next_interaction_; };
|
||||
|
||||
void deposited();
|
||||
bool wasDeposited();
|
||||
|
||||
private:
|
||||
double weight_;
|
||||
bool deposited_ = false;
|
||||
|
||||
CartesianVector velocity_;
|
||||
CartesianCoordinate position_cart_;
|
||||
CylinderCoordinate position_cyl_;
|
||||
CartesianCoordinate position_;
|
||||
|
||||
double time_alive_s_;
|
||||
// double time_in_bin_s_;
|
||||
double time_in_bin_s_;
|
||||
long int interaction_counter_;
|
||||
|
||||
// index of the interaction with the sortest distance (-1 if that's none of them)
|
||||
int index_next_interaction_ = -1;
|
||||
|
||||
std::shared_ptr<species::TrackedSpecie> specie_;
|
||||
long int id_;
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "blitz/array.h"
|
||||
|
||||
class RandomNumbers {
|
||||
public:
|
||||
RandomNumbers(int seed);
|
||||
@@ -21,31 +19,4 @@ class RandomNumbers {
|
||||
std::uniform_real_distribution<double> real_distribution_;
|
||||
};
|
||||
|
||||
// class to handle a random walk through a density field, where every
|
||||
// bin is visited exactly once
|
||||
class RandomIndex {
|
||||
public:
|
||||
// num_bins: contains the number of bins of all dimensions of a
|
||||
// density binning (order: radial, azimuthal, longitudinal,
|
||||
// pitch angle, energy)
|
||||
RandomIndex(blitz::TinyVector<int, 5> num_bins);
|
||||
|
||||
// get the next index
|
||||
blitz::TinyVector<int, 5> index();
|
||||
|
||||
// check if all bins have been visited
|
||||
bool visited_all();
|
||||
|
||||
// create a new random order and reset the check if all bins have been visited
|
||||
void reshuffle(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
const blitz::TinyVector<int, 5> num_bins_;
|
||||
|
||||
std::vector<size_t> one_dimensional_indices_;
|
||||
|
||||
size_t total_bin_number_;
|
||||
size_t current_index_in_vector_;
|
||||
};
|
||||
|
||||
#endif /* RANDOM_NUMBERS_H */
|
||||
|
||||
@@ -38,7 +38,7 @@ class Simulation {
|
||||
// at the 0th timestep
|
||||
void processEvents(int events, const double beta_particle_weight);
|
||||
|
||||
void processDensityEvents(int particles_per_bin, const double weight_factor);
|
||||
void processDensityEvents(int events, const double weight_factor);
|
||||
void processUntilTermination(particle::Particle& particle);
|
||||
|
||||
private:
|
||||
@@ -48,20 +48,11 @@ class Simulation {
|
||||
RandomNumbers* random,
|
||||
const double weight_factor,
|
||||
const int current,
|
||||
std::map<std::string, double>& particleNumbers,
|
||||
bool& all_bins_done);
|
||||
std::map<std::string, double>& particleNumbers);
|
||||
|
||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m);
|
||||
|
||||
|
||||
// draw the individual collision times of the possible interactions and return the
|
||||
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
||||
// interaction of the chosen time.
|
||||
double collisionTime(particle::Particle& particle, RandomNumbers* random);
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random);
|
||||
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m);
|
||||
@@ -90,11 +81,6 @@ class Simulation {
|
||||
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
||||
|
||||
std::vector<particle::Particle> queue_;
|
||||
|
||||
#ifdef debug
|
||||
double phyLossAtWallIon = 0;
|
||||
double createdDensity = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* SIMULATION_H */
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include "simulation/parameter.h"
|
||||
|
||||
class RandomIndex;
|
||||
class Mover;
|
||||
class Terminator;
|
||||
class Reflector;
|
||||
@@ -43,7 +42,7 @@ class Specie {
|
||||
std::string name() const;
|
||||
|
||||
virtual DensityField* densityField() = 0;
|
||||
virtual VelocityDistribution* velocityDistribution() = 0;
|
||||
virtual VelocityDistribution* velocityDistibution() = 0;
|
||||
virtual DriftVelocity* driftVelocity() = 0;
|
||||
|
||||
protected:
|
||||
@@ -68,7 +67,7 @@ class TrackedSpecie : public Specie {
|
||||
std::shared_ptr<DynamicDensityField> density_for_drawing);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistribution();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
DynamicDensityField* dynamicDensityField();
|
||||
@@ -92,9 +91,6 @@ class TrackedSpecie : public Specie {
|
||||
// getter for the raw pointer to the VelocityDistributionFromDensityField object
|
||||
VelocityDistributionFromDensityField* velocityDistributionFromDensityField();
|
||||
|
||||
// getter for the raw pointer to the RandomIndex object
|
||||
RandomIndex* randomIndex();
|
||||
|
||||
private:
|
||||
std::shared_ptr<DynamicDensityField> density_field_;
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
||||
@@ -113,8 +109,6 @@ class TrackedSpecie : public Specie {
|
||||
position_distribution_from_density_;
|
||||
std::shared_ptr<VelocityDistributionFromDensityField>
|
||||
velocity_distribution_from_density_;
|
||||
|
||||
std::shared_ptr<RandomIndex> random_index_;
|
||||
};
|
||||
|
||||
class BackgroundSpecie : public Specie {
|
||||
@@ -128,7 +122,7 @@ class BackgroundSpecie : public Specie {
|
||||
std::shared_ptr<DriftVelocity> drift_velocity);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistribution();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
private:
|
||||
|
||||
@@ -56,19 +56,25 @@ class VelocityDistributionFromDensityField : public VelocityDistribution {
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field);
|
||||
|
||||
// return a velocity vector drawn uniformly in the bin specifed by index
|
||||
CartesianVector drawVelocity(const blitz::TinyVector<int, 5> index,
|
||||
std::mt19937* engine);
|
||||
CartesianVector drawVelocity(const blitz::TinyVector<int, 5> index,
|
||||
std::mt19937* engine,
|
||||
const Coordinate& position,
|
||||
std::shared_ptr<MagneticField> magnetic_field);
|
||||
// returns a velocity vector drawn from the energy and pitch angle distributions
|
||||
// use the given magnetic field at the provided position to determine the
|
||||
// direction of velocity from the pitch angle
|
||||
// the direction of the perpendicular part of the velocity vector is drawn isotropically
|
||||
// draw from the distribution below the threshold energy if above = false
|
||||
// and from above otherwise
|
||||
CartesianVector rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const int E_th_bin,
|
||||
const bool above);
|
||||
|
||||
CartesianVector rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
const int E_th_bin,
|
||||
const bool above);
|
||||
private:
|
||||
// mass of the species of which the density field is a part of
|
||||
const double mass_kg_;
|
||||
double alpha_lower_limit;
|
||||
double alpha_upper_limit;
|
||||
|
||||
std::shared_ptr<DynamicDensityField> density_field_;
|
||||
|
||||
|
||||
@@ -47,10 +47,8 @@ LIBS += $(HDF5P_LIBRARIES)
|
||||
CXXFLAGS += $(JANSSON_INCLUDES)
|
||||
LIBS += $(JANSSON_LIBRARIES)
|
||||
|
||||
|
||||
CXXFLAGS += -g
|
||||
ifeq ($(DO_DEBUGGING),true)
|
||||
CXXFLAGS += -ftemplate-depth-30 -DBZ_DEBUG
|
||||
CXXFLAGS += -ftemplate-depth-30 -g -DBZ_DEBUG
|
||||
CXXFLAGS += -Ddebug
|
||||
CXXFLAGS += -Ddebug_level$(DEBUG_LEVEL)
|
||||
endif
|
||||
|
||||
+3
-10
@@ -277,24 +277,23 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
|
||||
std::to_string(SimConstants::engine_string_length_max) +
|
||||
", size of string: " + std::to_string(size));
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("RestartInfo: " + std::to_string(H5Tdetect_class(dtype, H5T_STRING)));
|
||||
#endif
|
||||
|
||||
const int ndims = H5Sget_simple_extent_ndims(dataspace);
|
||||
hsize_t dims[ndims];
|
||||
if (ndims != 1) {
|
||||
ERROR("The given dataset is not one dimensional. It has dims: " + ndims);
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(std::to_string(ndims));
|
||||
DEBUG_LEVEL_3("RestartInfo: " + std::to_string(size));
|
||||
#endif
|
||||
H5Sget_simple_extent_dims(dataspace, dims, NULL);
|
||||
|
||||
char data[SimConstants::engine_string_length_max];
|
||||
H5Dread(dataset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
||||
&data);
|
||||
|
||||
std::stringstream temp;
|
||||
temp << data;
|
||||
|
||||
H5Tclose(dtype);
|
||||
H5Sclose(dataspace);
|
||||
@@ -315,21 +314,15 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
|
||||
|
||||
size_t length;
|
||||
H5Dread(dataset, H5T_NATIVE_HSIZE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &length);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("RestartInfo: read length from file: " + std::to_string(length));
|
||||
#endif
|
||||
|
||||
H5Sclose(dataspace);
|
||||
H5Dclose(dataset);
|
||||
|
||||
H5Fclose(file);
|
||||
|
||||
std::stringstream temp;
|
||||
temp << data;
|
||||
out << temp.str().substr(0, length);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(std::to_string(out.str().size()));
|
||||
#endif
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -542,16 +542,12 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
||||
|
||||
for(int i = 0; i < MpiCommunication::mpiSize(); ++i) {
|
||||
std::string path = path_base + std::to_string(i);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
hid_t dataset_string = H5Dcreate2(file, (path + "/string").c_str(), dtype, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
||||
// this sadly seems to be the option that takes the least amount of effort.
|
||||
// H5Lexits() would be an option but (!) each group would need to be checked for existance first, which sucks
|
||||
if(dataset_string < 0) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Dataset could not be created");
|
||||
#endif
|
||||
dataset_string = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT);
|
||||
if(dataset_string < 0) {
|
||||
ERROR("Dataset for string can neither be created nor opened");
|
||||
@@ -560,9 +556,7 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
||||
|
||||
hid_t dataset_length = H5Dcreate2(file, (path + "/length").c_str(), H5T_NATIVE_HSIZE, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if(dataset_length < 0) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Dataset could not be created");
|
||||
#endif
|
||||
dataset_length = H5Dopen2(file, (path + "/length").c_str(), H5P_DEFAULT);
|
||||
if(dataset_length < 0) {
|
||||
ERROR("Dataset for length can neither be created nor opened");
|
||||
|
||||
+13
-21
@@ -10,6 +10,7 @@
|
||||
#include "poisson_solver/poisson_solver.h"
|
||||
#include "simulation/timer.h"
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "constants/ionization_constants.h"
|
||||
|
||||
// Note: error handling is a bit messy. Sometimes it's dealt with in the
|
||||
// called reset function (e.g. in the density field) and sometimes it's
|
||||
@@ -27,18 +28,12 @@ void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpec
|
||||
if(!do_restart_) {
|
||||
return;
|
||||
}
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Restarting rng");
|
||||
#endif
|
||||
restartRandomNumbers(random_numbers);
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Restarting poisson solver.");
|
||||
#endif
|
||||
restartPoissonSolver(poisson_solver);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Restarting timer.");
|
||||
#endif
|
||||
restartTimer(species.begin()->second.get());
|
||||
|
||||
for(const auto& pair: species) {
|
||||
@@ -46,6 +41,11 @@ void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpec
|
||||
restart_identifier_;
|
||||
restartDrawingDensityField(pair.second->densityForDrawing(), path);
|
||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||
// ist nicht gut so, weils von der injector version entkoppelt ist...
|
||||
// muss noch irgendwie geändert werden
|
||||
pair.second->positionDistributionFromDensity()
|
||||
->setMaximumDensityAboveAndBelow(
|
||||
ionization::ionization_energy_janev_atomic);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +74,7 @@ void Restart::restartTimer(species::TrackedSpecie* reference_specie) {
|
||||
{
|
||||
std::string path = reference_specie->name() + "/DensityField/SimulationData/" +
|
||||
restart_identifier_ + "/PhysicalTime";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
// probably add a function in the reader to read a single double value instead of
|
||||
// an 1d array of doubles
|
||||
blitz::Array<double, 1> restart_time = reader_.readD1Double(path);
|
||||
@@ -92,9 +90,7 @@ void Restart::restartTimer(species::TrackedSpecie* reference_specie) {
|
||||
{
|
||||
std::string path = reference_specie->name() + "/CurrentCollector/SimulationData/" +
|
||||
restart_identifier_ + "/PhysicalTime";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
// probably add a function in the reader to read a single double value instead of
|
||||
// a 1d array of doubles
|
||||
blitz::Array<double, 1> time_resolution = reader_.readD1Double(path);
|
||||
@@ -113,20 +109,18 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string
|
||||
// restart TimeInBin field
|
||||
{
|
||||
std::string path_to_data = path + "/TimeInBin";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path_to_data);
|
||||
#endif
|
||||
blitz::Array<double, 5> time_in_bin = reader_.readD5Double(path_to_data);
|
||||
field->restartTimeInBin(time_in_bin);
|
||||
}
|
||||
|
||||
// // restart deleted particles
|
||||
// {
|
||||
// std::string path_to_data = path + "/DeletedParticles";
|
||||
// DEBUG_LEVEL_3(path_to_data);
|
||||
// blitz::Array<long int, 5> deleted_particles = reader_.readD5LongInt(path_to_data);
|
||||
// field->restartDeletedParticlesArray(deleted_particles);
|
||||
// }
|
||||
// restart deleted particles
|
||||
{
|
||||
std::string path_to_data = path + "/DeletedParticles";
|
||||
DEBUG_LEVEL_3(path_to_data);
|
||||
blitz::Array<long int, 5> deleted_particles = reader_.readD5LongInt(path_to_data);
|
||||
field->restartDeletedParticlesArray(deleted_particles);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -136,9 +130,7 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string
|
||||
void Restart::restartPoissonSolver(PoissonSolver* solver) {
|
||||
std::string path = "PoissonSolver/SimulationData/" + restart_identifier_ +
|
||||
"/Potential/";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
blitz::Array<double, 3> potential = reader_.readD3Double(path);
|
||||
solver->setPotential(potential);
|
||||
}
|
||||
@@ -72,11 +72,7 @@ void SimulationOutput::writeSimulationData(
|
||||
PoissonSolver* poisson_solver,
|
||||
std::mt19937* engine) {
|
||||
if (MpiCommunication::mpi_rank == 0) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write density field data.");
|
||||
#endif
|
||||
|
||||
for (auto& task : tasks_density_fields_) {
|
||||
if (cpu_sync % task.intervall == 0) {
|
||||
std::string specie_path = "/" + task.specie_name;
|
||||
@@ -84,9 +80,7 @@ void SimulationOutput::writeSimulationData(
|
||||
specie_path, cpu_sync, task.overwrite_last);
|
||||
}
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write current collector data.");
|
||||
#endif
|
||||
for (auto& task : tasks_current_collector_) {
|
||||
if (cpu_sync % task.intervall == 0) {
|
||||
std::string specie_path = "/" + task.specie_name;
|
||||
@@ -94,9 +88,7 @@ void SimulationOutput::writeSimulationData(
|
||||
specie_path, cpu_sync, task.overwrite_last);
|
||||
}
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write deletion logger data.");
|
||||
#endif
|
||||
for (auto& task : tasks_deletion_logger_) {
|
||||
if (cpu_sync % task.intervall == 0) {
|
||||
std::string specie_path = "/" + task.specie_name;
|
||||
@@ -104,9 +96,7 @@ void SimulationOutput::writeSimulationData(
|
||||
specie_path, cpu_sync, task.overwrite_last);
|
||||
}
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write PoissonSolver data.");
|
||||
#endif
|
||||
if (cpu_sync % task_potential_.intervall == 0) {
|
||||
std::string poisson_path = "/" + task_potential_.specie_name;
|
||||
writeSimulationData(poisson_solver, poisson_path, cpu_sync,
|
||||
@@ -131,23 +121,15 @@ void SimulationOutput::writeSimulationData(DynamicDensityField* density_field,
|
||||
}
|
||||
std::string path = species_path + "/DensityField/SimulationData/" + sync_path;
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write spectrum.");
|
||||
#endif
|
||||
writeSpectrum(density_field, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write density.");
|
||||
#endif
|
||||
writeDensity(density_field, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write time in bin.");
|
||||
#endif
|
||||
writeTimeInBin(density_field, path);
|
||||
// DEBUG_LEVEL_3("Write deleted particles.");
|
||||
// writeDeletedParticles(density_field, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write deleted particles.");
|
||||
writeDeletedParticles(density_field, path);
|
||||
DEBUG_LEVEL_3("Write physical time.");
|
||||
#endif
|
||||
writePhysicalTime(density_field, path);
|
||||
}
|
||||
|
||||
@@ -161,17 +143,11 @@ void SimulationOutput::writeSimulationData(CurrentCollector* current_collector,
|
||||
}
|
||||
std::string path =
|
||||
species_path + "/CurrentCollector/SimulationData/" + sync_path;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write current crossings.");
|
||||
#endif
|
||||
writeCurrentCrossings(current_collector, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write current.");
|
||||
#endif
|
||||
writeCurrent(current_collector, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write physical time.");
|
||||
#endif
|
||||
writePhysicalTime(current_collector, path);
|
||||
}
|
||||
|
||||
@@ -184,9 +160,7 @@ void SimulationOutput::writeSimulationData(DeletionLogger* logger,
|
||||
sync_path = "LastSyncPeriod";
|
||||
}
|
||||
std::string path = species_path + "/DeletionLogger/" + sync_path;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write number of deletions.");
|
||||
#endif
|
||||
writeNumDeletions(logger, path);
|
||||
}
|
||||
|
||||
@@ -199,9 +173,7 @@ void SimulationOutput::writeSimulationData(PoissonSolver* poisson_solver,
|
||||
sync_path = "/LastSyncPeriod";
|
||||
}
|
||||
std::string path = poisson_path + "/SimulationData" + sync_path;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write potential.");
|
||||
#endif
|
||||
writePotential(poisson_solver, path);
|
||||
}
|
||||
|
||||
@@ -213,12 +185,10 @@ void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
|
||||
if (overwrite_last) {
|
||||
path_base = "/RestartInfo/LastSyncPeriod/CPU_";
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path_base);
|
||||
DEBUG_LEVEL_3("Write restart info.");
|
||||
#endif
|
||||
writeRandomEngineState(engine, path_base);
|
||||
// DEBUG_LEVEL_3("Done");
|
||||
DEBUG_LEVEL_3("Done");
|
||||
}
|
||||
|
||||
void SimulationOutput::writeRandomEngineState(std::mt19937* engine, std::string path) {
|
||||
@@ -244,13 +214,6 @@ void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
|
||||
writer.write(pair.second, path_to_deletions + "/ClusterFormation");
|
||||
}
|
||||
}
|
||||
|
||||
auto physDeletions = logger->numPhysDeletions();
|
||||
for (auto& pair : physDeletions) {
|
||||
if (pair.first == PhysicalDeletionType::wall) {
|
||||
writer.write(pair.second, path_to_deletions + "/Wall(physical)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimulationOutput::writeCurrentCrossings(
|
||||
@@ -299,11 +262,11 @@ void SimulationOutput::writeTimeInBin(DynamicDensityField* density_field,
|
||||
writer.write(density_field->timeInBinArray(), path + "/TimeInBin");
|
||||
}
|
||||
|
||||
// void SimulationOutput::writeDeletedParticles(DynamicDensityField* density_field,
|
||||
// std::string path) {
|
||||
// writer.write(density_field->deletedParticlesArray(),
|
||||
// path + "/DeletedParticles");
|
||||
// }
|
||||
void SimulationOutput::writeDeletedParticles(DynamicDensityField* density_field,
|
||||
std::string path) {
|
||||
writer.write(density_field->deletedParticlesArray(),
|
||||
path + "/DeletedParticles");
|
||||
}
|
||||
|
||||
void SimulationOutput::writePhysicalTime(DynamicDensityField* density_field,
|
||||
std::string path) {
|
||||
|
||||
@@ -10,9 +10,7 @@ namespace generator {
|
||||
|
||||
CylinderBinning buildPositionBinning(json_t* object) {
|
||||
if (json_object_by_path(object, {"CylinderBinning"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating position binning: cylinder binning.");
|
||||
#endif
|
||||
object = json_object_by_path(object, {"CylinderBinning"});
|
||||
|
||||
json_t* radial = json_object_by_path(object, {"Radial"});
|
||||
@@ -38,7 +36,6 @@ CylinderBinning buildPositionBinning(json_t* object) {
|
||||
json_read_length(json_object_by_path(longitudinal, {"MaxLength"}), "m");
|
||||
ASSERT_POSITIVE(&max_length, "Radius must be positive");
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with number of bins radial: " +
|
||||
std::to_string(number_of_bins_radial));
|
||||
DEBUG_LEVEL_3("with number of bins azimuthal: " +
|
||||
@@ -47,7 +44,6 @@ CylinderBinning buildPositionBinning(json_t* object) {
|
||||
std::to_string(number_of_bins_longitudinal));
|
||||
DEBUG_LEVEL_3("with radius: " + std::to_string(max_radius) + " m");
|
||||
DEBUG_LEVEL_3("with height: " + std::to_string(max_length) + " m");
|
||||
#endif
|
||||
|
||||
return CylinderBinning(number_of_bins_radial, max_radius,
|
||||
number_of_bins_azimuthal,
|
||||
@@ -63,18 +59,14 @@ CylinderBinning buildPositionBinningIncludingRedirection(
|
||||
json_path& path_to_binning) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating position binning: CreateSameAs.");
|
||||
#endif
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"})));
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
return buildPositionBinningIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildPositionBinning(parameter.jsonObjectFromBase(path_to_binning));
|
||||
@@ -84,9 +76,7 @@ CylinderBinning buildPositionBinningIncludingRedirection(
|
||||
EnergyBinning buildEnergyBinning(json_t* object) {
|
||||
std::string energy_type = json_string(json_object_by_path(object, {"Type"}));
|
||||
if (energy_type == "Logarithmic") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy binning: logarithmic.");
|
||||
#endif
|
||||
int number_of_bins =
|
||||
json_int(json_object_by_path(object, {"NumberOfBins"}));
|
||||
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
|
||||
@@ -97,11 +87,9 @@ EnergyBinning buildEnergyBinning(json_t* object) {
|
||||
json_read_energy(json_object_by_path(object, {"MaxEnergy"}), "eV");
|
||||
ASSERT_POSITIVE(&max_energy, "Max Energy must be positive");
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins));
|
||||
DEBUG_LEVEL_3("with min energy: " + std::to_string(min_energy));
|
||||
DEBUG_LEVEL_3("with max energy: " + std::to_string(max_energy));
|
||||
#endif
|
||||
|
||||
return EnergyBinning(min_energy, max_energy, number_of_bins);
|
||||
|
||||
@@ -116,22 +104,14 @@ EnergyBinning buildEnergyBinningIncludingRedirection(
|
||||
json_path& path_to_binning) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"}))) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
|
||||
#endif
|
||||
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"})));
|
||||
|
||||
#ifdef debug_level3
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
|
||||
return buildEnergyBinningIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildEnergyBinning(parameter.jsonObjectFromBase(path_to_binning));
|
||||
@@ -141,18 +121,12 @@ EnergyBinning buildEnergyBinningIncludingRedirection(
|
||||
PitchAngleBinning buildPitchAngleBinning(json_t* object) {
|
||||
std::string pitch_angle_type = json_string(json_object_by_path(object, {"Type"}));
|
||||
if (pitch_angle_type == "Linear") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating pitch angle binning: linear.");
|
||||
#endif
|
||||
|
||||
int number_of_bins =
|
||||
json_int(json_object_by_path(object, {"NumberOfBins"}));
|
||||
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins));
|
||||
#endif
|
||||
|
||||
return PitchAngleBinning(number_of_bins);
|
||||
|
||||
} else {
|
||||
@@ -166,21 +140,14 @@ PitchAngleBinning buildPitchAngleBinningIncludingRedirection(
|
||||
json_path& path_to_binning) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
|
||||
#endif
|
||||
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"})));
|
||||
|
||||
#ifdef debug_level3
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
|
||||
return buildPitchAngleBinningIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildPitchAngleBinning(parameter.jsonObjectFromBase(path_to_binning));
|
||||
|
||||
@@ -9,9 +9,7 @@ std::shared_ptr<CurrentCollector> buildCurrentCollector(
|
||||
Parameter& parameter,
|
||||
const json_path& path_to_collector,
|
||||
std::shared_ptr<Timer>& timer) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating current collector.");
|
||||
#endif
|
||||
json_path path_binning =
|
||||
json_path_append(path_to_collector, {"PositionBinning"});
|
||||
CylinderBinning position_binning =
|
||||
|
||||
@@ -10,9 +10,7 @@ namespace generator {
|
||||
|
||||
std::shared_ptr<ConstantDensityField> buildConstantDensityField(
|
||||
json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating constant density field.");
|
||||
#endif
|
||||
json_path path = {"ScalarField"};
|
||||
std::shared_ptr<ScalarField> field =
|
||||
buildScalarField(json_object_by_path(object, path));
|
||||
@@ -24,9 +22,7 @@ std::shared_ptr<DynamicDensityField> buildDynamicDensityField(
|
||||
const json_path& path_to_field,
|
||||
std::shared_ptr<Timer>& timer) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating dynamic density field with pitch angle.");
|
||||
#endif
|
||||
json_path path_binning = json_path_append(path_to_field, {"PositionBinning"});
|
||||
CylinderBinning position_binning =
|
||||
buildPositionBinningIncludingRedirection(parameter, path_binning);
|
||||
|
||||
@@ -9,18 +9,14 @@ std::shared_ptr<DriftVelocity> buildDriftVelocity(
|
||||
const json_path& path_to_drift_velocity) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"VectorField"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating drift velocity: Vector field.");
|
||||
#endif
|
||||
std::shared_ptr<VectorField> field =
|
||||
buildVectorField(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"VectorField"})));
|
||||
return std::shared_ptr<DriftVelocity>(new DriftVelocity(field));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"null"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating drift velocity: null.");
|
||||
#endif
|
||||
return nullptr;
|
||||
} else {
|
||||
ERROR("No drift velocity given.");
|
||||
@@ -33,18 +29,14 @@ std::shared_ptr<DriftVelocity> buildDriftVelocityIncludingRedirection(
|
||||
std::stringstream cpath;
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating drift velocity: CreateSameAs.");
|
||||
#endif
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"CreateSameAs"})));
|
||||
#ifdef debug_level3
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
return buildDriftVelocityIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildDriftVelocity(parameter, path_to_drift_velocity);
|
||||
|
||||
@@ -6,16 +6,12 @@
|
||||
namespace generator {
|
||||
|
||||
std::shared_ptr<ElectricField> electricField(json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating electric field.");
|
||||
#endif
|
||||
std::shared_ptr<VectorField> background;
|
||||
std::shared_ptr<VectorField> dynamic;
|
||||
|
||||
if (json_object_by_path(object, {"Background"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating background electric field.");
|
||||
#endif
|
||||
background = buildVectorField(
|
||||
json_object_by_path(object, {"Background", "VectorField"}));
|
||||
} else {
|
||||
@@ -23,9 +19,7 @@ std::shared_ptr<ElectricField> electricField(json_t* object) {
|
||||
}
|
||||
|
||||
if (json_object_by_path(object, {"Dynamic"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating dynamic electric field.");
|
||||
#endif
|
||||
dynamic = buildVectorField(
|
||||
json_object_by_path(object, {"Dynamic", "VectorField"}));
|
||||
} else {
|
||||
|
||||
@@ -11,31 +11,21 @@ std::shared_ptr<EnergyDistributionFunction> buildEnergyDistributionFunction(
|
||||
json_t* object = parameter.jsonObjectFromBase(path_to_function);
|
||||
|
||||
if (json_object_by_path(object, {"TritiumBetaDecay"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: tritium beta decay.");
|
||||
#endif
|
||||
return std::shared_ptr<EnergyDistributionFunction>(new TritiumBetaDecay());
|
||||
|
||||
} else if (json_object_by_path(object, {"MaxwellBoltzmann"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: Maxwell Boltzmann.");
|
||||
#endif
|
||||
double temperature_K = json_double(json_object_by_path(
|
||||
object, {"MaxwellBoltzmann", "Temperature", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with temperature: " + std::to_string(temperature_K) + " K");
|
||||
#endif
|
||||
return std::shared_ptr<EnergyDistributionFunction>(
|
||||
new MaxwellBoltzmann(temperature_K));
|
||||
} else if (json_object_by_path(object, {"Constant"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: Constant.");
|
||||
#endif
|
||||
double constant_eV = json_double(
|
||||
json_object_by_path(object, {"Constant", "constant", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with constant: " + std::to_string(constant_eV) + " eV");
|
||||
#endif
|
||||
return std::shared_ptr<EnergyDistributionFunction>(
|
||||
new Constant(constant_eV));
|
||||
}
|
||||
|
||||
@@ -11,20 +11,14 @@ namespace generator {
|
||||
|
||||
std::function<double(double)> function1D(json_t* object) {
|
||||
if (json_object_by_path(object, {"Constant"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: constant.");
|
||||
#endif
|
||||
double constant =
|
||||
json_double(json_object_by_path(object, {"Constant", "constant"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with constant: " + std::to_string(constant));
|
||||
#endif
|
||||
return D1ToD1::Constant(constant);
|
||||
|
||||
} else if (json_object_by_path(object, {"PiecewiseLinear"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear.");
|
||||
#endif
|
||||
std::vector<double> x_values = json_vector(
|
||||
json_object_by_path(object, {"PiecewiseLinear", {"xValues"}}));
|
||||
std::vector<double> y_values = json_vector(
|
||||
@@ -37,15 +31,11 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
return D1ToD1::PiecewiseLinear(x_values, y_values);
|
||||
|
||||
} else if (json_object_by_path(object, {"PiecewiseLinearFromFile"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear from file.");
|
||||
#endif
|
||||
|
||||
std::string absolute_filename = readAbsoluteFilename(
|
||||
json_object_by_path(object, {"PiecewiseLinearFromFile", "PathToH5"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with filename: " + absolute_filename);
|
||||
#endif
|
||||
Hdf5Reader reader(absolute_filename);
|
||||
|
||||
std::string x_values_key = json_string(
|
||||
@@ -63,9 +53,7 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
|
||||
double prefactor = json_double(json_object_by_path(
|
||||
object, {"PiecewiseLinearFromFile", {"prefactor"}}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with prefactor: " + std::to_string(prefactor));
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < y_values.size(); ++i) {
|
||||
y_values[i] = y_values[i] * prefactor;
|
||||
@@ -73,9 +61,7 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
return D1ToD1::PiecewiseLinear(x_values, y_values);
|
||||
|
||||
} else if (json_object_by_path(object, {"Product"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: Product.");
|
||||
#endif
|
||||
json_t* function_array = json_object_by_path(object, {"Product"});
|
||||
std::vector<std::function<double(double)>> functions;
|
||||
size_t index;
|
||||
@@ -86,9 +72,7 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
return D1ToD1::Product(functions);
|
||||
|
||||
} else if (json_object_by_path(object, {"Exponential"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: Exponential.");
|
||||
#endif
|
||||
double prefactor = json_double(json_object_by_path(
|
||||
object, {"Exponential", {"prefactor"}}));
|
||||
double scale = json_double(json_object_by_path(
|
||||
@@ -102,16 +86,12 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
|
||||
std::function<double(double, double, double)> function3D(json_t* object) {
|
||||
if (json_object_by_path(object, {"Constant3D"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function3d: Constant3D.");
|
||||
#endif
|
||||
double constant =
|
||||
json_double(json_object_by_path(object, {"Constant3D", "constant"}));
|
||||
return D3ToD1::Constant(constant);
|
||||
} else if (json_object_by_path(object, {"Product"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function3d: Product.");
|
||||
#endif
|
||||
std::function<double(double)> fi =
|
||||
function1D(json_object_by_path(object, {"Product", "fi"}));
|
||||
std::function<double(double)> fj =
|
||||
|
||||
@@ -7,9 +7,7 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
|
||||
const json_path& path_to_geometry) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_geometry, {"Cylinder"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating geometry: cylinder.");
|
||||
#endif
|
||||
double radius =
|
||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_geometry, {"Cylinder", "Radius"})),
|
||||
@@ -18,10 +16,8 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
|
||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_geometry, {"Cylinder", "Height"})),
|
||||
"m");
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with radius: " + std::to_string(radius) + " m");
|
||||
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
|
||||
#endif
|
||||
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
|
||||
} else {
|
||||
ERROR("This geometry is not implemented.");
|
||||
@@ -33,18 +29,14 @@ std::shared_ptr<Geometry> buildGeometryIncludingRedirection(
|
||||
Parameter& parameter, const json_path& path_to_geometry) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_geometry, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating geometry: CreateSameAs.");
|
||||
#endif
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_geometry, {"CreateSameAs"})));
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
return buildGeometryIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildGeometry(parameter, path_to_geometry);
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
namespace generator {
|
||||
|
||||
std::shared_ptr<GravityField> gravityField(json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating gravity field.");
|
||||
#endif
|
||||
return std::shared_ptr<GravityField>(new GravityField(
|
||||
buildVectorField(json_object_by_path(object, {"VectorField"}))));
|
||||
}
|
||||
|
||||
@@ -25,9 +25,7 @@ std::shared_ptr<Injector> buildInjector(
|
||||
json_object_foreach(array, key, value) {
|
||||
std::string specie_name =
|
||||
json_string(json_object_by_path(value, {"TrackedSpecieName"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Injected specie: " + specie_name);
|
||||
#endif
|
||||
InjectorInfo info;
|
||||
info.created_specie = tracked_species[specie_name];
|
||||
|
||||
@@ -43,9 +41,7 @@ std::shared_ptr<Injector> buildInjector(
|
||||
}
|
||||
|
||||
// EventPositionDistribution
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating event distribution.");
|
||||
#endif
|
||||
std::shared_ptr<ScalarField> field = buildScalarField(json_object_by_path(
|
||||
object, {"EventPositionDistribution", "ScalarField"}));
|
||||
|
||||
@@ -84,9 +80,7 @@ std::shared_ptr<Injector> buildInjector(
|
||||
position_limit_phi, position_limit_z));
|
||||
|
||||
// MotherDriftVelocity
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating mother drift velocity.");
|
||||
#endif
|
||||
std::shared_ptr<DriftVelocity> drift_velocity = buildDriftVelocity(
|
||||
parameter, json_path_append(path_to_injector, {"MotherDriftVelocity"}));
|
||||
|
||||
|
||||
@@ -33,9 +33,7 @@ void addInteractions(
|
||||
std::string type = json_string(json_object_by_path(value, {"Type"}));
|
||||
|
||||
if (type == "ElasticScattering") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: ElasticScattering");
|
||||
#endif
|
||||
std::function<double(double)> cross_section =
|
||||
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
|
||||
|
||||
@@ -45,9 +43,7 @@ void addInteractions(
|
||||
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with target " + target_name);
|
||||
#endif
|
||||
|
||||
std::shared_ptr<species::Specie> target =
|
||||
findTarget(target_name, tracked_species, background_species);
|
||||
@@ -57,15 +53,11 @@ void addInteractions(
|
||||
scattering_angle_distribution)));
|
||||
|
||||
} else if (type == "FreeMovement") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: FreeMovement");
|
||||
#endif
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::FreeMovement()));
|
||||
} else if (type == "ElectronIonization") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Ionization");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -191,9 +183,7 @@ void addInteractions(
|
||||
ERROR("This ionization model is not implemented: " + ionization_model);
|
||||
}
|
||||
} else if (type == "Excitation") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Excitation");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -211,9 +201,7 @@ void addInteractions(
|
||||
cross_section, target, excitation_energy)));
|
||||
|
||||
} else if (type == "Clustering") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Clustering");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -229,9 +217,7 @@ void addInteractions(
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ClusterFormation(cross_section, target, product)));
|
||||
} else if (type == "ChargeExchange") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -242,9 +228,7 @@ void addInteractions(
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ChargeExchange(cross_section, target)));
|
||||
} else if (type == "Recombination") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Recombination");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::TrackedSpecie> target =
|
||||
@@ -487,24 +471,18 @@ std::function<double(double, double)> build2DCrossSection(json_t* object) {
|
||||
std::shared_ptr<ScatteringAngleDistribution> buildScatteringAngleDistribution(
|
||||
json_t* object) {
|
||||
if (json_object_by_path(object, {"Isotropic"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic");
|
||||
#endif
|
||||
return std::shared_ptr<ScatteringAngleDistribution>(
|
||||
new IsotropicAngleDistribution());
|
||||
} else if (json_object_by_path(object, {"AngleDistributionFromFile"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Adding ScatteringAngleDistribution: AngleDistributionFromFile");
|
||||
#endif
|
||||
std::string absolute_filepath = readAbsoluteFilename(
|
||||
json_object_by_path(object, {"AngleDistributionFromFile", "PathToH5"}));
|
||||
return std::make_shared<AngleDistributionFromFile>(absolute_filepath);
|
||||
} else if (json_object_by_path(object, {"CompositeAngleDistribution"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Adding ScatteringAngleDistribution: CompositeAngleDistribution");
|
||||
#endif
|
||||
json_t* object_composite =
|
||||
json_object_by_path(object, {"CompositeAngleDistribution"});
|
||||
const double decider_energy = json_read_energy(
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace generator {
|
||||
|
||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||
std::vector<DeletionType> used_types;
|
||||
std::vector<PhysicalDeletionType> used_phys_types;
|
||||
|
||||
json_t* type = json_object_by_path(object, {"Type"});
|
||||
if (json_is_array(type)) {
|
||||
@@ -25,9 +24,7 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||
used_types.push_back(DeletionType::max_time_alive);
|
||||
} else if (type_alias == "cluster_formation") {
|
||||
used_types.push_back(DeletionType::cluster_formation);
|
||||
} else if (type_alias == "wall_physical") {
|
||||
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||
}else {
|
||||
} else {
|
||||
ERROR("This deletion type " + type_alias + " is not known.");
|
||||
}
|
||||
}
|
||||
@@ -38,18 +35,15 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||
used_types.push_back(DeletionType::max_interactions);
|
||||
used_types.push_back(DeletionType::max_time_alive);
|
||||
used_types.push_back(DeletionType::cluster_formation);
|
||||
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_shared<DeletionLogger>(used_types, used_phys_types);
|
||||
return std::make_shared<DeletionLogger>(used_types);
|
||||
}
|
||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(
|
||||
Parameter& parameter,
|
||||
const json_path& path_to_loggers) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating deletion logger.");
|
||||
#endif
|
||||
|
||||
json_path path_logger = json_path_append(path_to_loggers, {"Deletion"});
|
||||
json_t* object = parameter.jsonObjectFromBase(path_logger);
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
namespace generator {
|
||||
|
||||
std::shared_ptr<MagneticField> magneticField(json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating magnetic field.");
|
||||
#endif
|
||||
return std::shared_ptr<MagneticField>(new MagneticField(
|
||||
buildVectorField(json_object_by_path(object, {"VectorField"})),
|
||||
buildVectorField(json_object_by_path(object, {"GradientField"}))));
|
||||
|
||||
@@ -7,17 +7,13 @@ std::shared_ptr<Mover> buildMover(Parameter& parameter,
|
||||
const json_path& path_to_mover) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_mover, {"Boris"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating mover: Boris.");
|
||||
#endif
|
||||
double max_timestep_length = parameter.doubleValue(json_path_append(
|
||||
path_to_mover, {"Boris", "MaximalTimestepLength", "value"}));
|
||||
return std::shared_ptr<Mover>(new BorisMover(max_timestep_length));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_mover, {"Drift"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating mover: Drift.");
|
||||
#endif
|
||||
double maximal_moved_distance =
|
||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_mover, {"Drift", "MaximalMovedDistance"})));
|
||||
|
||||
@@ -10,9 +10,7 @@ namespace generator {
|
||||
std::shared_ptr<PoissonSolver> buildPoissonSolver(
|
||||
Parameter& parameter) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating Poisson solver.");
|
||||
#endif
|
||||
std::shared_ptr<Geometry> geometry;
|
||||
|
||||
json_t* object = json_object_by_path(
|
||||
@@ -50,9 +48,7 @@ namespace generator {
|
||||
|
||||
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
|
||||
const json_path& path_to_boundaries) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Creating Boundaries.");
|
||||
#endif
|
||||
std::map<std::string, GlobalBoundary> boundary_map {
|
||||
{"Bottom", {0., BoundaryType::dirichlet}},
|
||||
{"Top", {0., BoundaryType::dirichlet}},
|
||||
@@ -67,9 +63,7 @@ namespace generator {
|
||||
json_t* value;
|
||||
json_object_foreach(parameter.jsonObjectFromBase(path_to_boundaries),
|
||||
key, value) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Creating " + std::string(key) + ": ");
|
||||
#endif
|
||||
if(!(boundary_map.find(std::string(key)) == boundary_map.end())) {
|
||||
double boundary_value =
|
||||
json_double(json_object_by_path(value, {"value"}));
|
||||
@@ -88,10 +82,8 @@ namespace generator {
|
||||
". Using default boundary (dirichtlet, value 0)");
|
||||
continue;
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with type: " + boundary_type);
|
||||
DEBUG_LEVEL_3("with value: " + std::to_string(boundary_value));
|
||||
#endif
|
||||
|
||||
} else {
|
||||
SIM_INFO(std::string(key) + ": unknown location. Is ignored.");
|
||||
|
||||
@@ -8,9 +8,7 @@ std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
|
||||
const json_path& path_to_reflector) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_reflector, {"ReflectorDPS"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Create reflector: ReflectorDPS");
|
||||
#endif
|
||||
double position_z = json_read_length(
|
||||
parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_reflector, {"ReflectorDPS", "position_z"})),
|
||||
@@ -18,9 +16,7 @@ std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
|
||||
return std::shared_ptr<Reflector>(new ReflectorDPS(position_z));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_reflector, {"NoReflector"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Create reflector: NoReflector");
|
||||
#endif
|
||||
return std::shared_ptr<Reflector>(new NoReflector());
|
||||
} else {
|
||||
ERROR("This reflector is not implemented.");
|
||||
|
||||
@@ -7,17 +7,13 @@ namespace generator {
|
||||
DEBUG_LEVEL_3("Build Restart.");
|
||||
bool do_restart = json_bool(json_object_by_path(object, {"Do"}));
|
||||
if (!do_restart) {
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("No Restart desired.");
|
||||
#endif
|
||||
return Restart(false, "", "");
|
||||
}
|
||||
|
||||
std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}))
|
||||
+ ".h5";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Restart: file path:" + filepath);
|
||||
#endif
|
||||
|
||||
std::string identifier;
|
||||
int sync_period = json_int(json_object_by_path(object, {"SyncPeriod"}));
|
||||
@@ -31,9 +27,7 @@ namespace generator {
|
||||
identifier = "SyncPeriod_" + std::to_string(sync_period);
|
||||
}
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Restart: SyncPeriod to be started from: " + identifier);
|
||||
#endif
|
||||
|
||||
return Restart(do_restart, filepath, identifier);
|
||||
}
|
||||
|
||||
@@ -166,9 +166,7 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
|
||||
}
|
||||
ASSERT_NOTNEGATIVE(&intervall, "The intervall for RestartInfo has to be either 0"
|
||||
",if no output is required or positive otherwise");
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Restart output interval: " + std::to_string(intervall));
|
||||
#endif
|
||||
|
||||
bool overwrite_last = json_bool(
|
||||
json_object_by_path(object, {"RestartInfo", "OverwriteLast"}));
|
||||
|
||||
@@ -107,17 +107,13 @@ std::shared_ptr<Timer> SpeciesBuilder::lastSyncTimer() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::initTimer() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Init timer.");
|
||||
#endif
|
||||
timer_ = std::shared_ptr<Timer>(new Timer());
|
||||
last_sync_timer_ = std::shared_ptr<Timer>(new Timer());
|
||||
}
|
||||
|
||||
void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Init background species info.");
|
||||
#endif
|
||||
const char* key;
|
||||
json_t* value;
|
||||
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Background"}),
|
||||
@@ -130,9 +126,7 @@ void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Init tracked species info.");
|
||||
#endif
|
||||
const char* key;
|
||||
json_t* value;
|
||||
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key,
|
||||
@@ -145,15 +139,11 @@ void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill background species type.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
std::string type = json_string(parameter.jsonObjectFromBase(
|
||||
json_path_append(b.second.path_in_json, {"ParticleType"})));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Type: " + type);
|
||||
#endif
|
||||
if (SpeciesAlias::isAlias(type)) {
|
||||
b.second.type = SpeciesAlias::alias(type);
|
||||
} else {
|
||||
@@ -163,15 +153,11 @@ void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill tracked species type.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
std::string type = json_string(parameter.jsonObjectFromBase(
|
||||
json_path_append(b.second.path_in_json, {"ParticleType"})));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Type: " + type);
|
||||
#endif
|
||||
if (SpeciesAlias::isAlias(type)) {
|
||||
b.second.type = SpeciesAlias::alias(type);
|
||||
} else {
|
||||
@@ -181,9 +167,7 @@ void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill background density.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.density = buildConstantDensityField(parameter.jsonObjectFromBase(
|
||||
json_path_append(b.second.path_in_json, {"ConstantDensityField"})));
|
||||
@@ -191,9 +175,7 @@ void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill velocity distributions.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.velocity_distribution = buildVelocityDistribution(
|
||||
parameter,
|
||||
@@ -207,9 +189,7 @@ void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill drift velocity.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.drift_velocity = buildDriftVelocityIncludingRedirection(
|
||||
parameter, json_path_append(b.second.path_in_json, {"DriftVelocity"}));
|
||||
@@ -221,9 +201,7 @@ void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillMass() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill masses.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.mass_kg = SpeciesMasses::mass(b.second.type);
|
||||
}
|
||||
@@ -233,9 +211,7 @@ void SpeciesBuilder::fillMass() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillCharge() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill charges.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.charge_C = SpeciesCharges::charge(b.second.type);
|
||||
}
|
||||
@@ -245,9 +221,7 @@ void SpeciesBuilder::fillCharge() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillMover(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill movers.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
if ((b.second.mover == nullptr)) {
|
||||
b.second.mover = buildMover(
|
||||
@@ -257,9 +231,7 @@ void SpeciesBuilder::fillMover(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillTerminator(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill terminators.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
if ((b.second.terminator == nullptr)) {
|
||||
b.second.terminator = buildTerminator(
|
||||
@@ -269,9 +241,7 @@ void SpeciesBuilder::fillTerminator(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillReflector(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill reflectors.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
if ((b.second.reflector == nullptr)) {
|
||||
b.second.reflector = buildReflector(
|
||||
@@ -282,9 +252,7 @@ void SpeciesBuilder::fillReflector(Parameter& parameter) {
|
||||
|
||||
// TBD: Fill and create dynamic density fields with pitch angle distribution
|
||||
void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill tracked density.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
b.second.density_field = buildDynamicDensityField(
|
||||
parameter,
|
||||
@@ -302,9 +270,7 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::buildSpecies() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Build species from info.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
background_species[b.first] = std::shared_ptr<species::BackgroundSpecie>(
|
||||
new species::BackgroundSpecie(
|
||||
@@ -324,9 +290,7 @@ void SpeciesBuilder::buildSpecies() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill current collectors.");
|
||||
#endif
|
||||
for (auto& b : tracked_species) {
|
||||
auto current_collector = buildCurrentCollector(
|
||||
parameter,
|
||||
@@ -338,9 +302,7 @@ void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillLoggers(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill loggers.");
|
||||
#endif
|
||||
for (auto& b : tracked_species) {
|
||||
auto deletion_logger = buildDeletionLogger(
|
||||
parameter,
|
||||
@@ -351,9 +313,7 @@ void SpeciesBuilder::fillLoggers(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillInteractions(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill interactions.");
|
||||
#endif
|
||||
for (auto& b : tracked_species) {
|
||||
json_path path = tracked_species_info[b.first].path_in_json;
|
||||
path = json_path_append(path, {"Interactions"});
|
||||
|
||||
@@ -7,17 +7,13 @@ namespace generator {
|
||||
std::shared_ptr<Terminator> buildTerminator(
|
||||
Parameter& parameter,
|
||||
const json_path& path_to_terminator) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating terminator.");
|
||||
#endif
|
||||
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"MaximumInteractions"})));
|
||||
double max_time_alive = parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"MaxTimeAlive", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
||||
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
||||
parameter, json_path_append(path_to_terminator, {"BoundaryGeometry"}));
|
||||
|
||||
@@ -53,9 +53,7 @@ blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
|
||||
|
||||
std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
||||
if (json_object_by_path(object, {"VectorFieldConstant"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant");
|
||||
#endif
|
||||
blitz::TinyVector<double, 3> constant = json_blitz_vector<3>(
|
||||
json_object_by_path(object, {"VectorFieldConstant", "constant"}));
|
||||
|
||||
@@ -63,17 +61,13 @@ std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
||||
new VectorFieldConstant(CylinderVector(constant)));
|
||||
|
||||
} else if (json_object_by_path(object, {"VectorFieldFunctionInZ"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ");
|
||||
#endif
|
||||
std::function<double(double, double, double)> z_function = function3D(
|
||||
json_object_by_path(object, {"VectorFieldFunctionInZ", "zFunction"}));
|
||||
return std::shared_ptr<VectorField>(new VectorFieldFunctionInZ(z_function));
|
||||
|
||||
} else if (json_object_by_path(object, {"VectorFieldFromArray"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray");
|
||||
#endif
|
||||
|
||||
blitz::Array<double, 3> v_radial = readComponentFromFile(
|
||||
json_object_by_path(object,
|
||||
|
||||
@@ -11,10 +11,8 @@ std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
|
||||
const json_path& path_to_distribution) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_distribution, {"IsotropicDistribution"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Creating velocity distribution function: IsotropicDistribution");
|
||||
#endif
|
||||
std::shared_ptr<EnergyDistributionFunction> fE =
|
||||
buildEnergyDistributionFunction(
|
||||
parameter, json_path_append(path_to_distribution,
|
||||
@@ -28,10 +26,8 @@ std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
|
||||
|
||||
} else if (parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_distribution, {"DirectedDistribution"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Creating velocity distribution function: DirectedDistribution");
|
||||
#endif
|
||||
std::shared_ptr<EnergyDistributionFunction> fE =
|
||||
buildEnergyDistributionFunction(
|
||||
parameter, json_path_append(path_to_distribution,
|
||||
|
||||
@@ -10,10 +10,8 @@ std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
|
||||
const json_path& path_to_distribution) {
|
||||
if (parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_distribution, {"VelocityDistributionFromFunction"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Creating velocity distribution: VelocityDistributionFromFunction");
|
||||
#endif
|
||||
std::shared_ptr<VelocityDistributionFunction> v =
|
||||
buildVelocityDistributionFunction(
|
||||
parameter, json_path_append(path_to_distribution,
|
||||
@@ -23,9 +21,7 @@ std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
|
||||
new VelocityDistributionFromFunction(v));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_distribution, {"null"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating velocity distribution: null");
|
||||
#endif
|
||||
return nullptr;
|
||||
} else {
|
||||
ERROR("This velocity distribution is not implemented.");
|
||||
|
||||
@@ -13,18 +13,16 @@ ChargeExchange::ChargeExchange(std::function<double(double)> cross_section,
|
||||
InteractionOutput ChargeExchange::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform charge exchange.");
|
||||
#endif
|
||||
|
||||
// const auto x_impact = particle.position();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
|
||||
particle.velocity(CartesianVector(target_velocity_));
|
||||
particle.velocity(CartesianVector(v_target));
|
||||
return InteractionOutput();
|
||||
}
|
||||
};
|
||||
@@ -17,21 +17,19 @@ ClusterFormation::ClusterFormation(
|
||||
InteractionOutput ClusterFormation::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform cluster formation.");
|
||||
#endif
|
||||
const auto x_impact = particle.cartesianPosition();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(target_velocity_.cartesianEntries(), target_->mass_kg()) *
|
||||
kinematic::kineticEnergy(v_target, target_->mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
const blitz::TinyVector<double, 3> v_cluster =
|
||||
kinematic::velocity(energy_eV, product_->mass_kg()) *
|
||||
target_velocity_.cartesianEntries() / kinematic::norm(target_velocity_.cartesianEntries());
|
||||
v_target / kinematic::norm(v_target);
|
||||
// product inherits weight of the main particle (not the target, which is
|
||||
// assumed to be just a density, i.e. has no weight of its own)
|
||||
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
|
||||
|
||||
@@ -28,20 +28,14 @@ std::function<double(double, double)> eT2_ionization_bed() {
|
||||
} else {
|
||||
const double t = impact_energy / ionization_energy;
|
||||
const double w = energy_after_collision / ionization_energy;
|
||||
|
||||
double y = 1 / (w + 1);
|
||||
double ysq = y*y;
|
||||
double invtmw = 1. / (t - w);
|
||||
|
||||
const double factor = S_m2 / ionization_energy / (t + u + 1);
|
||||
const double summand_1 =
|
||||
(Ni / N - 2) / (t + 1) * (y + invtmw);
|
||||
(Ni / N - 2) / (t + 1) * (1 / (w + 1) + 1 / (t - w));
|
||||
const double summand_2 =
|
||||
(2 - Ni / N) * (ysq + invtmw*invtmw);
|
||||
|
||||
// const double dfdw = c[0] * std::pow(y, 3) + c[1] * std::pow(y, 4) +
|
||||
// c[2] * std::pow(y, 5) + c[3] * std::pow(y, 6);
|
||||
const double dfdw = ysq*(y*c[0] + ysq*(c[1] + y*(c[2] + y*c[3])));
|
||||
(2 - Ni / N) * (std::pow(w + 1, -2) + std::pow(t - w, -2));
|
||||
double y = 1 / (w + 1);
|
||||
const double dfdw = c[0] * std::pow(y, 3) + c[1] * std::pow(y, 4) +
|
||||
c[2] * std::pow(y, 5) + c[3] * std::pow(y, 6);
|
||||
const double summand_3 = std::log(t) / (N * (w + 1)) * dfdw;
|
||||
return factor * (summand_1 + summand_2 + summand_3);
|
||||
}
|
||||
@@ -63,20 +57,14 @@ std::function<double(double, double)> eT_ionization_bed() {
|
||||
} else {
|
||||
const double t = impact_energy / ionization_energy;
|
||||
const double w = energy_after_collision / ionization_energy;
|
||||
|
||||
double y = 1 / (w + 1);
|
||||
double ysq = y*y;
|
||||
double invtmw = 1. / (t - w);
|
||||
|
||||
const double factor = S_m2 / ionization_energy / (t + u + 1);
|
||||
const double summand_1 =
|
||||
(Ni / N - 2) / (t + 1) * (y + invtmw);
|
||||
(Ni / N - 2) / (t + 1) * (1 / (w + 1) + 1 / (t - w));
|
||||
const double summand_2 =
|
||||
(2 - Ni / N) * (ysq + invtmw*invtmw);
|
||||
|
||||
// const double dfdw = c[0] * std::pow(y, 2) + c[1] * std::pow(y, 3) +
|
||||
// c[2] * std::pow(y, 4) + c[3] * std::pow(y, 5);
|
||||
const double dfdw = ysq * (c[0] + y*(c[1] + y*(c[2] + y*c[3])));
|
||||
(2 - Ni / N) * (std::pow(w + 1, -2) + std::pow(t - w, -2));
|
||||
double y = 1 / (w + 1);
|
||||
const double dfdw = c[0] * std::pow(y, 2) + c[1] * std::pow(y, 3) +
|
||||
c[2] * std::pow(y, 4) + c[3] * std::pow(y, 5);
|
||||
const double summand_3 = std::log(t) / (N * (w + 1)) * dfdw;
|
||||
return factor * (summand_1 + summand_2 + summand_3);
|
||||
}
|
||||
@@ -173,8 +161,7 @@ std::function<double(double)> eT_elastic_scattering() {
|
||||
std::function<double(double)> T2pT2_charge_exchange_janev() {
|
||||
return [=](double energy) {
|
||||
const double sig_ll =
|
||||
// 6.59 / (std::pow(energy, 0.5) * (1 + 2.29 * std::pow(energy, 1.78))) +
|
||||
6.59 / (std::sqrt(energy) * (1 + 2.29 * std::pow(energy, 1.78))) +
|
||||
6.59 / (std::pow(energy, 0.5) * (1 + 2.29 * std::pow(energy, 1.78))) +
|
||||
12.85 * std::exp(-1.84 * std::pow(energy, -1.55)) /
|
||||
(std::pow(energy, 0.0673) * (1 + 2.6E-3 * std::pow(energy, 0.97) +
|
||||
1.63E-10 * std::pow(energy, 2.76)));
|
||||
@@ -209,13 +196,9 @@ std::function<double(double)> eT2_ionization_bed() {
|
||||
const double t = energy / ionization_energy;
|
||||
const double factor = S_m2 / (t + u + 1);
|
||||
const double yh = 2. / (t + 1);
|
||||
const double yh2 = yh*yh;
|
||||
// const double D =
|
||||
// c[0] / 3 * (1 - std::pow(yh, 3)) + c[1] / 4 * (1 - std::pow(yh, 4)) +
|
||||
// c[2] / 5 * (1 - std::pow(yh, 5)) + c[3] / 6 * (1 - std::pow(yh, 6));
|
||||
const double D =
|
||||
(c[0]/3 + c[1]/4 + c[2]/5 + c[3]/6) -
|
||||
yh2 * (yh*(c[0]/3 + c[2]/5 * yh2) + yh2 * (c[1]/4 + c[3]/6 * yh2));
|
||||
c[0] / 3 * (1 - std::pow(yh, 3)) + c[1] / 4 * (1 - std::pow(yh, 4)) +
|
||||
c[2] / 5 * (1 - std::pow(yh, 5)) + c[3] / 6 * (1 - std::pow(yh, 6));
|
||||
const double summand_1 = D * std::log(t);
|
||||
const double summand_2 =
|
||||
(2 - Ni / N) * ((t - 1) / t - std::log(t) / (t + 1));
|
||||
@@ -577,12 +560,8 @@ std::function<double(double)> eT2_excitation_vibrational_janev_first() {
|
||||
return 0.;
|
||||
}
|
||||
const double rel = energy / deltaE_eV;
|
||||
// return 5.78 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
// std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
// change calculation of deltaE_eV^{-4} to a simple constant? (don't know
|
||||
// it the compiler already changes that)
|
||||
return 5.78 * std::pow(deltaE_eV, -4) * 1/(rel*rel) *
|
||||
std::pow(1 - 1 / rel, 6.11 / std::sqrt(deltaE_eV)) * 1E-20;
|
||||
return 5.78 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -593,11 +572,8 @@ std::function<double(double)> eT2_excitation_vibrational_janev_second() {
|
||||
return 0.;
|
||||
}
|
||||
const double rel = energy / deltaE_eV;
|
||||
// return 5.78 * 0.628 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
// std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
// same comment as for the function above
|
||||
return 5.78 * 0.628 * std::pow(deltaE_eV, -4) / (rel*rel) *
|
||||
std::pow(1 - 1 / rel, 6.11 / std::sqrt(deltaE_eV)) * 1E-20;
|
||||
return 5.78 * 0.628 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -652,8 +628,7 @@ std::function<double(double)> eT2p_recombination_janev() {
|
||||
(1 + 1.1 * std::pow(energy, 0.512) +
|
||||
0.011 * std::pow(energy, 3.10)),
|
||||
-1) +
|
||||
// 0.133 * std::exp(-0.35 * std::pow(energy - 6.05, 2)));
|
||||
0.133 * std::exp(-0.35 * (energy - 6.05)*(energy - 6.05)));
|
||||
0.133 * std::exp(-0.35 * std::pow(energy - 6.05, 2)));
|
||||
};
|
||||
}
|
||||
std::function<double(double)> eT3p_recombination_janev() {
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
#include "simulation/kinematic.h"
|
||||
#include "simulation/scattering_angle_distribution.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "constants/sim_constants.h"
|
||||
#include "simulation/density_field.h"
|
||||
|
||||
namespace interaction {
|
||||
|
||||
ElasticScattering::ElasticScattering(
|
||||
@@ -19,21 +18,18 @@ ElasticScattering::ElasticScattering(
|
||||
InteractionOutput ElasticScattering::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform elastic scattering.");
|
||||
#endif
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
// const auto x_impact = particle.position();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
|
||||
const blitz::TinyVector<double, 3> v_laboratory =
|
||||
kinematic::velocityTargetFixed(v_impact, target_velocity_.cartesianEntries(),
|
||||
particle.mass_kg(),
|
||||
kinematic::velocityTargetFixed(v_impact, v_target, particle.mass_kg(),
|
||||
target_->mass_kg());
|
||||
|
||||
const double E_kin =
|
||||
@@ -45,84 +41,13 @@ InteractionOutput ElasticScattering::performInteraction(
|
||||
|
||||
const blitz::TinyVector<double, 3> v_impact_new =
|
||||
kinematic::rotateVelocityInCenterOfMassFrame(
|
||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(),
|
||||
target_->mass_kg(), theta, phi);
|
||||
v_impact, v_target, particle.mass_kg(), target_->mass_kg(), theta,
|
||||
phi);
|
||||
|
||||
particle.velocity(CartesianVector(v_impact_new));
|
||||
// no Gyrocentrum movement because boris push is used;
|
||||
|
||||
return InteractionOutput();
|
||||
}
|
||||
|
||||
double ElasticScattering::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
CartesianVector particle_velocity = particle.velocity();
|
||||
|
||||
target_velocity_ = target_->velocityDistribution()->
|
||||
rollVelocity(particle.cylinderPosition(),
|
||||
generator->engine());
|
||||
|
||||
// // if no drift velocity is present, then assume target at rest otherwise
|
||||
// // use the drift velocity
|
||||
if(target_->driftVelocity()) {
|
||||
// auto tmp = target_->driftVelocity()->driftVelocity(particle.position());
|
||||
target_velocity_.add(target_->driftVelocity()->driftVelocity(
|
||||
particle.cartesianPosition(), particle.cylinderPosition()),
|
||||
particle.cartesianPosition());
|
||||
}
|
||||
|
||||
// masses are irrelevant for the transformation
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||
target_velocity_.cartesianEntries(), 0, 0);
|
||||
|
||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
||||
|
||||
// std::stringstream out;
|
||||
// out << "particle "<< particle.specie()->name() <<" velocity: "
|
||||
// << particle_velocity.cartesianEntries();
|
||||
// out << "\ntarget "<< target_->name() <<" velocity: "
|
||||
// << target_velocity_.cartesianEntries();
|
||||
// out << "\nabsolute relative velocity: " << relative_velocity;
|
||||
|
||||
// check if the relative velocity is smaller than an epsilon compared to the larger
|
||||
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||
// a better version possible
|
||||
if(relative_velocity/std::max(
|
||||
kinematic::norm(particle_velocity.cartesianEntries()),
|
||||
kinematic::norm(target_velocity_.cartesianEntries())
|
||||
) < SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
// out << "energy collision time: " << energy_eV;
|
||||
|
||||
const double crosssection = microscopicCrossSection(energy_eV);
|
||||
// out << "\ncross section: " << crosssection;
|
||||
const double density = target_->densityField()->density(particle.cylinderPosition());
|
||||
|
||||
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
|
||||
// out << ", density: " << density;
|
||||
|
||||
const double random_number = generator->rollUniform(0.,1.);
|
||||
if (random_number == 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double distance_target_fixed =
|
||||
- 1./(crosssection * density) * log(random_number);
|
||||
|
||||
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
||||
|
||||
const double time = distance_target_fixed / relative_velocity;
|
||||
// out << "\ntime before collision: " << time;
|
||||
// if(density != 0)
|
||||
// DEBUG_LEVEL_1(out.str());
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
}; // namespace interaction
|
||||
@@ -18,9 +18,7 @@ Excitation::Excitation(std::function<double(double)> cross_section,
|
||||
|
||||
InteractionOutput Excitation::performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform excitation.");
|
||||
#endif
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
const blitz::TinyVector<double, 3> n_impact =
|
||||
|
||||
@@ -10,9 +10,7 @@ FreeMovement::FreeMovement()
|
||||
|
||||
InteractionOutput FreeMovement::performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform free movement.");
|
||||
#endif
|
||||
// do nothing
|
||||
return InteractionOutput();
|
||||
}
|
||||
@@ -25,8 +23,4 @@ double FreeMovement::macroscopicCrossSection(particle::Particle& particle) {
|
||||
// returns a very small number, so the interaction will only be
|
||||
return SimConstants::minimal_macroscopic_cross_section;
|
||||
}
|
||||
double FreeMovement::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
}; // namespace interaction
|
||||
@@ -29,44 +29,28 @@ ElectronIonization::ElectronIonization(
|
||||
InteractionOutput ElectronIonization::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform ionization.");
|
||||
#endif
|
||||
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
const auto x_impact = particle.cartesianPosition();
|
||||
const auto x_impact = particle.position();
|
||||
|
||||
blitz::TinyVector<double, 3> v_target = target_->velocityDistribution()->
|
||||
rollVelocity(particle.cylinderPosition(),
|
||||
generator->engine()).cartesianEntries();
|
||||
if(target_->driftVelocity()) {
|
||||
v_target += target_->driftVelocity()
|
||||
->driftVelocity(x_impact, particle.cylinderPosition())
|
||||
.cartesianEntries();
|
||||
}
|
||||
blitz::TinyVector<double, 3> v_target;
|
||||
blitz::TinyVector<double, 3> v_laboratory;
|
||||
double E_impact;
|
||||
do {
|
||||
v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
|
||||
v_target *= std::sqrt(target_->mass_kg()/ion_->mass_kg());
|
||||
v_laboratory = kinematic::velocityTargetFixed(
|
||||
v_impact, v_target, particle.mass_kg(), target_->mass_kg());
|
||||
|
||||
blitz::TinyVector<double, 3> v_laboratory = kinematic::velocityTargetFixed(
|
||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(), target_->mass_kg()
|
||||
);
|
||||
|
||||
double E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
// do {
|
||||
// v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
// v_laboratory = kinematic::velocityTargetFixed(
|
||||
// v_impact, v_target, particle.mass_kg(), target_->mass_kg());
|
||||
|
||||
// E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
// UnitConversion::JouleToeV;
|
||||
// } while (E_impact <= ionization_energy_eV_);
|
||||
E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
} while (E_impact <= ionization_energy_eV_);
|
||||
|
||||
const double E_impact_new =
|
||||
energy_distribution_->rollImpactParticleEnergyAfterCollision(E_impact,
|
||||
@@ -99,13 +83,13 @@ InteractionOutput ElectronIonization::performInteraction(
|
||||
kinematic::rotateVector(v_lab_norm, azimuth_angle_impact_new,
|
||||
polar_angle_impact_new) *
|
||||
v_lab_impact_new +
|
||||
target_velocity_.cartesianEntries();
|
||||
v_target;
|
||||
|
||||
const blitz::TinyVector<double, 3> v_ejected =
|
||||
kinematic::rotateVector(v_lab_norm, azimuth_angle_ejected,
|
||||
polar_angle_ejected) *
|
||||
v_lab_ejected +
|
||||
target_velocity_.cartesianEntries();
|
||||
v_target;
|
||||
|
||||
particle.velocity(v_impact_new);
|
||||
|
||||
|
||||
@@ -17,107 +17,105 @@ Recombination::Recombination(std::function<double(double)> cross_section,
|
||||
InteractionOutput Recombination::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform recombination.");
|
||||
#endif
|
||||
|
||||
// std::vector<double> macroscopic_bin_cross_sections_m;
|
||||
// const int number_energy_bins = recombination_target_->dynamicDensityField()
|
||||
// ->energyBinning()->binIndexMax();
|
||||
// std::vector<double> energyBinBorders = recombination_target_->
|
||||
// dynamicDensityField()->energyBinning()->binBorders();
|
||||
std::vector<double> macroscopic_bin_cross_sections_m;
|
||||
const int number_energy_bins = recombination_target_->dynamicDensityField()
|
||||
->energyBinning()->binIndexMax();
|
||||
std::vector<double> energyBinBorders = recombination_target_->
|
||||
dynamicDensityField()->energyBinning()->binBorders();
|
||||
|
||||
// if(recombination_target_->type() == species::ImplementedSpecies::electron) {
|
||||
// for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
// macroscopic_bin_cross_sections_m.push_back(
|
||||
// macroscopicCrossSection(particle.position(), bin));
|
||||
// }
|
||||
// } else {
|
||||
// const blitz::TinyVector<double, 3> v_particle =
|
||||
// particle.velocity().cartesianEntries();
|
||||
if(recombination_target_->type() == species::ImplementedSpecies::electron) {
|
||||
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
macroscopic_bin_cross_sections_m.push_back(
|
||||
macroscopicCrossSection(particle.position(), bin));
|
||||
}
|
||||
} else {
|
||||
const blitz::TinyVector<double, 3> v_particle =
|
||||
particle.velocity().cartesianEntries();
|
||||
|
||||
// if(!recombination_target_->driftVelocity()) {
|
||||
// ERROR(recombination_target_->name() + ": does not have a drift velocity!");
|
||||
// }
|
||||
if(!recombination_target_->driftVelocity()) {
|
||||
ERROR(recombination_target_->name() + ": does not have a drift velocity!");
|
||||
}
|
||||
|
||||
// const blitz::TinyVector<double, 3> v_partner =
|
||||
// recombination_target_->driftVelocity()
|
||||
// ->driftVelocity(particle.position()).cartesianEntries();
|
||||
const blitz::TinyVector<double, 3> v_partner =
|
||||
recombination_target_->driftVelocity()
|
||||
->driftVelocity(particle.position()).cartesianEntries();
|
||||
|
||||
// const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
// kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
|
||||
// recombination_target_->mass_kg());
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
|
||||
recombination_target_->mass_kg());
|
||||
|
||||
// const double kinetic_energy_eV =
|
||||
// kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) *
|
||||
// UnitConversion::JouleToeV;
|
||||
const double kinetic_energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
|
||||
// double energy_eV_bin_center;
|
||||
// for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
// energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
|
||||
// macroscopic_bin_cross_sections_m.push_back(
|
||||
// microscopicCrossSection(kinetic_energy_eV) *
|
||||
// recombination_target_->dynamicDensityField()
|
||||
// ->density(particle.position(), energy_eV_bin_center));
|
||||
// }
|
||||
// }
|
||||
double energy_eV_bin_center;
|
||||
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
|
||||
macroscopic_bin_cross_sections_m.push_back(
|
||||
microscopicCrossSection(kinetic_energy_eV) *
|
||||
recombination_target_->dynamicDensityField()
|
||||
->density(particle.position(), energy_eV_bin_center));
|
||||
}
|
||||
}
|
||||
|
||||
// const double total_macroscopic_cross_section_m =
|
||||
// std::accumulate(macroscopic_bin_cross_sections_m.begin(),
|
||||
// macroscopic_bin_cross_sections_m.end(), 0.0);
|
||||
const double total_macroscopic_cross_section_m =
|
||||
std::accumulate(macroscopic_bin_cross_sections_m.begin(),
|
||||
macroscopic_bin_cross_sections_m.end(), 0.0);
|
||||
|
||||
// if(total_macroscopic_cross_section_m <= 0.) {
|
||||
// ERROR("Total cross section is " +
|
||||
// std::to_string(total_macroscopic_cross_section_m) +
|
||||
// ". But recombination was chosen.");
|
||||
// }
|
||||
if(total_macroscopic_cross_section_m <= 0.) {
|
||||
ERROR("Total cross section is " +
|
||||
std::to_string(total_macroscopic_cross_section_m) +
|
||||
". But recombination was chosen.");
|
||||
}
|
||||
|
||||
// std::discrete_distribution<int> energy_bin_decider(
|
||||
// macroscopic_bin_cross_sections_m.begin(),
|
||||
// macroscopic_bin_cross_sections_m.end());
|
||||
std::discrete_distribution<int> energy_bin_decider(
|
||||
macroscopic_bin_cross_sections_m.begin(),
|
||||
macroscopic_bin_cross_sections_m.end());
|
||||
|
||||
// const int energy_bin = energy_bin_decider(*(generator->engine()));
|
||||
// const double energy_eV = (energyBinBorders[energy_bin] +
|
||||
// energyBinBorders[energy_bin+1]) / 2.;
|
||||
const int energy_bin = energy_bin_decider(*(generator->engine()));
|
||||
const double energy_eV = (energyBinBorders[energy_bin] +
|
||||
energyBinBorders[energy_bin+1]) / 2.;
|
||||
|
||||
// blitz::TinyVector<double, 3> position_bins = recombination_target_->dynamicDensityField()
|
||||
// ->positionBinning()->bin(particle.position().cylinderEntries());
|
||||
blitz::TinyVector<double, 3> position_bins = recombination_target_->dynamicDensityField()
|
||||
->positionBinning()->bin(particle.position().cylinderEntries());
|
||||
|
||||
// const blitz::Array<double, 1> mu_distribution =
|
||||
// recombination_target_->dynamicDensityField()
|
||||
// ->timeInBinArray()(position_bins(0),
|
||||
// position_bins(1),
|
||||
// position_bins(2),
|
||||
// blitz::Range::all(),
|
||||
// energy_bin);
|
||||
const blitz::Array<double, 1> mu_distribution =
|
||||
recombination_target_->dynamicDensityField()
|
||||
->timeInBinArray()(position_bins(0),
|
||||
position_bins(1),
|
||||
position_bins(2),
|
||||
blitz::Range::all(),
|
||||
energy_bin);
|
||||
|
||||
// std::vector<double> mu_borders = recombination_target_->dynamicDensityField()
|
||||
// ->pitchAngleBinning()->binBorders();
|
||||
std::vector<double> mu_borders = recombination_target_->dynamicDensityField()
|
||||
->pitchAngleBinning()->binBorders();
|
||||
|
||||
// std::discrete_distribution<int> mu_bin_decider(mu_distribution.begin(),
|
||||
// mu_distribution.end());
|
||||
std::discrete_distribution<int> mu_bin_decider(mu_distribution.begin(),
|
||||
mu_distribution.end());
|
||||
|
||||
// const int mu_bin = mu_bin_decider(*(generator->engine()));
|
||||
const int mu_bin = mu_bin_decider(*(generator->engine()));
|
||||
|
||||
// if((mu_bin == 0) || (mu_bin == mu_distribution.size()-1)) {
|
||||
// ERROR("Recombination: drawn mu is from over- or underflow bin!");
|
||||
// std::stringstream out;
|
||||
// out << "mu distribution values: n";
|
||||
// out << mu_distribution;
|
||||
// DEBUG_LEVEL_3(out.str());
|
||||
// }
|
||||
// const double mu = (mu_borders[mu_bin - 1] + mu_borders[mu_bin])/2.;
|
||||
if((mu_bin == 0) || (mu_bin == mu_distribution.size()-1)) {
|
||||
ERROR("Recombination: drawn mu is from over- or underflow bin!");
|
||||
std::stringstream out;
|
||||
out << "mu distribution values: n";
|
||||
out << mu_distribution;
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
const double mu = (mu_borders[mu_bin - 1] + mu_borders[mu_bin])/2.;
|
||||
|
||||
// recombination_target_->dynamicDensityField()->logDeletion(particle.position(),
|
||||
// energy_eV, mu);
|
||||
recombination_target_->dynamicDensityField()->logDeletion(particle.position(),
|
||||
energy_eV, mu);
|
||||
|
||||
InteractionOutput output;
|
||||
output.deleteCurrentParticle(true);
|
||||
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(
|
||||
particle.cartesianPosition(), DeletionType::recombination);
|
||||
particle.position(), DeletionType::recombination);
|
||||
}
|
||||
|
||||
return output;
|
||||
@@ -128,7 +126,7 @@ double Recombination::macroscopicCrossSection(particle::Particle& particle) {
|
||||
const int numBins = recombination_target_->dynamicDensityField()->
|
||||
energyBinning()->binIndexMax();
|
||||
double macroscopic_cross_section = 0.;
|
||||
const auto position = particle.cylinderPosition();
|
||||
const auto position = particle.position();
|
||||
for (int bin = 0; bin < numBins - 1; ++bin) {
|
||||
macroscopic_cross_section += macroscopicCrossSection(position, bin);
|
||||
}
|
||||
|
||||
@@ -85,18 +85,14 @@ void PoissonSolver::solvePotential(
|
||||
if (!(do_solver_) || !(solve)) {
|
||||
return;
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
||||
#endif
|
||||
blitz::Array<double, 3> interpolated_density =
|
||||
interpolateDensityToPotentialGrid(charge_density);
|
||||
int it = 1;
|
||||
do {
|
||||
solverIteration(interpolated_density);
|
||||
if (it % 1000 == 0) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it));
|
||||
#endif
|
||||
if (converged(interpolated_density)) {
|
||||
break;
|
||||
};
|
||||
@@ -108,9 +104,9 @@ void PoissonSolver::solvePotential(
|
||||
void PoissonSolver::solverIteration(
|
||||
const blitz::Array<double, 3>& interpolated_density) {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = stepsize(0)*stepsize(0); // shorthand
|
||||
const double dth_sq = stepsize(1)*stepsize(1); // shorthand
|
||||
const double dz_sq = stepsize(2)*stepsize(2); // shorthand
|
||||
const double dr_sq = std::pow(stepsize(0), 2); // shorthand
|
||||
const double dth_sq = std::pow(stepsize(1), 2); // shorthand
|
||||
const double dz_sq = std::pow(stepsize(2), 2); // shorthand
|
||||
|
||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
@@ -149,13 +145,13 @@ void PoissonSolver::solverIteration(
|
||||
: j - 1; // j-1 with periodic guard
|
||||
|
||||
const double scaling_factor = 2 / dr_sq + 2 / dz_sq +
|
||||
2 / (i*i * dr_sq * dth_sq);
|
||||
2 / (std::pow(i, 2) * dr_sq * dth_sq);
|
||||
|
||||
potential_(i, j, k).value =
|
||||
(1 / scaling_factor) *
|
||||
((1 / dr_sq * (1 + 1. / (2. * i))) * potential_(i + 1, j, k).value +
|
||||
(1 / dr_sq * (1 - 1. / (2. * i))) * potential_(i - 1, j, k).value +
|
||||
(1 / (i*i * dr_sq * dth_sq)) *
|
||||
(1 / (std::pow(i, 2) * dr_sq * dth_sq)) *
|
||||
(potential_(i, jp1, k).value + potential_(i, jm1, k).value) +
|
||||
(1 / dz_sq) * (potential_(i, j, k + 1).value +
|
||||
potential_(i, j, k - 1).value) +
|
||||
@@ -171,9 +167,9 @@ void PoissonSolver::solverIteration(
|
||||
bool PoissonSolver::converged(
|
||||
const blitz::Array<double, 3>& interpolated_density) {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = stepsize(0)*stepsize(0); // shorthand
|
||||
const double dth_sq = stepsize(1)*stepsize(1); // shorthand
|
||||
const double dz_sq = stepsize(2)*stepsize(2); // shorthand
|
||||
const double dr_sq = std::pow(stepsize(0), 2); // shorthand
|
||||
const double dth_sq = std::pow(stepsize(1), 2); // shorthand
|
||||
const double dz_sq = std::pow(stepsize(2), 2); // shorthand
|
||||
|
||||
double cumulated_quadradic_difference = 0.;
|
||||
double normalized_difference = 0.;
|
||||
@@ -200,7 +196,7 @@ bool PoissonSolver::converged(
|
||||
(potential_(i,j,k+1).value - 2*potential_(i,j,k).value +
|
||||
potential_(i,j,k-1).value)/dz_sq;
|
||||
|
||||
cumulated_quadradic_difference += difference*difference;
|
||||
cumulated_quadradic_difference += std::pow(difference, 2);
|
||||
|
||||
if(fabs(difference) > maximum_difference) {
|
||||
maximum_difference = fabs(difference);
|
||||
@@ -220,11 +216,11 @@ bool PoissonSolver::converged(
|
||||
(potential_(i+1,j,k).value - potential_(i-1,j,k).value)/
|
||||
(2*i*dr_sq) +
|
||||
(potential_(i,jp1,k).value - 2*potential_(i,j,k).value +
|
||||
potential_(i,jm1,k).value)/(i*i*dr_sq*dth_sq) +
|
||||
potential_(i,jm1,k).value)/(std::pow(i,2)*dr_sq*dth_sq) +
|
||||
(potential_(i,j,k+1).value - 2*potential_(i,j,k).value +
|
||||
potential_(i,j,k-1).value)/dz_sq;
|
||||
|
||||
cumulated_quadradic_difference += difference*difference;
|
||||
cumulated_quadradic_difference += std::pow(difference, 2);
|
||||
|
||||
if(fabs(difference) > maximum_difference) {
|
||||
maximum_difference = fabs(difference);
|
||||
@@ -239,18 +235,14 @@ bool PoissonSolver::converged(
|
||||
|
||||
normalized_difference =
|
||||
std::sqrt(cumulated_quadradic_difference / (nr * nth * nz));
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Poisson solver reached a normalized difference of: " +
|
||||
std::to_string(normalized_difference));
|
||||
#endif
|
||||
double normalized_maximum =
|
||||
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
|
||||
#ifdef debug_level1
|
||||
std::ostringstream message;
|
||||
message << "Maximum Difference normalized by order of magnitude: "
|
||||
<< normalized_difference;
|
||||
DEBUG_LEVEL_1(message.str());
|
||||
#endif
|
||||
DEBUG_LEVEL_0(message.str());
|
||||
return normalized_difference < target_accuracy_;
|
||||
}
|
||||
|
||||
@@ -258,9 +250,7 @@ blitz::Array<double, 3> PoissonSolver::potential() {
|
||||
// there might be a better way to do this... (if one can do array.memberValue without
|
||||
// explicitely looping)
|
||||
blitz::Array<double, 3> potentialValues(potential_.lbound(), potential_.extent());
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Extracting potential values");
|
||||
#endif
|
||||
for(int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
|
||||
@@ -303,10 +293,9 @@ blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(
|
||||
//might not work that way (if not needs a loop)
|
||||
interpolatedDensity(fixedIndex, blitz::Range::all(), blitz::Range::all()) /=
|
||||
potential_.extent(1);
|
||||
#ifdef debug_level3
|
||||
|
||||
DEBUG_LEVEL_3("Max Value in interpolated density array: " +
|
||||
std::to_string(blitz::max(interpolatedDensity)));
|
||||
#endif
|
||||
//for r=r_max, k=k_min and k=k_max do not use an interpolation,
|
||||
//since no boundary cell needs the information about its density value
|
||||
return interpolatedDensity;
|
||||
|
||||
@@ -56,23 +56,9 @@ blitz::TinyVector<double, 3> CartesianCoordinate::cartesianEntries() const {
|
||||
return cartesian_position;
|
||||
}
|
||||
|
||||
double CartesianCoordinate::sinAzimuth() const {
|
||||
double rad = std::sqrt(cartesian_position(0)*cartesian_position(0) +
|
||||
cartesian_position(1)*cartesian_position(1));
|
||||
return cartesian_position(1)/rad;
|
||||
}
|
||||
|
||||
double CartesianCoordinate::cosAzimuth() const {
|
||||
double rad = std::sqrt(cartesian_position(0)*cartesian_position(0) +
|
||||
cartesian_position(1)*cartesian_position(1));
|
||||
return cartesian_position(0)/rad;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> CartesianCoordinate::cylinderEntries() const {
|
||||
// const double radius = std::sqrt(std::pow(cartesian_position(0), 2) +
|
||||
// std::pow(cartesian_position(1), 2));
|
||||
const double radius = std::sqrt(cartesian_position(0)*cartesian_position(0) +
|
||||
cartesian_position(1)*cartesian_position(1));
|
||||
const double radius = std::sqrt(std::pow(cartesian_position(0), 2) +
|
||||
std::pow(cartesian_position(1), 2));
|
||||
const double phi = std::atan2(cartesian_position(1), cartesian_position(0));
|
||||
const double z = cartesian_position(2);
|
||||
return blitz::TinyVector<double, 3>(radius, phi, z);
|
||||
@@ -97,14 +83,6 @@ CylinderCoordinate::CylinderCoordinate(const Coordinate& coordinate)
|
||||
// limitPhi();
|
||||
}
|
||||
|
||||
double CylinderCoordinate::cosAzimuth() const {
|
||||
return std::cos(cylinder_position(1));
|
||||
}
|
||||
|
||||
double CylinderCoordinate::sinAzimuth() const {
|
||||
return std::sin(cylinder_position(1));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> CylinderCoordinate::cartesianEntries() const {
|
||||
return blitz::TinyVector<double, 3>(
|
||||
cylinder_position(0) * std::cos(cylinder_position(1)),
|
||||
@@ -156,16 +134,12 @@ CylinderVector CylinderVector::operator+(const CylinderVector& vector) {
|
||||
|
||||
blitz::TinyVector<double, 3> CylinderVector::cartesianEntries(
|
||||
const Coordinate& coordinate) const {
|
||||
// double phi = coordinate.cylinderEntries()(1);
|
||||
double cosphi = coordinate.cosAzimuth();
|
||||
double sinphi = coordinate.sinAzimuth();
|
||||
|
||||
const double A_x =
|
||||
cosphi * cylinder_vector(0) -
|
||||
sinphi * cylinder_vector(1);
|
||||
std::cos(coordinate.cylinderEntries()(1)) * cylinder_vector(0) -
|
||||
std::sin(coordinate.cylinderEntries()(1)) * cylinder_vector(1);
|
||||
const double A_y =
|
||||
cosphi * cylinder_vector(0) +
|
||||
sinphi * cylinder_vector(1);
|
||||
std::sin(coordinate.cylinderEntries()(1)) * cylinder_vector(0) +
|
||||
std::cos(coordinate.cylinderEntries()(1)) * cylinder_vector(1);
|
||||
const double A_z = cylinder_vector(2);
|
||||
return blitz::TinyVector<double, 3>(A_x, A_y, A_z);
|
||||
}
|
||||
@@ -179,7 +153,6 @@ blitz::TinyVector<double, 3> CylinderVector::cylinderEntries() const {
|
||||
return cylinder_vector;
|
||||
}
|
||||
|
||||
// think that function is wrong
|
||||
void CylinderVector::add(const Vector& vector, const Coordinate& coordinate) {
|
||||
cylinder_vector += vector.cylinderEntries(coordinate);
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ void CpuSynchronizer::synchronize(DynamicDensityField* field,
|
||||
sumToAll(field->time_in_bin_s_, field->sync_time_in_bin_s_);
|
||||
field->time_in_bin_s_ = field->sync_time_in_bin_s_;
|
||||
|
||||
// sumToAll(field->deleted_particles_, field->sync_deleted_particles_);
|
||||
// field->deleted_particles_ = field->sync_deleted_particles_;
|
||||
sumToAll(field->deleted_particles_, field->sync_deleted_particles_);
|
||||
field->deleted_particles_ = field->sync_deleted_particles_;
|
||||
if (reset) {
|
||||
density_for_drawing->time_in_bin_s_ = field->time_in_bin_s_;
|
||||
// density_for_drawing->deleted_particles_ = field->deleted_particles_;
|
||||
density_for_drawing->deleted_particles_ = field->deleted_particles_;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,15 +145,6 @@ void CpuSynchronizer::synchronize(DeletionLogger* logger) {
|
||||
pair.second = last_sync_num_deletion;
|
||||
logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
||||
}
|
||||
for (auto& pair : logger->num_phys_deletions) {
|
||||
double num_deletion = pair.second;
|
||||
double last_sync_num_deletion = logger->sync_num_phys_deletions[pair.first];
|
||||
sumToAll(num_deletion, last_sync_num_deletion);
|
||||
// last_sync_num_deletion now contains the total number of deletions
|
||||
// across all cpus -> update the values in the objects
|
||||
pair.second = last_sync_num_deletion;
|
||||
logger->sync_num_phys_deletions[pair.first] = last_sync_num_deletion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,8 @@ blitz::Array<double, 3> CurrentCollector::createAreaLongitudinal(
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
const double r1 = ir * dr;
|
||||
const double r2 = (ir + 1) * dr;
|
||||
// const double area_element =
|
||||
// (std::pow(r2, 2) - std::pow(r1, 2)) * M_PI / (area_z.extent(1));
|
||||
const double area_element =
|
||||
(r2*r2 - r1*r1) * M_PI / (area_z.extent(1));
|
||||
(std::pow(r2, 2) - std::pow(r1, 2)) * M_PI / (area_z.extent(1));
|
||||
area_z(ir, blitz::Range::all(), blitz::Range::all()) = area_element;
|
||||
}
|
||||
return area_z;
|
||||
@@ -138,7 +136,7 @@ void CurrentCollector::collect(particle::Particle* particle,
|
||||
blitz::TinyVector<int, 3> bin_old =
|
||||
position_binning_.bin(old_position.cylinderEntries());
|
||||
blitz::TinyVector<int, 3> bin_new =
|
||||
position_binning_.bin(particle->cylinderPosition().cylinderEntries());
|
||||
position_binning_.bin(particle->position().cylinderEntries());
|
||||
|
||||
const double weight = particle->weight();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ blitz::Array<double, 3> initiateVolumeArray(
|
||||
const double z2 = (iz + 1) * position_spacing(2);
|
||||
|
||||
const double bin_volume =
|
||||
M_PI * ((r2*r2) - (r1*r1)) * (z2 - z1) / phi.length();
|
||||
M_PI * (std::pow(r2, 2) - std::pow(r1, 2)) * (z2 - z1) / phi.length();
|
||||
|
||||
volume(ir, blitz::Range::all(), iz) = bin_volume;
|
||||
}
|
||||
@@ -83,28 +83,28 @@ DynamicDensityField::DynamicDensityField(
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
// deleted_particles_(initiate5DArray<long int>(
|
||||
// blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
// position_binning.radial_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
// position_binning.azimuth_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
// position_binning.longitudinal_binning.binIndexMax()),
|
||||
// blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
// pitch_angle_binning.binIndexMax()),
|
||||
// blitz::Range(energy_binning.binIndexMin(),
|
||||
// energy_binning.binIndexMax()))),
|
||||
// sync_deleted_particles_(initiate5DArray<long int>(
|
||||
// blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
// position_binning.radial_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
// position_binning.azimuth_binning.binIndexMax()),
|
||||
// blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
// position_binning.longitudinal_binning.binIndexMax()),
|
||||
// blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
// pitch_angle_binning.binIndexMax()),
|
||||
// blitz::Range(energy_binning.binIndexMin(),
|
||||
// energy_binning.binIndexMax()))),
|
||||
deleted_particles_(initiate5DArray<long int>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
sync_deleted_particles_(initiate5DArray<long int>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
density_per_m3_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
@@ -131,15 +131,15 @@ double DynamicDensityField::density(const Coordinate& position) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
// const double t = timer_->getDeltaT();
|
||||
const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), blitz::Range::all()));
|
||||
// const long int deleted_particles = blitz::sum(deleted_particles_(
|
||||
// position_bin(0), position_bin(1), position_bin(2),
|
||||
// blitz::Range::all(), blitz::Range::all()));
|
||||
const long int deleted_particles = blitz::sum(deleted_particles_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), blitz::Range::all()));
|
||||
|
||||
return (time_in_bin) / //- deleted_particles) /
|
||||
return (time_in_bin / t - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
}
|
||||
|
||||
@@ -149,18 +149,48 @@ double DynamicDensityField::density(const Coordinate& position,
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
// const double t = timer_->getDeltaT();
|
||||
const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), energy_bin));
|
||||
// const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
// position_bin(0), position_bin(1), position_bin(2),
|
||||
// blitz::Range::all(), energy_bin));
|
||||
const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), energy_bin));
|
||||
|
||||
return (time_in_bin) / // - deleted_particles) /
|
||||
return (time_in_bin / t - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
}
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position,
|
||||
double energy_split,
|
||||
bool above) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
const int energy_split_bin = energy_binning_.bin(energy_split);
|
||||
|
||||
blitz::Range range;
|
||||
|
||||
if(above) {
|
||||
range = blitz::Range(energy_split_bin, energy_binning_.binIndexMax());
|
||||
} else {
|
||||
if(energy_split_bin == energy_binning_.binIndexMin())
|
||||
return 0;
|
||||
range = blitz::Range(energy_binning_.binIndexMin(), energy_split_bin-1);
|
||||
}
|
||||
|
||||
const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), range));
|
||||
const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), range));
|
||||
|
||||
return (time_in_bin / t - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedPositionBin(
|
||||
const Coordinate& old_position,
|
||||
const Coordinate& new_position) const {
|
||||
@@ -186,14 +216,12 @@ bool DynamicDensityField::changedPitchAngleBin(double old_mu,
|
||||
const int old_bin = pitch_angle_binning_.bin(old_mu);
|
||||
const int new_bin = pitch_angle_binning_.bin(new_mu);
|
||||
|
||||
#ifdef debug_level3
|
||||
if(!(old_bin == new_bin)) {
|
||||
DEBUG_LEVEL_3("old mu: " + std::to_string(old_mu));
|
||||
DEBUG_LEVEL_3("old bin: " + std::to_string(old_bin));
|
||||
DEBUG_LEVEL_3("new mu: " + std::to_string(new_mu));
|
||||
DEBUG_LEVEL_3("new bin: " + std::to_string(new_bin));
|
||||
}
|
||||
#endif
|
||||
|
||||
return !(old_bin == new_bin);
|
||||
}
|
||||
@@ -201,7 +229,7 @@ bool DynamicDensityField::changedPitchAngleBin(double old_mu,
|
||||
void DynamicDensityField::logMovement(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle,
|
||||
double weight) {
|
||||
double time_in_bin_s) {
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
@@ -209,27 +237,25 @@ void DynamicDensityField::logMovement(const Coordinate& position,
|
||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
|
||||
time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
pitch_angle_bin, energy_bin) += weight;
|
||||
pitch_angle_bin, energy_bin) += time_in_bin_s;
|
||||
}
|
||||
|
||||
// void DynamicDensityField::logDeletion(const Coordinate& position,
|
||||
// double energy_eV,
|
||||
// double pitch_angle) {
|
||||
void DynamicDensityField::logDeletion(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle) {
|
||||
|
||||
// const blitz::TinyVector<int, 3> position_bin =
|
||||
// position_binning_.bin(position.cylinderEntries());
|
||||
// const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
// const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
|
||||
// deleted_particles_(position_bin(0), position_bin(1), position_bin(2), pitch_angle_bin,
|
||||
// energy_bin) += 1;
|
||||
// return;
|
||||
// }
|
||||
deleted_particles_(position_bin(0), position_bin(1), position_bin(2), pitch_angle_bin,
|
||||
energy_bin) += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::densityArray() {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("recalc Density array");
|
||||
#endif
|
||||
recalculateDensityArray();
|
||||
|
||||
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
|
||||
@@ -241,11 +267,45 @@ blitz::Array<double, 3> DynamicDensityField::densityArray() {
|
||||
blitz::Array<double, 3> density(lowerbound, extent);
|
||||
|
||||
blitz::fourthIndex iE;
|
||||
// DEBUG_LEVEL_3("density sum");
|
||||
DEBUG_LEVEL_3("density sum");
|
||||
density = blitz::sum(density_per_m3_, iE);
|
||||
return density.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::densityArray(
|
||||
double energy_split, bool above) {
|
||||
DEBUG_LEVEL_3("recalc Density array");
|
||||
recalculateDensityArray();
|
||||
|
||||
const int energy_split_bin = energy_binning_.bin(energy_split);
|
||||
|
||||
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1),
|
||||
density_per_m3_.lbound(2));
|
||||
blitz::TinyVector<int,3> extent(density_per_m3_.extent(0),
|
||||
density_per_m3_.extent(1),
|
||||
density_per_m3_.extent(2));
|
||||
blitz::Array<double, 3> density(lowerbound, extent);
|
||||
density = 0;
|
||||
|
||||
blitz::Range range;
|
||||
if(above) {
|
||||
range = blitz::Range(energy_split_bin, energy_binning_.binIndexMax());
|
||||
} else {
|
||||
if(energy_split_bin == energy_binning_.binIndexMin())
|
||||
return density;
|
||||
range = blitz::Range(energy_binning_.binIndexMin(), energy_split_bin-1);
|
||||
}
|
||||
|
||||
blitz::Range all = blitz::Range::all();
|
||||
|
||||
blitz::fourthIndex iE;
|
||||
DEBUG_LEVEL_3("density sum");
|
||||
density = blitz::sum(density_per_m3_(all, all, all, range), iE);
|
||||
|
||||
return density.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 4> DynamicDensityField::spectrumArray() {
|
||||
recalculateDensityArray();
|
||||
return density_per_m3_;
|
||||
@@ -255,9 +315,9 @@ blitz::Array<double, 5> DynamicDensityField::timeInBinArray() const {
|
||||
return time_in_bin_s_;
|
||||
}
|
||||
|
||||
// blitz::Array<long int, 5> DynamicDensityField::deletedParticlesArray() const {
|
||||
// return deleted_particles_;
|
||||
// }
|
||||
blitz::Array<long int, 5> DynamicDensityField::deletedParticlesArray() const {
|
||||
return deleted_particles_;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::binVolumeArray() const {
|
||||
return bin_volume_m3_;
|
||||
@@ -291,30 +351,53 @@ void DynamicDensityField::recalculateDensityArray() {
|
||||
blitz::fourthIndex ipitch;
|
||||
blitz::fifthIndex iE;
|
||||
|
||||
// const double t = timer_->getDeltaT();
|
||||
const double t = timer_->getDeltaT();
|
||||
|
||||
// reduction only seems to work for the last dimension (iE)
|
||||
// -> first reorder (by exchanging iE and ipitch) and afterwards doing
|
||||
// the reduction over iE (which now contains the pitch dimension)
|
||||
// blitz::Array<double, 5> temp((time_in_bin_s_(ir, iphi, iz, ipitch, iE)));
|
||||
|
||||
density_per_m3_ = blitz::sum((time_in_bin_s_(ir, iphi, iz, iE, ipitch)), iE) /
|
||||
density_per_m3_ = blitz::sum((time_in_bin_s_(ir, iphi, iz, iE, ipitch) / t -
|
||||
deleted_particles_(ir, iphi, iz, iE, ipitch)), iE) /
|
||||
bin_volume_m3_(ir, iphi, iz);
|
||||
//deleted_particles_(ir, iphi, iz, iE, ipitch)), iE) /
|
||||
// SimulationTimer::eventStopPoint("recalcDensityArray");
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber() {
|
||||
blitz::Array<double, 3> density = densityArray();
|
||||
double particleNumber = blitz::sum(density * bin_volume_m3_);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("particle number: " + std::to_string(particleNumber));
|
||||
#endif
|
||||
return particleNumber;
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber(blitz::TinyVector<int, 5> index) {
|
||||
return time_in_bin_s_(index);
|
||||
double DynamicDensityField::particleNumber(double E_thresh, bool above) {
|
||||
const int energy_bin = energy_binning_.bin(E_thresh);
|
||||
|
||||
double time_in_bin = 0;
|
||||
double deleted_particles = 0;
|
||||
|
||||
blitz::Range range;
|
||||
|
||||
if(above) {
|
||||
range = blitz::Range(energy_bin, energy_binning_.binIndexMax());
|
||||
} else {
|
||||
if(energy_bin == energy_binning_.binIndexMin())
|
||||
return 0;
|
||||
range = blitz::Range(energy_binning_.binIndexMin(), energy_bin-1);
|
||||
}
|
||||
|
||||
time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
blitz::Range::all(), blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all(), range));
|
||||
|
||||
deleted_particles = blitz::sum(deleted_particles_(
|
||||
blitz::Range::all(), blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all(), range));
|
||||
|
||||
const double t = timer_->getDeltaT();
|
||||
|
||||
return (time_in_bin / t - deleted_particles);
|
||||
}
|
||||
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
@@ -341,10 +424,10 @@ blitz::Array<double, 1> DynamicDensityField::
|
||||
void DynamicDensityField::resetDynamicDensityField() {
|
||||
//timer_->resetTime(); // time stays global
|
||||
time_in_bin_s_ = 0.;
|
||||
// deleted_particles_ = 0.;
|
||||
deleted_particles_ = 0.;
|
||||
density_per_m3_ = 0.;
|
||||
sync_time_in_bin_s_ = 0.;
|
||||
// sync_deleted_particles_ = 0.;
|
||||
sync_deleted_particles_ = 0.;
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartTimer(double time, double delta_t) {
|
||||
@@ -369,17 +452,17 @@ void DynamicDensityField::restartTimeInBin(blitz::Array<double, 5> time_in_bin)
|
||||
time_in_bin_s_ = time_in_bin.copy().reindex(time_in_bin_s_.lbound());
|
||||
}
|
||||
|
||||
// void DynamicDensityField::restartDeletedParticlesArray(
|
||||
// blitz::Array<long int, 5> deleted_particles) {
|
||||
// if(!blitz::all(deleted_particles_.length() == deleted_particles.length())) {
|
||||
// std::stringstream out;
|
||||
// out << "Expected a size of " << deleted_particles_.length();
|
||||
// out << ", received a length of " << deleted_particles.length();
|
||||
// out << " for deleted_particles array";
|
||||
// ERROR(out.str());
|
||||
// }
|
||||
// deleted_particles_ = deleted_particles.copy().reindex(deleted_particles_.lbound());
|
||||
// }
|
||||
void DynamicDensityField::restartDeletedParticlesArray(
|
||||
blitz::Array<long int, 5> deleted_particles) {
|
||||
if(!blitz::all(deleted_particles_.length() == deleted_particles.length())) {
|
||||
std::stringstream out;
|
||||
out << "Expected a size of " << deleted_particles_.length();
|
||||
out << ", received a length of " << deleted_particles.length();
|
||||
out << " for deleted_particles array";
|
||||
ERROR(out.str());
|
||||
}
|
||||
deleted_particles_ = deleted_particles.copy().reindex(deleted_particles_.lbound());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -8,8 +8,3 @@ DriftVelocity::DriftVelocity(std::shared_ptr<VectorField> drift_velocity)
|
||||
CartesianVector DriftVelocity::driftVelocity(const Coordinate& position) {
|
||||
return CartesianVector(drift_velocity_->value(position), position);
|
||||
}
|
||||
|
||||
CartesianVector DriftVelocity::driftVelocity(const CartesianCoordinate& cartPos,
|
||||
const CylinderCoordinate& cylPos) {
|
||||
return CartesianVector(drift_velocity_->value(cylPos), cartPos);
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
#include "simulation/energy_binning.h"
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
std::vector<double> generateLogBinBorders(double bin_min,
|
||||
double bin_max,
|
||||
@@ -26,11 +24,10 @@ std::vector<double> generateLinearBinBorders(double bin_min,
|
||||
const double bin_size = (bin_max - bin_min) / num_bins;
|
||||
|
||||
std::vector<double> bin_borders;
|
||||
for (int i = 0; i < num_bins; ++i) {
|
||||
for (int i = 0; i <= num_bins; ++i) {
|
||||
const double bin_border = bin_size * i + bin_min;
|
||||
bin_borders.push_back(bin_border);
|
||||
}
|
||||
bin_borders.push_back(bin_max);
|
||||
return bin_borders;
|
||||
}
|
||||
|
||||
@@ -69,10 +66,11 @@ PitchAngleBinning::PitchAngleBinning(int num_bins) :
|
||||
pitch_angle_bin_borders_(generateLinearBinBorders(-1, 1, num_bins)) {}
|
||||
|
||||
int PitchAngleBinning::bin(double pitch_angle) const {
|
||||
|
||||
auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
|
||||
pitch_angle_bin_borders_.end(),
|
||||
pitch_angle);
|
||||
// otherwise the valid mu-value of -1 is assigned to the underflow
|
||||
// otherwise the valid mu-value of -1 is assigned to the underflow
|
||||
// bin which can lead to a segfault in the drawing of the pitch
|
||||
// angle in "velocity_distribution.cpp"
|
||||
if(!(pitch_angle < pitch_angle_bin_borders_.front()) &&
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "simulation/errors.h"
|
||||
|
||||
EventPositionDistribution::EventPositionDistribution(
|
||||
std::shared_ptr<ScalarField> mother_density,
|
||||
@@ -67,6 +68,14 @@ void PositionDistributionFromDensity::setMaximumDensity() {
|
||||
maximum_density_ = blitz::max(density_->densityArray());
|
||||
}
|
||||
|
||||
void PositionDistributionFromDensity::setMaximumDensityAboveAndBelow(
|
||||
double energy_split) {
|
||||
maximum_density_below_ = blitz::max(
|
||||
density_->densityArray(energy_split, false));
|
||||
maximum_density_above_ = blitz::max(
|
||||
density_->densityArray(energy_split, true));
|
||||
}
|
||||
|
||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine) {
|
||||
if(isEqual(maximum_density_, 0.)) {
|
||||
// abuse the phi coordinate as a check if the density was zero
|
||||
@@ -82,36 +91,43 @@ CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* e
|
||||
random_z = z_values(*engine);
|
||||
random_n = density_values(*engine);
|
||||
// might be bad that the value gets recalculated for each call of density_->density(...)
|
||||
} while (random_n*maximum_density_ >= density_->density(CylinderCoordinate(
|
||||
} while (random_n*maximum_density_ > density_->density(CylinderCoordinate(
|
||||
blitz::TinyVector<double,3>(random_r, random_phi, random_z))));
|
||||
|
||||
return CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||
}
|
||||
|
||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine,
|
||||
int r_idx, int phi_idx, int z_idx) {
|
||||
double left_bin_border_radial = density_->positionBinning()
|
||||
->radial_binning.binBorders()[r_idx];
|
||||
double left_bin_border_azimuthal = density_->positionBinning()
|
||||
->azimuth_binning.binBorders()[phi_idx];
|
||||
double left_bin_border_longitudinal = density_->positionBinning()
|
||||
->longitudinal_binning.binBorders()[z_idx];
|
||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(
|
||||
std::mt19937* engine, double energy_split, bool above) {
|
||||
const double max_density = above ? maximum_density_above_ : maximum_density_below_;
|
||||
if(isEqual(max_density, 0.)) {
|
||||
// abuse the phi coordinate as a check if the density was zero
|
||||
// only works if phi \in (0, 2pi)
|
||||
return CylinderCoordinate(blitz::TinyVector<double,3>(0,-1,0));
|
||||
}
|
||||
|
||||
auto stepsize = density_->positionBinning()->stepsize();
|
||||
double random_r, random_phi, random_z, random_n;
|
||||
double density_at_position;
|
||||
|
||||
double r_rndm, phi_rndm, z_rndm;
|
||||
// std::stringstream out;
|
||||
// above ? out << "Above: " : out << "Below: ";
|
||||
// out << "densities: ";
|
||||
|
||||
r_rndm = density_values(*engine);
|
||||
phi_rndm = density_values(*engine);
|
||||
z_rndm = density_values(*engine);
|
||||
do {
|
||||
random_r = std::sqrt(r_values(*engine));
|
||||
random_phi = phi_values(*engine);
|
||||
random_z = z_values(*engine);
|
||||
random_n = density_values(*engine);
|
||||
density_at_position = density_->density(CylinderCoordinate(
|
||||
blitz::TinyVector<double,3>(random_r, random_phi, random_z)),
|
||||
energy_split, above);
|
||||
// out << density_at_position << "\n";
|
||||
// might be bad that the value gets recalculated for each call of density_->density(...)
|
||||
} while (random_n*max_density > density_at_position);
|
||||
|
||||
double radius = std::sqrt(left_bin_border_radial*left_bin_border_radial +
|
||||
(2*left_bin_border_radial + stepsize(0))
|
||||
*stepsize(0)*r_rndm);
|
||||
// DEBUG_LEVEL_2(out.str());
|
||||
|
||||
return CylinderCoordinate(blitz::TinyVector<double, 3>
|
||||
(radius,
|
||||
left_bin_border_azimuthal + stepsize(1) * phi_rndm,
|
||||
left_bin_border_longitudinal + stepsize(2) * z_rndm));
|
||||
return CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||
}
|
||||
+132
-34
@@ -9,7 +9,7 @@
|
||||
#include "simulation/density_field.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "simulation/random_numbers.h"
|
||||
#include "constants/ionization_constants.h"
|
||||
#include <sstream>
|
||||
|
||||
Injector::Injector(
|
||||
@@ -20,7 +20,8 @@ Injector::Injector(
|
||||
: injector_infos_(injector_info),
|
||||
activity_(activity),
|
||||
position_distribution_(position_distribution),
|
||||
mother_drift_velocity_(mother_drift_velocity) {
|
||||
mother_drift_velocity_(mother_drift_velocity),
|
||||
energySplit_(ionization::ionization_energy_janev_atomic) {
|
||||
ASSERT_POSITIVE(&activity_, "Injector: Activity must be positive");
|
||||
ASSERT_EXISTS(&position_distribution_,
|
||||
"Injector: The position distribution is null.");
|
||||
@@ -60,10 +61,6 @@ void Injector::initInjectionTimeDistribution(double delta_t) {
|
||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
std::mt19937* engine, const double current_time,
|
||||
const double beta_particle_weight) {
|
||||
// pull drawing from the position distribution into the "multiplicity" loop?
|
||||
// (would improve resolution stuff in space as well as just in velocity direction
|
||||
// especially for slow particles, i.e. ions)
|
||||
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
const double time_birth = current_time - injection_time_distribution_(*engine);
|
||||
@@ -71,17 +68,13 @@ std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
for (auto& injector_info : injector_infos_) {
|
||||
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
#endif
|
||||
|
||||
// for (int i = 0; i < injector_info.multiplicity; i++) {
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth, beta_particle_weight));
|
||||
// }
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth, beta_particle_weight));
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
@@ -92,24 +85,36 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const double weight_factor,
|
||||
const double injection_time) {
|
||||
blitz::TinyVector<int, 5> index = specie->randomIndex()->index();
|
||||
|
||||
const double num_part_in_bin = specie->densityForDrawing()->particleNumber(index);
|
||||
if(specie->type() == species::ImplementedSpecies::electron) {
|
||||
|
||||
if(num_part_in_bin == 0) {
|
||||
if(!(particleNumbersMap_[specie->name()][1] == 0))
|
||||
queue.push_back(drawNewDensityParticleAboveOrBelow(engine, specie,
|
||||
magnetic_field, weight_factor, injection_time, true));
|
||||
if(!(particleNumbersMap_[specie->name()][0] == 0))
|
||||
queue.push_back(drawNewDensityParticleAboveOrBelow(engine, specie,
|
||||
magnetic_field, weight_factor, injection_time, false));
|
||||
return;
|
||||
}
|
||||
|
||||
if(particleNumbersMap_[specie->name()][0] == 0) {
|
||||
return;
|
||||
}
|
||||
// draw the position
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()->drawPosition(engine,
|
||||
index(0), index(1), index(2));
|
||||
#ifdef debug_level3
|
||||
specie->positionDistributionFromDensity()->drawPosition(engine);
|
||||
|
||||
// check if density was empty (i.e. phi value lower than 0)
|
||||
if (position.cylinderEntries()(1) < 0) {
|
||||
DEBUG_LEVEL_3(specie->name() + ": has zero density");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
DEBUG_LEVEL_3("Injected r position: " +
|
||||
std::to_string(position.cylinderEntries()(0)));
|
||||
#endif
|
||||
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
@@ -118,28 +123,121 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
if(kinematic::norm(magnetic_field->value(position).
|
||||
cartesianEntries(position)) == 0) {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
drawVelocity(index, engine);
|
||||
rollVelocity(position, engine);
|
||||
} else {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
drawVelocity(index, engine, position, magnetic_field);
|
||||
rollVelocity(position, engine, magnetic_field);
|
||||
}
|
||||
|
||||
#ifdef debug_level2
|
||||
std::stringstream out;
|
||||
out << "drawn index: " << index;
|
||||
out << "\nnumber of particles (" << specie->name() << ") at index: " << num_part_in_bin;
|
||||
out << "\ndrawn position: " << position.cylinderEntries();
|
||||
out << "\ndrawn velocity: " << velocity.cartesianEntries();
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
velocity, injection_time, weight_factor*num_part_in_bin);
|
||||
velocity, injection_time, weight_factor*particleNumbersMap_[specie->name()][0]);
|
||||
|
||||
queue.push_back(drawn_particle);
|
||||
|
||||
}
|
||||
|
||||
double Injector::timePassed() const {
|
||||
return 1 / activity_;
|
||||
}
|
||||
|
||||
void Injector::fillParticleNumbers(std::shared_ptr<species::TrackedSpecie> specie) {
|
||||
// std::stringstream out;
|
||||
// out << specie->name() << ":";
|
||||
std::vector<double> numbers;
|
||||
double nTot = 0;
|
||||
if(specie->type() == species::ImplementedSpecies::electron) {
|
||||
double numberBelow = specie->densityForDrawing()->particleNumber(
|
||||
energySplit_, false);
|
||||
numbers.push_back(numberBelow);
|
||||
double numberAbove = specie->densityForDrawing()->particleNumber(
|
||||
energySplit_, true);
|
||||
numbers.push_back(numberAbove);
|
||||
// out << "\n\tN( E < " << energySplit_<< ")"
|
||||
// << " = " << numberBelow;
|
||||
// out << "\n\tN( E > " << energySplit_<< ")"
|
||||
// << " = " << numberAbove;
|
||||
nTot = numberBelow + numberAbove;
|
||||
} else {
|
||||
numbers.push_back(specie->densityForDrawing()->particleNumber());
|
||||
// out << numbers[0];
|
||||
nTot = numbers[0];
|
||||
}
|
||||
particleNumbersMap_[specie->name()] = numbers;
|
||||
// out << "\n\t N_total = " << nTot;
|
||||
|
||||
// DEBUG_LEVEL_2(out.str());
|
||||
}
|
||||
|
||||
particle::Particle Injector::drawNewDensityParticleAboveOrBelow(
|
||||
std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const double weight_factor,
|
||||
const double injection_time,
|
||||
const bool above) {
|
||||
|
||||
std::string above_string = above ? "Above" : "Below";
|
||||
// std::stringstream out;
|
||||
// // draw the position
|
||||
// out << above_string << "\n";
|
||||
// out << "\tPosition: ";
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()
|
||||
->drawPosition(engine, energySplit_, above);
|
||||
|
||||
// out << position.cylinderEntries();
|
||||
|
||||
double den_at_pos_below =
|
||||
specie->densityForDrawing()->density(position, energySplit_, false);
|
||||
// out << "\n\tDensity At position below: " << den_at_pos_below;
|
||||
|
||||
// check if density was empty (i.e. phi value lower than 0)
|
||||
if (position.cylinderEntries()(1) < 0) {
|
||||
ERROR(specie->name() + ": has zero density");
|
||||
}
|
||||
|
||||
// DEBUG_LEVEL_3("Injected z position: " +
|
||||
// std::to_string(position.cylinderEntries()(2)));
|
||||
// DEBUG_LEVEL_3("Injected r position: " +
|
||||
// std::to_string(position.cylinderEntries()(0)));
|
||||
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
const int energy_split_bin =
|
||||
specie->dynamicDensityField()->energyBinning()->bin(energySplit_);
|
||||
// out << "\n\tEnergy split bin: " << energy_split_bin;
|
||||
|
||||
// in case the magnetic field is 0 at the current position draw the velocity
|
||||
// with respect to the z-axis otherwise use the magnetic field
|
||||
if(kinematic::norm(magnetic_field->value(position).
|
||||
cartesianEntries(position)) == 0) {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine, energy_split_bin, above);
|
||||
} else {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine, magnetic_field,
|
||||
energy_split_bin,
|
||||
above);
|
||||
}
|
||||
|
||||
// out << "\n\tVelocity: " << velocity.cartesianEntries();
|
||||
|
||||
int index = above ? 1 : 0;
|
||||
// out << "\n\tWeight: " << weight_factor*particleNumbersMap_[specie->name()][index];
|
||||
|
||||
// out << "particleNumbersMap: ";
|
||||
// for(auto element : particleNumbersMap_[specie->name()])
|
||||
// out << element << " ";
|
||||
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
velocity, injection_time, weight_factor*particleNumbersMap_[specie->name()][index]);
|
||||
|
||||
// DEBUG_LEVEL_1(out.str());
|
||||
|
||||
return drawn_particle;
|
||||
}
|
||||
|
||||
double Injector::energySplit() const {
|
||||
return energySplit_;
|
||||
}
|
||||
@@ -29,12 +29,11 @@ std::vector<particle::Particle> InteractionOutput::newParticles() {
|
||||
|
||||
Interaction::Interaction(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target)
|
||||
: cross_section_(cross_section), target_(target),
|
||||
target_velocity_(blitz::TinyVector<double, 3> (0,0,0)) {};
|
||||
: cross_section_(cross_section), target_(target) {}
|
||||
|
||||
// assumes that v_particle >> v_target
|
||||
double Interaction::macroscopicCrossSection(particle::Particle& particle) {
|
||||
const auto x_particle = particle.cylinderPosition();
|
||||
const auto x_particle = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_particle =
|
||||
particle.velocity().cartesianEntries();
|
||||
if(!target_->driftVelocity()) {
|
||||
@@ -62,84 +61,4 @@ double Interaction::microscopicCrossSection(double energy_eV) {
|
||||
return cross_section_(energy_eV);
|
||||
}
|
||||
|
||||
// think i need to include the magnetic field for it to be really correct
|
||||
double Interaction::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
CartesianVector particle_velocity = particle.velocity();
|
||||
|
||||
// approximation for electrons: v_e >> v_t
|
||||
if(particle.specie()->type() == species::ImplementedSpecies::electron) {
|
||||
target_velocity_ = CartesianVector(blitz::TinyVector<double, 3>(0,0,0));
|
||||
} else {
|
||||
target_velocity_ = target_->velocityDistribution()->
|
||||
rollVelocity(particle.cylinderPosition(),
|
||||
generator->engine());
|
||||
|
||||
// // if no drift velocity is present, then assume target at rest otherwise
|
||||
// // use the drift velocity
|
||||
if(target_->driftVelocity()) {
|
||||
// auto tmp = target_->driftVelocity()->driftVelocity(particle.position());
|
||||
target_velocity_.add(target_->driftVelocity()->driftVelocity(
|
||||
particle.cartesianPosition(), particle.cylinderPosition()),
|
||||
particle.cartesianPosition());
|
||||
}
|
||||
}
|
||||
|
||||
// target_velocity_ = CartesianVector(blitz::TinyVector<double, 3>(0.,0.,0.));
|
||||
|
||||
// masses are irrelevant for the transformation
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||
target_velocity_.cartesianEntries(), 0, 0);
|
||||
|
||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
||||
|
||||
// std::stringstream out;
|
||||
// out << "particle "<< particle.specie()->name() <<" velocity: "
|
||||
// << particle_velocity.cartesianEntries();
|
||||
// out << "\ntarget "<< target_->name() <<" velocity: "
|
||||
// << target_velocity_.cartesianEntries();
|
||||
// out << "\nabsolute relative velocity: " << relative_velocity;
|
||||
|
||||
// check if the relative velocity is smaller than an epsilon compared to the larger
|
||||
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||
// a better version possible
|
||||
if(relative_velocity/std::max(
|
||||
kinematic::norm(particle_velocity.cartesianEntries()),
|
||||
kinematic::norm(target_velocity_.cartesianEntries())
|
||||
) < SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
// out << "energy collision time: " << energy_eV;
|
||||
|
||||
const double crosssection = microscopicCrossSection(energy_eV);
|
||||
// out << "\ncross section: " << crosssection;
|
||||
const double density = target_->densityField()->density(particle.cylinderPosition());
|
||||
|
||||
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
|
||||
// out << ", density: " << density;
|
||||
|
||||
const double random_number = generator->rollUniform(0.,1.);
|
||||
if (random_number == 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double distance_target_fixed =
|
||||
- 1./(crosssection * density) * log(random_number);
|
||||
|
||||
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
||||
|
||||
const double time = distance_target_fixed / relative_velocity;
|
||||
// out << "\ntime before collision: " << time;
|
||||
// if(density != 0)
|
||||
// DEBUG_LEVEL_1(out.str());
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
}; // namespace interaction
|
||||
@@ -92,7 +92,7 @@ double velocity(double energy_eV, double mass_kg) {
|
||||
}
|
||||
|
||||
double relativisticGamma(const blitz::TinyVector<double, 3>& velocity) {
|
||||
return std::sqrt(1. + blitz::dot(velocity, velocity) / (SI::c*SI::c));
|
||||
return std::sqrt(1. + blitz::dot(velocity, velocity) / std::pow(SI::c, 2));
|
||||
}
|
||||
|
||||
double relativisticGamma(double kin_energy_eV, double mass_eV) {
|
||||
@@ -105,8 +105,7 @@ double relativisticBeta(double velocity_ms) {
|
||||
|
||||
double relativisticBeta(double kin_energy_eV, double mass_eV) {
|
||||
const double gamma = relativisticGamma(kin_energy_eV, mass_eV);
|
||||
// return std::sqrt(1 - std::pow(1 / gamma, 2));
|
||||
return std::sqrt(1 - 1 / (gamma*gamma));
|
||||
return std::sqrt(1 - std::pow(1 / gamma, 2));
|
||||
}
|
||||
|
||||
double relativisticMomentum(double energy_eV, double mass_eV) {
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
#include "simulation/logger.h"
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types,
|
||||
std::vector<PhysicalDeletionType> used_phys_types) {
|
||||
DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types) {
|
||||
for (auto& type : used_types) {
|
||||
num_deletions[type] = 0;
|
||||
sync_num_deletions[type] = 0;
|
||||
}
|
||||
for (auto& type: used_phys_types) {
|
||||
num_phys_deletions[type] = 0.;
|
||||
sync_num_phys_deletions[type] = 0.;
|
||||
}
|
||||
}
|
||||
|
||||
void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
||||
@@ -20,21 +14,10 @@ void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
||||
}
|
||||
}
|
||||
|
||||
void DeletionLogger::logDeletion(const particle::Particle& particle,
|
||||
PhysicalDeletionType type) {
|
||||
if (num_phys_deletions.count(type) > 0) {
|
||||
num_phys_deletions.at(type) += particle.weight();
|
||||
}
|
||||
}
|
||||
|
||||
std::map<DeletionType, long int> DeletionLogger::numDeletions() const {
|
||||
return num_deletions;
|
||||
}
|
||||
|
||||
std::map<PhysicalDeletionType, double> DeletionLogger::numPhysDeletions() const {
|
||||
return num_phys_deletions;
|
||||
}
|
||||
|
||||
void DeletionLogger::numDeletions(long int new_value, DeletionType type) {
|
||||
if (num_deletions.count(type)) {
|
||||
num_deletions.at(type) = new_value;
|
||||
@@ -56,10 +39,4 @@ void DeletionLogger::resetDeletionLogger() {
|
||||
for (auto& pair : sync_num_deletions) {
|
||||
pair.second = 0;
|
||||
}
|
||||
for(auto& pair : num_phys_deletions) {
|
||||
pair.second = 0;
|
||||
}
|
||||
for (auto& pair : sync_num_phys_deletions) {
|
||||
pair.second = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+57
-90
@@ -21,7 +21,7 @@ BorisMover::BorisMover(double maximal_time_step_s)
|
||||
|
||||
// TBD: include F_g (simply add to electric force)
|
||||
void BorisMover::move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) {
|
||||
@@ -39,30 +39,26 @@ void BorisMover::move(particle::Particle* particle,
|
||||
// density)
|
||||
double max_time_alive = particle->specie()->dynamicDensityField()->physicalTime() -
|
||||
particle->timeAlive();
|
||||
double leftover_time = collision_time_s;
|
||||
|
||||
// auto old_position = particle->position();
|
||||
CartesianCoordinate old_position_cart = particle->cartesianPosition();
|
||||
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
|
||||
double leftover_distance = mfp_m;
|
||||
|
||||
auto old_position = particle->position();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
blitz::TinyVector<double, 3> B_old =
|
||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
|
||||
double old_mu;
|
||||
double new_mu;
|
||||
// if magnetic field is 0 use e_z as a reference for the pitch angle
|
||||
// calculation (don't know if best approach, probably not...)
|
||||
if (kinematic::norm(B_old) == 0) {
|
||||
old_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1),
|
||||
particle->velocity().cartesianEntries(old_position_cart));
|
||||
particle->velocity().cartesianEntries(old_position));
|
||||
} else {
|
||||
old_mu = kinematic::cosPitchAngle(
|
||||
B_old, particle->velocity().cartesianEntries(old_position_cart));
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position),
|
||||
particle->velocity().cartesianEntries(old_position));
|
||||
}
|
||||
new_mu = old_mu;
|
||||
|
||||
double timestep = 0;
|
||||
|
||||
@@ -77,47 +73,48 @@ void BorisMover::move(particle::Particle* particle,
|
||||
bool changed_energy_bin = false;
|
||||
bool left_simulation_domain = false;
|
||||
bool changed_mu_bin = false;
|
||||
bool died_in_bin = particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
bool died_in_bin = false;
|
||||
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
||||
changed_mu_bin || died_in_bin) && (leftover_time > 0.)) {
|
||||
old_position_cart = particle->cartesianPosition();
|
||||
old_position_cyl = particle->cylinderPosition();
|
||||
changed_mu_bin || died_in_bin) && (leftover_distance > 0.)) {
|
||||
old_position = particle->position();
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
double old_velocity = particle->absoluteVelocity();
|
||||
timestep = std::min(maximal_time_step_s_, leftover_time);
|
||||
timestep = std::min(maximal_time_step_s_,
|
||||
(leftover_distance + SimConstants::random_lower_limit) / old_velocity);
|
||||
timestep = std::min(timestep, max_distance / old_velocity);
|
||||
timestep = std::min(timestep, max_time_alive);
|
||||
|
||||
// can probably be removed
|
||||
// double moved_distance = 0.;
|
||||
double moved_distance = 0.;
|
||||
|
||||
const blitz::TinyVector<double, 3> E =
|
||||
electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
electric_field->value(old_position).cartesianEntries(old_position);
|
||||
const blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
const blitz::TinyVector<double, 3> g =
|
||||
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
gravity_field->value(old_position).cartesianEntries(old_position);
|
||||
|
||||
movementStep(particle, E, B, g, timestep);
|
||||
movementStep(particle, E, B, g, moved_distance, timestep);
|
||||
particle->increaseTimeAlive(timestep);
|
||||
// particle->increaseTimeInBin(timestep);
|
||||
particle->increaseTimeInBin(timestep);
|
||||
|
||||
auto new_position_cart = particle->cartesianPosition();
|
||||
auto new_position = particle->position();
|
||||
auto new_velocity = particle->velocity();
|
||||
|
||||
const blitz::TinyVector<double, 3> B_new =
|
||||
magnetic_field->value(particle->cylinderPosition()).
|
||||
cartesianEntries(new_position_cart);
|
||||
magnetic_field->value(new_position).cartesianEntries(new_position);
|
||||
|
||||
double new_mu;
|
||||
if (kinematic::norm(B_new) == 0) {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1), new_velocity.cartesianEntries());
|
||||
blitz::TinyVector<double, 3>(0,0,1),
|
||||
new_velocity.cartesianEntries(new_position));
|
||||
} else {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
B_new, new_velocity.cartesianEntries());
|
||||
magnetic_field->value(new_position).cartesianEntries(new_position),
|
||||
new_velocity.cartesianEntries(new_position));
|
||||
}
|
||||
|
||||
changed_mu_bin =
|
||||
@@ -126,24 +123,11 @@ void BorisMover::move(particle::Particle* particle,
|
||||
|
||||
changed_position_bin =
|
||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||
old_position_cyl, particle->cylinderPosition());
|
||||
old_position, new_position);
|
||||
|
||||
changed_energy_bin =
|
||||
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
||||
old_kinetic_energy, particle->kineticEnergy_eV());
|
||||
// #ifdef debug
|
||||
// if(changed_energy_bin &&
|
||||
// particle->specie()->type() == species::ImplementedSpecies::Tplus) {
|
||||
// std::stringstream out;
|
||||
// out << "Changed energy bin from: " << particle->specie()->dynamicDensityField()
|
||||
// ->energyBinning()->bin(old_kinetic_energy);
|
||||
// out << " (" << old_kinetic_energy << ") to: ";
|
||||
// out << particle->specie()->dynamicDensityField()->energyBinning()
|
||||
// ->bin(particle->kineticEnergy_eV());
|
||||
// out << " (" << particle->kineticEnergy_eV() << ")\n";
|
||||
// DEBUG(out.str());
|
||||
// }
|
||||
// #endif
|
||||
|
||||
left_simulation_domain =
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
@@ -151,7 +135,7 @@ void BorisMover::move(particle::Particle* particle,
|
||||
died_in_bin =
|
||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
|
||||
leftover_time -= timestep;
|
||||
leftover_distance -= moved_distance;
|
||||
|
||||
// if max_time_alive == 0 but the difference between the time alive and
|
||||
// the endtime > 0 (think can happen due to numerical accuracy)
|
||||
@@ -161,18 +145,11 @@ void BorisMover::move(particle::Particle* particle,
|
||||
? delta_timeresolution*SimConstants::compare_epsilon
|
||||
: (max_time_alive - timestep);
|
||||
}
|
||||
if(died_in_bin && !left_simulation_domain) {
|
||||
// && (leftover_time > SimConstants::compare_epsilon ||
|
||||
// changed_energy_bin || changed_mu_bin || changed_position_bin)) {
|
||||
// use new values, since that is necessary if died_in_bin and a change in
|
||||
// bin can occur at the same time
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
particle->cylinderPosition(), particle->kineticEnergy_eV(), new_mu,
|
||||
particle->weight());
|
||||
particle->deposited();
|
||||
}
|
||||
// particle->resetTimeInBin();
|
||||
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
||||
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
old_position, old_kinetic_energy, old_mu, particle->timeInBin());
|
||||
particle->resetTimeInBin();
|
||||
particle->specie()->currentCollector()->collect(particle, old_position);
|
||||
}
|
||||
|
||||
void BorisMover::movementStep(
|
||||
@@ -180,14 +157,13 @@ void BorisMover::movementStep(
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& gravity_field,
|
||||
// double& moved_distance,
|
||||
double& moved_distance,
|
||||
double timestep) const {
|
||||
const blitz::TinyVector<double, 3> v =
|
||||
particle->velocity().cartesianEntries();
|
||||
const double m = particle->mass_kg();
|
||||
const double q = particle->charge_C();
|
||||
|
||||
/*
|
||||
const double u_minus_x =
|
||||
v(0) + (q * electric_field(0) * timestep) / (2. * m)
|
||||
+ (gravity_field(0) * timestep) / 2.;
|
||||
@@ -242,17 +218,14 @@ void BorisMover::movementStep(
|
||||
u_plus_z + (q * electric_field(2) * timestep) / (2. * m)
|
||||
+ (gravity_field(2) * timestep) / 2.;
|
||||
const blitz::TinyVector<double, 3> u_new(u_new_x, u_new_y, u_new_z);
|
||||
*/
|
||||
|
||||
blitz::TinyVector<double, 3> acceleration = q * electric_field / m +
|
||||
gravity_field;
|
||||
/*
|
||||
Might be slower, but essentially the same code */
|
||||
Might be slower, but essentially the same code
|
||||
const blitz::TinyVector<double, 3> u_minus =
|
||||
v + (acceleration * timestep) / (2.);
|
||||
v + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
||||
const double gamma = kinematic::relativisticGamma(u_minus);;
|
||||
const blitz::TinyVector<double, 3> temp_1 =
|
||||
(q * magnetic_field * timestep) / (2. * m * gamma);
|
||||
(q * magnetic_field * maximal_time_step_s_) / (2. * m * gamma);
|
||||
const blitz::TinyVector<double, 3> u_prime =
|
||||
u_minus + (blitz::cross(u_minus, temp_1));
|
||||
const blitz::TinyVector<double, 3> temp_2 =
|
||||
@@ -260,15 +233,16 @@ void BorisMover::movementStep(
|
||||
const blitz::TinyVector<double, 3> u_plus =
|
||||
u_minus + (blitz::cross(u_prime, temp_2));
|
||||
const blitz::TinyVector<double, 3> u_new =
|
||||
u_plus + (acceleration * timestep) / (2.);
|
||||
u_plus + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
||||
*/
|
||||
|
||||
particle->velocity(CartesianVector(u_new));
|
||||
|
||||
const CartesianCoordinate distance(u_new * timestep);
|
||||
particle->move(distance);
|
||||
|
||||
// moved_distance += std::sqrt(
|
||||
// blitz::dot(distance.cartesianEntries(), distance.cartesianEntries()));
|
||||
moved_distance += std::sqrt(
|
||||
blitz::dot(distance.cartesianEntries(), distance.cartesianEntries()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -279,13 +253,13 @@ DriftMover::DriftMover(double maximal_distance)
|
||||
: maximal_distance_m_(maximal_distance){};
|
||||
|
||||
void DriftMover::move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
double mfp_m,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) {
|
||||
double leftover_time = collision_time_s;
|
||||
double leftover_distance = mfp_m;
|
||||
|
||||
auto old_position = particle->cartesianPosition();
|
||||
auto old_position = particle->position();
|
||||
auto old_velocity = particle->velocity();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
double old_mu = kinematic::cosPitchAngle(
|
||||
@@ -306,8 +280,8 @@ void DriftMover::move(particle::Particle* particle,
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || changed_mu_bin
|
||||
|| left_simulation_domain) &&
|
||||
(leftover_time > 0.) && !(died_in_bin)) {
|
||||
old_position = particle->cartesianPosition();
|
||||
(leftover_distance > 0.) && !(died_in_bin)) {
|
||||
old_position = particle->position();
|
||||
old_velocity = particle->velocity();
|
||||
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
@@ -350,15 +324,14 @@ void DriftMover::move(particle::Particle* particle,
|
||||
driftVelocity(force_over_charge, B);
|
||||
const double v_drift_norm = kinematic::norm(v_drift);
|
||||
|
||||
// const double stepsize = std::min(leftover_distance, maximal_distance_m_);
|
||||
const double stepsize = std::min(leftover_distance, maximal_distance_m_);
|
||||
// guard against very large timesteps i.e. v ~ 0 -> timestep = Inf
|
||||
// should be a very rare case (but has happend)
|
||||
double timestep = std::min(
|
||||
maximal_distance_m_ / std::sqrt(v_parallel_norm*v_parallel_norm +
|
||||
const double timestep = std::min(
|
||||
stepsize / std::sqrt(v_parallel_norm*v_parallel_norm +
|
||||
v_perp_norm*v_perp_norm +
|
||||
v_drift_norm*v_drift_norm),
|
||||
max_time_alive);
|
||||
timestep = std::min(timestep, collision_time_s);
|
||||
|
||||
const blitz::TinyVector<double, 3> movement_parallel =
|
||||
v_parallel * timestep;
|
||||
@@ -370,7 +343,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> dv_electric = timestep *
|
||||
particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
||||
|
||||
if (v_perp_norm/v_parallel_norm > SimConstants::compare_epsilon) {
|
||||
if (v_perp_norm > SimConstants::compare_epsilon) {
|
||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||
(B_norm * particle->charge_C());
|
||||
|
||||
@@ -428,7 +401,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
}
|
||||
|
||||
particle->increaseTimeAlive(timestep);
|
||||
// particle->increaseTimeInBin(timestep);
|
||||
particle->increaseTimeInBin(timestep);
|
||||
// if instead of eps*deltaT 0.0 is used the integral would be conserved
|
||||
// if no particles are lost at a boundary. however in that case the terminator does not
|
||||
// return the correct value if the time the particle is alive is identical
|
||||
@@ -442,23 +415,19 @@ void DriftMover::move(particle::Particle* particle,
|
||||
? particle->specie()->dynamicDensityField()
|
||||
->timeResolution()*SimConstants::compare_epsilon
|
||||
: (max_time_alive - timestep);
|
||||
#ifdef debug_level3
|
||||
if (max_time_alive == 0) {
|
||||
DEBUG_LEVEL_3("Mover: max_time_alive is 0.");
|
||||
DEBUG_LEVEL_3("Mover: particle time alive: " +
|
||||
std::to_string(particle->timeAlive()));
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto new_position = particle->cartesianPosition();
|
||||
const auto new_position = particle->position();
|
||||
|
||||
died_in_bin =
|
||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
#ifdef debug_level3
|
||||
if(died_in_bin) {
|
||||
DEBUG_LEVEL_3("Mover: particle died in bin.");
|
||||
}
|
||||
#endif
|
||||
|
||||
changed_position_bin =
|
||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||
@@ -475,24 +444,22 @@ void DriftMover::move(particle::Particle* particle,
|
||||
changed_mu_bin = particle->specie()->dynamicDensityField()
|
||||
->changedPitchAngleBin(old_mu, new_mu);
|
||||
|
||||
#ifdef debug_level3
|
||||
if(changed_mu_bin) {
|
||||
DEBUG_LEVEL_3("cos(pitch old): " + std::to_string(old_mu));
|
||||
DEBUG_LEVEL_3("cos(pitch new): " + std::to_string(new_mu));
|
||||
}
|
||||
#endif
|
||||
|
||||
left_simulation_domain =
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
|
||||
leftover_time -= timestep;
|
||||
leftover_distance -= stepsize;
|
||||
}
|
||||
|
||||
// only log a particle in the bin where its movement ends, i.e. if
|
||||
// the particle reached the end of the timestep
|
||||
if(died_in_bin)
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
old_position, old_kinetic_energy, old_mu, particle->weight());
|
||||
// particle->specie()->dynamicDensityField()->logMovement(
|
||||
// old_position, old_kinetic_energy, particle->timeInBin());
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
old_position, old_kinetic_energy, old_mu, particle->timeInBin());
|
||||
particle->resetTimeInBin();
|
||||
particle->specie()->currentCollector()->collect(particle, old_position);
|
||||
}
|
||||
|
||||
|
||||
+18
-20
@@ -24,11 +24,11 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const double time_birth,
|
||||
const double weight)
|
||||
: specie_(specie),
|
||||
position_cart_(position),
|
||||
position_cyl_(position),
|
||||
position_(position),
|
||||
velocity_(velocity, position),
|
||||
id_(this->last_id_),
|
||||
time_alive_s_(time_birth),
|
||||
time_in_bin_s_(0.),
|
||||
interaction_counter_(0),
|
||||
weight_(weight) {
|
||||
last_id_++;
|
||||
@@ -64,21 +64,15 @@ species::TrackedSpecie* Particle::specie() const {
|
||||
}
|
||||
|
||||
void Particle::position(const Coordinate& new_position) {
|
||||
position_cart_ = CartesianCoordinate(new_position);
|
||||
position_cyl_ = CylinderCoordinate(new_position);
|
||||
position_ = CartesianCoordinate(new_position);
|
||||
}
|
||||
|
||||
CartesianCoordinate Particle::cartesianPosition() const {
|
||||
return position_cart_;
|
||||
}
|
||||
|
||||
CylinderCoordinate Particle::cylinderPosition() const {
|
||||
return position_cyl_;
|
||||
CartesianCoordinate Particle::position() const {
|
||||
return position_;
|
||||
}
|
||||
|
||||
void Particle::move(const Coordinate& distance) {
|
||||
position_cart_.add(distance);
|
||||
position_cyl_ = CylinderCoordinate(position_cart_);
|
||||
position_.add(distance);
|
||||
}
|
||||
|
||||
double Particle::kineticEnergy_eV() const {
|
||||
@@ -107,6 +101,18 @@ double Particle::timeAlive() const {
|
||||
return time_alive_s_;
|
||||
}
|
||||
|
||||
void Particle::increaseTimeInBin(double time_s) {
|
||||
time_in_bin_s_ += time_s;
|
||||
}
|
||||
|
||||
void Particle::resetTimeInBin() {
|
||||
time_in_bin_s_ = 0.;
|
||||
}
|
||||
|
||||
double Particle::timeInBin() const {
|
||||
return time_in_bin_s_*weight_;
|
||||
}
|
||||
|
||||
long int Particle::ID() const {
|
||||
return id_;
|
||||
}
|
||||
@@ -115,12 +121,4 @@ double Particle::weight() const {
|
||||
return weight_;
|
||||
}
|
||||
|
||||
void Particle::deposited() {
|
||||
deposited_ = true;
|
||||
}
|
||||
|
||||
bool Particle::wasDeposited() {
|
||||
return deposited_;
|
||||
}
|
||||
|
||||
} // namespace particle
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "simulation/random_numbers.h"
|
||||
#include <algorithm>
|
||||
|
||||
RandomNumbers::RandomNumbers(int seed)
|
||||
: engine_(std::make_shared<std::mt19937>(seed)),
|
||||
@@ -16,60 +15,3 @@ double RandomNumbers::rollUniform(double min, double max) {
|
||||
std::mt19937* RandomNumbers::engine() {
|
||||
return engine_.get();
|
||||
}
|
||||
|
||||
// does NOT shuffle the indices!
|
||||
// num bins for the energy binning should include the underflow bin!
|
||||
RandomIndex::RandomIndex(blitz::TinyVector<int, 5> num_bins) :
|
||||
num_bins_(num_bins){
|
||||
|
||||
total_bin_number_ = blitz::product(num_bins_);
|
||||
|
||||
one_dimensional_indices_.reserve(total_bin_number_);
|
||||
|
||||
for(size_t i = 0; i < total_bin_number_; ++i) {
|
||||
one_dimensional_indices_.push_back(i);
|
||||
}
|
||||
|
||||
current_index_in_vector_ = 0;
|
||||
}
|
||||
|
||||
void RandomIndex::reshuffle(std::mt19937* engine) {
|
||||
current_index_in_vector_ = 0;
|
||||
std::shuffle(std::begin(one_dimensional_indices_),
|
||||
std::end(one_dimensional_indices_), *engine);
|
||||
}
|
||||
|
||||
bool RandomIndex::visited_all() {
|
||||
return current_index_in_vector_ == total_bin_number_;
|
||||
}
|
||||
|
||||
// return the next index in the shuffled index vector. Returns the last
|
||||
// index if all bins have been visited. Reshuffling resets this.
|
||||
// Note that the underflow bin for the energy is included, i.e. min index for E
|
||||
// is -1 not 0
|
||||
blitz::TinyVector<int, 5> RandomIndex::index() {
|
||||
size_t tmp_one_dimensional_idx = one_dimensional_indices_[current_index_in_vector_];
|
||||
|
||||
blitz::TinyVector<int, 5> return_index{0,0,0,0,0};
|
||||
|
||||
int tmp = 0;
|
||||
|
||||
size_t current_prod = total_bin_number_;
|
||||
|
||||
for(int d = 4; d >= 0; d--) {
|
||||
current_prod /= num_bins_(d);
|
||||
|
||||
tmp = tmp_one_dimensional_idx / current_prod;
|
||||
|
||||
return_index(d) = tmp;
|
||||
|
||||
tmp_one_dimensional_idx -= tmp * current_prod;
|
||||
}
|
||||
|
||||
return_index(4) -= 1;
|
||||
|
||||
if(!visited_all())
|
||||
current_index_in_vector_++;
|
||||
|
||||
return return_index;
|
||||
}
|
||||
@@ -5,12 +5,12 @@ ReflectorDPS::ReflectorDPS(double z_position_dps)
|
||||
|
||||
bool ReflectorDPS::needsReflectionBackToDomain(
|
||||
const particle::Particle* particle) const {
|
||||
return particle->cylinderPosition().cylinderEntries()(2) > z_position_dps_;
|
||||
return particle->position().cylinderEntries()(2) > z_position_dps_;
|
||||
}
|
||||
|
||||
void ReflectorDPS::reflectBackToDomain(particle::Particle* particle) const {
|
||||
blitz::TinyVector<double, 3> old_position =
|
||||
particle->cylinderPosition().cylinderEntries();
|
||||
particle->position().cylinderEntries();
|
||||
old_position(2) = 2 * z_position_dps_ - old_position(2);
|
||||
particle->position(CylinderCoordinate(old_position));
|
||||
blitz::TinyVector<double, 3> old_velocity =
|
||||
|
||||
@@ -58,7 +58,7 @@ CompositeAngleDistribution::CompositeAngleDistribution(
|
||||
|
||||
double CompositeAngleDistribution::roll(std::mt19937* engine,
|
||||
double energy_eV) {
|
||||
if (!(energy_eV > decider_energy_)) {
|
||||
if (energy_eV <= decider_energy_) {
|
||||
return lower_distribution_->roll(engine, energy_eV);
|
||||
} else {
|
||||
return higher_distribution_->roll(engine, energy_eV);
|
||||
|
||||
+51
-254
@@ -3,7 +3,6 @@
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "constants/sim_constants.h"
|
||||
#include "simulation/cpu_synchronizer.h"
|
||||
#include "simulation/current_collector.h"
|
||||
@@ -48,42 +47,26 @@ void Simulation::init(Parameter& parameter) {
|
||||
electric_field_ = generator::electricField(parameter);
|
||||
gravity_field_ = generator::gravityField(parameter);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Creating species.");
|
||||
#endif
|
||||
generator::SpeciesBuilder builder(parameter);
|
||||
tracked_species_ = builder.trackedSpecies();
|
||||
background_species_ = builder.backgroundSpecies();
|
||||
timer_ = builder.timer();
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Creating injector.");
|
||||
#endif
|
||||
injector_ = generator::buildInjector(tracked_species_, background_species_,
|
||||
parameter);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init random numbers.");
|
||||
#endif
|
||||
random_ = generator::buildRandomNumbers(parameter);
|
||||
|
||||
for(auto& tracked_specie : tracked_species_) {
|
||||
tracked_specie.second->randomIndex()->reshuffle(random_->engine());
|
||||
}
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init poisson solver.");
|
||||
#endif
|
||||
poisson_solver_ = generator::buildPoissonSolver(parameter);
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init cpu synchronizer.");
|
||||
#endif
|
||||
cpu_synchronizer_ = std::make_shared<CpuSynchronizer>();
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Init done.");
|
||||
#endif
|
||||
|
||||
Restart restarter = generator::buildRestart(parameter);
|
||||
restarter.restart(tracked_species_, poisson_solver_.get(), random_.get());
|
||||
@@ -94,15 +77,11 @@ void Simulation::init(Parameter& parameter) {
|
||||
// writing the metadata
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init output.");
|
||||
#endif
|
||||
output_ = generator::buildSimulationOutput(
|
||||
parameter.jsonObjectFromBase({"Output"}), tracked_species_);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Output meta data.");
|
||||
#endif
|
||||
output_->writeMetaData(tracked_species_, poisson_solver_);
|
||||
}
|
||||
|
||||
@@ -140,8 +119,8 @@ void Simulation::start() {
|
||||
|
||||
// number of physical beta events defining the timescale through
|
||||
// time_resolution_events/Activity
|
||||
const double time_resolution_events =
|
||||
parameter_.doubleValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||
const int time_resolution_events =
|
||||
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||
MpiCommunication::mpiSize());
|
||||
|
||||
// number of beta decay events per timestep and CPU (will get normalized s.t.
|
||||
@@ -154,28 +133,25 @@ void Simulation::start() {
|
||||
static_cast<double>(beta_decay_events*MpiCommunication::mpiSize());
|
||||
|
||||
// number of density events per timestep and CPU
|
||||
const int particles_per_bin =
|
||||
parameter_.intValue(json_path({"Simulation",
|
||||
"NumberDensityParticlesPerBinPerCPU"}), 0);
|
||||
const int density_events =
|
||||
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
|
||||
|
||||
// calculate a 'stride' for the density events s.t. the same number of syncs
|
||||
// would be performed
|
||||
const int density_stride = std::ceil(particles_per_bin *
|
||||
const int density_stride = std::ceil(density_events *
|
||||
(static_cast<double>(event_stride)/beta_decay_events));
|
||||
// calculate the scaling factor for the particle weight for particles
|
||||
// drawn from the density
|
||||
const double density_weight_factor =
|
||||
1./(MpiCommunication::mpiSize()*particles_per_bin);
|
||||
1./(MpiCommunication::mpiSize()*density_events);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin));
|
||||
#endif
|
||||
DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events));
|
||||
|
||||
SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps));
|
||||
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
||||
|
||||
int leftover_events_time_resolution = beta_decay_events;
|
||||
int leftover_density_events = particles_per_bin;
|
||||
int leftover_density_events = density_events;
|
||||
|
||||
const double delta_t = time_resolution_events*injector_->timePassed();
|
||||
|
||||
@@ -193,6 +169,8 @@ void Simulation::start() {
|
||||
|
||||
timer_->setDeltaT(delta_t);
|
||||
injector_->initInjectionTimeDistribution(delta_t);
|
||||
for(auto element: tracked_species_)
|
||||
injector_->fillParticleNumbers(element.second);
|
||||
|
||||
int num_cpu_syncs = 0;
|
||||
bool reset = true;
|
||||
@@ -215,11 +193,9 @@ void Simulation::start() {
|
||||
int density_events_of_cycle =
|
||||
eventsOfCycle(density_stride, leftover_density_events);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Events of cycle: " + std::to_string(events_of_cycle));
|
||||
DEBUG_LEVEL_1("Density Events of cycle: " +
|
||||
std::to_string(density_events_of_cycle));
|
||||
#endif
|
||||
|
||||
SIM_INFO("Processing timestep: " + std::to_string(timesteps));
|
||||
SIM_INFO("Leftover events this timestep this CPU: " +
|
||||
@@ -228,14 +204,12 @@ void Simulation::start() {
|
||||
std::to_string(leftover_density_events));
|
||||
|
||||
// process both density and beta events before a cpu synchronization
|
||||
processDensityEvents(particles_per_bin, density_weight_factor);
|
||||
processDensityEvents(density_events_of_cycle, density_weight_factor);
|
||||
processEvents(events_of_cycle, beta_particle_weight);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timesteps));
|
||||
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||
std::to_string(leftover_events_time_resolution));
|
||||
#endif
|
||||
|
||||
leftover_events_time_resolution -= events_of_cycle;
|
||||
leftover_density_events -= density_events_of_cycle;
|
||||
@@ -270,21 +244,7 @@ void Simulation::start() {
|
||||
SimulationTimer::eventStartPoint("Reset");
|
||||
if(reset) {
|
||||
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Ions (T+) lost at wall (physical value): " << phyLossAtWallIon;
|
||||
phyLossAtWallIon = 0.;
|
||||
double total_tp = 0;
|
||||
double total_tp_sync = 0.;
|
||||
#endif
|
||||
for(auto& pair : tracked_species_) {
|
||||
#ifdef debug
|
||||
if(pair.second->type() == species::ImplementedSpecies::Tplus) {
|
||||
total_tp = blitz::sum(pair.second->dynamicDensityField()->timeInBinArray());
|
||||
total_tp_sync = blitz::sum(
|
||||
pair.second->densityForDrawing()->timeInBinArray());
|
||||
}
|
||||
#endif
|
||||
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
||||
|
||||
pair.second->currentCollector()->resetCurrentCollector();
|
||||
@@ -293,21 +253,14 @@ void Simulation::start() {
|
||||
|
||||
// the density from which new particles are drawn is only updated after a timestep
|
||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||
pair.second->positionDistributionFromDensity()
|
||||
->setMaximumDensityAboveAndBelow(injector_->energySplit());
|
||||
|
||||
injector_->fillParticleNumbers(pair.second);
|
||||
}
|
||||
#ifdef debug
|
||||
out << "\n\ttotal number in tp: " << total_tp;
|
||||
out << "\n\tdiff to expected: " << (timesteps+1)*0.02 - total_tp;
|
||||
out << "\n\ttotal number created: " << createdDensity;
|
||||
out << "\n\tdiff to expected: " << (timesteps)*0.02/MpiCommunication::mpiSize()
|
||||
- createdDensity;
|
||||
out << "\n\ttotal number in density drawing field: " << total_tp_sync;
|
||||
out << "\n\tdiff to in density: " << total_tp_sync - total_tp;
|
||||
DEBUG(out.str());
|
||||
createdDensity = 0;
|
||||
#endif
|
||||
|
||||
leftover_events_time_resolution = beta_decay_events;
|
||||
leftover_density_events = particles_per_bin;
|
||||
leftover_density_events = density_events;
|
||||
|
||||
timer_->increaseTimestep(delta_t);
|
||||
timesteps++;
|
||||
@@ -321,24 +274,18 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
||||
}
|
||||
|
||||
void Simulation::processEvents(int events, const double beta_particle_weight) {
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Processing events.");
|
||||
#endif
|
||||
int current_event = 0;
|
||||
|
||||
while ((current_event < events) || (!queue_.empty())) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
if (queue_.empty()) {
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
current_event += 1;
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||
#endif
|
||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||
new_particles = determineInjectedParticles(random_.get(),
|
||||
beta_particle_weight);
|
||||
@@ -351,23 +298,19 @@ void Simulation::processEvents(int events, const double beta_particle_weight) {
|
||||
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << particle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << particle.cartesianPosition().cartesianEntries();
|
||||
output_ss << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
}
|
||||
#endif
|
||||
SimulationTimer::eventStopPoint(std::string("ParticleInjection"));
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Injected particles to queue.");
|
||||
#endif
|
||||
|
||||
queue_.insert(queue_.end(), new_particles.begin(),
|
||||
new_particles.end());
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Particles in queue: " +
|
||||
std::to_string(queue_.size()));
|
||||
#endif
|
||||
const int particle_number =
|
||||
particleNumberFromQueue(queue_.size(), random_.get());
|
||||
|
||||
@@ -380,14 +323,9 @@ void Simulation::processEvents(int events, const double beta_particle_weight) {
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::processDensityEvents(int particles_per_bin, const double weight_factor) {
|
||||
#ifdef debug
|
||||
void Simulation::processDensityEvents(int events, const double weight_factor) {
|
||||
DEBUG_LEVEL_0("Processing density events.");
|
||||
#endif
|
||||
// number of full grid traversions
|
||||
int current_event = 0;
|
||||
// set to true if all grids of all species have been visited
|
||||
bool all_bins_done = false;
|
||||
|
||||
// calculate the number of particles currently contained within the densities
|
||||
// of the different tracked species before injection in order to avoid
|
||||
@@ -396,24 +334,20 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
||||
std::map<std::string, double> particleNumbers;
|
||||
for(auto& pair: tracked_species_) {
|
||||
particleNumbers[pair.first] = (pair.second->densityForDrawing()->particleNumber());
|
||||
// injector_->fillParticleNumbers(pair.second);
|
||||
}
|
||||
|
||||
while ((current_event < particles_per_bin) || (!queue_.empty())) {
|
||||
#ifdef debug_level2
|
||||
while ((current_event < events) || (!queue_.empty())) {
|
||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
if (queue_.empty()) {
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current density event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("DensityInjection"));
|
||||
new_particles = determineInjectedDensityParticles(random_.get(),
|
||||
weight_factor, current_event, particleNumbers,
|
||||
all_bins_done);
|
||||
weight_factor, current_event, particleNumbers);
|
||||
SimulationTimer::eventStopPoint(std::string("DensityInjection"));
|
||||
|
||||
#if defined debug_level3
|
||||
@@ -422,34 +356,24 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
||||
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << particle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << particle.cartesianPosition().cartesianEntries();
|
||||
output_ss << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
}
|
||||
#endif
|
||||
// if no new particles could be injected from the density, it is not possible
|
||||
// that during another iteration cycle new particles will be injected
|
||||
// (drawing field only changes after timesteps)
|
||||
|
||||
if(all_bins_done) {
|
||||
current_event += 1;
|
||||
for(auto& element : tracked_species_) {
|
||||
element.second->randomIndex()->reshuffle(random_->engine());
|
||||
}
|
||||
}
|
||||
|
||||
if(!new_particles.empty()) {
|
||||
queue_.insert(queue_.end(), new_particles.begin(), new_particles.end());
|
||||
} else {
|
||||
continue;
|
||||
if(new_particles.empty()) {
|
||||
return;
|
||||
}
|
||||
current_event += 1;
|
||||
|
||||
queue_.insert(queue_.end(), new_particles.begin(), new_particles.end());
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Particles in queue: " +
|
||||
std::to_string(queue_.size()));
|
||||
#endif
|
||||
std::to_string(queue_.size()));
|
||||
const int particle_number =
|
||||
particleNumberFromQueue(queue_.size(), random_.get());
|
||||
particleNumberFromQueue(queue_.size(), random_.get());
|
||||
|
||||
// extract particle from queue here, so that an extension of the queue does
|
||||
// not mess up the reference
|
||||
@@ -462,128 +386,82 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
||||
|
||||
void Simulation::processUntilTermination(
|
||||
particle::Particle& particle) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Process particle until termination");
|
||||
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
||||
#endif
|
||||
while (particle.specie()->terminator()->isAlive(&particle)) {
|
||||
auto old_position = particle.cylinderPosition();
|
||||
auto old_position = particle.position();
|
||||
double old_energy = particle.kineticEnergy_eV();
|
||||
|
||||
std::vector<double> macroscopic_cross_sections_m;
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("MFP calculation"));
|
||||
// const double mfp_m = meanFreePath(particle, random_.get(),
|
||||
// macroscopic_cross_sections_m);
|
||||
const double collision_time = collisionTime(particle, random_.get());
|
||||
const double mfp_m = meanFreePath(particle, random_.get(),
|
||||
macroscopic_cross_sections_m);
|
||||
SimulationTimer::eventStopPoint(std::string("MFP calculation"));
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Mover"));
|
||||
particle.specie()->mover()->move(&particle, collision_time, electric_field_.get(),
|
||||
particle.specie()->mover()->move(&particle, mfp_m, electric_field_.get(),
|
||||
magnetic_field_.get(), gravity_field_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("Mover"));
|
||||
|
||||
bool was_reflected = false;
|
||||
if (particle.specie()->reflector()->needsReflectionBackToDomain(
|
||||
&particle)) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Reflect particle.");
|
||||
#endif
|
||||
old_position = particle.cylinderPosition();
|
||||
old_position = particle.position();
|
||||
particle.specie()->reflector()->reflectBackToDomain(&particle);
|
||||
particle.specie()->currentCollector()->collect(&particle, old_position);
|
||||
was_reflected = true;
|
||||
}
|
||||
|
||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||
&particle) &&
|
||||
!particle.specie()->terminator()->leftSimulationDomain(
|
||||
&particle)) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
||||
". Reached timeresolution.");
|
||||
#endif
|
||||
if(particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.position(),
|
||||
DeletionType::max_time_alive);
|
||||
#ifdef debug
|
||||
if(!particle.wasDeposited()) {
|
||||
std::stringstream out;
|
||||
out << "particle " << particle.specie()->name();
|
||||
out << " reached maximum time alive and is deleted without contributing";
|
||||
out << " to the density";
|
||||
ERROR(out.str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||
&particle)) {
|
||||
#if defined debug_level3
|
||||
DEBUG_LEVEL_1("Terminate particle " + particle.specie()->name()
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||
+ ". Left simulation domain.");
|
||||
std::stringstream output_ss;
|
||||
output_ss << "Position (cyl): " << particle.cylinderPosition().cylinderEntries();
|
||||
output_ss << " (cart): " << particle.cartesianPosition().cartesianEntries();
|
||||
// ERROR(output_ss.str());
|
||||
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
|
||||
output_ss << " (cart): " << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.position(),
|
||||
DeletionType::wall);
|
||||
particle.specie()->deletionLogger()->logDeletion(particle,
|
||||
PhysicalDeletionType::wall);
|
||||
}
|
||||
#ifdef debug
|
||||
if(particle.specie()->type() == species::ImplementedSpecies::Tplus) {
|
||||
phyLossAtWallIon += particle.weight();
|
||||
}
|
||||
if(particle.wasDeposited()) {
|
||||
std::stringstream out;
|
||||
out << "particle " << particle.specie()->name();
|
||||
out << " left simulation domain but still contributes to the density";
|
||||
ERROR(out.str());
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(particle.specie()->dynamicDensityField()->changedPositionBin(
|
||||
old_position, particle.cylinderPosition())) &&
|
||||
old_position, particle.position())) &&
|
||||
!(particle.specie()->dynamicDensityField()->changedEnergyBin(
|
||||
old_energy, particle.kineticEnergy_eV())) &&
|
||||
!was_reflected) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform interaction.");
|
||||
DEBUG_LEVEL_3("Number of Interactions: " +
|
||||
std::to_string(particle.interactionCounter()));
|
||||
DEBUG_LEVEL_3("Ekin before interact: " +
|
||||
std::to_string(particle.kineticEnergy_eV()));
|
||||
#if defined debug_level3
|
||||
std::stringstream output_ss;
|
||||
output_ss << "Position (cyl): " << particle.cylinderPosition().cylinderEntries();
|
||||
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
|
||||
// output_ss << "\n (cart): " << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Interaction"));
|
||||
interaction::InteractionOutput output = interact(particle, random_.get());//,
|
||||
// macroscopic_cross_sections_m);
|
||||
interaction::InteractionOutput output = interact(particle, random_.get(),
|
||||
macroscopic_cross_sections_m);
|
||||
SimulationTimer::eventStopPoint(std::string("Interaction"));
|
||||
|
||||
// particle has reached time resolution, but was not deposited due to
|
||||
// the interaction taking place at the same time.
|
||||
// If the particle is not destroyed in the interaction put it into the mover
|
||||
// in order to log the position. (Not ideal, but otherwise it would be a bit
|
||||
// more effort to calculate the pitchangle here again...)
|
||||
// should work, since the check for died in bin should immediatly happen (hopefully)
|
||||
// if(particle.specie()->terminator()->reachedMaxTimeAlive(&particle)
|
||||
// && !particle.wasDeposited() && !output.deleteCurrentParticle()) {
|
||||
// particle.specie()->mover()->move(&particle, 1,
|
||||
// electric_field_.get(), magnetic_field_.get(), gravity_field_.get());
|
||||
// if(!particle.wasDeposited()) {
|
||||
// ERROR("particle was not deposited even though it should have been");
|
||||
// }
|
||||
// }
|
||||
|
||||
particle.increaseInteractionCounter();
|
||||
|
||||
for (auto& new_particle : output.newParticles()) {
|
||||
@@ -591,20 +469,16 @@ void Simulation::processUntilTermination(
|
||||
}
|
||||
|
||||
if (output.deleteCurrentParticle()) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(particle.specie()->name() + " removed due to interaction.");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (particle.specie()->terminator()->reachedMaxInteractions(&particle)) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||
+ ". Reached max interactions.");
|
||||
#endif
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(
|
||||
particle.cylinderPosition(), DeletionType::max_interactions);
|
||||
particle.position(), DeletionType::max_interactions);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -634,44 +508,6 @@ double Simulation::meanFreePath(particle::Particle& particle,
|
||||
}
|
||||
}
|
||||
|
||||
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
||||
// algorithm lib)
|
||||
double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||
std::vector<double> collision_times;
|
||||
double tmp;
|
||||
|
||||
for(auto& interaction : particle.specie()->interactions()) {
|
||||
tmp = interaction->drawCollisionTime(particle, random);
|
||||
collision_times.push_back(tmp);
|
||||
}
|
||||
|
||||
auto min_iterator = std::min_element(collision_times.begin(), collision_times.end());
|
||||
|
||||
particle.indexNextInteration((min_iterator - collision_times.begin()));
|
||||
|
||||
#ifdef debug_level3
|
||||
std::stringstream out;
|
||||
out << "collision times:\n[ ";
|
||||
|
||||
for(auto& element : collision_times) {
|
||||
out << element << " ";
|
||||
}
|
||||
out << "]";
|
||||
out << "\nmin value: " << *min_iterator;
|
||||
out << "\nindexNextInteraction: " << particle.indexNextInteraction();
|
||||
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
#endif
|
||||
|
||||
return *min_iterator;
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
particle::Particle& particle, RandomNumbers* random) {
|
||||
return particle.specie()->interactions().at(particle.indexNextInteraction())
|
||||
->performInteraction(particle, random);
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
@@ -705,8 +541,7 @@ std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
||||
// weight_factor has to be such that particleNumber * weight_factor = weight
|
||||
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
RandomNumbers* random, const double weight_factor, const int current,
|
||||
std::map<std::string, double>& particleNumbers, bool& all_bins_done) {
|
||||
|
||||
std::map<std::string, double>& particleNumbers) {
|
||||
std::vector<particle::Particle> new_particles{};
|
||||
|
||||
if(!new_particles.empty()) {
|
||||
@@ -716,89 +551,51 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
|
||||
const double injection_time = timer_->time() - timer_->getDeltaT();
|
||||
|
||||
bool tmp_done = false;
|
||||
all_bins_done = true;
|
||||
|
||||
for(auto& pair: tracked_species_) {
|
||||
|
||||
tmp_done = pair.second->randomIndex()->visited_all();
|
||||
|
||||
if (particleNumbers[pair.first] == 0) {
|
||||
all_bins_done = all_bins_done && true;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined debug_level3
|
||||
if (current == 0) {
|
||||
#if defined debug_level2
|
||||
// if (current == 0) {
|
||||
std::stringstream out;
|
||||
out << pair.second->name();
|
||||
out << "particle number from density: ";
|
||||
out << particleNumbers[pair.first];
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
// }
|
||||
#endif
|
||||
|
||||
if(!tmp_done) {
|
||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||
pair.second, new_particles, magnetic_field_,
|
||||
weight_factor, injection_time);
|
||||
#ifdef debug
|
||||
if(!new_particles.empty()) {
|
||||
if(new_particles.back().specie()->type() == species::ImplementedSpecies::Tplus
|
||||
&& pair.second->type() == species::ImplementedSpecies::Tplus) {
|
||||
// if(createdDensity + new_particles.back().weight() == createdDensity){
|
||||
// std::stringstream out;
|
||||
// out << "catastrophic cancellation!\ncreated density: " << createdDensity;
|
||||
// out << "\n\tweight: " << new_particles.back().weight();
|
||||
// DEBUG(out.str());
|
||||
// }
|
||||
createdDensity += new_particles.back().weight();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// if species is not done tmp_done && ... = false
|
||||
all_bins_done = all_bins_done && tmp_done;
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
//maybe put that into the poisson solver
|
||||
blitz::Array<double,3> Simulation::chargedensity() {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Initialize chargedensity Array");
|
||||
#endif
|
||||
//not great but the size and bounds of the density arrays are needed...
|
||||
std::shared_ptr<species::TrackedSpecie> firstTracked =
|
||||
tracked_species_.begin()->second;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("shared pointer extracted, key: "
|
||||
+ tracked_species_.begin()->first);
|
||||
#endif
|
||||
|
||||
if(!firstTracked)
|
||||
ERROR("Extracted pointer is null.");
|
||||
|
||||
blitz::Array<double,3> init = firstTracked->
|
||||
dynamicDensityField()->densityArray();
|
||||
blitz::Array<double, 3> chargeden(init.lbound(), init.extent());
|
||||
chargeden = 0.;
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Collect chargedensity");
|
||||
#endif
|
||||
for (auto& pair : tracked_species_) {
|
||||
chargeden += pair.second->charge_C() * pair.second->dynamicDensityField()->
|
||||
densityArray();
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Maximum value in the chargedensity: " +
|
||||
std::to_string(blitz::max(chargeden)));
|
||||
#endif
|
||||
|
||||
return chargeden;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "simulation/terminator.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "simulation/random_numbers.h"
|
||||
|
||||
namespace species {
|
||||
|
||||
@@ -59,33 +58,15 @@ TrackedSpecie::TrackedSpecie(
|
||||
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
||||
velocity_distribution_from_density_(
|
||||
std::make_shared<VelocityDistributionFromDensityField>(
|
||||
density_for_drawing, mass_kg)) {
|
||||
blitz::TinyVector<int, 5> num_bins;
|
||||
auto tmp = density_field->positionBinning()->numBins();
|
||||
num_bins(0) = tmp(0); num_bins(1) = tmp(1); num_bins(2) = tmp(2);
|
||||
|
||||
num_bins(3) = density_field->pitchAngleBinning()->numBins();
|
||||
// include underflow bin in the energy direction only
|
||||
num_bins(4) = density_field->energyBinning()->numBins() + 1;
|
||||
|
||||
random_index_ = std::make_shared<RandomIndex> (RandomIndex(num_bins));
|
||||
}
|
||||
|
||||
RandomIndex* TrackedSpecie::randomIndex() {
|
||||
return random_index_.get();
|
||||
}
|
||||
density_for_drawing, mass_kg)) {}
|
||||
|
||||
DensityField* TrackedSpecie::densityField() {
|
||||
return density_field_.get();
|
||||
}
|
||||
|
||||
VelocityDistribution* TrackedSpecie::velocityDistribution() {
|
||||
// return velocity_distribution_.get();
|
||||
// return the distribution from the calculated density distribution instead of
|
||||
// the one (potentially) given at construction.
|
||||
return velocity_distribution_from_density_.get();
|
||||
VelocityDistribution* TrackedSpecie::velocityDistibution() {
|
||||
return velocity_distribution_.get();
|
||||
}
|
||||
|
||||
DriftVelocity* TrackedSpecie::driftVelocity() {
|
||||
return drift_velocity_.get();
|
||||
}
|
||||
@@ -163,7 +144,7 @@ BackgroundSpecie::BackgroundSpecie(
|
||||
DensityField* BackgroundSpecie::densityField() {
|
||||
return density_field_.get();
|
||||
}
|
||||
VelocityDistribution* BackgroundSpecie::velocityDistribution() {
|
||||
VelocityDistribution* BackgroundSpecie::velocityDistibution() {
|
||||
return velocity_distribution_.get();
|
||||
}
|
||||
DriftVelocity* BackgroundSpecie::driftVelocity() {
|
||||
|
||||
@@ -38,7 +38,7 @@ bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
|
||||
|
||||
bool Terminator::leftSimulationDomain(
|
||||
const particle::Particle* particle) const {
|
||||
return !(geometry_->isInside(particle->cylinderPosition()));
|
||||
return !(geometry_->isInside(particle->position()));
|
||||
}
|
||||
|
||||
double Terminator::maxTimeAlive() const {
|
||||
|
||||
@@ -25,11 +25,8 @@ std::function<double(double)> tritiumDecayEnergySpectrum(double prefactor) {
|
||||
const double eta = 2.0 * M_PI * Z / (137.0 * beta);
|
||||
const double fermi_function = eta / (1. - std::exp(-eta));
|
||||
|
||||
// return T2BetaDecay::spectrum_prefactor * fermi_function *
|
||||
// (energy_eV + HEPunits::me) * p *
|
||||
// std::pow(T2BetaDecay::E0_T - energy_eV, 2) * prefactor;
|
||||
return T2BetaDecay::spectrum_prefactor * fermi_function *
|
||||
(energy_eV + HEPunits::me) * p *
|
||||
(T2BetaDecay::E0_T - energy_eV)*(T2BetaDecay::E0_T - energy_eV) * prefactor;
|
||||
std::pow(T2BetaDecay::E0_T - energy_eV, 2) * prefactor;
|
||||
};
|
||||
}
|
||||
@@ -37,10 +37,6 @@ VelocityDistributionFromDensityField::VelocityDistributionFromDensityField(
|
||||
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
||||
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
||||
mass_kg_(mass_kg) {
|
||||
double maxAbsExponent = std::max(std::abs(std::log10(energyBinBorders_.front())),
|
||||
std::abs(std::log10(energyBinBorders_.back())));
|
||||
alpha_lower_limit = -300/maxAbsExponent;
|
||||
alpha_upper_limit = 300/maxAbsExponent;
|
||||
// necessary to include the underflow bin in the energy domain
|
||||
energyBinBorders_.insert(energyBinBorders_.begin(), 0);
|
||||
}
|
||||
@@ -99,7 +95,6 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
// can NOT be removed, needed for drawing of velocity of interaction partners
|
||||
CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field) {
|
||||
@@ -125,12 +120,85 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
pitchAngleBinBorders_.end(),
|
||||
pitchAngleValues.begin());
|
||||
|
||||
double pitchAngle = pitchAngle_dist(*engine);
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianB_values =
|
||||
magnetic_field->value(position).cartesianEntries(position);
|
||||
const double Bmagnitude = kinematic::norm(cartesianB_values);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
blitz::TinyVector<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle
|
||||
* cartesianB_values/Bmagnitude
|
||||
+ std::sqrt(1 - pitchAngle*pitchAngle)
|
||||
* kinematic::rotateVector(v_perp, cartesianB_values, theta);
|
||||
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Note: right now assumes that the density (either above or below)
|
||||
the threshold value is non-zero, i.e. in the case that
|
||||
that is not the case will create no sensible result
|
||||
*/
|
||||
CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const int E_th_bin, const bool above) {
|
||||
|
||||
// draw energy from DynamicDensityField
|
||||
blitz::Array<double, 1> energyValues = density_field_->
|
||||
sliceSpectrumArray(position);
|
||||
|
||||
auto bordersBeginIterator = energyBinBorders_.begin();
|
||||
auto bordersEndIterator = energyBinBorders_.end();
|
||||
auto valuesBeginIterator = energyValues.begin();
|
||||
|
||||
if(above) {
|
||||
bordersBeginIterator += E_th_bin - density_field_->energyBinning()->binIndexMin();
|
||||
valuesBeginIterator = energyValues(blitz::Range(E_th_bin, blitz::toEnd)).begin();
|
||||
} else {
|
||||
if(E_th_bin == density_field_->energyBinning()->binIndexMin()) {
|
||||
return CartesianVector(blitz::TinyVector<double, 3>(0,0,0));
|
||||
}
|
||||
bordersEndIterator = bordersBeginIterator + E_th_bin
|
||||
- density_field_->energyBinning()->binIndexMin() + 1;
|
||||
}
|
||||
|
||||
std::piecewise_constant_distribution<double> energy_dist(
|
||||
bordersBeginIterator,
|
||||
bordersEndIterator,
|
||||
valuesBeginIterator);
|
||||
|
||||
double energy_eV = energy_dist(*engine);
|
||||
|
||||
// draw pitch angle from DynamicDensityField
|
||||
|
||||
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||
sliceTimeInBinArray(position, energy_eV);
|
||||
|
||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||
pitchAngleBinBorders_.begin(),
|
||||
pitchAngleBinBorders_.end(),
|
||||
pitchAngleValues.begin());
|
||||
|
||||
double pitchAngle = pitchAngle_dist(*engine);
|
||||
|
||||
|
||||
#ifdef debug
|
||||
if((std::isnan(pitchAngle)) || (std::isnan(energy_eV))) {
|
||||
std::stringstream out;
|
||||
out << "pitchAngle: " << pitchAngle;
|
||||
above ? out << "Above" : out << "Below";
|
||||
out << " threshold bin of " << E_th_bin;
|
||||
out << "\npitchAngle: " << pitchAngle;
|
||||
out << "\nenergy value: " << energy_eV;
|
||||
out << "\nenergy values: " << energyValues;
|
||||
out << "\npitch angle values: " << pitchAngleValues;
|
||||
@@ -165,202 +233,58 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
// if valid is false after function, the number of particles in the cell at the given index
|
||||
// is 0
|
||||
CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
||||
const blitz::TinyVector<int, 5> index, std::mt19937* engine) {
|
||||
|
||||
// const double number_particles_in_bin = density_field_->particleNumber(index);
|
||||
|
||||
const double energy_step = energyBinBorders_[index(4) + 1]
|
||||
- energyBinBorders_[index(4)];
|
||||
|
||||
const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1]
|
||||
- pitchAngleBinBorders_[index(3)];
|
||||
|
||||
double energy_eV = energyBinBorders_[index(4)]
|
||||
+ theta_distribution_(*engine)*energy_step;
|
||||
|
||||
double pitchAngle = pitchAngleBinBorders_[index(3)]
|
||||
+ theta_distribution_(*engine)*pitch_angle_step;
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> zDirection(0,0,1);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
// vector perpendicular to e_z
|
||||
blitz::TinyVector<double, 3> v_perp(1,0,0);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle * zDirection
|
||||
+ std::sqrt(1 - pitchAngle*pitchAngle)
|
||||
* kinematic::rotateVector(v_perp, zDirection, theta);
|
||||
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
||||
const blitz::TinyVector<int, 5> index, std::mt19937* engine,
|
||||
const Coordinate& position,
|
||||
std::shared_ptr<MagneticField> magnetic_field) {
|
||||
CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
const int E_th_bin, const bool above) {
|
||||
|
||||
// since a 0 is included in the bin borders for the energy
|
||||
const double energy_step = energyBinBorders_[index(4) + 2]
|
||||
- energyBinBorders_[index(4) + 1];
|
||||
// draw energy from DynamicDensityField
|
||||
blitz::Array<double, 1> energyValues = density_field_->
|
||||
sliceSpectrumArray(position);
|
||||
|
||||
const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1]
|
||||
- pitchAngleBinBorders_[index(3)];
|
||||
auto bordersBeginIterator = energyBinBorders_.begin();
|
||||
auto bordersEndIterator = energyBinBorders_.end();
|
||||
auto valuesBeginIterator = energyValues.begin();
|
||||
|
||||
// double energy_eV = energyBinBorders_[index(4) + 1]
|
||||
// + theta_distribution_(*engine)*energy_step;
|
||||
double energy_eV;
|
||||
double alpha = 1;
|
||||
if(index(4) == -1) {
|
||||
// linear drawing inbetween E=0, N(0)=0 to E=Er and N(Er)=Nr
|
||||
energy_eV = energyBinBorders_[index(4) + 2]*
|
||||
std::sqrt(theta_distribution_(*engine));
|
||||
// #ifdef debug
|
||||
// std::stringstream out;
|
||||
// out << "underflow bin.\n\tdrawn energy: " << energy_eV;
|
||||
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
if(above) {
|
||||
bordersBeginIterator += E_th_bin - density_field_->energyBinning()->binIndexMin();
|
||||
valuesBeginIterator = energyValues(blitz::Range(E_th_bin, blitz::toEnd)).begin();
|
||||
} else {
|
||||
double nl = density_field_->particleNumber(index);
|
||||
double nr = density_field_->particleNumber(index +
|
||||
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
|
||||
// double alpha;
|
||||
// no reason for specific values, just to avoid these cases
|
||||
if(nl == 0) {
|
||||
alpha = 1;
|
||||
} else if (nr == 0) {
|
||||
alpha = -1;
|
||||
} else if (nr == 0 && nl == 0) {
|
||||
alpha = 0;
|
||||
} else {
|
||||
alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/
|
||||
energyBinBorders_[index(4) + 1]);
|
||||
}
|
||||
|
||||
// alpha = std::abs(alpha) > 100 ?(alpha/std::abs(alpha))*100 : alpha;
|
||||
alpha = std::min(std::max(alpha, alpha_lower_limit), alpha_upper_limit);
|
||||
|
||||
if(alpha == -1) {
|
||||
energy_eV = std::pow(energyBinBorders_[index(4) + 2]
|
||||
/ energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) *
|
||||
energyBinBorders_[index(4) + 1];
|
||||
// energy_eV = (std::pow(2, theta_distribution_(*engine)) - 1)*energy_step
|
||||
// + energyBinBorders_[index(4) + 1];
|
||||
// #ifdef debug
|
||||
// std::stringstream out;
|
||||
// out << "alpha = -1\n\tdrawn energy: " << energy_eV;
|
||||
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
} else {
|
||||
double xl_alphap1 = std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||
double xr_alphap1 = std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||
energy_eV = std::pow((xr_alphap1 - xl_alphap1)*
|
||||
theta_distribution_(*engine) + xl_alphap1, 1/(alpha + 1));
|
||||
// #ifdef debug
|
||||
// if(std::abs(alpha) > 100) {
|
||||
// std::stringstream out;
|
||||
// out << "alpha: " << alpha;
|
||||
// out << "\nxl_alphap1: " << xl_alphap1;
|
||||
// out << "\nxr_alphap1: " << xr_alphap1;
|
||||
// DEBUG(out.str());
|
||||
// }
|
||||
// #endif
|
||||
// #ifdef debug
|
||||
// std::stringstream out;
|
||||
// out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV;
|
||||
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||
// DEBUG(out.str());
|
||||
// #endif
|
||||
if(E_th_bin == density_field_->energyBinning()->binIndexMin()) {
|
||||
return CartesianVector(blitz::TinyVector<double, 3>(0,0,0));
|
||||
}
|
||||
bordersEndIterator = bordersBeginIterator +
|
||||
E_th_bin - density_field_->energyBinning()->binIndexMin();
|
||||
}
|
||||
|
||||
double pitchAngle = pitchAngleBinBorders_[index(3)]
|
||||
+ theta_distribution_(*engine)*pitch_angle_step;
|
||||
std::piecewise_constant_distribution<double> energy_dist(
|
||||
bordersBeginIterator,
|
||||
bordersEndIterator,
|
||||
valuesBeginIterator);
|
||||
|
||||
double energy_eV = energy_dist(*engine);
|
||||
|
||||
#ifdef debug
|
||||
if((std::isnan(pitchAngle)) || (std::isnan(energy_eV))) {
|
||||
std::stringstream out;
|
||||
out << "pitchAngle: " << pitchAngle;
|
||||
out << "\nenergy value: " << energy_eV;
|
||||
out << "\nalpha: " << alpha;
|
||||
out << "\ncurrent index: " << index;
|
||||
out << "\nNl: " << density_field_->particleNumber(index);
|
||||
out << "\nNl: " << density_field_->particleNumber(index +
|
||||
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
out << "\nEl: " << energyBinBorders_[index(4) + 1];
|
||||
out << "\nEr: " << energyBinBorders_[index(4) + 2];
|
||||
out << "\nEl^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||
out << "\nEr^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||
// out << "\nenergy values: " << energyValues;
|
||||
// out << "\npitch angle values: " << pitchAngleValues;
|
||||
out << "\nenergy bin borders: [ ";
|
||||
for(auto element : energyBinBorders_) {
|
||||
out << element << " ";
|
||||
}
|
||||
out << "]";
|
||||
// draw pitch angle from DynamicDensityField
|
||||
|
||||
ERROR(out.str());
|
||||
}
|
||||
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||
sliceTimeInBinArray(position, energy_eV);
|
||||
|
||||
// if(std::isinf(energy_eV)) {
|
||||
// std::stringstream out;
|
||||
// out << "pitchAngle: " << pitchAngle;
|
||||
// out << "\nenergy value: " << energy_eV;
|
||||
// out << "\ncurrent index: " << index;
|
||||
// out << "\nalpha: " << alpha;
|
||||
// out << "\nNl: " << density_field_->particleNumber(index);
|
||||
// out << "\nNl: " << density_field_->particleNumber(index +
|
||||
// blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||
// out << "\nEl: " << energyBinBorders_[index(4) + 1];
|
||||
// out << "\nEr: " << energyBinBorders_[index(4) + 2];
|
||||
// // out << "\nenergy values: " << energyValues;
|
||||
// // out << "\npitch angle values: " << pitchAngleValues;
|
||||
// out << "\nenergy bin borders: [ ";
|
||||
// for(auto element : energyBinBorders_) {
|
||||
// out << element << " ";
|
||||
// }
|
||||
// out << "]";
|
||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||
pitchAngleBinBorders_.begin(),
|
||||
pitchAngleBinBorders_.end(),
|
||||
pitchAngleValues.begin());
|
||||
|
||||
// ERROR(out.str());
|
||||
// }
|
||||
#endif
|
||||
|
||||
#ifdef debug_level2
|
||||
std::stringstream out;
|
||||
out << "left Pitchangle value: "<< pitchAngleBinBorders_[index(3)];
|
||||
out << "\nright Pitchangle value: " << pitchAngleBinBorders_[index(3)+1];
|
||||
out << "\npitchAngle: " << pitchAngle;
|
||||
out << "\nleft energy value: "<< energyBinBorders_[index(4) + 1];
|
||||
out << "\nright energy value: " << energyBinBorders_[index(4)+2];
|
||||
out << "\nenergy value: " << energy_eV;
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
double pitchAngle = pitchAngle_dist(*engine);
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianB_values =
|
||||
magnetic_field->value(position).cartesianEntries(position);
|
||||
blitz::TinyVector<double, 3> cartesianB_values(0,0,1);
|
||||
const double Bmagnitude = kinematic::norm(cartesianB_values);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
blitz::TinyVector<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
blitz::TinyVector<double, 3> v_perp(1,0,0);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle
|
||||
* cartesianB_values/Bmagnitude
|
||||
|
||||
@@ -14,14 +14,10 @@ IsotropicDistribution::IsotropicDistribution(
|
||||
blitz::TinyVector<double, 3> rollUnitVector(std::mt19937* engine) {
|
||||
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
||||
const double theta = distribution(*engine) * 2 * M_PI;
|
||||
// const double phi = std::acos(1. - 2.*distribution(*engine));
|
||||
double cosphi = 1. - 2.*distribution(*engine);
|
||||
// phi in [0, pi] --> sin(phi) > 0
|
||||
double sinphi = std::sqrt(1 - cosphi*cosphi);
|
||||
|
||||
return blitz::TinyVector<double, 3>(std::cos(theta) * sinphi,
|
||||
std::sin(theta) * sinphi,
|
||||
cosphi);
|
||||
const double phi = std::acos(1. - 2.*distribution(*engine));
|
||||
return blitz::TinyVector<double, 3>(std::cos(theta) * std::sin(phi),
|
||||
std::sin(theta) * std::sin(phi),
|
||||
std::cos(phi));
|
||||
}
|
||||
|
||||
CartesianVector IsotropicDistribution::rollVelocity(std::mt19937* engine) {
|
||||
|
||||
Reference in New Issue
Block a user