Skip to content

cell_problem

cell_problem

Helper problems that are used to solve the cell problem in the HMM.

Classes:

Name Description
PeriodicLinearProblem

linear problem class that automatically adds periodic boundary conditions on boxes.

hommx.cell_problem.PeriodicLinearProblem

Bases: dolfinx_mpc.LinearProblem

Class for solving a linear variational problem with periodic boundary conditions with multi point constraints of the form \(a(u, v) = L(v)\) for all v using PETSc as a linear algebra backend.

The solution is only unique up to a constant. This is handled by telling the PETSc KSP solver about the nullspace.

Parameters:

Name Type Description Default
a

A bilinear UFL form, the left hand side of the variational problem.

required
L

A linear UFL form, the right hand side of the variational problem.

required
mpc

The multi point constraint.

required
bcs

A list of Dirichlet boundary conditions.

required
u

The solution function. It will be created if not provided. The function has to be based on the functionspace in the mpc, i.e.

.. highlight:: python .. code-block:: python

u = dolfinx.fem.Function(mpc.function_space)
required
petsc_options

Parameters that is passed to the linear algebra backend PETSc. #type: ignore For available choices for the 'petsc_options' kwarg, see the PETSc-documentation https://www.mcs.anl.gov/petsc/documentation/index.html.

required
form_compiler_options

Parameters used in FFCx compilation of this form. Run ffcx --help at the commandline to see all available options. Takes priority over all other parameter values, except for scalar_type which is determined by DOLFINx.

required
jit_options

Parameters used in CFFI JIT compilation of C code generated by FFCx. See https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/jit.py#L22-L37 for all available parameters. Takes priority over all other parameter values.

required

Examples: Example usage:

.. highlight:: python
.. code-block:: python

   problem = LinearProblem(
       a, L, mpc, [bc0, bc1], petsc_options={"ksp_type": "preonly", "pc_type": "lu"}
   )

solve

solve() -> fem.Function

Solve the problem.

solve_with_rhs

solve_with_rhs(L: fem.Form) -> fem.Function

Solves for a different right-hand side, reusing the assembled operator.

Parameters:

Name Type Description Default
L fem.Form

Compiled linear form to use as the right-hand side.

required

Returns:

Type Description
fem.Function

The solution function. Note that the same function is reused across calls, so copy

fem.Function

its values before invoking this again if you need to keep them.

hommx.cell_problem.warn_if_cell_problem_options_unsuitable

warn_if_cell_problem_options_unsuitable(petsc_options: dict | None, logger: logging.Logger | None = None) -> None

Warns if the cell problem solver options cannot handle the singular operator.

Parameters:

Name Type Description Default
petsc_options dict | None

Cell problem PETSc options to inspect.

required
logger logging.Logger | None

Logger to warn on. Defaults to this module's logger.

None

hommx.cell_problem._clear_petsc_options

_clear_petsc_options(prefix: str) -> None

Removes every option starting with prefix from the global PETSc options database.

Parameters:

Name Type Description Default
prefix str

Options prefix to purge, without a leading dash.

required

hommx.cell_problem.create_periodic_boundary_conditions

create_periodic_boundary_conditions(function_space: fem.FunctionSpace, bcs: list[fem.DirichletBC] | None = None) -> dolfinx_mpc.MultiPointConstraint

Creates periodic boundary condition on the unit square or unit cube. For implementation details see _create_periodic_boundary_conditions_2d and _create_periodic_boundary_conditions_3d

hommx.cell_problem._create_periodic_boundary_conditions_1d

_create_periodic_boundary_conditions_1d(msh: mesh.Mesh, function_space: fem.FunctionSpace, bcs: list[fem.DirichletBC] | None = None) -> dolfinx_mpc.MultiPointConstraint

Creates periodic boundary condition on the unit interval using dolfinx_mpc.

We force \(u(x_1) = u(x_0)\), so on the unit interval \((x_0, x_1) = (0, 1)\). The slave DoF is the one at \(x_1\). Unlike 2D and 3D there are no corners or edges, so no DoF is constrained more than once. -> No extra care.

Parameters:

Name Type Description Default
msh mesh.Mesh

Mesh that the boundary conditions should be applied to

required
function_space fem.FunctionSpace

Function Space on which the bc should be applied

required
bcs list[fem.DirichletBC] | None

Dirichlet Boundary Conditions, here the constraint is ignored

None

hommx.cell_problem._create_periodic_boundary_conditions_2d

_create_periodic_boundary_conditions_2d(msh: mesh.Mesh, function_space: fem.FunctionSpace, bcs: list[fem.DirichletBC] | None = None) -> dolfinx_mpc.MultiPointConstraint

Creates periodic boundary condition on the unit square using dolfinx_mpc.

This is done using create_periodic_constraints. We do this by forcing \(u(x, y_1) = u(x, y_0)\) and \(u(x_1, y) = u(x_0, y)\), on the unit square we would have \((x_0, x_1) = (y_0, y_1) = (0, 1)\) Internally we create slave DoFs at \(u(x, y_1)\) and \(u(x_1, y)\). Some attention need to be paid because the node at \((x_1,y_1)\) is constrained twice. We use a workaround adapted from: dolfinx_mpc

Parameters:

Name Type Description Default
msh mesh.Mesh

Mesh that the boundary conditions should be applied to

required
function_space fem.FunctionSpace

Function Space on whicht the bc should be applied

required
bcs list[fem.DirichletBC] | None

Dirichlet Boundary Conditions, here the constraint is ignored

None

hommx.cell_problem._create_periodic_boundary_conditions_3d

_create_periodic_boundary_conditions_3d(msh: mesh.Mesh, function_space: fem.FunctionSpace, bcs: list[fem.DirichletBC] | None = None) -> dolfinx_mpc.MultiPointConstraint

Creates periodic boundary condition on the unit cube using dolfinx_mpc.

This is done using create_periodic_constraints. We do this by forcing \(u(x, y_1, z) = u(x, y_0, z)\) and so on for all directions on the unit square we would have \((z_0, z_1) = (x_0, x_1) = (y_0, y_1) = (0, 1)\) Internally we create slave DoFs at \(u(x, y_1, z)\) and \(u(x_1, y, z)\) etc. Some attention need to be paid because the nodes at \((x_1, y_1, z)\) are constrained twice etc for other edges And \((x_1, y_1, z_1)\) is constrained three times. We use a workaround adapted from: dolfinx_mpc

Parameters:

Name Type Description Default
msh mesh.Mesh

Mesh that the boundary conditions should be applied to

required
function_space fem.FunctionSpace

Function Space on which the bc should be applied

required
bcs list[fem.DirichletBC] | None

Dirichlet Boundary Conditions, here the constraint is ignored

None