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(element)[source]

Bases: object

A caching object for work vectors and matrices.

Parameters

element – The element to use for the caching.

DG_inv_mass(DG)[source]

Inverse DG mass matrix :arg DG: the DG space :returns: A PETSc Mat.

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(element)[source]
inject(uf, uc)[source]

Inject a function (primal restriction)

Parameters
  • uc – The source (fine grid) function.

  • uf – The target (coarse grid) function.

is_native(element)[source]
op(source, target, transfer_op)[source]

Primal transfer (either prolongation or injection).

Parameters
  • source – The source function.

  • target – The target function.

  • transfer_op – The transfer operation for the DG space.

prolong(uc, uf)[source]

Prolong a function.

Parameters
  • uc – The source (coarse grid) function.

  • uf – The target (fine grid) function.

restrict(gf, gc)[source]

Restrict a dual function.

Parameters
  • gf – The source (fine grid) dual function.

  • gc – The target (coarse grid) dual function.

work_vec(V)[source]

A work Vec for V :arg V: a function space. :returns: A PETSc Vec for V.

firedrake.mg.interface module

firedrake.mg.interface.prolong(coarse, fine)[source]
firedrake.mg.interface.restrict(fine_dual, coarse_dual)[source]
firedrake.mg.interface.inject(fine, coarse)[source]

firedrake.mg.kernels module

class firedrake.mg.kernels.MacroKernelBuilder(scalar_type, num_entities)[source]

Bases: tsfc.kernel_interface.firedrake.KernelBuilderBase

Kernel builder for integration on a macro-cell.

Parameters

num_entities – the number of micro-entities to integrate over.

oriented = False
set_coefficients(coefficients)[source]
set_coordinates(domain)[source]

Prepare the coordinate field.

Parameters

domainufl.Domain

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

Some coffee AST

firedrake.mg.kernels.dg_injection_kernel(Vf, Vc, ncell)[source]
firedrake.mg.kernels.inject_kernel(Vf, Vc)[source]
firedrake.mg.kernels.prolong_kernel(expression)[source]
firedrake.mg.kernels.restrict_kernel(Vf, Vc)[source]
firedrake.mg.kernels.to_reference_coordinates(ufl_coordinate_element, parameters=None)[source]

firedrake.mg.mesh module

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(), or NonNestedHierarchy().

comm[source]
firedrake.mg.mesh.MeshHierarchy(mesh, refinement_levels, refinements_per_level=1, reorder=None, distribution_parameters=None, callbacks=None, mesh_builder=<function Mesh>)[source]

Build a hierarchy of meshes by uniformly refining a coarse mesh.

Parameters
  • mesh – the coarse Mesh() to refine

  • refinement_levels – the number of levels of refinement

  • refinements_per_level – the number of refinements for each level in the hierarchy.

  • distribution_parameters – options controlling mesh distribution, see Mesh() for details. If None, use the same distribution parameters as were used to distribute the coarse mesh, otherwise, these options override the default.

  • reorder – optional flag indicating whether to reorder the refined meshes.

  • callbacks – 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.

firedrake.mg.mesh.ExtrudedMeshHierarchy(base_hierarchy, height, base_layer=-1, refinement_ratio=2, layers=None, kernel=None, extrusion_type='uniform', gdim=None, mesh_builder=<function 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.

firedrake.mg.mesh.NonNestedHierarchy(*meshes)[source]

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.utils module

firedrake.mg.utils.coarse_cell_to_fine_node_map(Vc, Vf)[source]
firedrake.mg.utils.coarse_node_to_fine_node_map(Vc, Vf)[source]
firedrake.mg.utils.fine_node_to_coarse_node_map(Vf, Vc)[source]
firedrake.mg.utils.get_level(obj)[source]

Try and obtain hierarchy and level info from an object.

If no level info is available, return None, None.

firedrake.mg.utils.has_level(obj)[source]

Does the provided object have level info?

firedrake.mg.utils.physical_node_locations(V)[source]
firedrake.mg.utils.set_level(obj, hierarchy, level)[source]

Attach hierarchy and level info to an object.

Module contents