Esempio n. 1
0
def EnrichedFunctionSpace(spaces):
    """
    Create enriched finite element function space.

    *Arguments*
        spaces
            a list (or tuple) of :py:class:`FunctionSpaces
            <dolfin.functions.functionspace.FunctionSpace>`.

    *Usage*
        The function space may be created by

        .. code-block:: python

            V = EnrichedFunctionSpace(spaces)

    """
    cpp.deprecation("'EnrichedFunctionSpace'", "1.7.0", "2.0.0",
                    "Use 'FunctionSpace(mesh, EnrichedElement(...))'.")

    # Check arguments
    if not len(spaces) > 0:
        cpp.dolfin_error("functionspace.py", "create enriched function space",
                         "Need at least one subspace")
    if not all(isinstance(V, FunctionSpace) for V in spaces):
        cpp.dolfin_error("functionspace.py", "create enriched function space",
                         "Invalid subspaces: " + str(spaces))

    # Get common mesh and constrained_domain, must all be the same
    mesh, constrained_domain = _get_common_mesh_and_constrained_domain(spaces)

    # Create element
    element = ufl.EnrichedElement(*[V.ufl_element() for V in spaces])

    return FunctionSpace(mesh, element, constrained_domain=constrained_domain)
Esempio n. 2
0
def reconstruct_element(element, cell=None):
    """Rebuild element with a new cell."""
    if cell is None:
        return element
    if isinstance(element, ufl.FiniteElement):
        family = element.family()
        degree = element.degree()
        return ufl.FiniteElement(family, cell, degree)
    if isinstance(element, ufl.VectorElement):
        family = element.family()
        degree = element.degree()
        dim = len(element.sub_elements())
        return ufl.VectorElement(family, cell, degree, dim)
    if isinstance(element, ufl.TensorElement):
        family = element.family()
        degree = element.degree()
        shape = element.value_shape()
        symmetry = element.symmetry()
        return ufl.TensorElement(family, cell, degree, shape, symmetry)
    if isinstance(element, ufl.EnrichedElement):
        eles = [
            reconstruct_element(sub, cell=cell) for sub in element._elements
        ]
        return ufl.EnrichedElement(*eles)
    if isinstance(element, ufl.RestrictedElement):
        return ufl.RestrictedElement(
            reconstruct_element(element.sub_element(), cell=cell),
            element.restriction_domain())
    if isinstance(element,
                  (ufl.TraceElement, ufl.InteriorElement, ufl.HDivElement,
                   ufl.HCurlElement, ufl.BrokenElement, ufl.FacetElement)):
        return type(element)(reconstruct_element(element._element, cell=cell))
    if isinstance(element, ufl.OuterProductElement):
        return ufl.OuterProductElement(element._A, element._B, cell=cell)
    if isinstance(element, ufl.OuterProductVectorElement):
        dim = len(element.sub_elements())
        return ufl.OuterProductVectorElement(element._A,
                                             element._B,
                                             cell=cell,
                                             dim=dim)
    if isinstance(element, ufl.OuterProductTensorElement):
        return element.reconstruct(cell=cell)
    if isinstance(element, ufl.MixedElement):
        eles = [
            reconstruct_element(sub, cell=cell)
            for sub in element.sub_elements()
        ]
        return ufl.MixedElement(*eles)
    raise NotImplementedError(
        "Don't know how to reconstruct element of type %s" % type(element))
Esempio n. 3
0
    def __init__(self, spaces):
        """
        Create enriched finite element function space.

        *Arguments*
            spaces
                a list (or tuple) of :py:class:`FunctionSpaces
                <dolfin.functions.functionspace.FunctionSpace>`.

        *Usage*
            The function space may be created by

            .. code-block:: python

                V = EnrichedFunctionSpace(spaces)

        """

        # Check arguments
        if not len(spaces) > 0:
            cpp.dolfin_error("functionspace.py",
                             "create enriched function space",
                             "Need at least one subspace")
        if not all(isinstance(V, FunctionSpaceBase) for V in spaces):
            cpp.dolfin_error("functionspace.py",
                             "create enriched function space",
                             "Invalid subspaces: " + str(spaces))

        # Create element
        element = ufl.EnrichedElement(*[V.ufl_element() for V in spaces])

        # Get common mesh and constrained_domain, must all be the same
        mesh, constrained_domain = _get_common_mesh_and_constrained_domain(
            spaces, "enriched")

        # Initialize base class
        FunctionSpaceBase.__init__(self,
                                   mesh,
                                   element,
                                   constrained_domain=constrained_domain)
Esempio n. 4
0
    def __init__(self, spaces):
        """
        Create enriched finite element function space.

        *Arguments*
            spaces
                a list (or tuple) of :py:class:`FunctionSpaces
                <dolfin.functions.functionspace.FunctionSpace>`.

        *Usage*
            The function space may be created by

            .. code-block:: python

                V = EnrichedFunctionSpace(spaces)

        """

        # Check arguments
        if not len(spaces) > 0:
            cpp.dolfin_error("functionspace.py",
                             "create enriched function space",
                             "Need at least one subspace")
        if not all(isinstance(V, FunctionSpaceBase) for V in spaces):
            cpp.dolfin_error("functionspace.py",
                             "create enriched function space",
                             "Invalid subspaces: " + str(spaces))
        #if not all(V.mesh() == spaces[0].mesh() for V in spaces):
        #    cpp.dolfin_error("functionspace.py",
        # "Nonmatching meshes for mixed function space: " + str([V.mesh() for V in spaces]))

        # Create element
        element = ufl.EnrichedElement(*[V.ufl_element() for V in spaces])

        # Initialize base class
        FunctionSpaceBase.__init__(self, spaces[0].mesh(), element, constrained_domain=spaces[0].dofmap().constrained_domain)