Source code for pysrw.configuration

"""Constants, simulation variables and configuration parameters."""

from dataclasses import dataclass
from typing import Literal
from traceback import print_exc

from scipy.constants import c, e, h, pi, m_e, m_p

HC_CONST = h * c * (1e9 / e)  # eV * nm

PART_DATA = {"electron": [m_e * c ** 2 / e * 1e-9, -1],
             "proton": [m_p * c ** 2 / e * 1e-9, 1],
             "lead": [208 * m_p * c ** 2 / e * 1e-9, 82]}
"""str: Mass (in GeV) and charge (in elementary units) of known particles."""

MAG_INTERP = {"bilinear": 1, "biquadratic": 2, "bicubic": 3}
"""str: the interpolation strategy to adapt the passed field map to the 
mesh of the magnet object. Une of `bilinear`, `biquadratic` or `bicubic`."""

SR_APPROX = {"manual": 0, "auto-undulator": 1, "auto-wiggler": 2}
"""str: computation method for simulation of SR emission.
With 'manual' (discouraged), the simulation parameters are not optimized by 
the code and the result may significantly depend on the user input values.
The 'auto-undulator' mode (default) is often the best choice for most 
simulations involving small deflections, such as undulators or weak magnets.
The 'auto-wiggler' mode is the most general case and it is normally needed for 
high-deflection magnets (wigglers or strong dipoles) and results in 
longer simulation time.
"""

STOKES_APPROX = {"near field": 1, "far field": 2}
"""str: approximation method for stokes parameter calculation."""

POL = {"H": 0, "V": 1, "45": 2, "135": 3, "circR": 4, "circL": 5, "TOT": 6}
"""str: polarization states."""

DOMAIN = {"frequency": 0, "time": 1}
COORDINATES = {"cartesian": 0, "angular": 1}
SR_FIELD_UNITS = {"arbitrary": 0, "sqr_phflux": 1}

DEFAULT_PROP_OPT = {"aperture": {"autoResizeBefore": False, 
                                 "autoResizeAfter": False},
                    "lens": {"autoResizeBefore": False,
                             "autoResizeAfter": False},
                    "planeMirror": {"autoResizeBefore": False,
                                    "autoResizeAfter": False},
                    "drift": {"autoResizeBefore": False,    
                              "autoResizeAfter": False}
                }

[docs] @dataclass class CONFIG: """A dataclass to store the simulation parameters.""" PART_TYPE: Literal["electron", "proton", "custom"] = "electron" PART_MASS: float = PART_DATA["electron"][0] PART_CHARGE: int = PART_DATA["electron"][1] B_SCALING: float = PART_CHARGE * PART_DATA["electron"][0] / PART_MASS REL_PREC: float = 1e-3 SR_APPROX: str = "auto-undulator"
[docs] @classmethod def initParticleType(cls, particleType="electron", charge=None, mass=None): """Initialize type of particle. Args: particleType (optional): 'electron', 'proton' or 'custom'. charge (optional): charge of custom particle in elementary units. mass (optional): mass of custom particle in GeV. """ try: particleType = particleType.lower() if mass and charge: particleType = "custom" else: mass, charge = PART_DATA[particleType] cls.PART_TYPE = particleType cls.PART_CHARGE = charge cls.PART_MASS = mass cls.B_SCALING = charge * PART_DATA["electron"][0] / mass except: cls.initParticleType("electron") print("Cannot set particle type, working with default 'electron'.")