cosapp.drivers.utils

Functions

dealias_problem(problem[, name])

Resolve unknown aliasing in problem due to pulling connectors (if any) in context system.

Classes

Constraint(lhs, rhs, is_inequality)

Named tuple representing a non-negative constraint of the kind lhs <op> rhs, where <op> is either == (equality) or >= (inequality constraint), depending on Boolean attribute is_inequality.

ConstraintParser()

ConstraintType(value)

Enum covering constraint types

DesignProblemHandler(system)

Class managing tied design and off-design problems, including unknown aliasing.

SystemAnalyzer(system)

Class containing data collected on a system, to be shared between different drivers.

class cosapp.drivers.utils.Constraint(lhs: str, rhs: str, is_inequality: bool = True)[source]

Bases: NamedTuple

Named tuple representing a non-negative constraint of the kind lhs <op> rhs, where <op> is either == (equality) or >= (inequality constraint), depending on Boolean attribute is_inequality.

  • lhs [str]: left-hand side.

  • rhs [str]: right-hand side.

  • is_inequality [bool].

  • expression [str]: non-negative constraint lhs - rhs.

property expression
is_inequality: bool

Alias for field number 2

lhs: str

Alias for field number 0

rhs: str

Alias for field number 1

class cosapp.drivers.utils.ConstraintParser[source]

Bases: object

classmethod parse(expression: Union[str, List[str]])Set[cosapp.drivers.utils.Constraint][source]

Parse a string expression or a list thereof as a set of non-negative constraints to be used in solvers.

  • expression [str or List[str]]:

    Human-readable equality or inequality constraints, such as ‘x >= y’, ‘0 < alpha < 1’, or a list thereof.

  • constraints [Set[Constraint]]:

    Set of Constraint named tuple objects.

classmethod types()Dict[str, cosapp.drivers.utils.ConstraintType][source]
class cosapp.drivers.utils.ConstraintType(value)[source]

Bases: enum.Enum

Enum covering constraint types

EQ = {'operator': '==', 'sort': <function ConstraintType.<lambda>>}
GE = {'operator': '>=', 'sort': <function ConstraintType.<lambda>>}
LE = {'operator': '<=', 'sort': <function ConstraintType.<lambda>>}
property description
expression(lhs: str, rhs: str)str[source]
property is_inequality
property operator
sort(lhs: str, rhs: str)Tuple[str, str][source]
class cosapp.drivers.utils.DesignProblemHandler(system: Optional[cosapp.systems.System] = None)[source]

Bases: cosapp.drivers.utils.SystemAnalyzer

Class managing tied design and off-design problems, including unknown aliasing.

check_context(design: cosapp.core.numerics.basics.MathematicalProblem, offdesign: cosapp.core.numerics.basics.MathematicalProblem)None[source]
clear()None[source]

Reset inner problems

copy(prune=True)cosapp.drivers.utils.DesignProblemHandler[source]

Returns a copy of the current object.

  • prune, Optional[bool]:

    If True (default), resolve unknown aliasing first. If False, returned handler contains copies of object problems.

copy_problems(prune=True)Tuple[cosapp.core.numerics.basics.MathematicalProblem, cosapp.core.numerics.basics.MathematicalProblem][source]

Export design and off-design problems.

  • prune, Optional[bool]:

    If True (default), resolve unknown aliasing first. If False, returned problems are copies of object attributes.

  • (design, offdesign): Copies of design and off-design problems,

    as a tuple of MathematicalProblem objects.

extend(other: cosapp.drivers.utils.DesignProblemHandler, prune=True, copy=True, overwrite=False)cosapp.drivers.utils.DesignProblemHandler[source]

Extend both design and off-design problems from other handler.

Parameters
  • prune [bool (-) – If True (default), added problems are pruned before being added.

  • optional] – If True (default), added problems are pruned before being added.

  • copy [bool (-) – Determines whether problem copies should be made before extension.

  • optional] – Determines whether problem copies should be made before extension.

  • overwrite [bool (-) – Overwrite option, forwarded to MathematicalProblem.extend.

  • optional] – Overwrite option, forwarded to MathematicalProblem.extend.

classmethod make(design: cosapp.core.numerics.basics.MathematicalProblem, offdesign: cosapp.core.numerics.basics.MathematicalProblem)cosapp.drivers.utils.DesignProblemHandler[source]
merged_problem(name='merged', offdesign_prefix='offdesign', copy=True)cosapp.core.numerics.basics.MathematicalProblem[source]

Merge design and off-design problems into a single MathematicalProblem instance.

Parameters
  • name [str (-) – Merged problem name (default: ‘merged’).

  • optional] – Merged problem name (default: ‘merged’).

  • offdesign_prefix [str (-) – If not empty or None, applies a prefix to dict keys in off-design unknowns and equations.

  • optional] – If not empty or None, applies a prefix to dict keys in off-design unknowns and equations.

  • copy [bool (-) – Perform copies if True (default).

  • optional] – Perform copies if True (default).

new_problem(name: str)cosapp.core.numerics.basics.MathematicalProblem[source]

Create new MathematicalProblem instance

property problems

design and off-design problems as a tuple

Type

Tuple[MathematicalProblem, MathematicalProblem]

prune()None[source]

Remove connected unknowns and resolve unknown aliasing in design and off-desing problems.

class cosapp.drivers.utils.SystemAnalyzer(system: Optional[cosapp.systems.System] = None)[source]

Bases: object

Class containing data collected on a system, to be shared between different drivers.

check_system()None[source]

Check that object is associated to a system.

Raises

ValueError

clear()None[source]

Hook function to clear internal data, if any. Called at object instanciation.

property system

system of interest

Type

System

cosapp.drivers.utils.dealias_problem(problem: cosapp.core.numerics.basics.MathematicalProblem, name=None)cosapp.core.numerics.basics.MathematicalProblem[source]

Resolve unknown aliasing in problem due to pulling connectors (if any) in context system.

  • problem [MathematicalProblem]:

    Mathematical problem to be de-aliased.

  • name [str, optional]:

    Name of output MathematicalProblem object.

MathematicalProblem:

New mathematical problem, with identical equations as source problem, but de-aliased unknowns.