# Magnetic Fields

group MagneticFields

Magnetic field models.

Enums

enum class TF17DiskModel

Values:

enumerator Bd1
enumerator Dd1
enum class TF17HaloModel

Values:

enumerator C0
enumerator C1

Functions

void initHelicalTurbulence(ref_ptr<Grid3f> grid, double Brms, double lMin, double lMax, double alpha = -11 / 3., int seed = 0, double H = 0)

Create a random initialization of a turbulent field including helicity

Parameters:
• grid – grid on which the turbulence is calculated

• Brms – RMS field strength

• lMin – Minimum wavelength of the turbulence

• lMax – Maximum wavelength of the turbulence

• alpha – Power law index of <B^2(k)> ~ k^alpha (alpha = -11/3 corresponds to a Kolmogorov spectrum)

• seedRandom seed

• H – Helicity

inline double turbulentCorrelationLength(double lMin, double lMax, double alpha = -11 / 3.)

Analytically calculate the correlation length of the simple model turbulent field

inline void initTurbulence(ref_ptr<Grid3f> grid, double Brms, double lMin, double lMax, double alpha = -11 / 3., int seed = 0)

Create a random initialization of a turbulent field.

Parameters:
• grid – grid on which the turbulence is calculated

• lMin – Minimum wavelength of the turbulence

• lMax – Maximum wavelength of the turbulence

• alpha – Power law index of <B^2(k)> ~ k^alpha (alpha = -11/3 corresponds to a Kolmogorov spectrum)

• Brms – RMS field strength

• seedRandom seed

class ArchimedeanSpiralField : public MagneticField
#include <ArchimedeanSpiralField.h>

Magnetic field model following an Archimedean spiral.

See e.g. Jokipii, Levy & Hubbard 1977

class CMZField : public MagneticField
#include <CMZField.h>

Magnetic Field Model in the Galactic Center from M. Guenduez et al.

Poloidal Model (Model C) is taken from Katia Ferriere and Philippe Terral 2014 “Analytical models of X-shape magnetic fields in galactic halos” [arXiv:1312.1974] Azimuthal Model is taken from M.Guenduez, J.B. Tjus, K.Ferriere, R.-J. Dettmar (2019) [arXiv:1906.05211]

class ToroidalHaloField : public MagneticField
#include <GalacticMagneticField.h>

Galactic halo field model from Prouza & Smida 2003 and Sun et al. 2008.

class LogarithmicSpiralField : public MagneticField
#include <GalacticMagneticField.h>

Galactic disk field model of axisymmetric (ASS) or bisymmetric (BSS) logarithmic spiral shape.

class JF12Field : public MagneticField
#include <JF12Field.h>

JF12Field galactic magnetic field model.

Implements the JF2012 magnetic field model, consisting of a large-scale regular and random (striated) field and a small-scale random (turbulent) field. See: Jansson 2012a, ApJ. 757, A New Model of the Galactic Magnetic Field Jansson 2012b, arXiv:1210.7820, The Galactic Magnetic Field

All three components may individually turned on and off. Currently only best fit values of the field paramaters are implemented and cannot be changed.

The field is defined in the usual galactocentric coordinate system with the Galactic center at the origin, the x-axis pointing in the opposite direction of the Sun, and the z-axis pointing towards Galactic north.

The regular field components (disk, toroidal halo and polodial halo field) may be turned on and off individually.

Subclassed by JF12FieldSolenoidal, PlanckJF12bField

class PlanckJF12bField : public JF12Field
#include <JF12Field.h>

PlanckJF12bField: the JF12 galactic magnetic field model with corrections suggested by the Planck Collaboration.

See: Planck Collaboration, “Planck intermediate results. XLII.

Large-scale Galactic magnetic fields”, A&A 596 (2016) A103; arXiv:1601.00546

This variant of the JF12 field uses only different parameters compared to the standard JF12 implementation.

class JF12FieldSolenoidal : public JF12Field
#include <JF12FieldSolenoidal.h>

JF12FieldSolenoidal galactic magnetic field model.

Implements a modified JF2012 Galactic magnetic field model. This implementation inherits most methods from the initial JF12Field, just the regular disk field and the poloidal halo “X field” are altered.

