cosapp.core.numerics.boundary¶
Classes
Abstract Boundary class to manage methods specific to Boundary type. |
|
|
|
|
Attribute Reference for scalar object. |
|
Numerical solver boundary. |
Class handling undefined Boundary. |
|
|
Masked Attribute Reference for MutableSequence-like object. |
|
|
Specific methods for MutableSequence-like Boundary. |
|
|
Attribute Reference for unmasked numpy arrays. |
Specific methods for numpy.ndarray Boundary. |
|
|
Masked Attribute Reference for numpy arrays. |
Specific methods for Number Boundary. |
|
|
Explicit time derivative. |
|
Time-dependent solver unknown. |
Class handling undefined Boundary. |
|
|
Numerical solver unknown. |
- class cosapp.core.numerics.boundary.AbstractBoundaryImpl[source]¶
Bases:
ABCAbstract Boundary class to manage methods specific to Boundary type.
- 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.
- class cosapp.core.numerics.boundary.AttrRef(context: System, key: str)[source]¶
Bases:
objectAttribute Reference for scalar object.
In addition to System and its derivatives, manage also complex object which could be included in the evaluation context.
- Parameters:
obj (cosapp.systems.System) – System in which the boundary name is defined.
key (str) – Name of the boundary
- property value: Number¶
- class cosapp.core.numerics.boundary.Boundary(context: System, name: str, mask: numpy.ndarray | None = None, default: Number | numpy.ndarray | None = None, inputs_only=True, **kwargs)[source]¶
Bases:
objectNumerical 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¶
Base name of the boundary.
- Type:
str
- 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.
- classmethod create_attr_ref(context: System, basename: str, value: Number | Collection | None, mask: numpy.ndarray | None = None) tuple[AttrRef | NumpyMaskedAttrRef | MaskedAttrRef, AbstractBoundaryImpl, bool][source]¶
Returns an AttrRef, MaskedAttrRef, or ǸumpyMaskedAttrRef` object from a name and its evaluation context. The NumpyMaskedAttrRef derives from AttrRef if the context variable refers to a numpy.array and MaskedAttrRef for a variable referring to an object similar to a MutableSequence. In the two latter cases, a mask may be applied on value.
- Parameters:
context (-) – System in which the boundary is defined.
basename (-) – Name of the boundary without its mask if any.
value (-) – Value of the context variable.
mask (-) – Mask to apply on the variable; default is None (i.e. no mask).
- Returns:
Union[AttrRef, NumpyMaskedAttrRef, MaskedAttrRef] – (Masked) Attribute Reference object.
AbstractBoundaryImpl – Object containing methods specific according to the variable type.
bool – Specify if the boundary value is a scalar.
- static create_mask(system: System, varname: str, selector: str, mask: numpy.ndarray | None = None) tuple[Number | Collection | None, numpy.ndarray | None][source]¶
Evaluate the basename expression within its context and generate a mask if a selector is specified in the fullname expression.
- Parameters:
system (-) – System to which variable belongs.
basename (-) – Variable name without any optional array mask.
selector (-) – Expression corresponding to an array mask.
mask (-) – Imposed mask to apply on the variable; default is None (i.e. no mask).
- Returns:
Optional[Union[Number, Collection]] – Value of the context variable.
Optional[numpy.ndarray] – Imposed or generated mask to apply on the variable.
- property default_value: Number | ndarray¶
- find_port(inputs_only=False) None[source]¶
Find port associated to its AttrRef. In the case of a complex object, the port containing it is retrieved and checks.
- Parameters:
[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.
- static is_mutable_sequence(value: Any) bool[source]¶
Determine if an object is MutableSequence-like.
- property is_scalar: bool¶
Returns whether this boundary is scalar or not.
- 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_expression(expression: str) MaskedVarInfo[source]¶
Decompose a variable specification into its base name and selector.
- Parameters:
expression (str) – Variable specification (variable name + optional array mask, if required)
- Returns:
- str (variable name)
- str (array selector)
- property portname: str¶
name of the port accessed by the boundary.
- Type:
str
- property ref: AttrRef | MaskedAttrRef | NumpyMaskedAttrRef¶
attribute reference accessed by the boundary.
- Type:
- property size: int¶
- property value: Number | ndarray¶
- property variable: str¶
name of the variable accessed by the boundary.
- Type:
str
- property variable_reference: VariableReference¶
variable reference accessed by the boundary.
- Type:
VariableReference
- class cosapp.core.numerics.boundary.GenericBoundaryImpl[source]¶
Bases:
AbstractBoundaryImplClass handling undefined Boundary.
- class cosapp.core.numerics.boundary.MaskedAttrRef(obj: System, key: str, mask: numpy.ndarray)[source]¶
Bases:
AttrRefMasked Attribute Reference for MutableSequence-like object.
Include a mask applying to an evaluation context vector.
- Parameters:
obj (cosapp.systems.System) – System in which the boundary name is defined.
key (str) – Name of the boundary
mask (numpy.ndarray) – Mask of the values in the vector boundary.
- classmethod make_from_attr_ref(attr_ref: AttrRef, obj: BasePort | Any, name: str, mask: ndarray) MaskedAttrRef[source]¶
- property value: MutableSequence¶
- class cosapp.core.numerics.boundary.MaskedVarInfo(basename, selector, mask)[source]¶
Bases:
NamedTuple- basename: str¶
Alias for field number 0
- property fullname: str¶
- mask: ndarray | None¶
Alias for field number 2
- selector: str¶
Alias for field number 1
- class cosapp.core.numerics.boundary.MutableSeqBoundaryImpl[source]¶
Bases:
AbstractBoundaryImplSpecific methods for MutableSequence-like Boundary.
- class cosapp.core.numerics.boundary.NumpyArrayAttrRef(obj: System, key: str)[source]¶
Bases:
AttrRefAttribute Reference for unmasked numpy arrays.
- Parameters:
obj (cosapp.systems.System) – System in which the boundary name is defined.
key (str) – Name of the boundary
- property value¶
- class cosapp.core.numerics.boundary.NumpyBoundaryImpl[source]¶
Bases:
AbstractBoundaryImplSpecific methods for numpy.ndarray Boundary.
- class cosapp.core.numerics.boundary.NumpyMaskedAttrRef(obj: System, key: str, mask: numpy.ndarray)[source]¶
Bases:
AttrRefMasked Attribute Reference for numpy arrays.
Include a mask applying to an evaluation context vector.
- Parameters:
obj (cosapp.systems.System) – System in which the boundary name is defined.
key (str) – Name of the boundary
mask (numpy.ndarray) – Mask of the values in the vector boundary.
- classmethod make_from_attr_ref(attr_ref: AttrRef, obj: BasePort | Any, name: str, mask: ndarray) NumpyMaskedAttrRef[source]¶
- property value: ndarray¶
- class cosapp.core.numerics.boundary.ScalarBoundaryImpl[source]¶
Bases:
AbstractBoundaryImplSpecific methods for Number Boundary.
- class cosapp.core.numerics.boundary.TimeDerivative(context: System, name: str, source: Any, initial_value: Any = None)[source]¶
Bases:
BoundaryExplicit 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
- 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: 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]
- property value: Number | ndarray¶
- class cosapp.core.numerics.boundary.TimeUnknown(context: 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,AbstractTimeUnknownTime-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:
- 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: System) tuple[EvalString, Any, type][source]¶
Static method to evaluate the type and default value of an expression used as time 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
- 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¶
- class cosapp.core.numerics.boundary.UndefinedBoundaryImpl[source]¶
Bases:
AbstractBoundaryImplClass handling undefined Boundary.
- class cosapp.core.numerics.boundary.Unknown(context: 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:
BoundaryNumerical 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.
- check_numerical_type() None[source]¶
Check if the unknown is suitable for a solver.
- Raises:
TypeError – If the unknown is neither a numerical variable nor a mutable sequence.
Warning
- UserWarning
If the unknown is declared as an array of integers.
- cosapp.core.numerics.boundary.object__getstate__(self, /)¶
Helper for pickle.