cosapp.drivers.time.scenario

Classes

InterpolAssignString(lhs, rhs, context)

Creates an executable assignment to handle time boundary conditions of the kind lhs = F(t, data), where F is an interpolation function of some dataset at time t, and where lhs refers to a variable name in system context.

Interpolator(data[, kind])

Class describing a function defined from tabulated data, based on interpolating function interpolator.

Scenario(name, owner)

Class managing boundary and initial conditions for time simulations

TimeAssignString(lhs, rhs, context)

Creates an executable assignment to handle time boundary conditions of the kind lhs = F(t, data), where F is a function of some dataset at time t, and where lhs refers to a variable name in system context.

class cosapp.drivers.time.scenario.InterpolAssignString(lhs: str, rhs: Callable[[float], Any], context: System)[source]

Bases: TimeAssignString

Creates an executable assignment to handle time boundary conditions of the kind lhs = F(t, data), where F is an interpolation function of some dataset at time t, and where lhs refers to a variable name in system context. This class is very similar to cosapp.core.eval_str.AssignString, except the right-hand side is a function. In order to limit the scope of the callable function, the rhs can only be of type Interpolator.

exec() None[source]

Evaluates rhs at context time, and executes assignment lhs <- rhs.

class cosapp.drivers.time.scenario.Interpolator(data, kind=Kind.Linear)[source]

Bases: object

Class describing a function defined from tabulated data, based on interpolating function interpolator. Function interpolator must return a callable function x -> f(x), interpolating [y_0, …, y_n] at points [x_0, …, x_n].

class Kind(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Interpolator kind

CubicSpline = <class 'scipy.interpolate._cubic.CubicSpline'>
Linear = <class 'scipy.interpolate._interpolate.interp1d'>
Pchip = <class 'scipy.interpolate._cubic.PchipInterpolator'>
property data: ndarray
property kind: Kind
class cosapp.drivers.time.scenario.Scenario(name: str, owner: Driver)[source]

Bases: object

Class managing boundary and initial conditions for time simulations

add_init(modifications: Dict[str, Any]) None[source]

Add a set of initial conditions, from a dictionary of the kind {‘variable’: value, …}

Parameters:

modifications (Dict[str, Any]) – Dictionary of (variable name, value)

Examples

>>> scenario.add_init({'myvar': 42, 'port.dummy': '-2 * alpha'})
add_values(modifications: Dict[str, Any]) None[source]

Add a set of variables to the list of case values, from a dictionary of the kind {‘variable’: value, …}

Each variable and its value can be contextual, as in {‘child1.port2.var’: ‘2 * child2.foo’}, as long as they are both evaluable in the context of the driver’s owner. Explicit time dependency can be given using variable ‘t’ in values, as in ‘exp(-t / tau)’

Parameters:

modifications (Dict[str, Any]) – Dictionary of (variable name, value)

Examples

>>> scenario.add_values({'myvar': 42, 'port.dummy': 'cos(omega * t)'})
apply_init_values() None[source]

Execute assignments corresponding to initial conditions

property case_values: List[AssignString]

list of boundary conditions

Type:

List[AssignString]

clear_init() None[source]

Clears the list of initial conditions

clear_values() None[source]

Clears the list of boundary conditions

property context: System

evaluation context of initial and boundary conditions, that is the system controled by owner driver

Type:

System

property init_values: List[AssignString]

list of initial conditions

Type:

List[AssignString]

classmethod make(name: str, driver: Driver, init: Dict[str, Any], values: Dict[str, Any]) Scenario[source]

Scenario factory

property owner: Driver

owner driver

Type:

Driver

set_init(modifications: Dict[str, Any]) None[source]

Set initial conditions, from a dictionary of the kind {‘variable’: value, …}

See add_init for further detail.

set_values(modifications: Dict[str, Any]) None[source]

Set case values, from a dictionary of the kind {‘variable’: value, …}

See add_values for further detail.

property stop: Event

discrete event triggering the end of scenario

Type:

Event

update_values() None[source]

Execute assignments corresponding to boundary conditions

class cosapp.drivers.time.scenario.TimeAssignString(lhs: str, rhs: Callable[[float], Any], context: System)[source]

Bases: object

Creates an executable assignment to handle time boundary conditions of the kind lhs = F(t, data), where F is a function of some dataset at time t, and where lhs refers to a variable name in system context. This class is very similar to cosapp.core.eval_str.AssignString, except the right-hand side is a callable function.

property constant
exec(t: float) None[source]

Evaluates rhs(t), and executes assignment lhs <- rhs(t).

property rhs: Callable[[float], Any]

assignment right-hand side function

Type:

Callable