LCOV - code coverage report
Current view: top level - include/crpropa/magneticField - MagneticField.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 12 17 70.6 %
Date: 2024-04-29 14:43:01 Functions: 3 7 42.9 %

          Line data    Source code
       1             : #ifndef CRPROPA_MAGNETICFIELD_H
       2             : #define CRPROPA_MAGNETICFIELD_H
       3             : 
       4             : #include "crpropa/Units.h"
       5             : #include "crpropa/Vector3.h"
       6             : #include "crpropa/Referenced.h"
       7             : 
       8             : #ifdef CRPROPA_HAVE_MUPARSER
       9             : #include "muParser.h"
      10             : #endif
      11             : 
      12             : namespace crpropa {
      13             : /**
      14             :  * \addtogroup MagneticFields
      15             :  * @{
      16             :  */
      17             : 
      18             : /**
      19             :  @class MagneticField
      20             :  @brief Abstract base class for magnetic fields.
      21             :  */
      22           0 : class MagneticField: public Referenced {
      23             : public:
      24           0 :         virtual ~MagneticField() {
      25           0 :         }
      26           0 :         virtual Vector3d getField(const Vector3d &position) const {
      27           0 :                 return Vector3d(0,0,0);
      28             :         };
      29     5760379 :         virtual Vector3d getField(const Vector3d &position, double z) const {
      30     5760379 :                 return getField(position);
      31             :         };
      32             : };
      33             : 
      34             : /**
      35             :  @class PeriodicMagneticField
      36             :  @brief Magnetic field decorator implementing periodic fields.
      37             : 
      38             :  The periodic cube is defined by its origin (Vector3d) and an
      39             :  extends parameter (Vector3d). All points x=(x_1, x_2, x_3) 
      40             :  that are described by x_i = origin_i + epsilon * extend_i, 
      41             :  with epsilon = 0...1 are within the base cube. Magnetic field
      42             :  strengths for all positions outside of this cube are calculated 
      43             :  based on the values in the base cube. 
      44             :  This can be done periodically or reflectively.
      45             : */
      46             : 
      47             : class PeriodicMagneticField: public MagneticField {
      48             :         ref_ptr<MagneticField> field;
      49             :         Vector3d origin, extends;
      50             :         bool reflective;
      51             : public:
      52             :         /**
      53             :          * Constructor
      54             :          * @param field magnetic field reference pointer
      55             :          * @param extends length, width, and height of the base cube 
      56             :         */
      57             :         PeriodicMagneticField(ref_ptr<MagneticField> field,
      58             :                         const Vector3d &extends);
      59             :         /**
      60             :          * Constructor
      61             :          * @param field magnetic field reference pointer
      62             :          * @param extends length, width, and height of the base cube
      63             :          * @param origin defines the reference position 
      64             :          * @param reflective for periodic or reflective behavior  
      65             :         */
      66             :         PeriodicMagneticField(ref_ptr<MagneticField> field, const Vector3d &extends,
      67             :                         const Vector3d &origin, bool reflective);
      68             :         Vector3d &getOrigin();
      69             :         void setOrigin(const Vector3d &origin);
      70             :         Vector3d &getExtends();
      71             :         void setExtends(const Vector3d &origin);
      72             :         bool isReflective();
      73             :         void setReflective(bool reflective);
      74             :         Vector3d getField(const Vector3d &position) const;
      75             : };
      76             : 
      77             : /**
      78             :  @class MagneticFieldList
      79             :  @brief Magnetic field decorator implementing a superposition of fields.
      80             :  */
      81           2 : class MagneticFieldList: public MagneticField {
      82             :         std::vector<ref_ptr<MagneticField> > fields;
      83             : public:
      84             :         void addField(ref_ptr<MagneticField> field);
      85             :         Vector3d getField(const Vector3d &position) const;
      86             : };
      87             : 
      88             : /**
      89             :  @class MagneticFieldEvolution
      90             :  @brief Magnetic field decorator implementing an evolution of type (1+z)^m.
      91             :  */
      92           2 : class MagneticFieldEvolution: public MagneticField {
      93             :         ref_ptr<MagneticField> field;
      94             :         double m;
      95             : public:
      96             :         /**
      97             :          * Constructor
      98             :          * @param field magnetic field reference pointer
      99             :          * @param m cosmic evolution parameter 
     100             :         */
     101             :         MagneticFieldEvolution(ref_ptr<MagneticField> field, double m);
     102             :         Vector3d getField(const Vector3d &position, double z = 0) const;
     103             : };
     104             : 
     105             : /**
     106             :  @class UniformMagneticField
     107             :  @brief Magnetic field with one B-field vector.
     108             :  */
     109             : class UniformMagneticField: public MagneticField {
     110             :         Vector3d value;
     111             : public:
     112             :         /**
     113             :          * Constructor
     114             :          * @param value magnetic field strength
     115             :         */
     116          33 :         UniformMagneticField(const Vector3d &value) :
     117          33 :                         value(value) {
     118             :         }
     119     5760340 :         Vector3d getField(const Vector3d &position) const {
     120     5760340 :                 return value;
     121             :         }
     122             : };
     123             : 
     124             : /**
     125             :  @class MagneticDipoleField
     126             :  @brief Magnetic dipole field defined by the magnetic moment and the 'core' radius.
     127             :  */
     128           1 : class MagneticDipoleField: public MagneticField {
     129             :         Vector3d origin;
     130             :         Vector3d moment;
     131             :         double radius;
     132             : public:
     133             :         /**
     134             :          * Constructor
     135             :          * @param origin        singularity of the dipole field
     136             :          * @param moment        magnetic moment of the dipole field
     137             :          * @param radius        inside a radius around the origin the 
     138             :          *                                      magnetic field is constant: moment * 2 * mu0 / 3  
     139             :         */
     140           1 :         MagneticDipoleField(const Vector3d &origin, const Vector3d &moment, const double radius) :
     141           1 :                         origin(origin), moment(moment), radius(radius) {
     142             :         }
     143             :         Vector3d getField(const Vector3d &position) const;
     144             : };
     145             : 
     146             : #ifdef CRPROPA_HAVE_MUPARSER
     147             : /**
     148             :  @class RenormalizeMagneticField
     149             :  @brief Renormalize strength of a given field by expression in which B is the strength variable.
     150             :  */
     151             : class RenormalizeMagneticField: public MagneticField {
     152             :         ref_ptr<MagneticField> field;
     153             :         std::string expression;
     154             :         mu::Parser *p;
     155             :         double Bmag;
     156             : public:
     157             :         /**
     158             :          * Constructor
     159             :          * @param field                 magnetic field reference pointer
     160             :          * @param expression    muParser expression used to renormalize the field, 
     161             :          *                                              e.g., "gauss". 
     162             :         */
     163             :         RenormalizeMagneticField(ref_ptr<MagneticField> field, std::string expression);
     164           1 :         ~RenormalizeMagneticField() { delete p; }
     165             :         Vector3d getField(const Vector3d &position);
     166             : };
     167             : #endif
     168             : 
     169             : /** @} */
     170             : } // namespace crpropa
     171             : 
     172             : #endif // CRPROPA_MAGNETICFIELD_H

Generated by: LCOV version 1.14