firedrake.mg package¶
Submodules¶
firedrake.mg.embedded module¶
- class firedrake.mg.embedded.TransferManager(*, native_transfers=None, use_averaging=True)[source]¶
Bases:
object
An object for managing transfers between levels in a multigrid hierarchy (possibly via embedding in DG spaces).
- Parameters:
native_transfers – dict mapping UFL element to “natively supported” transfer operators. This should be a three-tuple of (prolong, restrict, inject).
use_averaging – Use averaging to approximate the projection out of the embedded DG space? If False, a global L2 projection will be performed.
- class Cache(ufl_element, value_shape)[source]¶
Bases:
object
A caching object for work vectors and matrices.
- Parameters:
element – The element to use for the caching.
- DG_work(V)[source]¶
A DG work Function matching V :arg V: a function space. :returns: A Function in the embedding DG space.
- V_DG_mass(V, DG)[source]¶
Mass matrix from between V and DG spaces. :arg V: a function space :arg DG: the DG space :returns: A PETSc Mat mapping from V -> DG
- V_approx_inv_mass(V, DG)[source]¶
Approximate inverse mass. Computes (cellwise) (V, V)^{-1} (V, DG). :arg V: a function space :arg DG: the DG space :returns: A PETSc Mat mapping from V -> DG.
- V_dof_weights(V)[source]¶
Dof weights for averaging projection.
- Parameters:
V – function space to compute weights for.
- Returns:
A PETSc Vec.
- V_inv_mass_ksp(V)[source]¶
A KSP inverting a mass matrix :arg V: a function space. :returns: A PETSc KSP for inverting (V, V).
- cache_dat_versions(V, transfer_op, source, target)[source]¶
Record the returned dat_versions of the source and target.
- inject(uf, uc)[source]¶
Inject a function (primal restriction)
- Parameters:
uf – The source (fine grid) function.
uc – The target (coarse grid) function.
- prolong(uc, uf)[source]¶
Prolong a function.
- Parameters:
uc – The source (coarse grid) function.
uf – The target (fine grid) function.
- requires_transfer(V, transfer_op, source, target)[source]¶
Determine whether either the source or target have been modified since the last time a grid transfer was executed with them.
- restrict(source, target)[source]¶
Restrict a dual function.
- Parameters:
source – The source (fine grid)
Cofunction
.target – The target (coarse grid)
Cofunction
.
firedrake.mg.interface module¶
firedrake.mg.kernels module¶
- class firedrake.mg.kernels.MacroKernelBuilder(scalar_type, num_entities)[source]¶
Bases:
KernelBuilderBase
Kernel builder for integration on a macro-cell.
- Parameters:
num_entities – the number of micro-entities to integrate over.
- oriented = False¶
- set_coordinates(domain)[source]¶
Prepare the coordinate field.
- Parameters:
domain –
ufl.AbstractDomain
- firedrake.mg.kernels.compile_element(expression, dual_space=None, parameters=None, name='evaluate')[source]¶
Generate code for point evaluations.
- Parameters:
expression – A UFL expression (may contain up to one coefficient, or one argument)
dual_space – if the expression has an argument, should we also distribute residual data?
- Returns:
The generated code (
loopy.TranslationUnit
)
firedrake.mg.mesh module¶
- firedrake.mg.mesh.ExtrudedMeshHierarchy(base_hierarchy, height, base_layer=-1, refinement_ratio=2, layers=None, kernel=None, extrusion_type='uniform', gdim=None, mesh_builder=<cyfunction ExtrudedMesh>)[source]¶
Build a hierarchy of extruded meshes by extruding a hierarchy of meshes.
- Parameters:
base_hierarchy – the unextruded base mesh hierarchy to extrude.
height – the height of the domain to extrude to. This is in contrast to the extrusion routines, which take in layer_height, the height of an individual layer. This is because when refining in the extruded dimension, the height of an individual layer will vary.
base_layer – the number of layers to use the extrusion of the coarsest grid.
refinement_ratio – the ratio by which base_layer should be increased on every refinement. refinement_ratio = 2 means standard uniform refinement. refinement_ratio = 1 means to not refine in the extruded dimension, i.e. the multigrid hierarchy will use semicoarsening.
layers – as an alternative to specifying base_layer and refinement_ratio, one may specify directly the number of layers to be used by each level in the extruded hierarchy. This option cannot be combined with base_layer and refinement_ratio. Note that the ratio of successive entries in this iterable must be an integer for the multigrid transfer operators to work.
mesh_builder – function used to turn a
Mesh
into an extruded mesh. Used by pyadjoint.
See
ExtrudedMesh()
for the meaning of the remaining parameters.
- class firedrake.mg.mesh.HierarchyBase(meshes, coarse_to_fine_cells, fine_to_coarse_cells, refinements_per_level=1, nested=False)[source]¶
Bases:
object
Create an encapsulation of an hierarchy of meshes.
- Parameters:
meshes – list of meshes (coarse to fine)
coarse_to_fine_cells – list of numpy arrays for each level pair, mapping each coarse cell into fine cells it intersects.
fine_to_coarse_cells – list of numpy arrays for each level pair, mapping each fine cell into coarse cells it intersects.
refinements_per_level – number of mesh refinements each multigrid level should “see”.
nested – Is this mesh hierarchy nested?
Note
Most of the time, you do not need to create this object yourself, instead using
MeshHierarchy()
,ExtrudedMeshHierarchy()
, orNonNestedHierarchy()
.- property comm¶
- firedrake.mg.mesh.MeshHierarchy(mesh, refinement_levels, refinements_per_level=1, netgen_flags=False, reorder=None, distribution_parameters=None, callbacks=None, mesh_builder=<cyfunction Mesh>)[source]¶
Build a hierarchy of meshes by uniformly refining a coarse mesh.
- Parameters:
mesh (MeshGeometry) – the coarse mesh to refine
refinement_levels (int) – the number of levels of refinement
refinements_per_level (int) – the number of refinements for each level in the hierarchy.
netgen_flags (bool, dict) – either a bool or a dictionary containing options for Netgen. If not False the hierachy is constructed using ngsPETSc, if None hierarchy constructed in a standard manner.
distribution_parameters (dict) – options controlling mesh distribution, see
Mesh()
for details. IfNone
, use the same distribution parameters as were used to distribute the coarse mesh, otherwise, these options override the default.reorder (bool) – optional flag indicating whether to reorder the refined meshes.
callbacks (tuple) – A 2-tuple of callbacks to call before and after refinement of the DM. The before callback receives the DM to be refined (and the current level), the after callback receives the refined DM (and the current level).
mesh_builder – Function to turn a DM into a
Mesh
. Used by pyadjoint.
- Returns:
A
HierarchyBase
object representing themesh hierarchy.
- firedrake.mg.mesh.SemiCoarsenedExtrudedHierarchy(base_mesh, height, nref=1, base_layer=-1, refinement_ratio=2, layers=None, kernel=None, extrusion_type='uniform', gdim=None, mesh_builder=<cyfunction ExtrudedMesh>)[source]¶
Build a hierarchy of extruded meshes with refinement only in the extruded dimension.
- Parameters:
base_mesh – the unextruded base mesh to extrude.
nref – Number of refinements.
height – the height of the domain to extrude to. This is in contrast to the extrusion routines, which take in layer_height, the height of an individual layer. This is because when refining in the extruded dimension, the height of an individual layer will vary.
base_layer – the number of layers to use the extrusion of the coarsest grid.
refinement_ratio – the ratio by which base_layer should be increased on every refinement. refinement_ratio = 2 means standard uniform refinement. refinement_ratio = 1 means to not refine in the extruded dimension, i.e. the multigrid hierarchy will use semicoarsening.
layers – as an alternative to specifying base_layer and refinement_ratio, one may specify directly the number of layers to be used by each level in the extruded hierarchy. This option cannot be combined with base_layer and refinement_ratio. Note that the ratio of successive entries in this iterable must be an integer for the multigrid transfer operators to work.
mesh_builder – function used to turn a
Mesh
into an extruded mesh. Used by pyadjoint.
See
ExtrudedMesh()
for the meaning of the remaining parameters.See also
ExtrudedMeshHierarchy()
if you want to extruded a hierarchy of unstructured meshes.
firedrake.mg.opencascade_mh module¶
- firedrake.mg.opencascade_mh.OpenCascadeMeshHierarchy(stepfile, element_size, levels, comm=<mpi4py.MPI.Intracomm object>, distribution_parameters=None, callbacks=None, order=1, mh_constructor=<function MeshHierarchy>, cache=True, verbose=True, gmsh='gmsh', project_refinements_to_cad=True, reorder=None)[source]¶
firedrake.mg.ufl_utils module¶
- firedrake.mg.ufl_utils.coarsen(expr, self, coefficient_mapping=None)[source]¶
- firedrake.mg.ufl_utils.coarsen(mesh: Mesh, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(expr: Expr, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(expr: BaseForm, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(form: Form, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(form: FormSum, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(bc: DirichletBC, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(V: WithGeometryBase, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(expr: Function, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(expr: Cofunction, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(problem: NonlinearVariationalProblem, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(basis: VectorSpaceBasis, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(mspbasis: MixedVectorSpaceBasis, self, coefficient_mapping=None)
- firedrake.mg.ufl_utils.coarsen(context: _SNESContext, self, coefficient_mapping=None)