mtnlion.problem_space module

Tools for assigning a problem space to a given model.

class mtnlion.problem_space.ElementAssigner(model: mtnlion.model.Model)[source]

Bases: object

Provides a set of tools to generate and assign elements to variables in a given model.

assign_elements(element: dolfin.FiniteElement, domains: Iterable = (), names: Iterable = ()) → mtnlion.problem_space.ElementAssigner[source]

Assign a given element to given domains or variable names.

Parameters
  • element – FEniCS element to assign

  • domains – An iterable of domain names to assign

  • names – An iterable of variable names to assign

Returns

ElementAssigner

check_assigned_elements() → None[source]

Check to make sure all variables have assigned elements.

Returns

None

generate_elements() → mtnlion.element.ElementSpace[source]

Create the element space defined by the model and assigned elements.

Returns

ElementSpace

static update_element_map(variable: mtnlion.variable.Variable, element: dolfin.FiniteElement, domains: Iterable[str]) → None[source]

Update the element map for a given variable to use the given element on the specified domains.

Parameters
  • variableVariable to update

  • element – Element to assign

  • domains – Domains of the variable to assign

Returns

None

class mtnlion.problem_space.FunctionManager(mesh: dolfin.mesh, element_space: mtnlion.element.ElementSpace)[source]

Bases: object

Manages the mesh, function space, trial function vector, and test function vector.

assign(to_fenics: dolfin.Function, from_domain: Mapping[Any, mtnlion.domain.Domain]) → None[source]

Assign a mixed element function from a Domain based variable.

Parameters
  • to_fenics – Function to assign

  • from_domain – Domain variable to assign from

function() → dolfin.Function[source]

Create a FEniCS function defined in the mixed element function space

get_subspace(variable_name: str, domain: str) → List[dolfin.FunctionSpace][source]

Retrieve the subspace definition for a given variable, domain, and optionally index if the variable is an approximation.

Parameters
  • variable_name – name of the variable

  • domain – domain to retrieve

Returns

Function Space

initialize_from_constant(variable_name: str, constants: Iterable[dolfin.Constant], domain: str, time_index: int = 0) → None[source]

Initialize a variable from a constant value.

Parameters
  • variable_name – Name of the variable

  • constants – List of constants, lenght should be 0 if the function is not an approximation

  • domain – Domain to apply the constant to

  • time_index – Time index to apply the constant to

Returns

None

initialize_from_expression(variable_name: str, expressions: Iterable[dolfin.Constant], domain: str, time_index: int = 0) → None[source]

Initialize a variable from an expression.

Parameters
  • variable_name – Name of the variable

  • expressions – List of constants, lenght should be 0 if the function is not an approximation

  • domain – Domain to apply the constant to

  • time_index – Time index to apply the constant to

Returns

None

split(function: dolfin.Function) → Mapping[Any, mtnlion.domain.Domain][source]

Split a FEniCS function into a domain structure.

Parameters

function – FEniCS function

class mtnlion.problem_space.ProblemSpace(model: mtnlion.model.Model, domain, time_discretization)[source]

Bases: mtnlion.problem_space.ElementAssigner

Defines the relationship between the model, domain, and temporal discretization schemes.

generate_variables() → mtnlion.problem_space.ProblemSpace[source]

Given the element mapping defined by the variables in the model, generate the element space for the model and use that element space to form the test and trial function vectors. The vectors are then split into individual functions and assigned to variables.

Returns

ProblemSpace

class mtnlion.problem_space.ProblemSpaceAssembler(problem_space: mtnlion.problem_space.ProblemSpace, parameters, lambdas=())[source]

Bases: object

Handles the assembly of the FFL form from the definition of the model as it relates to the problem space.

form_dependents(form_name: str) → Iterator[source]

Search the list of forms to see if form_name occurs in any formula parameters.

Parameters

form_name – Name of the form

Returns

filter object

formulate() → dolfin.Form[source]

Formulate the model equations on the problem space.

static iter_forms(mapping: Mapping) → Generator[source]

Generator to iterate through a mapping of mappings.

Parameters

mapping – Top level mapping

Returns

generator

primary_forms

Fetch the formulas that are not dependent on other forms.

Returns

Mapping of formulas

secondary_forms

Fetch the formulas that are dependent on other forms.

Returns

Mapping of formulas

class mtnlion.problem_space.UndefinedFormula(formula: str, domain: str)[source]

Bases: object

This class is a placeholder for formulas that do not exist (yet).