LCOV - code coverage report
Current view: top level - include/crpropa/magneticField - UF26Field.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 100.0 % 1 1
Test Date: 2026-11-13 09:48:01 Functions: - 0 0

            Line data    Source code
       1              : #ifndef CRPROPA_UF26FIELD_H
       2              : #define CRPROPA_UF26FIELD_H
       3              : 
       4              : #include <string>
       5              : #include "crpropa/magneticField/MagneticField.h"
       6              : #include "crpropa/Grid.h"
       7              : #include "crpropa/Units.h"
       8              : 
       9              : namespace crpropa {
      10              : /**
      11              :  * \addtogroup MagneticFields
      12              :  * @{
      13              :  */
      14              : 
      15              : /**
      16              :  @class UF26Field
      17              :  @brief UF26 model of the random Galactic magnetic field
      18              : 
      19              :  Implements the two random-field models of UF26, expDisk and ringDisk
      20              :  (Table 2 of M. Unger and G.R. Farrar, arXiv:2608.21293). The coherent
      21              :  field of the same authors is available as UF23Field.
      22              : 
      23              :  The models describe the rms strength b(x) of the isotropic random field,
      24              :  i.e. <|B|^2> = b^2, where the average is over a volume large compared to
      25              :  the coherence length of the field. Each Cartesian component therefore has
      26              :  an rms of b/sqrt(3). The rms strength is given by getTurbulentStrength().
      27              : 
      28              :  As for the turbulent component of JF12Field, a realization of the field is
      29              :  obtained by scaling a turbulent grid with B_rms = 1 to the local rms
      30              :  strength, B(x) = b(x) * B_grid(x). The grid is created with
      31              :  randomTurbulent() or set with setTurbulentGrid(). The paper does not
      32              :  determine the coherence length; randomTurbulent() uses Lc = 30 pc by
      33              :  default, the value used for the deflection estimates in the paper. The
      34              :  scaling breaks
      35              :  div B = 0 at the level of Lc divided by the scale of variation of b
      36              :  (>~ 1 kpc).
      37              : 
      38              :  Usage together with the coherent UF23 field, e.g. for backtracking or
      39              :  lens production (Python):
      40              : 
      41              :  \code{.py}
      42              :  B = MagneticFieldList()
      43              :  B.addField(UF23Field(UF23Field.base))
      44              :  B26 = UF26Field(UF26Field.expDisk)
      45              :  B26.randomTurbulent(seed)  # or randomTurbulent(seed, Lc), default Lc = 30 pc
      46              :  B.addField(B26)
      47              :  \endcode
      48              : 
      49              :  For a different spectrum, create the grid e.g. with SimpleGridTurbulence
      50              :  (Brms = 1) and pass it with setTurbulentGrid().
      51              : 
      52              :  Assumes a galactocentric coordinate system with the Galactic center
      53              :  at the origin, the x-axis pointing in the opposite direction of the
      54              :  Sun, and the z-axis pointing towards Galactic North. The Sun is at
      55              :  a distance of 8.178 kpc from the Galactic center.
      56              : 
      57              :  */
      58           12 : class UF26Field : public MagneticField {
      59              : public:
      60              :         /// models of Table 2 of the UF26 paper
      61              :         enum ModelType {
      62              :                 expDisk,
      63              :                 ringDisk
      64              :         };
      65              : 
      66              :         /**
      67              :          @brief constructor
      68              :          @param mt model type (expDisk or ringDisk)
      69              :          */
      70              :         UF26Field(const ModelType mt);
      71              : 
      72              :         /// no default constructor
      73              :         UF26Field() = delete;
      74              : 
      75              : #ifdef CRPROPA_HAVE_FFTW3F
      76              :         /**
      77              :          @brief create and set a random realization of the turbulent grid
      78              : 
      79              :          Kolmogorov spectrum with B_rms = 1 and lMax/lMin = 34 on a periodic grid
      80              :          of 256^3 points (200 MB) with a spacing of lMin/2. The length scales
      81              :          follow from the coherence length: for Lc = 30 pc, lMin = 4.0 pc,
      82              :          lMax = 136 pc and the box size is 512 pc. Lc = 60 pc corresponds to
      83              :          the grid of JF12Field::randomTurbulent().
      84              :          @param seed random seed, 0: random realization
      85              :          @param lc   coherence length of the turbulence
      86              :          */
      87              :         void randomTurbulent(int seed = 0, double lc = 30 * parsec);
      88              : #endif
      89              : 
      90              :         /**
      91              :          Set a turbulent grid
      92              :          @param grid    vector grid containing a random field of Brms = 1
      93              :          */
      94              :         void setTurbulentGrid(ref_ptr<Grid3f> grid);
      95              :         ref_ptr<Grid3f> getTurbulentGrid();
      96              :         /// true if a turbulent grid is set
      97              :         bool isUsingTurbulentField() const;
      98              : 
      99              :         /// rms strength b of the random field (Eqs. 12 and 15 in quadrature)
     100              :         double getTurbulentStrength(const Vector3d &pos) const;
     101              : 
     102              :         /**
     103              :          @brief realization of the random field, b(pos) * B_grid(pos)
     104              :          @throws std::runtime_error if no turbulent grid is set
     105              :          */
     106              :         Vector3d getTurbulentField(const Vector3d &pos) const;
     107              : 
     108              :         /// same as getTurbulentField()
     109              :         Vector3d getField(const Vector3d &pos) const;
     110              : 
     111              :         ModelType getModelType() const;
     112              :         std::string getModelName() const;
     113              : 
     114              : private:
     115              :         // rms strengths in microgauss for positions in kpc
     116              :         double rmsDisk(const Vector3d &posInKpc) const;
     117              :         double rmsAnnulus(const Vector3d &posInKpc) const;
     118              : 
     119              :         /// model type given in constructor
     120              :         const ModelType fModelType;
     121              : 
     122              :         // disk, Eqs. (12)-(14) [kpc, microgauss]
     123              :         double fDiskB = 0;     ///< b_d at the solar circle
     124              :         double fDiskZ = 0;     ///< 1/e height z_d
     125              :         double fDiskL = 0;     ///< radial scale length l_r
     126              :         double fDiskRc = 0;    ///< cusp smoothing radius r_c
     127              :         double fDiskRmax = 0;  ///< outer cutoff radius R_max
     128              :         double fDiskWmax = 0;  ///< width of outer cutoff w_max
     129              :         // annulus, Eq. (15) [kpc, microgauss]
     130              :         double fAnnulusB = 0;  ///< peak amplitude b_a,0
     131              :         double fAnnulusR = 0;  ///< peak radius r_a
     132              :         double fAnnulusW = 0;  ///< radial Gaussian width w_a
     133              :         double fAnnulusZ = 0;  ///< 1/e height z_a
     134              :         bool fHasAnnulus = false;
     135              : 
     136              :         // pre-calculated: sqrt(R_sun^2 + r_c^2)
     137              :         double fSunRadiusSmoothed = 0;
     138              : 
     139              :         // turbulent grid with B_rms = 1
     140              :         ref_ptr<Grid3f> turbulentGrid;
     141              : };
     142              : 
     143              : /** @}*/
     144              : } // namespace crpropa
     145              : 
     146              : #endif // CRPROPA_UF26FIELD_H
        

Generated by: LCOV version 2.0-1