|
4 | 4 | from .variable_container import Variable, node
|
5 | 5 | from .derivations import Species
|
6 | 6 | from . import derivations
|
7 |
| -from .remkit_context import RMKContext |
8 | 7 | from abc import ABC, abstractmethod
|
9 | 8 |
|
10 | 9 |
|
| 10 | +def timeDerivative( |
| 11 | + name: str, timeNorm: float, variable: Variable, **kwargs |
| 12 | +) -> Variable: |
| 13 | + """Generate a time derivative of a given variable as a variable, making sure units and grids are correct. |
| 14 | +
|
| 15 | + Args: |
| 16 | + name (str): Variable name for the time derivative |
| 17 | + timeNorm (float): Time normalisation |
| 18 | + variable (Variable): Variable whose derivative should be taken |
| 19 | +
|
| 20 | + Returns: |
| 21 | + Variable: Variable with correct time derivative units |
| 22 | + """ |
| 23 | + |
| 24 | + for key in [ |
| 25 | + "units", |
| 26 | + "unitSI", |
| 27 | + "normSI", |
| 28 | + "isOnDualGrid", |
| 29 | + "isDistribution", |
| 30 | + "isSingleHarmonic", |
| 31 | + "isScalar", |
| 32 | + "subtype", |
| 33 | + ]: |
| 34 | + assert key not in kwargs, key + " not allowed in time derivative variable call" |
| 35 | + |
| 36 | + latexWrapped = "$" in variable.unitsSI |
| 37 | + unitSI = variable.unitsSI.replace("$", "") + "/s" |
| 38 | + if latexWrapped: |
| 39 | + unitSI = "$" + unitSI + "$" |
| 40 | + var = Variable( |
| 41 | + name, |
| 42 | + variable.grid, |
| 43 | + **kwargs, |
| 44 | + units=variable.unitsNorm + " / time norm.", |
| 45 | + unitSI=unitSI, |
| 46 | + normSI=variable.normSI / timeNorm, |
| 47 | + isOnDualGrid=variable.isOnDualGrid, |
| 48 | + isScalar=variable.isScalar, |
| 49 | + isDistribution=variable.isDistribution, |
| 50 | + isSingleHarmonics=variable.isSingleHarmonic, |
| 51 | + subtype=variable.subtype + "_time_derivative" |
| 52 | + ) |
| 53 | + |
| 54 | + return var |
| 55 | + |
| 56 | + |
| 57 | +# cyclic import workaround |
| 58 | +from .remkit_context import RMKContext |
| 59 | + |
| 60 | + |
11 | 61 | def density(name: str, context: RMKContext, **kwargs) -> Variable:
|
12 | 62 | """Generate a density variable based on normalisation data within a RMKContext. Accepts regular Variable kwargs, except for those having to do with units, which are set automatically.
|
13 | 63 |
|
|
0 commit comments