cosapp.core.numerics.residues

Classes

AbstractResidue(context, name)

Abstract class defining residue for solvers.

DeferredResidue(context, target[, reference])

Class representing a residue whose left-hand side evaluation is deferred.

Residue(context, equation, name, reference, …)

Classical residue definition based on an equality equation

class cosapp.core.numerics.residues.AbstractResidue(context: System, name: str)[source]

Bases: object

Abstract class defining residue for solvers.

Parameters
  • context (-) – CoSApp Module in which this residue is defined

  • name (-) – Residue name

property context

CoSApp system usable in string evaluation.

Type

System

abstract copy()cosapp.core.numerics.residues.AbstractResidue[source]

Copy the object.

Returns

The duplicated object.

Return type

AbstractResidue

property name

Residue name

Type

str

property reference

Reference value to normalize the residue with.

Type

Number or numpy.ndarray

abstract update(**kwargs)Union[numbers.Number, numpy.ndarray][source]

Update the value of the residue.

Returns

The updated value

Return type

Number or numpy.ndarray

property value

residue’s value.

Type

Number or numpy.ndarray

class cosapp.core.numerics.residues.DeferredResidue(context: System, target: str, reference=1.0)[source]

Bases: object

Class representing a residue whose left-hand side evaluation is deferred.

The right-hand side of the residue is a targetted quantity. Upon request, a Residue object is generated, with lhs = value(target).

Parameters
  • context (-) – CoSApp System to which residue is linked.

  • target (-) – Targetted quantity, and left-hand side of the equation.

  • reference (-) – Reference value to normalize the residue; default is unity.

  • variables (-) – Names of variables involved in the residue

property context

evaluation context of residue

Type

System

equation()str[source]

Returns target equation with updated lhs value

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

target_value()Any[source]

Evaluates and returns current value of target

property variables

names of variables involved in residue

Type

FrozenSet[str]

class cosapp.core.numerics.residues.Residue(context: System, equation: str, name: Optional[str] = None, reference: Union[Number, Collection, numpy.ndarray, str] = 1)[source]

Bases: cosapp.core.numerics.residues.AbstractResidue

Classical residue definition based on an equality equation

Left-hand side == Right-hand side

The right-hand side is assumed null if not specified.

The residue can be defined by providing directly the numerical values of the left and right-hand sides. An alternative is to provide an string expression to be evaluated.

Parameters
  • context (-) – CoSApp System to which residue is linked

  • lhs (-) – Left-hand side of the equation.

  • rhs (-) – Right-hand side of the equation; default None (i.e. equals zeros).

  • name (-) – Residue name; default None (built from lhs and rhs)

  • reference (-) – Reference value to normalized the residue; default is unity

copy()cosapp.core.numerics.residues.Residue[source]

Copy the residue object.

Returns

The duplicated residue

Return type

Residue

property equation

Equation defining the residue

Type

str

eval_sides()Tuple[Any, Any][source]

Evaluate and return left- and right-hand sides as a tuple

static evaluate_residue(lhs: Union[numbers.Number, collections.abc.Collection, numpy.ndarray], rhs: Union[numbers.Number, collections.abc.Collection, numpy.ndarray], reference: Union[numbers.Number, collections.abc.Collection, numpy.ndarray, str] = 1)Union[float, numpy.ndarray][source]

Evaluate the normalized residue from left- and right-hand sides of an equation.

The formula depends on the left- and right-hand side value of the equation:

residues = (lhs - rhs) / reference

Parameters
  • lhs (-) – Left-hand side of the equation

  • rhs (-) – Right-hand side of the equation

  • reference (-) – Reference value to normalize the equation with; default is unity

Returns

Normalized residue

Return type

Number or numpy.ndarray

static residue_norm(left: Union[numbers.Number, collections.abc.Collection, numpy.ndarray], right: Optional[Union[numbers.Number, collections.abc.Collection, numpy.ndarray]] = None)Union[numbers.Number, numpy.ndarray][source]

Computes the order of magnitude of left- and right-hand sides to approximate the reference value.

Parameters
  • left (-) – Left-hand side of the equation

  • right (-) – Right-hand side of the equation if not None

Returns

An approximated reference value

Return type

Number or numpy.ndarray

static split_equation(equation: str)Tuple[str, str][source]

Parses and splits an equation of the kind ‘lhs == rhs’. Returns string tuple (lhs, rhs).

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

Returns a JSONable representation of the equation.

Returns

JSONable representation

Return type

Dict[str, Any]

update()Union[numbers.Number, numpy.ndarray][source]

Update the residue value

Returns

The updated residues

Return type

Number or numpy.ndarray