cosapp.drivers.time.utils¶
Functions
|
Function returning a cubic polynomial interpolating two end points (x, y), with imposed derivatives dy/dx. |
Classes
|
Polynomial function that accepts array coefficients, in order to fit array quantities over a one-dimensional interval. |
|
Class providing a continuous time view on a system, by replacing transient variables by time functions. |
|
Class dedicated to the management of time step for time drivers. |
|
Dictionary of AbstractTimeUnknown objects, mapped to str variable names. |
|
Class representing a group of variables [a, b, c, ...] jointly solved by a time driver, with b = da/dt, c = db/dt and so on. |
|
Class dedicated to the analysis of a system's independent transient variables. |
- class cosapp.drivers.time.utils.Polynomial(coefs: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], shift=0.0)[source]¶
Bases:
objectPolynomial function that accepts array coefficients, in order to fit array quantities over a one-dimensional interval.
- deriv() Polynomial[source]¶
Derivative of the polynomial
- class cosapp.drivers.time.utils.SystemInterpolator(driver: AbstractTimeDriver)[source]¶
Bases:
objectClass providing a continuous time view on a system, by replacing transient variables by time functions.
- property interp: dict[str, Callable]¶
interpolant dictionary
- Type:
dict[str, Callable]
- property transients: dict[str, TimeUnknown]¶
- class cosapp.drivers.time.utils.TimeStepManager(transients={}, dt=None, max_growth_rate=None)[source]¶
Bases:
objectClass dedicated to the management of time step for time drivers.
- property max_growth_rate: Number¶
Maximum growth rate of time step
- max_time_step() float[source]¶
Compute maximum admissible time step, from transients’ max_time_step (inf by default). Raises ValueError if any transients’ max_time_step is not strictly positive.
- property nominal_dt: Number¶
Time step
- time_step(previous=None) float[source]¶
Compute time step, making sure that it does not exceed any transient’s max_time_step (numpy.inf by default), and that all transient max_time_step are strictly positive. If previous is specified, the returned time step is bounded by max_growth_rate * previous.
An exception is raised if time step is ultimately found to be infinity.
- property transients¶
- class cosapp.drivers.time.utils.TimeUnknownDict(**mapping)[source]¶
Bases:
MutableMappingDictionary of AbstractTimeUnknown objects, mapped to str variable names. Automatically updates a dictionary of time step constrained variables, accessible with read-only property constrained.
- property constrained: dict[str, AbstractTimeUnknown]¶
shallow copy of the subset of time step constrained variables.
- Type:
dict[str, AbstractTimeUnknown]
- get(key: str, *default: Any | None) AbstractTimeUnknown[source]¶
Get value associated to key. Behaves as dict.get().
- items(constrained=False) Iterator[tuple[str, AbstractTimeUnknown]][source]¶
Iterator on (key, value) tuples, akin to dict.items(). If constrained is True, the iterator applies only to time step constrained variables.
- keys(constrained=False) Iterator[str][source]¶
Iterator on dictionary keys, akin to dict.keys(). If constrained is True, the iterator applies only to time step constrained variables.
- max_time_step() float[source]¶
Compute maximum admissible time step, from transients’ max_time_step (inf by default). Raises ValueError if any transients’ max_time_step is not strictly positive.
- pop(key: str, *default: Any | None) AbstractTimeUnknown[source]¶
Pop value associated to key. Behaves as dict.pop().
- update([E, ]**F) None. Update D from mapping/iterable E and F.[source]¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values(constrained=False) Iterator[AbstractTimeUnknown][source]¶
Iterator on dictionary values, akin to dict.values(). If constrained is True, the iterator applies only to time step constrained variables.
- class cosapp.drivers.time.utils.TimeUnknownStack(context: System, name: str, transients: list[TimeUnknown])[source]¶
Bases:
AbstractTimeUnknownClass representing a group of variables [a, b, c, …] jointly solved by a time driver, with b = da/dt, c = db/dt and so on. By nature, the unknown is therefore an array. If variables a, b, c… are arrays themselves, they are automatically flattened.
- Parameters:
context (System) – System CoSApp in which all transients to be stacked are defined
name (str) – Name of this time unknown stack
transients (list[TimeUnknown]) – Stacked unknowns
Notes
The group variables must all be defined as variables of the same system.
- property der: EvalString¶
Expression of time derivative of stacked vector, given as an EvalString
- property max_abs_step_expr: EvalString¶
Expression of the maximum step allowed for the stacked variable
- Type:
- property max_time_step_expr: EvalString¶
Expression of the maximum time step allowed for the instantaneous time evolution of the stacked variable
- Type:
- property name: str¶
Name of the variable
- Type:
str
- property value: ndarray¶
Value of the time unknown
- Type:
numpy.ndarray
- class cosapp.drivers.time.utils.TimeVarManager(context: System)[source]¶
Bases:
objectClass dedicated to the analysis of a system’s independent transient variables. For example, in a system where
\[ \begin{align}\begin{aligned}dH/dt = f(a, b),\\dx/dt = v,\\dv/dt = a,\end{aligned}\end{align} \]the manager will identify two independent variables H and [x, v], with time derivatives f(a, b) and [v, a], respectively. Variable [x, v] and its derivative are handled by class TimeUnknownStack.
- static get_tree(ders: dict[T, T]) dict[T, list[T]][source]¶
Parse a dictionary of the kind (var, d(var)/dt), to detect a dependency chain from one root variable to its successive time derivatives. Returns a dictionary of the kind: (root var ‘X’, [X_0, X_1, .., X_n]), where X_n is the expression of the nth-order time derivative of X.
- max_time_step() float[source]¶
Compute maximum admissible time step, from transients’ max_time_step (numpy.inf by default). Raises ValueError if any transients’ max_time_step is not strictly positive.
- property problem¶
Time problem handled by manager
- property rates: dict[str, TimeDerivative]¶
Dictionary of all rate variables in current system, linking each variable (key) to its associated TimeDerivative object (value).
- property transients: TimeUnknownDict¶
Dictionary of all transient variables in current system, linking each variable (key) to its associated time unknown (value). For stand-alone, order-1 derivatives, transient unknowns are of type TimeUnknown. For higher-order derivatives, related variables are gathered into a TimeUnknownStack object.
- cosapp.drivers.time.utils.TwoPointCubicPolynomial(xs: tuple[float, float], ys: tuple[float, float] | ndarray, dy: tuple[float, float] | ndarray) Polynomial[source]¶
Function returning a cubic polynomial interpolating two end points (x, y), with imposed derivatives dy/dx.
y(x) can be either a scalar or a multi-dimensional quantity, based on the format of input arrays ys and dy. If ys and dy are tuples of floats or 1D arrays (resp. ND), they are interpreted as the values and derivatives of a scalar (resp. vector) quantity at end points xs.
- Parameters:
xs (-)
tuple[float (end point derivatives as a one- or multi-dimensional array.)
float] (end point abscissa.)
ys (-)
tuple[float
numpy.ndarray (float] |)
dy (-)
tuple[float
numpy.ndarray
- Returns:
poly – a float or a numpy array of floats, depending on the dimension of input data ys and dy.
- Return type:
cubic polynomial function returning either
- cosapp.drivers.time.utils.object__getstate__(self, /)¶
Helper for pickle.