Source code for torx.specializations.grillix.trunk.penalization_m

"""Contains functionality to interface penalization."""
import xarray as xr
import numpy as np
from pathlib import Path
from inspect import getmodule
from torx.autodoc_decorators_m import autodoc_class

[docs] @autodoc_class class Penalization: """Low-level interface to the grillix/trunk/penalization.nc file."""
[docs] @classmethod def from_filepath(cls, filepath: Path): """Initialize from top-level filepath.""" pen_us = "penalization.nc" if not Path(filepath / "trunk" / pen_us).is_file(): # Provides support for legacy anglicized spelling return cls(filepath / "trunk" / "penalisation.nc") return cls(filepath / "trunk" / pen_us)
[docs] def __init__(self, penalization_file: Path): """Initialize the penalization.""" self._dataset = xr.open_dataset(penalization_file)
@property def charfun(self) -> xr.DataArray: """ Penalization characteristic function. Defined for inner points only. """ return self._dataset["charfun"].rename(n_points_grid="points") @property def dirindfun(self) -> xr.DataArray: """ Direction indication function. Defined for inner points only. """ return self._dataset["dirindfun"].rename(n_points_grid="points") @property def p_inds(self) -> xr.DataArray: """Indices of points in the penalization region w.r.t. full mesh.""" return self._dataset["p_inds"] @property def pb_inds(self) -> xr.DataArray: """Indices of points next to penalization region w.r.t. full mesh.""" return self._dataset["pb_inds"] @property def penfuns_type(self) -> int: """Type of smoothstep function used.""" return self._dataset.penfuns_type @property def hermite_order(self) -> int: """Order of hermite polynomial used is penfuns_type = HERMITE.""" return self._dataset.hermite_order @property def charfun_parwidth(self) -> float: """Width of penalization characteristic.""" return self._dataset.charfun_parwidth @property def charfun_radlimwidth(self) -> float: """Radial width of penalization function in CIRCULAR.""" return self._dataset.charfun_radlimwidth @property def dirindfun_parwidth(self) -> float: """Width of direction-indicator function.""" return self._dataset.dirindfun_parwidth @property def dphi(self) -> float: """Toroidal grid distance between planes.""" return self._dataset.dphi @property def dphi_max(self) -> float: """Maximum angle to be traced for building penalization.""" return self._dataset.dphi_max @property def charfun_at_target(self) -> float: """Value of penalization charfun at divertor target contour.""" return self._dataset.charfun_at_target