示例#1
0
文件: function.py 项目: RuruX/dolfinx
def VectorFunctionSpace(mesh: cpp.mesh.Mesh,
                        element: ElementMetaData,
                        dim=None,
                        restriction=None) -> "FunctionSpace":
    """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)
示例#2
0
    def __init__(self,
                 mesh: cpp.mesh.Mesh,
                 element: typing.Union[ufl.FiniteElementBase, ElementMetaData],
                 cppV: typing.Optional[cpp.fem.FunctionSpace] = None,
                 form_compiler_parameters: dict = {},
                 jit_parameters: dict = {}):
        """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 DOLFINx objects
        ufc_element, ufc_dofmap = jit.ffcx_jit(
            mesh.mpi_comm(),
            self.ufl_element(),
            form_compiler_parameters=form_compiler_parameters,
            jit_parameters=jit_parameters)

        ffi = cffi.FFI()
        cpp_element = cpp.fem.FiniteElement(
            ffi.cast("uintptr_t", ffi.addressof(ufc_element)))
        cpp_dofmap = cpp.fem.create_dofmap(
            mesh.mpi_comm(), ffi.cast("uintptr_t", ffi.addressof(ufc_dofmap)),
            mesh.topology)

        # Initialize the cpp.FunctionSpace
        self._cpp_object = cpp.fem.FunctionSpace(mesh, cpp_element, cpp_dofmap)
示例#3
0
文件: function.py 项目: RuruX/dolfinx
def TensorFunctionSpace(mesh: cpp.mesh.Mesh,
                        element: ElementMetaData,
                        shape=None,
                        symmetry: bool = None,
                        restriction=None) -> "FunctionSpace":
    """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)
示例#4
0
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())
示例#5
0
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())
示例#6
0
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())
示例#7
0
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())
示例#8
0
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())
示例#9
0
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())
示例#10
0
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())
示例#11
0
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())
示例#12
0
 def from_cpp(cls, obj: _cpp.mesh.Mesh, domain: ufl.Mesh) -> Mesh:
     """Create Mesh object from a C++ Mesh object"""
     obj._ufl_domain = domain
     obj.__class__ = Mesh
     domain._ufl_cargo = obj
     return obj