A solenoidal transition for the disk field (which redirects the magnetic flux of the magnetic spiral field at the boundaries and lets the field strength tend to 0 in a continuous way) and an improved version of the JF12 X field (with parabolic field lines at z = 0 instead of sharp kinks) were added in order to smooth the field and avoid violations of magnetic flux conservation, see: Kleimann et al, 2018, arXiv:1809.07528, Solenoidal improvements for the JF12 Galactic magnetic field model.

The turbulent field component is the exact same as in the initial JF12 implementation and should be used with care since the new regular and old turbulent field do not match in the transition regions of the spiral field.

class MagneticField : public Referenced
#include <MagneticField.h>

Abstract base class for magnetic fields.

class PeriodicMagneticField : public MagneticField
#include <MagneticField.h>

Magnetic field decorator implementing periodic fields.

The periodic cube is defined by its origin (Vector3d) and an extends parameter (Vector3d). All points x=(x_1, x_2, x_3) that are described by x_i = origin_i + epsilon * extend_i, with epsilon = 0…1 are within the base cube. Magnetic field strengths for all positions outside of this cube are calculated based on the values in the base cube. This can be done periodically or reflectively.

class MagneticFieldList : public MagneticField
#include <MagneticField.h>

Magnetic field decorator implementing a superposition of fields.

class MagneticFieldEvolution : public MagneticField
#include <MagneticField.h>

Magnetic field decorator implementing an evolution of type (1+z)^m.

class UniformMagneticField : public MagneticField
#include <MagneticField.h>

Magnetic field with one B-field vector.

class MagneticDipoleField : public MagneticField
#include <MagneticField.h>

Magnetic dipole field defined by the magnetic moment and the ‘core’ radius.

class RenormalizeMagneticField : public MagneticField
#include <MagneticField.h>

Renormalize strength of a given field by expression in which B is the strength variable.

class MagneticFieldGrid : public MagneticField
#include <MagneticFieldGrid.h>

Magnetic field on a periodic (or reflective), cartesian grid with trilinear interpolation.

This class wraps a Grid3f to serve as a MagneticField.

class ModulatedMagneticFieldGrid : public MagneticField
#include <MagneticFieldGrid.h>

Modulated magnetic field on a periodic grid.

This class wraps a Grid3f to serve as a MagneticField. The field is modulated on-the-fly with a Grid1f. The Grid3f and Grid1f do not need to share the same origin, spacing or size.

class PolarizedSingleModeMagneticField : public MagneticField
#include <PolarizedSingleModeMagneticField.h>

General polarized single mode magnetic field (including linear, circular and elliptic polarizations and the case of maximal helicity).

class PT11Field : public MagneticField
#include <PT11Field.h>

Implements Pshirkov2011 galactic magnetic field model.

Implements the Pshirkov2011 galactic magnetic field model, consisting of large-scale regular disk and halo fields. For the disk field an axisymmetric (ASS) and the bisymmetric (BSS, default) model can be chosen. For the halo field the BHM Halo field model (Sun et al. 2008) is considered.

Currently only best fit values of the field parameters are implemented. The field is defined in the usual galactocentric coordinate system with the Galactic center at the origin, the x-axis pointing in the opposite direction of the Sun, and the z-axis pointing towards Galactic north.

See: Pshirkov, Tinyakov, Kronberg Newton-McGee 2011 - Deriving global structure of the Galactic Magnetic Field from Faraday Rotation Measures of extragalactic sources, DOI: 10.1088/0004-637X/738/2/192, arXiv:1103.0814

class TF17Field : public MagneticField
#include <TF17Field.h>

TF17Field galactic magnetic field model.

Implements the TF2017 galactic magnetic field model, consisting of large-scale regular disk and halo fields. The field is defined in the usual galactocentric coordinate system with the Galactic center at the origin, the x-axis pointing in the opposite direction of the Sun, and the z-axis pointing towards Galactic north. See: Terral, Ferriere 2017 - Constraints from Faraday rotation on the magnetic field structure in the galactic halo, DOI: 10.1051/0004-6361/201629572, arXiv:1611.10222

class GridTurbulence : public TurbulentField
#include <GridTurbulence.h>

Turbulent grid-based magnetic field with a general energy spectrum.

Subclassed by SimpleGridTurbulence

class HelicalGridTurbulence : public SimpleGridTurbulence
#include <HelicalGridTurbulence.h>

Turbulent grid-based magnetic field with a simple power-law spectrum.

class PlaneWaveTurbulence : public TurbulentField
#include <PlaneWaveTurbulence.h>

