WIP: Firedrake connection-functional
The goal of this merge request is to supersed this previous firedrakeConnection merge request by providing a better developer interface.
As well as adding some documentation, some tests, and a tentative implementation of exporting a mesh to firedrake, the new structure is as follows:
For firedrake
conversion we have functions implementing the following:
-
Reference Cell
- Map between firedrake reference cell and modepy unit coordinates
- Pull unit nodes from the firedrake reference element (
finat
element) - Generate matrix to flip negative elements
- Generate matrix to resample a function from firedrake's unit nodes at the unit nodes meshmode is using
-
Mesh Generation
- From a mesh topology produce
- Nodal adjacency
- Facial adjacency groups
- vertex indices
- Boundary tags
- boundary tags
- From a mesh geometry produce
- vertices/nodes
- element orientations
- a mesh element group
- As well as flip any negatively oriented elements, and handle the consequences with facial adjacency groups etc.
- From a mesh topology produce
The above functions are then used in import_firedrake_mesh
to create a meshmode Mesh
and obtain the orientation of each cell in the firedrake mesh. Then, we have only make one new class (for creating a connection from meshmode into firedrake)
class FromFiredrakeConnection:
"""
.. attribute:: to_discr
The discretization corresponding to the firedrake function space
"""
def __init__(self, cl_ctx, fdrake_fspace):
"""make the connection"""
def from_fspace(self, dim=1):
"""
Firedrake puts functions mapping into R^m and R^n in different function
spaces if m != n, but we want this connection to be able to transport any
function on this mesh that has this reference element
"""
def from_firedrake(self, fdrake_fntn, out=None):
"""
Convert a firedrake function and return it, optionally storing in
array out
"""
def from_meshmode(self, field, out=None):
"""
Convert a meshmode field and return it as a firedrake function, optionally
storing in already instantiated firedrake function out
"""
The class stores the parts of the firedrake function space it needs to implement from_fspace
, as well as privately storing the node permutation (fd->meshmode) and the resampling matrix. To implement conversion (fd->mm) one way it just reorders the nodes then resamples them.
Some care is taken to handle "CG"
firedrake spaces as well. Conversion fd->mm is easy, conversion mm->fd is disabled by default in this case, but can be forced to work if the user believes they are converting a continuous function. That assumption can also be verified.
TODO: finish exporting discretizations as "DG"
firedrake spaces (i.e. the ToFiredrakeConnection
class). This seems to be a little easier now that I know most of the big problems. The grubbiest part right now would be boundary tagging. Tests are needed
TODO: more testing is probably good idea on the import side as well, especially related to boundary tagging.