mtnlion.formula module¶
The Formula class is the basis for defining models. The formulas define the name, applicable domains, and arguments required to be able to fully assemble the formula for FFL.
-
exception
mtnlion.formula.
ArgumentError
[source]¶ Bases:
Exception
Raised when an argument doesn’t match the class specified
-
class
mtnlion.formula.
Arguments
(variables: Iterable[mtnlion.variable.Variable] = (), parameters: Iterable = (), lambdas: Iterable[Callable] = (), time_discretization: Iterable = ())[source]¶ Bases:
object
This class is designed to serve as a data class to pass variables, parameters, formulas, lambda functions, and time discretization schemes to any formula. This class also handles the assignment of named tuples from generic tuples and performs basic error checking.
-
assign_argument_classes
(variables: Type[NamedTuple], parameters: Type[NamedTuple], lambdas: Type[NamedTuple], time_discretization: Type[NamedTuple]) → None[source]¶ Assign the classes that the Iterable’s should be converted to.
- Parameters
variables – Named tuple for variables
parameters – Named tuple for parameters
lambdas – Named tuple for lambdas
time_discretization – Named tuple for time_discretizations
- Returns
None
-
convert
() → None[source]¶ Convert the internal properties to the classes defined in _classes. :return: None
-
pop_parameters
(parameters: Iterable[str]) → NamedTuple[source]¶ Return a tuple containing the values of the requested arguments. The requested arguments are then removed from the object.
- Parameters
parameters – List of arguments to pop
- Returns
Tuple
-
-
class
mtnlion.formula.
FormMap
(formula: mtnlion.formula.Formula, measure_map: mtnlion.cell.MeasureMap, eval_domain: str, formulation: Optional[mtnlion.domain.Domain[str, List]] = None, name: Optional[str] = None)[source]¶ Bases:
object
A mapping between formula specifications (unformulated), the formulated FFL representation, the domain/boundary measure map, and evaluation domain.
-
domains
¶ Domains that the formula is defined in
-
name
¶ Name of the formula
-
primary_domain
¶ Return the value of the measure’s primary (parent) domain. This is usually set if the current measure is a boundary.
- Returns
Primary domain
-
variables
¶ List of test functions in the formula
-
-
class
mtnlion.formula.
Formula
(name: Optional[str] = None, domains: Iterable[str] = ())[source]¶ Bases:
abc.ABC
Formula defines the name, domains of evaluation, and relevant dependencies in order to define the FFL formulation.
The method Formula.form must be overridden to return the fully specified form given the arguments. The arguments are defined by overriding one or more of Formula.Variables, Formula.Formulas, Formula.Parameters, Formula.Lambdas, and Formula.TimeDiscretization.
Formula.Variables: Must contain the names of variables defined in a given model Formula.Formulas: Must contain the names of Formulas defined in a given model Formula.Parameters: Contains the names of parameters that will be provided later Formula.Lambdas: Contains the names of lambda functions that will be provided later Formula.TimeDiscretization: Contains the names of time derivatives that will be defined later. This can be either a time stepping scheme for Rothes, or a member of the solution vector for MOL.
-
append_arguments
(type_: Type[NamedTuple], arguments: Iterable) → Type[NamedTuple][source]¶ Append argument names to the given type definition.
- Parameters
type – Existing type
arguments – New arguments to add
- Returns
NamedTuple
-
form
(arguments: mtnlion.formula.Arguments, domain: str) → ufl.core.expr.Expr[source]¶ This method must be overloaded to define the form of the Formula.
- Parameters
arguments – All arguments defined by overriding one or more of Formula.Variables, Formula.Formulas, Formula.Parameters, Formula.Lambdas, and Formula.TimeDiscretization
domain – The current domain in which the function is being evaluated
- Returns
FFL form
-
formulate
(arguments: mtnlion.formula.Arguments, domain: str) → ufl.core.expr.Expr[source]¶ Validate arguments and perform type conversions necessary for evaluating Formula.form.
- Parameters
arguments – Arguments required to evaluate
domain – Domain in which the form is evaluated
- Returns
FFL form
-
parameters
¶ Return a tuple of argument names.
- Returns
Names of the required parameters
-
time_discretizations
¶ Return a tuple of argument names.
- Returns
Names of the required time_discretizations
-
static
typedef
(name: str, parameter_string: Iterable) → Type[NamedTuple][source]¶ Creates a namedtuple class with a given name and parameter string.
- Parameters
name – Name of the new class
parameter_string – string of parameter names for each tuple element. Comma or space delimited.
- Returns
namedtuple
-
variables
¶ Return a tuple of argument names.
- Returns
Names of the required variables
-