138 lines
5.6 KiB
C++
Executable File
138 lines
5.6 KiB
C++
Executable File
#ifndef DENSITY_FIELD_H
|
|
#define DENSITY_FIELD_H
|
|
|
|
#include <memory>
|
|
|
|
#include "simulation/coordinates.h"
|
|
#include "simulation/cpu_synchronizer.h"
|
|
#include "simulation/energy_binning.h"
|
|
#include "simulation/position_binning.h"
|
|
#include "simulation/timer.h"
|
|
|
|
// defined in "simulation/scalar_field.h"
|
|
class ScalarField;
|
|
// defined in "simulation/event_position_dirstribution.h"
|
|
class EventPositionDistribution;
|
|
|
|
// class for a generic density field, specifying the minimum requirements
|
|
class DensityField {
|
|
public:
|
|
// pure virtual function requiring that a function to obtain the density (m^-3) at
|
|
// the Coordinate position is returned
|
|
virtual double density(const Coordinate& position) = 0;
|
|
// pure virtual function requiring that a function to obtain the density (m^-3) at
|
|
// the Coordinate position and energy energy_eV is returned
|
|
virtual double density(const Coordinate& position, double energy_eV) = 0;
|
|
};
|
|
|
|
// class for the density field for TrackedSpecies, i.e. simulated species
|
|
class DynamicDensityField : public DensityField {
|
|
public:
|
|
// Constructor: create the necessary array storing the time particles (4d r,phi,z,E) have spent in a bin,
|
|
// a corresponding array that stores the number of deletions (4d r,phi,z,E) in a bin
|
|
// as well as the 4d array for the actual density (in m^-3) and the
|
|
// array with the volumes of the individual bins from the CylinderBinning and EnergyBinnig
|
|
DynamicDensityField(const CylinderBinning& position_binning,
|
|
const EnergyBinning& energy_binning,
|
|
std::shared_ptr<Timer> timer);
|
|
|
|
// returns true if the bin of the old_position Coordinate and the bin of the
|
|
// new_position Coordinate are different otherwise returns false
|
|
bool changedPositionBin(const Coordinate& old_position,
|
|
const Coordinate& new_position) const;
|
|
|
|
// returns true if the bin of old_energy_eV is different than the bin of new_energy_eV
|
|
// otherwise returns false
|
|
bool changedEnergyBin(double old_energy_eV, double new_energy_eV) const;
|
|
|
|
// increases the value of the time_in_bin array by time_in_bin_s at the bin index
|
|
// determined by the Coordinate position and energy_eV
|
|
void logMovement(const Coordinate& position,
|
|
double energy_eV,
|
|
double time_in_bin_s);
|
|
|
|
// increases the value of the deleted_particles array by 1 at the bin index determined
|
|
// by position and energy_eV
|
|
void logDeletion(const Coordinate& position, double energy_eV);
|
|
|
|
// return the value of the density_per_m3 array at the bin index
|
|
// determined by the Coordinate position summed over all energy bins
|
|
double density(const Coordinate& position);
|
|
// return the value of the density_per_m3 array at the bin index
|
|
// determined by the Coordinate position and energy_eV
|
|
double density(const Coordinate& position, double energy_eV);
|
|
|
|
// calculate and return the 3d density array (m^-3), no resolution in the energy direction
|
|
blitz::Array<double, 3> densityArray();
|
|
// calculate and return the 4d density array (m^-3), with a resolution in energy direction
|
|
blitz::Array<double, 4> spectrumArray();
|
|
// getter for the time_in_bin array
|
|
blitz::Array<double, 4> timeInBinArray() const;
|
|
// getter for the deleted_particles array
|
|
blitz::Array<long int, 4> deletedParticlesArray() const;
|
|
// getter for the bin_volume_m3 array
|
|
blitz::Array<double, 3> binVolumeArray() const;
|
|
|
|
// return a raw pointer to the EnergyBinning member object
|
|
const EnergyBinning* energyBinning() const;
|
|
// return a raw pointer to the CylinderBinning member object
|
|
const CylinderBinning* positionBinning() const;
|
|
|
|
// return the time from the timer member
|
|
double physicalTime() const;
|
|
|
|
// make the private member variables accessable by the CpuSynchronizer
|
|
friend class CpuSynchronizer;
|
|
|
|
private:
|
|
// coordinate ordering: r, phi, z, E
|
|
// bin numbering
|
|
// radial:
|
|
// 0, ..., num_bin_r-1: r < r_max
|
|
// num_bin_r: r >= r_max
|
|
//
|
|
// azimuthal:
|
|
// 0, ..., num_bin_phi: all
|
|
//
|
|
// longitudinal:
|
|
// -1: z < 0
|
|
// 0, ..., num_bin_z-1: 0 <= z < z_max
|
|
// num_bin_z: z >= z_max
|
|
BinCoordinate densityBin(const CylinderCoordinate& position) const;
|
|
// uses time_in_bin, deleted_particles (4d), bin_volume_m3 (3d) and the timer to
|
|
// recalculate the density_per_m3 array (4d)
|
|
void recalculateDensityArray();
|
|
|
|
// array storing the cumulative time particles of a species have spent in certain bins
|
|
blitz::Array<double, 4> time_in_bin_s_;
|
|
// array storing the cumulative time particles of a species have been deleted due to recombination
|
|
blitz::Array<long int, 4> deleted_particles_;
|
|
// array storing the physical density (units: m^-3), histogram in energy dimension
|
|
blitz::Array<double, 4> density_per_m3_;
|
|
// arrya storing the volumes of the individual bins of the time_in_bin array (or rather the CylinderBinning object)
|
|
blitz::Array<double, 3> bin_volume_m3_;
|
|
|
|
const CylinderBinning position_binning_;
|
|
const EnergyBinning energy_binning_;
|
|
|
|
std::shared_ptr<Timer> timer_;
|
|
};
|
|
|
|
// class for the density field for BackgroundSpecies, i.e. non-simulated species
|
|
class ConstantDensityField : public DensityField {
|
|
public:
|
|
// Constructor: making the shared_ptr density a member variable
|
|
ConstantDensityField(std::shared_ptr<ScalarField> density);
|
|
|
|
// return the value of the of the ScalarField density at the position Coordinate position
|
|
double density(const Coordinate& position);
|
|
// return the value of the of the ScalarField density at the position Coordinate position
|
|
// (energy_eV is ignored, since ScalarField does not have an energy resolution)
|
|
double density(const Coordinate& position, double energy_eV);
|
|
|
|
private:
|
|
std::shared_ptr<ScalarField> density_;
|
|
};
|
|
|
|
#endif /* DENSITY_FIELD_H */
|