Line data Source code
1 : #ifndef CRPROPA_MAGNETICFIELDGRID_H 2 : #define CRPROPA_MAGNETICFIELDGRID_H 3 : 4 : #include "crpropa/magneticField/MagneticField.h" 5 : #include "crpropa/Grid.h" 6 : 7 : namespace crpropa { 8 : /** 9 : * \addtogroup MagneticFields 10 : * @{ 11 : */ 12 : 13 : /** 14 : @class MagneticFieldGrid 15 : @brief Magnetic field on a periodic (or reflective), cartesian grid with trilinear interpolation. 16 : 17 : This class wraps a Grid3f to serve as a MagneticField. 18 : */ 19 : class MagneticFieldGrid: public MagneticField { 20 : ref_ptr<Grid3f> grid; 21 : public: 22 : /** 23 : *Constructor 24 : @param grid Grid3f storing the magnetic field vectors 25 : */ 26 : MagneticFieldGrid(ref_ptr<Grid3f> grid); 27 : void setGrid(ref_ptr<Grid3f> grid); 28 : ref_ptr<Grid3f> getGrid(); 29 : Vector3d getField(const Vector3d &position) const; 30 : }; 31 : 32 : /** 33 : @class ModulatedMagneticFieldGrid 34 : @brief Modulated magnetic field on a periodic grid. 35 : 36 : This class wraps a Grid3f to serve as a MagneticField. 37 : The field is modulated on-the-fly with a Grid1f. 38 : The Grid3f and Grid1f do not need to share the same origin, spacing or size. 39 : */ 40 : class ModulatedMagneticFieldGrid: public MagneticField { 41 : ref_ptr<Grid3f> grid; 42 : ref_ptr<Grid1f> modGrid; 43 : public: 44 0 : ModulatedMagneticFieldGrid() { 45 : } 46 : /** 47 : *Constructor 48 : @param grid Grid3f storing the magnetic field vectors 49 : @param modGrid Grid1f used to scale the magnetic field strength 50 : B^new_i = B^old_i * scale 51 : */ 52 : ModulatedMagneticFieldGrid(ref_ptr<Grid3f> grid, ref_ptr<Grid1f> modGrid); 53 : void setGrid(ref_ptr<Grid3f> grid); 54 : void setModulationGrid(ref_ptr<Grid1f> modGrid); 55 : ref_ptr<Grid3f> getGrid(); 56 : ref_ptr<Grid1f> getModulationGrid(); 57 : void setReflective(bool gridReflective, bool modGridReflective); 58 : Vector3d getField(const Vector3d &position) const; 59 : }; 60 : /** @} */ 61 : } // namespace crpropa 62 : 63 : #endif // CRPROPA_MAGNETICFIELDGRID_H