pyoomph.equations.generic module

class pyoomph.equations.generic.AverageConstraint(*, ode_storage_domain=None, only_for_stationary_solve=False, set_zero_on_normal_mode_eigensolve=True, scaling_factor=None, **kwargs)[source]

Bases: _AverageOrIntegralConstraintBase

Enforces the value of a field to have a fixed averaged value by a global Lagrange multiplier. If you have e.g. a field “u”, you can enforce the average of “u” to be 1 by adding

AverageConstraint(u=1)

Parameters:
  • dimensional_dx (bool) – Flag indicating whether the constraint is defined in dimensional or non-dimensional form.

  • ode_storage_domain (Optional[str]) – The storage domain for the ODEs, will default to some generated name.

  • only_for_stationary_solve (bool) – Flag indicating whether the constraint is only applied during stationary solves.

  • set_zero_on_normal_mode_eigensolve (bool) – Flag indicating whether the constraint is set to zero during angular eigensolves.

  • scaling_factor (Union[str, ExpressionNumOrNone]) – The scaling factor for the constraint.

  • **kwargs (ExpressionOrNum) – Constraints as name=value pairs.

class pyoomph.equations.generic.ConnectFieldsAtInterface(fields, *, lagr_mult_prefix='_lagr_conn_', use_highest_space=False)[source]

Bases: InterfaceEquations

Enforces continuity of fields at the interface. The fields are connected via Lagrange multipliers. The Lagrange multipliers are automatically chosen such that the condition <inner>=<outer> is satisfied.

Parameters:
  • fields (Union[str, Dict[str, str], List[str]]) – Either a single field name or a list of field names when the fields have the same name on both sides. Alternatively, a dict mapping each inner to each outer name if the fields have different names.

  • lagr_mult_prefix (str) – Prefix for the Lagrange multipliers. Defaults to “_lagr_conn_”.

  • use_highest_space (bool) – Flag indicating whether to use the highest space for the Lagrange multipliers. If the fields have different spatial discretizations on both sides, we have to decide which space to use for the Lagrange multipliers. If this flag is set to True, the highest space will be used. Defaults to False.

class pyoomph.equations.generic.ElementSpace(space)[source]

Bases: Equations

Sets the element space of the current equations. By default, pyoomph will take the highest order element space of all fields defined on the domain. With this class, you can e.g. set the element space to second order (“C2”), although you only have first-order fields (“C1”) defined.

Parameters:

space (FiniteElementSpaceEnum) – Set the desired element space for the equations of the domain.

class pyoomph.equations.generic.EquationCompilationFlags(analytical_position_jacobian=None, analytical_jacobian=None, warn_on_large_numerical_factor=None, debug_jacobian_epsilon=None, ccode_expression_mode=None, with_adaptivity=None)[source]

Bases: BaseEquations

Allows to control some flags for code generation when added to other equations.

Parameters:
  • analytical_position_jacobian (Optional[bool]) – Flag indicating whether to use analytical position Jacobian (default is True).

  • analytical_jacobian (Optional[bool]) – Flag indicating whether to use analytical Jacobian (default is True).

  • warn_on_large_numerical_factor (Optional[bool]) – Flag indicating whether to warn on large numerical factor (default is False).

  • debug_jacobian_epsilon (Optional[float]) – Epsilon value for debugging Jacobian. Will calculate both FD and analytical Jacobian and compares them. If the difference is larger than this epsilon, it will print a warning. Only use for debugging.

  • ccode_expression_mode (Optional[str]) – Mode for C-code expression, e.g. “expand”, “normal”, “collect_common_factors”, “factor”.

  • with_adaptivity (Optional[bool]) – Flag indicating whether you allow for spatial adaptivity.

class pyoomph.equations.generic.ExtremumObservables(*direct_vars, **named_extrema)[source]

Bases: Equations

You can add these to continuum Equations to find minima and maxima of given expressions. If you want to find the minimum/maximum of a scalar quantity “u”, you can add an ExtremumObservables("u") or, alternatively, give it a name like ExtremumObservables(my_name_for_u=var("u")). More than one argument can be passed to register multiple extremum observables. For e.g. the maximum of a norm of a vectorial variable v, you can add ExtremumObservables(v_norm=square_root(dot(var("v"),var("v")))).

Once registered, you can evaluate the extremum values by calling the evaluate_maximum or evaluate_minimum method of the corresponding mesh (available via problem.get_mesh(...))

Parameters:

arguments. (Either strings as positional arguments or expressions as keyword)

class pyoomph.equations.generic.InitialCondition(*, degraded_start='auto', IC_name='', **kwargs)[source]

Bases: BaseEquations

