LCOV - code coverage report
Current view: top level - include/crpropa/magneticField/turbulentField - GridTurbulence.h (source / functions) Coverage Total Hit
Test: coverage.info.cleaned Lines: 100.0 % 1 1
Test Date: 2026-06-18 09:49:19 Functions: - 0 0

            Line data    Source code
       1              : #ifndef CRPROPA_GRIDTURBULENCE_H
       2              : #define CRPROPA_GRIDTURBULENCE_H
       3              : 
       4              : #ifdef CRPROPA_HAVE_FFTW3F
       5              : 
       6              : #include "crpropa/Grid.h"
       7              : #include "crpropa/magneticField/turbulentField/TurbulentField.h"
       8              : 
       9              : #include "fftw3.h"
      10              : 
      11              : namespace crpropa {
      12              : /**
      13              :  * \addtogroup MagneticFields
      14              :  * @{
      15              :  */
      16              : 
      17              : /**
      18              :  @class GridTurbulence
      19              :  @brief Turbulent grid-based magnetic field with a general energy spectrum
      20              :  */
      21            6 : class GridTurbulence : public TurbulentField {
      22              :   protected:
      23              :         unsigned int seed;
      24              :         ref_ptr<Grid3f> gridPtr;
      25              : 
      26              :         void initGrid(const GridProperties &grid);
      27              :         void initTurbulence();
      28              : 
      29              :   public:
      30              :         /**
      31              :          Create a random initialization of a turbulent field.
      32              :          @param spectrum    TurbulenceSpectrum instance to define the spectrum of
      33              :          turbulence
      34              :          @param gridProp        GridProperties instance to define the underlying grid
      35              :          @param seed     Random seed
      36              :          */
      37              :         GridTurbulence(const TurbulenceSpectrum &spectrum,
      38              :                        const GridProperties &gridProp, unsigned int seed = 0);
      39              : 
      40              :         Vector3d getField(const Vector3d &pos) const;
      41              : 
      42              :         /** Return a const reference to the grid */
      43              :         const ref_ptr<Grid3f> &getGrid() const;
      44              : 
      45              :         /* Helper functions for synthetic turbulent field models */
      46              :         // Check the grid properties before the FFT procedure
      47              :         static void checkGridRequirements(ref_ptr<Grid3f> grid, double lMin,
      48              :                                           double lMax);
      49              :         // Execute inverse discrete FFT in-place for a 3D grid, from complex to real
      50              :         // space
      51              :         static void executeInverseFFTInplace(ref_ptr<Grid3f> grid,
      52              :                                              fftwf_complex *Bkx, fftwf_complex *Bky,
      53              :                                              fftwf_complex *Bkz);
      54              : 
      55              :         // Usefull checks for a grid field
      56              :         /** Evaluate the mean vector of all grid points */
      57              :         Vector3f getMeanFieldVector() const;
      58              :         /** Evaluate the mean of all grid points */
      59              :         double getMeanFieldStrength() const;
      60              :         /** Evaluate the RMS of all grid points */
      61              :         double getRmsFieldStrength() const;
      62              :         /** Evaluate the RMS of all grid points per axis */
      63              :         std::array<float, 3> getRmsFieldStrengthPerAxis() const;
      64              :         /** Evaluate generated power-spectrum */
      65              :         std::vector<std::pair<int, float>> getPowerSpectrum() const;
      66              :         /** Dump a Grid3f to a binary file */
      67              :         void dumpToFile(std::string filename) const;
      68              : };
      69              : 
      70              : /** @}*/
      71              : } // namespace crpropa
      72              : 
      73              : #endif // CRPROPA_HAVE_FFTW3F
      74              : 
      75              : #endif // CRPROPA_GRIDTURBULENCE_H
        

Generated by: LCOV version 2.0-1