cosapp.drivers.time.utils

Functions

TwoPointCubicInterpolator(xs, ys, dy)

Function returning a cubic polynomial interpolator for either scalar or vector quantities, based on the format of input arrays ys and dy.

TwoPointCubicPolynomial(xs, ys, dy)

Function returning a cubic polynomial interpolating two end points (x, y), with imposed derivatives dy/dx.

Classes

SystemInterpolator(driver)

Class providing a continuous time view on a system, by replacing transient variables by time functions.

TimeStepManager([transients, dt, ...])

Class dedicated to the management of time step for time drivers.

TimeUnknownDict(**mapping)

Dictionary of AbstractTimeUnknown objects, mapped to str variable names.

TimeUnknownStack(context, name, transients)

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.

TimeVarManager(context)

Class dedicated to the analysis of a system's independent transient variables.

class cosapp.drivers.time.utils.SystemInterpolator(driver: ExplicitTimeDriver)[source]

Bases: object

Class providing a continuous time view on a system, by replacing transient variables by time functions.

exec(t: float) None[source]
property interp: Dict[str, Callable]

interpolant dictionary

Type:

Dict[str, Callable]

property system: System

System modified by interpolator

property transients: Dict[str, TimeUnknown]
class cosapp.drivers.time.utils.TimeStepManager(transients={}, dt=None, max_growth_rate=None)[source]

Bases: object

Class 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: MutableMapping

Dictionary of AbstractTimeUnknown objects, mapped to str variable names. Automatically updates a dictionary of time step constrained variables, accessible with read-only property constrained.

clear() None.  Remove all items from D.[source]
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: AbstractTimeUnknown

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. 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 context: System

Evaluation context of the stacked unknown

Type:

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:

EvalString

property max_time_step_expr: EvalString

Expression of the maximum time step allowed for the instantaneous time evolution of the stacked variable

Type:

EvalString

property name: str

Name of the variable

Type:

str

reset() None[source]

Reset stack value from original system variables

touch() None[source]

Set owner systems as ‘dirty’.

property value: ndarray

Value of the time unknown

Type:

numpy.ndarray

class cosapp.drivers.time.utils.TimeVarManager(context: System)[source]

Bases: object

Class 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.

property context: System

System handled by manager

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.

update_transients() None[source]

Update the transient variable dictionary (see property transients for details)

cosapp.drivers.time.utils.TwoPointCubicInterpolator(xs: Tuple[float, float], ys: ndarray, dy: ndarray) Callable[[float], float | ndarray][source]

Function returning a cubic polynomial interpolator for either scalar or vector quantities, based on the format of input arrays ys and dy. If ys and dy are 1D (resp. 2D) arrays, they are interpreted as the values and derivatives of a scalar (resp. vector) quantity at end points xs.

Arguments:

  • xs, Tuple[float, float]: end point abscissa

  • ys, numpy.ndarray: end point values as a 1D or 2D array

  • dy, numpy.ndarray: end point derivatives as a 1D or 2D array

Returns:

poly: cubic polynomial function returning either

a float or a numpy array of floats, depending on the dimension of input data ys and dy.

cosapp.drivers.time.utils.TwoPointCubicPolynomial(xs: Tuple[float, float], ys: Tuple[float, float], dy: Tuple[float, float]) Polynomial[source]

Function returning a cubic polynomial interpolating two end points (x, y), with imposed derivatives dy/dx.

Arguments:

  • xs, Tuple[float, float]: end point abscissa

  • ys, Tuple[float, float]: end point values

  • dy, Tuple[float, float]: end point derivatives

Returns:

poly: cubic numpy.polynomial.Polynomial function