cosapp.core.numerics.boundary

Classes

AbstractTimeUnknown(**kwargs)

Boundary(context, name, mask, default, …)

Numerical solver boundary.

TimeDerivative(context, name, source, …)

Explicit time derivative.

TimeUnknown(context, name, der, …)

Time-dependent solver unknown.

Unknown(context, name, max_abs_step, …)

Numerical solver unknown.

class cosapp.core.numerics.boundary.AbstractTimeUnknown(**kwargs)[source]

Bases: abc.ABC

property constrained

is unknown constrained by a limiting time step?

Type

bool

property d_dt

Value of time derivative

abstract property der

Expression of the time derivative, given as an EvalString

extrapolated_time_step(step: float)float[source]

Time step necessary to attain a variation of step at a rate given by current value of the time derivative.

property max_abs_step

Maximum absolute step in one iteration

Type

float

abstract property max_abs_step_expr

Expression of the maximum absolute step in one iteration, given as an EvalString.

property max_time_step

Maximum admissible time step in one iteration

Type

float

abstract property max_time_step_expr

Expression of the maximum admissible time step, given as an EvalString.

abstract reset()None[source]

Reset transient unknown to a reference value

class cosapp.core.numerics.boundary.Boundary(context: cosapp.systems.System, name: str, mask: Optional[numpy.ndarray] = None, default: Optional[Union[numbers.Number, numpy.ndarray]] = None, **kwargs)[source]

Bases: object

Numerical solver boundary.

Parameters
  • context (cosapp.systems.System) – System in which the boundary is defined.

  • name (str) – Name of the boundary

  • mask (numpy.ndarray or None) – Mask of the values in the vector boundary.

  • default (Number, numpy.ndarray or None) – Default value to set the boundary with.

static container(system: cosapp.systems.System, name: str)BasePort[source]

Checks that variable name is a valid boundary in system. If so, returns the container port. Raises an exception otherwise.

Parameters
  • system (-) – System in which a boundary may be defined.

  • name (-) – Name of the variable to check

Returns

- container – Port containing the variable, if the latter is found valid (raises an exception otherwise)

Return type

BasePort

Raises
  • - AttributeError if name is not found in system

  • - TypeError if container is a sub-system (not a port)

  • - ValueError if container is an output port

  • - ScopeError if container port does not belong to system

property context

System in which the boundary is defined.

Type

cosapp.systems.System

property default_value

default value for the boundary.

Type

Number, numpy.ndarray or None

property mask

Mask of the values in the vector boundary.

Type

numpy.ndarray or None

property name

Contextual name of the boundary.

Type

str

static parse(context: cosapp.systems.System, name: str, mask: Optional[numpy.ndarray] = None)types.SimpleNamespace[source]

Parse port and variable name from a name and its evaluation context. Also checks that the variable belongs to an input port.

Parameters
  • context (-) – System in which the boundary is defined.

  • name (-) – Name of the boundary

  • mask (-) – Mask to apply on the variable; default is None (i.e. no mask)

Returns

info – Structure containing fields varname, fullname, port and mask.

Return type

SimpleNameSpace

property port

port containing the boundary.

Type

BasePort

property ref

variable reference accessed by the boundary.

Type

VariableReference

set_default_value(value: Optional[Union[numbers.Number, numpy.ndarray]], mask: Optional[numpy.ndarray] = None)None[source]

Set the default value.

Parameters
  • value (Number, numpy.ndarray or None) – Default value

  • mask (numpy.ndarray[bool] or None, optional) – Mask to apply on the default value; default None (i.e. no mask)

set_to_default()None[source]

Set the current value with the default one.

touch()None[source]

Set owner system as ‘dirty’.

property value

Current value of the boundary.

Type

Number or numpy.ndarray

property variable

name of the variable accessed by the boundary.

Type

str

class cosapp.core.numerics.boundary.TimeDerivative(context: cosapp.systems.System, name: str, source: Any, initial_value: Any = None)[source]

Bases: cosapp.core.numerics.boundary.Boundary

Explicit time derivative.

Parameters
  • context (cosapp.systems.System) – System in which the unknown is defined.

  • name (str) – Name of the variable

  • source (str) – Variable such that name = d(source)/dt

  • initial_value (Any) – Time derivative initial value

property initial_value

Initial value of time derivative

