Line data Source code
1 : #ifndef CRPROPA_MASSDISTRIBUTION_H 2 : #define CRPROPA_MASSDISTRIBUTION_H 3 : 4 : #include "crpropa/massDistribution/Density.h" 5 : #include "crpropa/Vector3.h" 6 : #include "crpropa/Grid.h" 7 : 8 : #include "kiss/logger.h" 9 : 10 : #include <vector> 11 : 12 : namespace crpropa { 13 : 14 : /** 15 : @class DensityList 16 : @brief Superposition of density models. 17 : The addDensity function adds a new density to the list. 18 : The getDensity function handles the activated types in loaded densities, whereas get(type)Density disregards the activation state. 19 : */ 20 2 : class DensityList: public Density { 21 : private: 22 : std::vector<ref_ptr<Density> > DensityList ; 23 : 24 : public: 25 : /** Add new density to list. 26 : @param density density to add 27 : */ 28 : void addDensity(ref_ptr<Density> density); 29 : 30 : /** Get density at a given position. 31 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 32 : @returns Density in particles/m^3, sum up densities from added densities 33 : */ 34 : double getDensity(const Vector3d &position) const; 35 : /** Get HI density at a given position. 36 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 37 : @returns Density of HI at given position in particles/m^3, sum up all HI densities from added densities 38 : */ 39 : double getHIDensity(const Vector3d &position) const; 40 : /** Get HII density at a given position. 41 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 42 : @returns Density of HII at given position in particles/m^3, sum up all HII densities from added densities 43 : */ 44 : double getHIIDensity(const Vector3d &position) const; 45 : /** Get H2 density at a given position. 46 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 47 : @returns Density of H2 at given position in particles/m^3, sum up all H2 densities from added densities 48 : */ 49 : double getH2Density(const Vector3d &position) const; 50 : /** Get the density of nucleons. 51 : This is the number of nucleons per volume, summed up all activated density and weight molecular hydrogyen twice 52 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 53 : @returns Density of nucleons at given position in particles/m^3, sum up all nucleon densities from added densities 54 : */ 55 : double getNucleonDensity(const Vector3d &position) const; 56 : 57 : std::string getDescription(); 58 : }; 59 : 60 : /** 61 : @class DensityGrid 62 : @brief Wrapper to use a Grid1f for a density 63 : 64 : The DensityGrid uses a given grid for the chosen density type. More than one type can be chosen to follow the same distribution. 65 : If no type is chosen a warning will be raised and all densities are 0. 66 : */ 67 4 : class DensityGrid: public Density { 68 : private: 69 : ref_ptr<Grid1f> grid; //< Grid with data 70 : bool isForHI, isForHII, isForH2; 71 : void checkAndWarn(); //< raise a warning if all density types are deactivated. 72 : 73 : public: 74 : DensityGrid(ref_ptr<Grid1f> grid, bool isForHI = false, bool isForHII = false, bool isForH2 = false); 75 : 76 : /** Get HI density at a given position. 77 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 78 : @returns Density of HI at given position in particles/m^3, sum up all HI densities from added densities 79 : */ 80 : double getHIDensity(const Vector3d &position) const; 81 : 82 : /** Get HII density at a given position. 83 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 84 : @returns Density of HII at given position in particles/m^3, sum up all HII densities from added densities 85 : */ 86 : double getHIIDensity(const Vector3d &position) const; 87 : 88 : /** Get H2 density at a given position. 89 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 90 : @returns Density of H2 at given position in particles/m^3, sum up all H2 densities from added densities 91 : */ 92 : double getH2Density(const Vector3d &position) const; 93 : 94 : /** Get density at a given position. 95 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 96 : @returns Density in particles/m^3, sum up densities from added densities 97 : */ 98 : double getDensity(const Vector3d &position) const; 99 : 100 : /** Get the density of nucleons. 101 : This is the number of nucleons per volume, summed up all activated density and weight molecular hydrogyen twice 102 : @param position position in Galactic coordinates with Earth at (-8.5 kpc, 0, 0) 103 : @returns Density of nucleons at given position in particles/m^3, sum up all nucleon densities from added densities 104 : */ 105 : double getNucleonDensity(const Vector3d &position) const; 106 : 107 : bool getIsForHI(); 108 : bool getIsForHII(); 109 : bool getIsForH2(); 110 : 111 : /* set if the density is for HI type. 112 : @param b if True the density is used for HI 113 : */ 114 : void setIsForHI(bool b); 115 : 116 : /* set if the density is for HII type. 117 : @param b if True the density is used for HII 118 : */ 119 : void setIsForHII(bool b); 120 : 121 : /* set if the density is for H2 type. 122 : @param b if True the density is used for H2 123 : */ 124 : void setIsForH2(bool b); 125 : 126 : /* Change the grid for the density 127 : @param grid (Grid1f) new grid for the density. 128 : */ 129 : void setGrid(ref_ptr<Grid1f> grid); 130 : 131 : std::string getDescription(); 132 : }; 133 : 134 : } // namespace crpropa 135 : 136 : #endif // CRPROPA_MASSDISTRIBUTION_H