zoomy_core.model.derivation.operations

zoomy_core.model.derivation.operations#

Derivation operations that do more than a substitution: SolveFor, SolveLinearSystem, ChangeOfVariables. They follow the Operation protocol of zoomy_core.model.operations and act on a Model before it is lifted to a SystemModel.

Module Contents#

Classes#

SolveFor

Reorient an equation in place into variable = solution. Pipeline counterpart of equation.solve_for(var), which returns a new equation.

SolveLinearSystem

Solve a coupled linear system A v = b for a family of variables with sympy.linsolve. solve() returns an indexable MomentFamily of oriented rows v_i = solution_i that can be passed to .apply.

Granularity

Structural level an Operation acts on: LEAF, TERM, EQUATION or SYSTEM.

ChangeOfVariables

Rename a coefficient family a(i, ...) -> relation(q(i, ...)) across the model and swap a for q in the unknowns. The unknown swap (model.redeclare_unknown) is what distinguishes it from a plain substitution.

Functions#

granularity_of

Return the Granularity of an operation from its system_level / whole_model_op / single_term_only flags.

API#

class zoomy_core.model.derivation.operations.SolveFor(variable, name=None)#

Bases: zoomy_core.model.operations.Operation

Reorient an equation in place into variable = solution. Pipeline counterpart of equation.solve_for(var), which returns a new equation.

Initialization

Store the variable to isolate.

apply_to_equation(eq)#

Replace the equation by the oriented relation variable = solution.

class zoomy_core.model.derivation.operations.SolveLinearSystem(equations, variables, name='solve_linear_system')#

Solve a coupled linear system A v = b for a family of variables with sympy.linsolve. solve() returns an indexable MomentFamily of oriented rows v_i = solution_i that can be passed to .apply.

Initialization

Store the equations and the unknown variables.

solve()#

Solve the system, hiding opaque Galerkin brackets behind symbols during the solve.

Returns

MomentFamily whose component i is variables[i] = solution_i.

class zoomy_core.model.derivation.operations.Granularity#

Structural level an Operation acts on: LEAF, TERM, EQUATION or SYSTEM.

LEAF#

‘LEAF’

TERM#

‘TERM’

EQUATION#

‘EQUATION’

SYSTEM#

‘SYSTEM’

zoomy_core.model.derivation.operations.granularity_of(op) → str#

Return the Granularity of an operation from its system_level / whole_model_op / single_term_only flags.

Args

  • op: an Operation instance.

class zoomy_core.model.derivation.operations.ChangeOfVariables(old, new, relation, name=None)#

Bases: zoomy_core.model.operations.Operation

Rename a coefficient family a(i, ...) -> relation(q(i, ...)) across the model and swap a for q in the unknowns. The unknown swap (model.redeclare_unknown) is what distinguishes it from a plain substitution.

Args

  • old: name of the family currently in Q.

  • new: name of the replacing family.

  • relation: callable mapping the applied new function to the substituted expression.

Initialization

Store the family names and the relation.

whole_model_op#

True

transforms_bcs#

True

apply_to_model(model)#

Rewrite every equation and relation, then redeclare the unknowns old -> new.