property initial_value_expr

Initial value of time derivative, returned as an EvalString

reset(value: Optional[Any] = None)None[source]
property source

Value of the variable whose rate is evaluated

property source_expr

Variable whose rate is evaluated, returned as an EvalString

static source_type(expression: Any, context: cosapp.systems.System)Tuple[source]

Static method to evaluate the type and default value of an expression used as rate source

to_dict()Dict[str, Any][source]

Returns a JSONable representation of the time derivative.

Returns

JSONable representation

Return type

Dict[str, Any]

update(dt: numbers.Number)numbers.Number[source]

Evaluate rate-of-change of source over time interval dt

property value

Current value of the boundary.

Type

Number or numpy.ndarray

class cosapp.core.numerics.boundary.TimeUnknown(context: cosapp.systems.System, name: str, der: Any, max_time_step: Union[numbers.Number, str] = inf, max_abs_step: Union[numbers.Number, str] = inf, pulled_from: Optional[cosapp.core.variableref.VariableReference] = None)[source]

Bases: cosapp.core.numerics.boundary.Boundary, cosapp.core.numerics.boundary.AbstractTimeUnknown

Time-dependent solver unknown.

Parameters
  • context (cosapp.systems.System) – System in which the unknown is defined.

  • name (str) – Name of the unknown

max_time_step

Max time step authorized in one iteration; default numpy.inf

Type

float

copy()cosapp.core.numerics.boundary.TimeUnknown[source]

Copy time-dependent unknown object.

Returns

Duplicated unknown

Return type

TimeUnknown

property d_dt

Value of time derivative

property der

Expression of time derivative, given as an EvalString

static der_type(expression: Any, context: cosapp.systems.System)Tuple[source]

Static method to evaluate the type and default value of an expression used as time derivative

static is_number(value)bool[source]

Is value suitable for a derivative?

property max_abs_step

Maximum absolute step in one iteration

Type

float

property max_abs_step_expr

Maximum admissible step, given as an EvalString.

property max_time_step

Maximum admissible time step in one iteration

Type

float

property max_time_step_expr

Maximum admissible time step, given as an EvalString.

property pulled_from

Original time unknown before pulling; None otherwise.

Type

VariableReference or None

reset()None[source]

Reset transient unknown to a reference value. Inactive for class TimeUnknown.

to_dict()Dict[str, Any][source]

Returns a JSONable representation of the transient unknown.

Returns

JSONable representation

Return type

Dict[str, Any]

property value

Current value of the boundary.

Type

Number or numpy.ndarray

class cosapp.core.numerics.boundary.Unknown(context: cosapp.systems.System, name: str, max_abs_step: numbers.Number = inf, max_rel_step: numbers.Number = inf, lower_bound: numbers.Number = - inf, upper_bound: numbers.Number = inf, mask: Optional[numpy.ndarray] = None)[source]

Bases: cosapp.core.numerics.boundary.Boundary

Numerical solver unknown.

Parameters
  • context (cosapp.systems.System) – System in which the unknown is defined.

  • name (str) – Name of the unknown

  • lower_bound (float) – Minimum value authorized; default -numpy.inf

  • upper_bound (float) – Maximum value authorized; default numpy.inf

  • max_abs_step (float) – Max absolute step authorized in one iteration; default numpy.inf

  • max_rel_step (float) – Max relative step authorized in one iteration; default numpy.inf

  • mask (numpy.ndarray or None) – Mask of unknown values in the vector variable.

lower_bound

Minimum value authorized; default -numpy.inf

Type

float

upper_bound

Maximum value authorized; default numpy.inf

Type

float

max_abs_step

Largest absolute step authorized in one iteration; default numpy.inf

Type

float

max_rel_step

Largest relative step authorized in one iteration; default numpy.inf

Type

float

Notes

The dimensionality of the variable should be taken into account in the bounding process.

copy()cosapp.core.numerics.boundary.Unknown[source]

Copy the unknown object.

Returns

Duplicated unknown

Return type

Unknown

to_dict()Dict[str, Any][source]

Returns a JSONable representation of the unknown.

Returns

JSONable representation

Return type

Dict[str, Any]

transfer(context: cosapp.systems.System, name: str)Unknown[source]

Transfer a copy of the unknown in a new context.

Returns

Duplicated unknown, in new context

Return type

Unknown