def __init__(self, mesh: cpp.mesh.Mesh):
        """Create function that evaluates to the mesh coordinates at each
        vertex.

        """

        # Initialize C++ part
        self._cpp_object = cpp.function.MeshCoordinates(mesh)

        # Initialize UFL part
        ufl_element = mesh.ufl_domain().ufl_coordinate_element()
        if ufl_element.family() != "Lagrange" or ufl_element.degree() != 1:
            raise RuntimeError("MeshCoordinates only supports affine meshes")
        super().__init__(element=ufl_element, domain=mesh.ufl_domain())
Exemple #2
0
def VectorFunctionSpace(mesh: cpp.mesh.Mesh,
                        element: ElementMetaData,
                        dim=None,
                        restriction=None):
    """Create vector finite element (composition of scalar elements) function space."""

    e = ElementMetaData(*element)
    ufl_element = ufl.VectorElement(e.family, mesh.ufl_cell(), e.degree, form_degree=e.form_degree, dim=dim)
    return FunctionSpace(mesh, ufl_element)
    def __init__(self,
                 mesh: cpp.mesh.Mesh,
                 element: typing.Union[ufl.FiniteElementBase, ElementMetaData],
                 cppV: typing.Optional[cpp.function.FunctionSpace] = None):
        """Create a finite element function space."""

        # Create function space from a UFL element and existing cpp
        # FunctionSpace
        if cppV is not None:
            assert mesh is None
            ufl_domain = cppV.mesh.ufl_domain()
            super().__init__(ufl_domain, element)
            self._cpp_object = cppV
            return

        # Initialise the ufl.FunctionSpace
        if isinstance(element, ufl.FiniteElementBase):
            super().__init__(mesh.ufl_domain(), element)
        else:
            e = ElementMetaData(*element)
            ufl_element = ufl.FiniteElement(e.family,
                                            mesh.ufl_cell(),
                                            e.degree,
                                            form_degree=e.form_degree)
            super().__init__(mesh.ufl_domain(), ufl_element)

        # Compile dofmap and element and create DOLFIN objects
        ufc_element, ufc_dofmap_ptr = jit.ffc_jit(
            self.ufl_element(),
            form_compiler_parameters=None,
            mpi_comm=mesh.mpi_comm())

        ffi = cffi.FFI()
        ufc_element = dofmap.make_ufc_finite_element(
            ffi.cast("uintptr_t", ufc_element))
        cpp_element = cpp.fem.FiniteElement(ufc_element)

        ufc_dofmap = dofmap.make_ufc_dofmap(
            ffi.cast("uintptr_t", ufc_dofmap_ptr))
        cpp_dofmap = cpp.fem.create_dofmap(ufc_dofmap, mesh)

        # Initialize the cpp.FunctionSpace
        self._cpp_object = cpp.function.FunctionSpace(mesh, cpp_element,
                                                      cpp_dofmap)
Exemple #4
0
def TensorFunctionSpace(mesh: cpp.mesh.Mesh,
                        element: ElementMetaData,
                        shape=None,
                        symmetry: bool = None,
                        restriction=None):
    """Create tensor finite element (composition of scalar elements) function space."""

    e = ElementMetaData(*element)
    ufl_element = ufl.TensorElement(e.family, mesh.ufl_cell(), e.degree, shape, symmetry)
    return FunctionSpace(mesh, ufl_element)
def Circumradius(mesh: cpp.mesh.Mesh) -> ufl.Circumradius:
    """Return symbolic cell circumradius for given mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            R = Circumradius(mesh)

    """

    return ufl.Circumradius(mesh.ufl_domain())
def CellNormal(mesh: cpp.mesh.Mesh) -> ufl.CellNormal:
    """Return symbolic cell normal for given manifold mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            n = CellNormal(mesh)

    """

    return ufl.CellNormal(mesh.ufl_domain())
def SpatialCoordinate(mesh: cpp.mesh.Mesh) -> ufl.SpatialCoordinate:
    """Return symbolic physical coordinates for given mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            x = SpatialCoordinate(mesh)

    """

    return ufl.SpatialCoordinate(mesh.ufl_domain())
def CellVolume(mesh: cpp.mesh.Mesh) -> ufl.CellVolume:
    """Return symbolic cell volume for given mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            vol = CellVolume(mesh)

    """

    return ufl.CellVolume(mesh.ufl_domain())
def FacetNormal(mesh: cpp.mesh.Mesh) -> ufl.FacetNormal:
    """Return symbolic facet normal for given mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            n = FacetNormal(mesh)

    """

    return ufl.FacetNormal(mesh.ufl_domain())
def MaxFacetEdgeLength(mesh: cpp.mesh.Mesh) -> ufl.MaxFacetEdgeLength:
    """Return symbolic maximum facet edge length of a cell
    for given mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            maxfe = MaxFacetEdgeLength(mesh)

    """

    return ufl.MaxFacetEdgeLength(mesh.ufl_domain())
def MinCellEdgeLength(mesh: cpp.mesh.Mesh) -> ufl.MinCellEdgeLength:
    """Return symbolic minimum cell edge length of a cell
    for given mesh.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            mince = MinCellEdgeLength(mesh)

    """

    return ufl.MinCellEdgeLength(mesh.ufl_domain())
    def __init__(self, mesh: cpp.mesh.Mesh):
        """Create function that evaluates to the facet area/length on each
        facet.

        *Example of usage*

            .. code-block:: python

                mesh = UnitSquare(4,4)
                fa = FacetArea(mesh)

        """

        # Initialize C++ part
        self._cpp_object = cpp.function.FacetArea(mesh)

        # Initialize UFL part
        # NB! This is defined as a piecewise constant function for
        # each cell, not for each facet!
        ufl_element = ufl.FiniteElement("Discontinuous Lagrange",
                                        mesh.ufl_cell(), 0)
        super().__init__(domain=mesh.ufl_domain(),
                         element=ufl_element,
                         name="FacetArea")
def CellDiameter(mesh: cpp.mesh.Mesh) -> ufl.CellDiameter:
    r"""Return function cell diameter for given mesh.

    Note that diameter of cell :math:`K` is defined as
    :math:`\sup_{\mathbf{x, y} \in K} |\mathbf{x - y}|`.

    *Example of usage*

        .. code-block:: python

            mesh = UnitSquare(4,4)
            h = CellDiameter(mesh)

    """

    return ufl.CellDiameter(mesh.ufl_domain())