MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / functionspace

Function functionspace

python/dolfinx/fem/function.py:645–708  ·  view source on GitHub ↗

Create a finite element function space. Args: mesh: Mesh that space is defined on. element: Finite element description. Returns: A function space.

(
    mesh: Mesh,
    element: (
        ufl.finiteelement.AbstractFiniteElement
        | ElementMetaData
        | tuple[str, int]
        | tuple[str, int, tuple]
        | tuple[str, int, tuple, bool]
    ),
)

Source from the content-addressed store, hash-verified

643
644
645def functionspace(
646 mesh: Mesh,
647 element: (
648 ufl.finiteelement.AbstractFiniteElement
649 | ElementMetaData
650 | tuple[str, int]
651 | tuple[str, int, tuple]
652 | tuple[str, int, tuple, bool]
653 ),
654) -> FunctionSpace:
655 """Create a finite element function space.
656
657 Args:
658 mesh: Mesh that space is defined on.
659 element: Finite element description.
660
661 Returns:
662 A function space.
663 """
664 # Create UFL element
665 dtype = mesh.geometry.x.dtype
666 try:
667 e = ElementMetaData(*element) # type: ignore
668 ufl_e = basix.ufl.element(
669 e.family,
670 mesh.basix_cell(), # type: ignore
671 e.degree,
672 shape=e.shape,
673 symmetry=e.symmetry,
674 dtype=dtype,
675 )
676 except TypeError:
677 ufl_e = element # type: ignore
678
679 # Check that element and mesh cell types match
680 if ((domain := mesh.ufl_domain()) is None) or ufl_e.cell != domain.ufl_cell():
681 raise ValueError("Non-matching UFL cell and mesh cell shapes.")
682 # Create DOLFINx objects
683 element = finiteelement(mesh.topology.cell_type, ufl_e, dtype) # type: ignore
684
685 if ufl_e.is_real:
686 cpp_dofmap = _cpp.fem.build_real_element_dofmap(
687 mesh.topology._cpp_object,
688 element.basix_element.entity_dofs, # type: ignore
689 element.basix_element.entity_closure_dofs, # type: ignore
690 int(np.prod(element.value_shape)), # type: ignore
691 )
692 else:
693 cpp_dofmap = _cpp.fem.create_dofmap(
694 mesh.comm,
695 mesh.topology._cpp_object,
696 element._cpp_object, # type: ignore
697 )
698 assert np.issubdtype(mesh.geometry.x.dtype, element.dtype), ( # type: ignore
699 "Mesh and element dtype are not compatible."
700 )
701
702 # Initialize the cpp.FunctionSpace

Callers 15

test_linear_pdeMethod · 0.90
test_nonlinear_pdeMethod · 0.90
VFunction · 0.90
WFunction · 0.90
QFunction · 0.90
test_eval_manifoldFunction · 0.90
test_cffi_expressionFunction · 0.90
test_tabulate_dofsFunction · 0.90
test_entity_dofsFunction · 0.90

Calls 9

finiteelementFunction · 0.90
ElementMetaDataClass · 0.85
basix_cellMethod · 0.80
ufl_domainMethod · 0.80
ufl_cellMethod · 0.80
create_dofmapMethod · 0.80
FunctionSpaceClass · 0.70
elementMethod · 0.45

Tested by 15

test_linear_pdeMethod · 0.72
test_nonlinear_pdeMethod · 0.72
VFunction · 0.72
WFunction · 0.72
QFunction · 0.72
test_eval_manifoldFunction · 0.72
test_cffi_expressionFunction · 0.72
test_tabulate_dofsFunction · 0.72
test_entity_dofsFunction · 0.72