Class representing initial conditions for a set of equations. If the initial conditions dpend on time, i.e. on var("time), it will be used to initialize the history steps before the first step. Otherwise, by default, the first time step will be calculated by a first order step.

Parameters:
  • degraded_start (Union[bool, Literal['auto']]) – Flag indicating whether to use degraded start (i.e. first order time stepping in the first step) or not. Defaults to “auto”, meaning we degrade if the initial condition does not depend on time.

  • IC_name (str) – Name of the initial condition. Defaults to an empty string, which are the default initial conditions.

  • **kwargs (Union[Expression, int, float]) – Keyword arguments representing the initial conditions for each variable.

class pyoomph.equations.generic.IntegralConstraint(*, dimensional_dx=True, ode_storage_domain=None, only_for_stationary_solve=False, set_zero_on_normal_mode_eigensolve=True, scaling_factor=None, **kwargs)[source]

Bases: _AverageOrIntegralConstraintBase

Enforces the value of a field to have a fixed integral value by a global Lagrange multiplier. If you have e.g. a field “u”, you can enforce the integral of “u” to be 1 by adding

IntegralConstraint(u=1)

Parameters:
  • dimensional_dx (bool) – Flag indicating whether the constraint is defined in dimensional or non-dimensional form.

  • ode_storage_domain (Optional[str]) – The storage domain for the ODEs, will default to some generated name.

  • only_for_stationary_solve (bool) – Flag indicating whether the constraint is only applied during stationary solves.

  • set_zero_on_normal_mode_eigensolve (bool) – Flag indicating whether the constraint is set to zero during angular eigensolves.

  • scaling_factor (Union[str, ExpressionNumOrNone]) – The scaling factor for the constraint.

  • **kwargs (ExpressionOrNum) – Constraints as name=value pairs.

class pyoomph.equations.generic.IntegralObservables(_coordinate_system=None, _lagrangian=False, **integral_observables)[source]

Bases: Equations

Integral expressions will be evaluated by spatial integration over the mesh domain. E.g. an

IntegralObservables(volume=1)

will calculate the volume by integration over the mesh domain. In e.g. axisymmetry, the factor 2*pi*r will be included. Also, the output is dimensional, i.e. if you have set the scaling to a metric quantity, you will get a result in cubic meters here. When combined with an IntegralObservablesOutput object, they will be written to an output file.

You can also introduce dependent IntegralObservables. If you have a field “u”, you can calculated the average of “u” on the domain by

IntegralObservables(_denom=1,_u_integral=var(“u”),u_avg=lambda _u_integral,_denom:_u_integral/_denom)

Here, _denom will be the integral over 1 and _u_integral will be the integral over “u”. The function u_avg will be evaluated as average. The parameter names in the lambda function must match the names of the integral observables. The underscore prevents writing the helper observables to output.

Parameters:
  • _coordinate_system (Optional[BaseCoordinateSystem]) – The coordinate system to use. Defaults to None, i.e. the one of the equations or the problem.

  • **integral_observables (Union[ExpressionOrNum, Callable[..., ExpressionOrNum]]) – Integral observables to be added.

class pyoomph.equations.generic.LocalExpressions(**local_expressions)[source]

Bases: Equations

Local expressions are additional expressions for output, evaluated on the nodes of the mesh. They are not solved, but only calculated for output. Since it works node-wise, it might give problems, e.g. for 1/r terms at the axis of symmetry. An alternative is to use the ProjectExpressions class, which calculates such expressions by projection. However, these are degrees of freedom, i.e. it will be slower.

Parameters:

**local_expressions (ExpressionOrNum) – A dict of expressions to be evaluated on the nodes of the mesh for output only.

class pyoomph.equations.generic.ODEObservables(**ode_observables)[source]

Bases: ODEEquations

Adds observables to ODEs. Observables are just expressions which will be also written to the output file when combined with an ODEFileOutput object. If you have e.g. a harmonic oscillator (with variable y) and want to observe the total energy, you can add the total energy as an observable:

HarmonicOscillator(...)+ODEObservables(Etot=1/2*partial_t(y)**2+1/2*omega**2*y**2)

Parameters:

**ode_observables (Union[Expression, int, float]) – Observables to be added, identified by the name.

class pyoomph.equations.generic.RefineToLevel(level='max')[source]

Bases: Equations

Refine elements to a certain level. If the level is set to “max”, the elements will be refined to the maximum level set by e.g. max_refinement_level.

pyoomph.equations.generic.RefineToMaxLevel

alias of RefineToLevel

class pyoomph.equations.generic.RemeshMeshSize(size=None)[source]

Bases: BaseEquations

Can be added to boundaries or corners to set the local mesh size. The size can be a constant or a function of the point. If the size is a function, it must be a function of the point and return a float.

Parameters:

size (Union[float, Callable[[RemesherPointEntry], float], None]) – The local size, i.e. the typical nondimensional length of an element here. Can be a constant or a function of the point.

class pyoomph.equations.generic.RemeshWhen(remeshing_opts=None, *, max_expansion=None, min_expansion=None, min_solves_before_remesh=0, reinit_initial_size_after_one_step=False, active=True, min_quality_decrease=None, on_invalid_triangulation=False)[source]

Bases: Equations

Checks whether the mesh has been deformed to much based on either the passed RemeshingOptions object or the passed parameters. If the mesh has been deformed too much, it will be marked for remeshing. The remeshing will be done after the current Newton solve, followed by a subsequent interpolation from the previous mesh.

Parameters:
  • remeshing_opts (Optional[RemeshingOptions]) – An object containing the remeshing sensitivity.

  • max_expansion (Optional[float]) – Maximum expansion factor of an element before remeshing is invoked.

  • min_expansion (Optional[float]) – Minimum expansion factor of an element before remeshing is invoked.

  • min_solves_before_remesh (Optional[int]) – Minimum number of sucessful solves before remeshing is invoked.

  • reinit_initial_size_after_one_step (Optional[bool]) – Flag indicating whether to reinitialize the initial size after one step.

  • active (bool) – Flag indicating whether the remeshing is active.

  • min_quality_decrease (Optional[float]) – Minimum quality decrease of an element before remeshing is invoked.

  • on_invalid_triangulation (bool) – Flag indicating whether to remesh if the triangulation is invalid.

class pyoomph.equations.generic.RemeshingOptions(max_expansion=1.75, min_expansion=0.6, min_solves_before_remesh=0, reinit_initial_size_after_one_step=False, active=True, min_quality_decrease=0.2, on_invalid_triangulation=False)[source]

Bases: object

A class containing the remeshing sensitivity options to be used with the RemeshWhen class.

Parameters:
  • max_expansion (float) – Maximum expansion factor of an element before remeshing is invoked.

  • min_expansion (float) – Minimum expansion factor of an element before remeshing is invoked.

  • min_solves_before_remesh (int) – Minimum number of sucessful solves before remeshing is invoked.

  • reinit_initial_size_after_one_step (bool) – Flag indicating whether to reinitialize the initial size after one step.

  • active (bool) – Flag indicating whether the remeshing is active.

  • min_quality_decrease (float) – Minimum quality decrease of an element before remeshing is invoked.

  • on_invalid_triangulation (bool) – Flag indicating whether to remesh if the triangulation is invalid.

class pyoomph.equations.generic.Scaling(**kwargs)[source]

Bases: BaseEquations

Set the scales used for nondimensionalization on the equation level. It will override the scales set on the problem level by Problem.set_scaling(…=…).

Parameters:

**scales (ExpressionOrNum) – Used scales for nondimensionalization.

class pyoomph.equations.generic.SetCoordinateSystem(coord_sys)[source]

Bases: Equations

Set the default coordinate system for the current equations. It will override the coordinate system set on the problem level.

Parameters:

coord_sys (BaseCoordinateSystem) – Pass an coordinate system instance from the pyoomph.expressions.coordsys module.

class pyoomph.equations.generic.SpatialErrorEstimator(*fluxes, for_which='both', **kwargs)[source]

Bases: Equations

Spatial error estimators are used to estimate where a mesh should be refined. You can either pass variable name(s) and numerical factor(s), e.g.

SpatialErrorEstimator(u=1,v=10)

In that case, the jumps of the gradients grad(u) and 10*grad(v) will be used as error estimators. Alternatively, you can also provide custom expressions as estimators, e.g. for discontinuous fields, it might be better to just add

SpatialErrorEstimator(5*var(“u”))

so that the jump in “u” is used, after weighting by the factor 5, as error estimator. Error estimators expressions must be nondimensional.

for_which controls whether these error estimators are used for the base solution, potential eigenfunctions or both.

class pyoomph.equations.generic.SpatialIntegrationOrder(order)[source]

Bases: Equations

Sets the order of the Gauss-Lengendre quadrature for spatial integration. The default is depends on the element space, can be adjusted problem-wide by setting the attribute spatial_integration_order, or locally by adding this equation to the equations.

Note that not all orders are supported for all element spaces. Pyoomph will select the closest supported order.

Parameters:

order (int) – The desired order of the Gauss-Legendre quadrature (2,3,4,5 are supported by most, but not all finite element spaces).

class pyoomph.equations.generic.SubstituteVarByExpression(also_on_interfaces=True, **def_vars)[source]

Bases: BaseEquations

If not defined in this domain, all statements of var(name) in the weak formulations in this domain will be replaced by the given expressions. If you e.g. use a AdvectionDiffusionEquations, you can combine it with SubstituteVarByExpression(velocity=vector(ux,uy)) to introduce a prescribed velocity.

You can do the same on the problem level, i.e. as fallback for all equations, by the Problem-method define_named_var(). With this class, you can do it on particular domains only.

also_on_interfaces

A flag indicating whether the substitution should also be applied on interfaces.

def_vars

A dictionary containing the variables and their corresponding expressions to be subsitutes.

class pyoomph.equations.generic.TemporalErrorEstimator(**fieldfactors)[source]

Bases: BaseEquations

Adding temporal error estimators to the equations. Each field can have a different factor. If you have e.g. field “u” and “v”, add a

TemporalErrorEstimator(u=1,v=10)

to the equations to weight the error estimator for “u” with 1 and “v” with 10. Errors in “v” will be more weighted then.

Parameters:

fieldfactors (float) – A dict of field names and their corresponding temporal error weighting factors for temporal error estimation.

class pyoomph.equations.generic.TestScaling(**kwargs)[source]

Bases: BaseEquations

Set the scales of the test functions used for nondimensionalization on the equation level.

Parameters:

**testscales (ExpressionOrNum) – Used scales for nondimensionalization of the test functions.