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

property constrained: bool

is unknown constrained by a limiting time step?

Type:

bool

property d_dt: Any

Value of time derivative

abstract property der: EvalString

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: float

Maximum absolute step in one iteration

Type:

float

abstract property max_abs_step_expr: EvalString

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

property max_time_step: float

Maximum admissible time step in one iteration

Type:

float

abstract property max_time_step_expr: EvalString

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: numpy.ndarray | None = None, default: Number | numpy.ndarray | None = None, inputs_only: bool = True, **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.

  • inputs_only (bool, optional) – If True (default), output variables are regarded as invalid.

property basename: str

Contextual name of the boundary.

Type:

str

property context: cosapp.systems.System

System in which the boundary is defined.

Type:

cosapp.systems.System

contextual_name(context: 'System' | None = None) str[source]

str : Contextual name of the boundary, relative to context. If context is None (default), uses current variable context.

copy() Boundary[source]
property default_value: Number | ndarray | None

default value for the boundary.

Type:

Number, numpy.ndarray or None

property mask: ndarray | None

Mask of the values in the vector boundary.

Type:

numpy.ndarray or None

property name: str

Contextual name of the boundary.

Type:

str

static parse(context: cosapp.systems.System, name: str, mask: numpy.ndarray | None = None, inputs_only: bool = False) 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:
  • [cosapp.systems.System] (- context) – System in which the boundary is defined.

  • [str] (- name) – Name of the boundary

  • None (- mask [numpy.ndarray[bool] or) – Mask to apply on the variable; default is None (i.e. no mask)

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

  • [bool (- inputs_only) – If True, output variables are regarded as invalid. Default is False.

  • optional] – If True, output variables are regarded as invalid. Default is False.

Returns:

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

Return type:

SimpleNameSpace

property port: BasePort

port containing the boundary.

Type:

BasePort

property ref: VariableReference

variable reference accessed by the boundary.

Type:

VariableReference

set_default_value(value: Number | ndarray | None, mask: ndarray | None = 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 port as ‘dirty’.

property value: Number | ndarray

Current value of the boundary.

Type:

Number or numpy.ndarray

property variable: str

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

copy() TimeDerivative[source]
property initial_value: Number | ndarray

Initial value of time derivative

property initial_value_expr: EvalString

Initial value of time derivative, returned as an EvalString

reset(value: Any = None) None[source]
property source: Number | ndarray

Value of the variable whose rate is evaluated

property source_expr: EvalString

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: Number) Number[source]

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

property value: Number | ndarray

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: Number | str = inf, max_abs_step: Number | str = inf, pulled_from: VariableReference | None = None)[source]

Bases: 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() TimeUnknown[source]

Copy time-dependent unknown object.

Returns:

Duplicated unknown

Return type:

TimeUnknown

property d_dt: Any

Value of time derivative

property der: EvalString

Expression of time derivative, given as an EvalString

static der_type(expression: Any, context: cosapp.systems.System) Tuple[EvalString, Any, Type][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: float

Maximum absolute step in one iteration

Type:

float

property max_abs_step_expr: EvalString

Maximum admissible step, given as an EvalString.

property max_time_step: float

Maximum admissible time step in one iteration

Type:

float

property max_time_step_expr: EvalString

Maximum admissible time step, given as an EvalString.

property pulled_from: VariableReference | None

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: Number | ndarray

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: Number = inf, max_rel_step: Number = inf, lower_bound: Number = -inf, upper_bound: Number = inf, mask: numpy.ndarray | None = None)[source]

Bases: 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() 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