cosapp.core.numerics.basics¶
Classes
|
Container object for unknowns and equations. |
Storage class for solver solution |
|
|
-
class
cosapp.core.numerics.basics.MathematicalProblem(name: str, context: Optional[cosapp.systems.System])[source]¶ Bases:
objectContainer object for unknowns and equations.
- Parameters
name (str) – Name of the mathematical problem
context (cosapp.systems.System) – Context in which the mathematical problem will be evaluated.
-
activate_targets() → None[source]¶ Activate deferred residues (targets) and incorporate them in the mathematical problem residue list. Warning: This operation is irreversible, as targets are purged.
-
add_equation(equation: Union[str, Iterable[Union[dict, str, Tuple[str, str]]]], name: Optional[str] = None, reference: Union[numbers.Number, numpy.ndarray, str] = 1) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Add residue equation.
You can add residue equation one by one or provide a list of dictionary to add multiple equation at once. The dictionary key are the arguments of this method.
- Parameters
equation (str or Iterable of str of the kind 'lhs == rhs') – Equation or list of equations to add
name (str, optional) – Name of the equation; default None => ‘lhs == rhs’
reference (Number, numpy.ndarray or "norm", optional) – Reference value(s) used to normalize the equation; default is 1. If value is “norm”, actual reference value is estimated from order of magnitude.
- Returns
The modified MathematicalSystem
- Return type
-
add_rate(name: str, source: Any, initial_value: Optional[Any] = None) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Add a time derivative.
- Parameters
name (str) – Name of the new time-dependent (transient) variable
source (Any) – Name of the variable or evaluable expression whose time derivative will be computed
- Returns
The modified MathematicalSystem
- Return type
-
add_target(expression: Union[str, Iterable[str]], reference: Union[numbers.Number, numpy.ndarray, str] = 1, weak=False) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Add deferred equation.
- Parameters
expression (str) – Targetted expression
reference (Number, numpy.ndarray or "norm", optional) – Reference value(s) used to normalize the (deferred) equation; default is 1. If value is “norm”, actual reference value is estimated from order of magnitude.
weak (bool, optional) – If True, the target is disregarded if the corresponding variable is connected; default is False.
- Returns
The modified MathematicalSystem
- Return type
-
add_transient(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) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Add a time-dependent unknown.
- Parameters
name (str) – Name of the new time-dependent (transient) variable
der (Any) – Name of the variable or evaluable expression defining the time derivative of transient variable
max_time_step (Number or evaluable expression (str), optional) – Maximal time step for the time integration of the transient variable; numpy.inf by default.
max_abs_step (Number or evaluable expression compatible with transient variable, optional) – Maximum variable step admissible over one time step; numpy.inf by default.
pulled_from (VariableReference, optional) – Original time unknown before pulling; None by default.
- Returns
The modified MathematicalSystem
- Return type
-
add_unknown(name: Union[str, Iterable[Union[dict, str, cosapp.core.numerics.boundary.Unknown]]], 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) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Add unknown variables.
You can set variable one by one or provide a list of dictionary to set multiple variable at once. The dictionary key are the arguments of this method.
- Parameters
name (str or Iterable of dictionary or str) – Name of the variable or list of variable to add
max_rel_step (float, optional) – Maximal relative step by which the variable can be modified by the numerical solver; default numpy.inf
max_abs_step (float, optional) – Maximal absolute step by which the variable can be modified by the numerical solver; default numpy.inf
lower_bound (float, optional) – Lower bound on which the solver solution is saturated; default -numpy.inf
upper_bound (float, optional) – Upper bound on which the solver solution is saturated; default numpy.inf
mask (numpy.ndarray or None) – Mask of unknown values in the vector variable
- Returns
The modified MathematicalSystem
- Return type
-
property
context¶ Context in which the mathematical system is evaluated.
- Type
cosapp.systems.System or None
-
copy(activate_targets=False) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Copy the MathematicalSystem object.
- Returns
The duplicated mathematical problem.
- Return type
-
property
deferred_residues¶ Dict of deferred residues defined for this system.
- Type
Dict[str, WeakDeferredResidue]
-
extend(other: cosapp.core.numerics.basics.MathematicalProblem, copy=True, unknowns=True, equations=True, overwrite=False, unknown_wrapper: Optional[Callable[[str], str]] = None, residue_wrapper: Optional[Callable[[str], str]] = None) → cosapp.core.numerics.basics.MathematicalProblem[source]¶ Extend the current mathematical system with the other one.
- Parameters
other [MathematicalProblem] (-) – The other mathematical system to add
copy [bool (-) – Should the objects be copied; default is True.
optional] – Should the objects be copied; default is True.
unknowns [bool (-) – If False, unknowns are discarded; default is True.
optional] – If False, unknowns are discarded; default is True.
equations [bool (-) – If False, equations are discarded; default is True.
optional] – If False, equations are discarded; default is True.
overwrite [bool (-) – If False (default), common unknowns/equations raise ValueError. If True, attributes are silently overwritten.
optional] – If False (default), common unknowns/equations raise ValueError. If True, attributes are silently overwritten.
- Returns
The resulting mathematical system
- Return type
-
get_target_residues() → Dict[str, cosapp.core.numerics.residues.Residue][source]¶
-
property
n_equations¶ Number of equations (including deferred equations).
- Type
int
-
property
n_unknowns¶ Number of unknowns.
- Type
int
-
property
name¶ Mathematical system name.
- Type
str
-
property
rates¶ Time derivatives computed during system evolution.
- Type
Dict[str, TimeDerivative]
-
property
residues_names¶ Names of residues, flattened to have the same size as residues_vector.
- Type
Tuple[str]
-
property
residues_vector¶ Vector of residues.
- Type
numpy.ndarray
-
property
shape¶ Number of unknowns and equations.
- Type
(int, int)
-
static
target_key(target: str) → str[source]¶ Returns dict key to be used for targetted quantity target
-
to_dict() → Dict[str, Any][source]¶ Returns a JSONable representation of the mathematical problem.
- Returns
JSONable representation
- Return type
Dict[str, Any]
-
property
transients¶ Unknown time-dependent numerical features defined for this system.
- Type
Dict[str, TimeUnknown]
-
property
unknowns_names¶ Names of unknowns flatten to have the same size as residues_vector.
- Type
Tuple[str]
-
class
cosapp.core.numerics.basics.SolverResults[source]¶ Bases:
objectStorage class for solver solution
-
x¶ Solution vector
- Type
Sequence[float]
-
success¶ Whether or not the solver exited successfully.
- Type
bool
-
message¶ Description of the cause of the termination.
- Type
str
-
fun¶ Values of objective function.
- Type
ndarray
-
jac_lup¶ LU decomposition of Jacobian given as tuple (LU, perm); (None, None) if not available.
- Type
(ndarray[float], ndarray[int]), optional
-
jac¶ Values of function Jacobian; None if not available.
- Type
ndarray, optional
-
jac_errors¶ Dictionary with singular Jacobian matrix error indexes
- Type
dict, optional
-
jac_calls¶ Number of calls to the Jacobian matrix calculation
- Type
int
-
fres_calls¶ Number of calls to the residues function
- Type
int
-
trace¶ Resolution history (if requested) with the evolution of x, residues and jacobian
- Type
List[Dict[str, Any]]
-
-
class
cosapp.core.numerics.basics.WeakDeferredResidue(deferred, weak)[source]¶ Bases:
NamedTuple-
deferred: cosapp.core.numerics.residues.DeferredResidue¶ Alias for field number 0
-
make_residue(reference=None) → cosapp.core.numerics.residues.Residue[source]¶ Generates the residue corresponding to equation ‘target == value(target)’
-
property
target¶ targetted quantity
- Type
str
-
property
variables¶ names of variables involved in residue
- Type
Set[str]
-
weak: bool¶ Alias for field number 1
-