Moved drawing from density to seperate classes

This commit is contained in:
2025-02-05 10:31:56 +01:00
parent b529021149
commit 57ef99a57b
15 changed files with 376 additions and 280 deletions
+4 -2
View File
@@ -31,8 +31,10 @@ class Restart {
private:
void restartTimer(species::TrackedSpecie* reference_specie);
void restartDrawingDensityField(DynamicDensityField* field, std::string path); // only necc densityfield for the one that is drawn from
void restartPoissonSolver(PoissonSolver* solver); // only load in the potential and calc the electric field
// only necessary for densityfield that is drawn from
void restartDrawingDensityField(DynamicDensityField* field, std::string path);
// only load in the potential and calc the electric field
void restartPoissonSolver(PoissonSolver* solver);
void restartRandomNumbers(RandomNumbers* random);
bool do_restart_;
+14 -13
View File
@@ -46,9 +46,11 @@ class DynamicDensityField : public DensityField {
double energy_eV,
double pitch_angle);
// return the particle number stored in the density of this object
double particleNumber();
blitz::TinyVector<double, 5> draw(std::mt19937* engine);
// returns true if the old pitch angle and the new pitch angle are in different bins
// of the pitch angle binning
bool changedPitchAngleBin(double old_pitch_angle, double new_pitch_angle) const;
blitz::Array<double, 3> densityArray();
@@ -57,6 +59,16 @@ class DynamicDensityField : public DensityField {
blitz::Array<long int, 5> deletedParticlesArray() const;
blitz::Array<double, 3> binVolumeArray() const;
// 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...)
blitz::Array<double, 1> sliceSpectrumArray(const Coordinate& position) const;
// return an array of the time in bin at the Coordinate position and the energy
// energy_eV (only pitch angle direction left); over and underflow bin are removed
blitz::Array<double, 1> sliceTimeInBinArray(const Coordinate& position,
double energy_eV) const;
const EnergyBinning* energyBinning() const;
const CylinderBinning* positionBinning() const;
const PitchAngleBinning* pitchAngleBinning() const;
@@ -68,19 +80,15 @@ class DynamicDensityField : public DensityField {
friend class CpuSynchronizer;
void setDensityDistribution();
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);
private:
// BinCoordinate densityBin(const CylinderCoordinate& position) const;
void recalculateDensityArray();
void initPositionDistributions();
// use ordering r, phi, z, pitch_angle, E
// use ordering r, phi, z, pitch_angle, E
blitz::Array<double, 5> time_in_bin_s_;
blitz::Array<long int, 5> deleted_particles_;
@@ -92,13 +100,6 @@ class DynamicDensityField : public DensityField {
const CylinderBinning position_binning_;
const EnergyBinning energy_binning_;
// random distributions for drawing from
std::uniform_real_distribution<double> r_dist_;
std::uniform_real_distribution<double> phi_dist_;
std::uniform_real_distribution<double> z_dist_;
std::uniform_real_distribution<double> density_dist_;
const PitchAngleBinning pitch_angle_binning_;
std::shared_ptr<Timer> timer_;
@@ -6,6 +6,7 @@
#include "simulation/coordinates.h"
#include "simulation/scalar_field.h"
#include "simulation/density_field.h"
struct Limit {
Limit() : min(0), max(0){};
@@ -14,6 +15,9 @@ struct Limit {
double max;
};
// Might be possible to generalize the distributions (i.e. create parent class
// and let the two that are defined now inherit from it)
class EventPositionDistribution {
public:
EventPositionDistribution(std::shared_ptr<ScalarField> mother_density,
@@ -33,4 +37,31 @@ class EventPositionDistribution {
std::uniform_real_distribution<double> density_values;
};
// Class to draw a position from the density provided by a pointer
// to a DynamicDensityField object
class PositionDistributionFromDensity {
public:
// Constructor taking a pointer to a DynamicDensityField object
PositionDistributionFromDensity(std::shared_ptr<DynamicDensityField> density);
// draw a position from the density provided at construction using the rejection method
CylinderCoordinate drawPosition(std::mt19937* engine);
// 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();
private:
// variable storing the maximum value of the density
double maximum_density_ = 1.;
std::shared_ptr<DynamicDensityField> density_;
// distributions for the spatial directions and for the density
std::uniform_real_distribution<double> r_values;
std::uniform_real_distribution<double> phi_values;
std::uniform_real_distribution<double> z_values;
std::uniform_real_distribution<double> density_values;
};
#endif /* EVENT_POSITION_DISTRIBUTION_H */
+8 -7
View File
@@ -41,13 +41,14 @@ class Injector {
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine,
const double current_time);
// void rollNewParticleFromDensityField(std::mt19937* engine,
// std::shared_ptr<species::TrackedSpecie> specie,
// std::vector<particle::Particle>& queue,
// const double weight,
// const double injection_time);
void rollNewParticleFromDensityField(std::mt19937* engine,
// draw new particles from the DynamicDensityField of the provided specie
// 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 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,
+11
View File
@@ -18,6 +18,8 @@ class DeletionLogger;
class CurrentCollector;
class VelocityDistribution;
class DriftVelocity;
class PositionDistributionFromDensity;
class VelocityDistributionFromDensityField;
namespace interaction {
class Interaction;
@@ -84,6 +86,11 @@ class TrackedSpecie : public Specie {
std::vector<std::shared_ptr<interaction::Interaction>> interactions();
void addInteraction(std::shared_ptr<interaction::Interaction> interaction);
// getter for the raw pointer to the positionDistributionFromDensity object
PositionDistributionFromDensity* positionDistributionFromDensity();
// getter for the raw pointer to the VelocityDistributionFromDensityField object
VelocityDistributionFromDensityField* velocityDistributionFromDensityField();
private:
std::shared_ptr<DynamicDensityField> density_field_;
std::shared_ptr<VelocityDistribution> velocity_distribution_;
@@ -98,6 +105,10 @@ class TrackedSpecie : public Specie {
std::vector<std::shared_ptr<interaction::Interaction>> interactions_;
std::shared_ptr<DynamicDensityField> density_for_drawing_;
std::shared_ptr<PositionDistributionFromDensity>
position_distribution_from_density_;
std::shared_ptr<VelocityDistributionFromDensityField>
velocity_distribution_from_density_;
};
class BackgroundSpecie : public Specie {
+41 -13
View File
@@ -25,22 +25,50 @@ class VelocityDistributionFromFunction : public VelocityDistribution {
std::shared_ptr<VelocityDistributionFunction> fv_;
};
/*
todo: implement this for direct interactions of simulated particles
class DensityField;
// only applicable to TrackedSpecies (i.e. only for DynamicDensityFields)
// other density don't have any information about the velocity direction
class DynamicDensityField;
class MagneticField;
// Class to draw a velocity from the pitch angle resolved density
class VelocityDistributionFromDensityField : public VelocityDistribution {
public:
VelocityDistributionFromDensityField(
std::shared_ptr<DensityField> density_field);
CartesianVector driftVelocity_ms(const CylinderVector& position);
CartesianVector rollVelocity_ms(
const CylinderVector& position, std::mt19937* engine);
public:
// Constructor: takes shared ptr to the DynamicDensityField object from which
// should be drawn and the mass of the species to which the density
// field belongs
VelocityDistributionFromDensityField(
std::shared_ptr<DynamicDensityField> density_field, double mass_kg);
// stub: can be implemented to return the drift velocity of the particles
// at the CylinderVector position of the density field
CartesianVector driftVelocity_ms(const CylinderVector& position);
// returns a velocity vector drawn from the energy and pitch angle distributions
// since no magnetic field is given use e_z as the direction wrt the definition
// of the pitch angle
CartesianVector rollVelocity(const Coordinate& position, std::mt19937* engine);
// 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
CartesianVector rollVelocity(
const Coordinate& position, std::mt19937* engine,
std::shared_ptr<MagneticField> magnetic_field);
private:
std::shared_ptr<DensityField> density_field_;
// mass of the species of which the density field is a part of
const double mass_kg_;
std::shared_ptr<DynamicDensityField> density_field_;
blitz::Array<double, 1> energy_values;
blitz::Array<double, 1> mu_values;
std::vector<double> energyBinBorders_;
std::vector<double> pitchAngleBinBorders_;
std::uniform_real_distribution<double> theta_distribution_;
};
*/
#endif /* VELOCITY_DISTRIBUTION_H */