Interpolation-free turbulent magnetic field based on the GJ99 and TD13 papers.

Overview

This class provides a turbulent magnetic field that is generated as described by (Giacalone and Jokipii, 1999) and (Tautz and Dosch, 2013). Instead of using an inverse Fourier transform to generate the field on a grid &#8212; which then needs to be interpolated to obtain in-between values &#8212; this method only generates the wave modes making up the turbulent magnetic field ahead of time. At run time, when the field’s value at a particular position is required, these plane waves are then evaluated analytically at that position. This guarantees that the resulting field is completely free of divergence, reproduces the mean field strength accurately, and does not suffer from other interpolation-induced problems. The disadvantage is that the number of wave modes is drastically smaller when compared with initTurbulence, which might have physical ramifications on the particles propagating through the field. Furthermore, depending on the exact setting, the implementation is somewhat slower (see Schlegel et al. for details).

Using the SIMD optimization

In order to mitigate some of the performance impact that is inherent in this method of field generation, an optimized version is provided. According to our tests (see the paper above), this version runs 20-30x faster than the baseline implementation and matches the speed of trilinear interpolation on a grid at a bit less than 100 wavemodes. To do this, it uses special CPU instructions called AVX, which are unfortunately not supported by every CPU. On Linux, you can check whether your CPU supports AVX by using the lscpu command, and searching the flags section for the string “avx”. Alternatively, if you are building on the same CPU that CRPropa will run on, you can have the compiler detect this for you automatically (see below).

An additional speedup of about 1.33 can be achieved if the CPU supports the FMA extension in addition to AVX. Again, you can either check for this manually, or have the compiler figure it out for you.

Note** that the optimized and non-optimized implementations to not return the exact same results. In fact, since the effective wave numbers used by the optimized implementation are very slightly different from those used by the non-optimized version (a difference smaller than the precision of a double, but nevertheless relevant at some point), the wavemodes go out of phase for large distances from the origin, and the fields are no longer comparable at all.

If you are building on the same machine that the code will run on:

1. In cmake: enable the FAST_WAVES flag.

2. Also in cmake: set SIMD_EXTENSIONS to “native”. The compiler will automatically detect support for your CPU and run the build with the appropriate settings.

3. Generate files and exit cmake, then build.

1. If your CPU does not support the necessary extensions, the build will fail with an error telling you so. In this case, you won’t be able to use the optimization; go back into cmake, disable FAST_WAVES, and build again.

2. If the build runs through without errors, the code is built with the optimization.

If you are building on a different machine from the one where the code will run:

1. Figure out which extensions your target machine supports, using lscpu | grep avx for AVX, and lscpu | grep fma for FMA. Run these commands on your target machine, not on your build machine. If your target machine does not run Linux, you may have to use different commands.

2. If the CPU does not support AVX, you can stop here, and build normally. The CPU does not support the necessary extensions, and will not run code that is compiled using them.

3. If the CPU does support AVX, continue. In cmake, enable the FAST_WAVES flag.

4. Also in cmake, set SIMD_EXTENSIONS to the appropriate value. If your target CPU supports only AVX, but not FMA, set it to “avx”. If it supports both, set it to “avx+fma”.

5. Generate and exit cmake, then build.

6. If you made a mistake and used the wrong flags, you should see an illegal instruction error when trying to import CRPropa, or (at the latest) when trying to call getField.

class SimpleTurbulenceSpectrum : public TurbulenceSpectrum
#include <SimpleGridTurbulence.h>

Defines the energy spectrum of simple power-law turbulence.

class SimpleGridTurbulence : public GridTurbulence
#include <SimpleGridTurbulence.h>

Turbulent grid-based magnetic field with a simple power-law spectrum.

Subclassed by HelicalGridTurbulence

class TurbulenceSpectrum : public Referenced
#include <TurbulentField.h>

Defines the energy spectrum of turbulence parametrizied by A(k) ~ k^q /(1 + k^2)^{(s + q)/2 + 1}.

Subclassed by SimpleTurbulenceSpectrum

class TurbulentField : public MagneticField
#include <TurbulentField.h>

An abstract base class for different models of turbulent magnetic fields.

This module provides common methods for all turbulent (synthetic) magnetic fields. Does not actually implement any turbulent field.

Subclassed by GridTurbulence, PlaneWaveTurbulence