RMK_support package#
grid submodule#
- class Grid(xGrid: ndarray, vGrid: ndarray = array([1.]), lMax=0, mMax=0, interpretXGridAsWidths=False, interpretVGridAsWidths=False, isPeriodic=False, isLengthInMeters=False)#
Bases:
objectClass containing x and v-grid data
- __init__(xGrid: ndarray, vGrid: ndarray = array([1.]), lMax=0, mMax=0, interpretXGridAsWidths=False, interpretVGridAsWidths=False, isPeriodic=False, isLengthInMeters=False)#
Grid constructor
- Parameters:
xGrid (numpy.ndarray) – x coordinates of each spatial grid cell centre or their widths. If using widths set interpretXGridAsWidths to True.
vGrid (numpy.ndarray, optional) – v coordinates of each velocity grid cell centres or their widths. If using widths set interpretVGridAsWidths to True. Defaults to a single cell (effectively no v-grid)
lMax (int, optional) – Maximum l harmonic number. Defaults to 0.
mMax (int, optional) – Maximum m harmonic number. Defaults to 0.
interpretXGridAsWidths (bool, optional) – If True interprets xGrid as cell widths. Defaults to False.
interpretVGridAsWidths (bool, optional) – If True interprets vGrid as cell widths. Defaults to False.
isPeriodic (bool, optional) – If True the x grid is set to be periodic. This means that the right boundary of the rightmost cell is the left boundary of the leftmost cell. Defaults to False.
isLengthInMeters (bool, optional) – If True will instruct ReMKiT1D to use the built-in normalization to deduce the normalized coordinates of the spatial grid. CAUTION: This can lead to issues if the default normalization is not used in the rest of the simulation. Defaults to False.
- dict()#
Returns dictionary form of grid to be used in json output
- Returns:
ReMKiT1D-ready dictionary form of grid data
- Return type:
dict
- distFullInterp(data: ndarray) ndarray#
Interpolate a distribution function so that the odd harmonics live on the regular grid and even harmonics on the dual grid
- Parameters:
data (np.ndarray) – Distribution data to be interpolated
- Returns:
Interpolated distribution
- Return type:
np.ndarray
- domainIntegral(data: ndarray, isOnDualGrid: bool = False) ndarray#
Return the integral of data along the x dimension, assuming it is the first dimension of the data passed
- Parameters:
data (np.ndarray) – Data to be integrated along the x direction
isOnDualGrid (bool, optional) – True if the data is on the dual grid. Defaults to False.
- Returns:
Data integrated along x
- Return type:
np.ndarray
- dualToGrid(data: ndarray) ndarray#
Linearly interpolate 1D data from dual to regular grid. Linearly extrapolates to first and last point if the grid is not periodic.
- Parameters:
data (np.ndarray) – Data to be interpolated
- Returns:
Interpolated data on regular grid
- Return type:
np.ndarray
- dualXGridWidths(extendedBoundaryCells=False) ndarray#
Return the widths of the dual grid cells, potentially extending the boundary cells so that the dual domain covers the regular domain. Note that the returned array is the same length as the grid, with the last value set to 1 if the grid is not periodic and to dx[0]/2+dx[-1]/2 if it is
- Parameters:
extendedBoundaryCells (bool, optional) – If true and the grid is not periodic will extend the left and right boundary cells to completely cover the first and last dual cell. Defaults to False.
- Returns:
Dual grid cell widths (same length as regular cell widths)
- Return type:
np.ndarray
- getH(lNum: int, mNum=0, im=False) int#
Return harmonic with given l and m numbers. Defaults to real components.
- Parameters:
lNum (int) – l number of harmonic
mNum (int, optional) – m number of harmonic. Defaults to 0.
im (bool, optional) – True if the required component is imaginary. Defaults to False.
- Raises:
ValueError – If corresponding harmonic isn’t found
- Returns:
index of corresponding harmonic in Fortran 1 indexing
- Return type:
int
- gridToDual(data: ndarray) ndarray#
Linearly interpolate 1D data from regular to dual grid. Linearly extrapolates to right boundary if the grid is not periodic
- Parameters:
data (np.ndarray) – Data to be interpolated
- Returns:
Interpolated data on dual grid
- Return type:
np.ndarray
- property imaginaryHarmonic#
- property isLengthInMeters#
- property isPeriodic#
- property lGrid#
- property lMax#
- property mGrid#
- property mMax#
- property numH: int#
Get total number of harmonics
- Returns:
Total number of harmonics including all used l and m harmonics
- Return type:
int
- property numV: int#
Get number of velocity cells in grid
- Returns:
Number of velocity magnitude cells in grid
- Return type:
int
- property numX: int#
Get number of spatial cells in grid
- Returns:
Number of spatial cells
- Return type:
int
- profile(data: ndarray, dim: str = 'X', latexName: str | None = None) Profile#
Wrapped Profile constructor with bounds checking
- Parameters:
data (np.ndarray) – Profile values
dim (str, optional) – Dimension profile corresponds to. Must be one of “X”,”H”,”V”. Defaults to “X”.
latexName (Union[str,None], optional) – Latex name of the profile used in generating run summaries. Defaults to None.
- Returns:
Bounds-checked Profile
- Return type:
- staggeredDistToDual(data: ndarray) ndarray#
Interpolate even harmonics of a distribution variable to the dual grid while keeping odd harmonics unchanged
- Parameters:
data (np.ndarray) – Distribution data to be interpolated
- Returns:
Distribution with all harmonics living on the dual grid
- Return type:
np.ndarray
- staggeredDistToGrid(data: ndarray) ndarray#
Interpolate odd harmonics of a distribution variable onto the regular grid while keeping even harmonics unchanged
- Parameters:
data (np.ndarray) – Distribution data to be interpolated
- Returns:
Distribution data where all harmonics live on the regular grid
- Return type:
np.ndarray
- property vGrid#
- property vWidths#
- velocityMoment(distFun: ndarray, momentOrder: int, momentHarmonic=1) ndarray#
Return velocity moment of distribution function (x,h,v), single harmonic variable (x,v), or velocity space vector (v)
- Parameters:
distFun (np.ndarray) – Distribution or single harmonic variable values.
momentOrder (int) – Moment order
momentHarmonic (int, optional) – Harmonic index (Fortran 1 indexing) to take moment of in case of distribution variable. Defaults to 1.
- Returns:
Moment represented as a contracted array
- Return type:
np.ndarray
- property xGrid#
- xGridCellVolumes() ndarray#
Return cell volumes on the regular grid
- Returns:
Regular cell volumes
- Return type:
np.ndarray
- xGridCellVolumesDual(extendedBoundaryCells=False) ndarray#
Return cell volumes on the dual grid, potentially extending the boundary cells so that the dual domain covers the regular domain. Note that the returned array is the same length as the grid, with the last value set to 1 if the grid is not periodic and to V[0]/2+V[-1]/2 if it is
- Parameters:
extendedBoundaryCells (bool, optional) – If true and the grid is not periodic will extend the left and right boundary cells to completely cover the first and last dual cell. Defaults to False.
- Returns:
Dual cell volumes
- Return type:
np.ndarray
- property xGridDual#
- property xJacobian#
- property xWidths#
- class Profile(data: ndarray, dim: str = 'X', latexName: str | None = None)#
Bases:
objectWrapper for profiles in x,h,v spaces in ReMKiT1D
- __init__(data: ndarray, dim: str = 'X', latexName: str | None = None)#
Wrapper for profiles in one of ReMKiT1D’s dimensions
- Parameters:
data (np.ndarray) – Data - should conform to the dimension
dim (str, optional) – Profile dimension - of of [“X”,”H”,”V”]. Defaults to “X”.
latexName (Optiona[s], optional) – Latex representation of the profile. Defaults to None, using dim.
- property data#
- property dim#
- latex() str#
- property latexName#
variable_container submodule#
derivations submodule#
model_construction submodule#
stencils submodule#
integrators submodule#
IO_support submodule#
common_models submodule#
common_variables submodule#
calculation_tree_support submodule#
- class Node(leafVar: str)#
Bases:
objectCalculation tree node class. Should only ever be invoked for leaf nodes representing variables.
- __init__(leafVar: str) None#
- property additiveMode#
- property constant#
- dict() dict#
Return ReMKiT1D format dictionary representing this node’s kernel
- Returns:
Node kernel dictionary
- Return type:
dict
- evaluate(varDict: Dict[str, ndarray]) ndarray#
- latex(latexRemap: Dict[str, str] = {}) str#
Generate LaTeX representation of the Node
- Parameters:
latexRemap (Dict[str,str], optional) – Variable name remap dictionary. Defaults to {}.
- Returns:
LaTeX-parsable node representation
- Return type:
str
- property leafVar#
- property unaryTransform#
- class NodeIterator#
Bases:
objectHelper class for iterating over a calculation tree
- __init__() None#
- class UnaryTransform(tag: str, realParams: List[float] = [], intParams: List[int] = [], logicalParams: List[bool] = [], unaryCallable: Callable[[List[float], List[int], List[bool], ndarray], ndarray] | None = None, latexTemplate: str | None = None)#
Bases:
objectRepresentation of ReMKiT1D’s unary transformations. Should only ever be directly created for parameterized transformations.
- __init__(tag: str, realParams: List[float] = [], intParams: List[int] = [], logicalParams: List[bool] = [], unaryCallable: Callable[[List[float], List[int], List[bool], ndarray], ndarray] | None = None, latexTemplate: str | None = None) None#
UnaryTransform constructor
- Parameters:
tag (str) – Transform tag
realParams (List[float], optional) – Real parameter list to pass to Fortran transform object. Defaults to [].
intParams (List[int], optional) – Integer parameter list to pass to Fortran transform object. Defaults to [].
logicalParams (List[bool], optional) – Logical parameter list to pass to Fortran transform object.. Defaults to [].
unaryCallable (Union[ Callable[[List[float], List[int], List[bool], np.ndarray], np.ndarray], None ], optional) – Associated function for use in evaluation. Defaults to None - disabling evaluations of nodes with this transform.
latexTemplate (Union[str,None], optional) – Latex template for non-default representations (should contain $0 where the node representation goes, and $1, $2 and so on for all of the params, starting with the real params. For example ‘($0)^{$1})’ with a single integer parameter would replace $1 with that integer value). Defaults to None - LaTeX representation of ‘text{tag}($0)’
- dict() dict#
Return unary transformation properties as ReMKiT1D dictionary
- Returns:
Transformation dictionary readable by ReMKiT1D
- Return type:
dict
- evaluate(array: ndarray) ndarray#
Evaluate the unary transform on given array if the callable is defined, otherwise throw error
- Parameters:
array (np.ndarray) – Array to transform
- Returns:
Result of applying the unary transformation on a numpy array
- Return type:
np.ndarray
- latex(nodeLatex: str) str#
Wraps node LaTeX string with the transform’s represenation
- Parameters:
nodeLatex (str) – LaTeX representation of node the transform acts on
- Returns:
LaTeX-parsable representation of transform acting on node
- Return type:
str
- contract(node: Node, contractVals: ndarray, resultLen: int, resultIndex: int = 1)#
Dot product of the node with contractVals. Useful for contracting distributions with velocity profiles.
- Parameters:
node (Node) – Node argument
contractVals (np.ndarray) – Vector to contract the node values with (should in practice be velocity space profile)
resultLen (int) – Expected result length (should be the spatial dimension size)
resultIndex (int, optional) – In case of contracting a full distribution this corresponds to the harmonics index to return. Defaults to 1.
- expand(node: Node, expandVals: ndarray, numCopies: int = 1) Node#
Direct product of node values and expandVals, i.e. given a node with values [a,b,c], the result will be a node with values a*expandVals,b*expandVals,c*expandVals
- Parameters:
node (Node) – Unary argument
expandVals (np.ndarray) – Array to take the direct product with (for example a velocity profile in order to construct a single harmonic variable from a fluid variable)
numCopies (int, optional) – Number of copies of the result (appended in sequence). Defaults to 1.
- packTree(self, nodeCounter, parentsCounter, container, parents)#
- powUnary(power: int | float) UnaryTransform#
- shift(node: Node, shiftAmount: int) Node#
Shift the flattened node data by a set amount. Assumes data is already flat.
amjuel_reader submodule#
amjuel_support submodule#
crm_support submodule#
sk_normalization submodule#
dashboard_support submodule#
tex_parsing submodule#
- numToScientificTex(num: float, removeUnity=False, decimals: int = 2)#
Convert a float to scientific LaTeX notation.
- Parameters:
num (float) – Float to convert
removeUnity (bool, optional) – If true and the number is sufficiently close to 1 or -1 the 1 will be dropped. Defaults to False.
decimals (int, optional) – Tolerance for truncation of decimal points. Defaults to 2 decimal places.