Source code for Muscat.FE.Spaces.FESpaces
# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#
from typing import Any, NewType, Dict, Type, Union, Iterable
from enum import Enum, unique
import Muscat.MeshContainers.ElementsDescription as ED
from Muscat.Helpers.Factory import Factory
import Muscat.FE.Spaces.PointSpaces as PointSpaces
import Muscat.FE.Spaces.BarSpaces as BarSpaces
import Muscat.FE.Spaces.TriSpaces as TriSpaces
import Muscat.FE.Spaces.TetSpaces as TetSpaces
import Muscat.FE.Spaces.QuadSpaces as QuadSpaces
import Muscat.FE.Spaces.HexaSpaces as HexaSpaces
import Muscat.FE.Spaces.WedgeSpaces as WedgeSpaces
import Muscat.FE.Spaces.PyrSpaces as PyrSpaces
from Muscat.FE.Spaces.SpaceBase import SpaceBase
[docs]
@unique
class SpaceType(Enum):
NA : int = -1
LagrangeSpaceP0: int = 0
LagrangeSpaceP1: int = 1
LagrangeSpaceP2: int = 2
LagrangeSpaceGeo: int = 3
ConstantSpaceGlobal: int = 4
LagrangeSpaceP2Serendipity : int = 5
Numerical: int = 100
[docs]
class FESpace:
def __init__(self, spaceType: SpaceType):
super().__init__()
self.storage: Dict[ED.ElementType, SpaceBase] = {}
self.type = spaceType
self.name = spaceType.name
#if true means some shape function are shared across the elements; meaning we must compute a global numbering
self.hasSharedShapeFunctions = True
def __getitem__(self, elementType: Union[str, ED.ElementType]) -> SpaceBase:
return self.storage[ED.ElementType(elementType)]
def __setitem__(self, elementType: Union[str, ED.ElementType], value: SpaceBase):
self.storage[ED.ElementType(elementType)] = value
[docs]
def ToDict(self):
return {k: v for k, v in self.storage.items()}
[docs]
def items(self):
return self.storage.items()
[docs]
def InitSpaces(self):
for space in self.storage.values():
space.Create()
def __call__(self):
return self
[docs]
class FESpaceFactory(Factory):
_Catalog = {}
_SetCatalog = set()
[docs]
def RegisterFESpace(feSpace: FESpace):
return FESpaceFactory.RegisterClass(feSpace.type, feSpace, withError=True)
[docs]
def GetFESpaceByName(spaceName: str) -> FESpace:
return FESpaceFactory.Create(SpaceType[spaceName])
[docs]
def GetFESpaceByType(spaceType: SpaceType) -> FESpace:
return FESpaceFactory.Create(SpaceType(spaceType))
[docs]
def GetAvailableFESpacesTypes() -> Iterable[SpaceType]:
return FESpaceFactory.keys()
[docs]
def GetListOfAvailableFESpaces() -> Iterable[FESpace]:
return (v[1] for v in FESpaceFactory.AllEntries())
LagrangeSpaceGeo = FESpace(SpaceType.LagrangeSpaceGeo)
"""Isoparametric Lagrange space (if the mesh is quadratic the field is P2)."""
LagrangeSpaceGeo[ED.Point_1] = PointSpaces.Point_P0_Lagrange()
LagrangeSpaceGeo[ED.Bar_2] = BarSpaces.Bar_P1_Lagrange()
LagrangeSpaceGeo[ED.Bar_3] = BarSpaces.Bar_P2_Lagrange()
LagrangeSpaceGeo[ED.Triangle_3] = TriSpaces.Tri_P1_Lagrange()
LagrangeSpaceGeo[ED.Triangle_6] = TriSpaces.Tri_P2_Lagrange()
LagrangeSpaceGeo[ED.Tetrahedron_4] = TetSpaces.Tet_P1_Lagrange()
LagrangeSpaceGeo[ED.Tetrahedron_10] = TetSpaces.Tet_P2_Lagrange()
LagrangeSpaceGeo[ED.Quadrangle_4] = QuadSpaces.Quad_P1_Lagrange()
LagrangeSpaceGeo[ED.Quadrangle_8] = QuadSpaces.Quad8_P2_Lagrange()
LagrangeSpaceGeo[ED.Quadrangle_9] = QuadSpaces.Quad_P2_Lagrange()
LagrangeSpaceGeo[ED.Hexahedron_8] = HexaSpaces.Hexa_P1_Lagrange()
LagrangeSpaceGeo[ED.Hexahedron_20] = HexaSpaces.Hexa20_P2_Lagrange()
LagrangeSpaceGeo[ED.Hexahedron_27] = HexaSpaces.Hexa_P2_Lagrange()
LagrangeSpaceGeo[ED.Wedge_6] = WedgeSpaces.Wedge_P1_Lagrange()
LagrangeSpaceGeo[ED.Wedge_15] = WedgeSpaces.Wedge15_P2_Lagrange()
LagrangeSpaceGeo[ED.Wedge_18] = WedgeSpaces.Wedge_P2_Lagrange()
LagrangeSpaceGeo[ED.Pyramid_5] = PyrSpaces.Pyr_P1_Lagrange()
LagrangeSpaceGeo[ED.Pyramid_13] = PyrSpaces.Pyr13_P2_Lagrange()
LagrangeSpaceGeo[ED.Pyramid_14] = PyrSpaces.Pyr14_P2_Lagrange()
RegisterFESpace(LagrangeSpaceGeo())
ConstantSpaceGlobal = FESpace(SpaceType.ConstantSpaceGlobal)
"""Global constant space. Used to integrate expressions over a domain into a scalar."""
ConstantSpaceGlobal[ED.Point_1] = PointSpaces.Point_P0_Global()
ConstantSpaceGlobal[ED.Bar_2] = BarSpaces.Bar_P0_Global()
ConstantSpaceGlobal[ED.Bar_3] = BarSpaces.Bar_P0_Global()
ConstantSpaceGlobal[ED.Triangle_3] = TriSpaces.Tri_P0_Global()
ConstantSpaceGlobal[ED.Triangle_6] = TriSpaces.Tri_P0_Global()
ConstantSpaceGlobal[ED.Tetrahedron_4] = TetSpaces.Tet_P0_Global()
ConstantSpaceGlobal[ED.Tetrahedron_10] = TetSpaces.Tet_P0_Global()
ConstantSpaceGlobal[ED.Quadrangle_4] = QuadSpaces.Quad_P0_Global()
ConstantSpaceGlobal[ED.Quadrangle_8] = QuadSpaces.Quad_P0_Global()
ConstantSpaceGlobal[ED.Quadrangle_9] = QuadSpaces.Quad_P0_Global()
ConstantSpaceGlobal[ED.Hexahedron_8] = HexaSpaces.Hexa_P0_Global()
ConstantSpaceGlobal[ED.Hexahedron_20] = HexaSpaces.Hexa_P0_Global()
ConstantSpaceGlobal[ED.Hexahedron_27] = HexaSpaces.Hexa_P0_Global()
ConstantSpaceGlobal[ED.Wedge_6] = WedgeSpaces.Wedge_P0_Global()
ConstantSpaceGlobal[ED.Wedge_15] = WedgeSpaces.Wedge_P0_Global()
ConstantSpaceGlobal[ED.Wedge_18] = WedgeSpaces.Wedge_P0_Global()
ConstantSpaceGlobal[ED.Pyramid_5] = PyrSpaces.Pyr_P0_Global()
ConstantSpaceGlobal[ED.Pyramid_13] = PyrSpaces.Pyr_P0_Global()
ConstantSpaceGlobal[ED.Pyramid_14] = PyrSpaces.Pyr_P0_Global()
RegisterFESpace(ConstantSpaceGlobal())
LagrangeSpaceP0 = FESpace(SpaceType.LagrangeSpaceP0)
LagrangeSpaceP0.hasSharedShapeFunctions = False
"""Degree 0 Lagrange space. This space is constant per element (one value per element)."""
LagrangeSpaceP0[ED.Point_1] = PointSpaces.Point_P0_Lagrange()
LagrangeSpaceP0[ED.Bar_2] = BarSpaces.Bar_P0_Lagrange()
LagrangeSpaceP0[ED.Bar_3] = BarSpaces.Bar_P0_Lagrange()
LagrangeSpaceP0[ED.Triangle_3] = TriSpaces.Tri_P0_Lagrange()
LagrangeSpaceP0[ED.Triangle_6] = TriSpaces.Tri_P0_Lagrange()
LagrangeSpaceP0[ED.Tetrahedron_4] = TetSpaces.Tet_P0_Lagrange()
LagrangeSpaceP0[ED.Tetrahedron_10] = TetSpaces.Tet_P0_Lagrange()
LagrangeSpaceP0[ED.Quadrangle_4] = QuadSpaces.Quad_P0_Lagrange()
LagrangeSpaceP0[ED.Quadrangle_8] = QuadSpaces.Quad_P0_Lagrange()
LagrangeSpaceP0[ED.Quadrangle_9] = QuadSpaces.Quad_P0_Lagrange()
LagrangeSpaceP0[ED.Hexahedron_8] = HexaSpaces.Hexa_P0_Lagrange()
LagrangeSpaceP0[ED.Hexahedron_20] = HexaSpaces.Hexa_P0_Lagrange()
LagrangeSpaceP0[ED.Hexahedron_27] = HexaSpaces.Hexa_P0_Lagrange()
LagrangeSpaceP0[ED.Wedge_6] = WedgeSpaces.Wedge_P0_Lagrange()
LagrangeSpaceP0[ED.Wedge_15] = WedgeSpaces.Wedge_P0_Lagrange()
LagrangeSpaceP0[ED.Wedge_18] = WedgeSpaces.Wedge_P0_Lagrange()
LagrangeSpaceP0[ED.Pyramid_5] = PyrSpaces.Pyr_P0_Lagrange()
LagrangeSpaceP0[ED.Pyramid_13] = PyrSpaces.Pyr_P0_Lagrange()
LagrangeSpaceP0[ED.Pyramid_14] = PyrSpaces.Pyr_P0_Lagrange()
RegisterFESpace(LagrangeSpaceP0())
LagrangeSpaceP1 = FESpace(SpaceType.LagrangeSpaceP1)
"""Degree 1 Lagrange space. This space implement linear interpolation functions."""
LagrangeSpaceP1[ED.Point_1] = PointSpaces.Point_P0_Lagrange()
LagrangeSpaceP1[ED.Bar_2] = BarSpaces.Bar_P1_Lagrange()
LagrangeSpaceP1[ED.Bar_3] = BarSpaces.Bar_P1_Lagrange()
LagrangeSpaceP1[ED.Triangle_3] = TriSpaces.Tri_P1_Lagrange()
LagrangeSpaceP1[ED.Triangle_6] = TriSpaces.Tri_P1_Lagrange()
LagrangeSpaceP1[ED.Tetrahedron_4] = TetSpaces.Tet_P1_Lagrange()
LagrangeSpaceP1[ED.Tetrahedron_10] = TetSpaces.Tet_P1_Lagrange()
LagrangeSpaceP1[ED.Quadrangle_4] = QuadSpaces.Quad_P1_Lagrange()
LagrangeSpaceP1[ED.Quadrangle_8] = QuadSpaces.Quad_P1_Lagrange()
LagrangeSpaceP1[ED.Quadrangle_9] = QuadSpaces.Quad_P1_Lagrange()
LagrangeSpaceP1[ED.Hexahedron_8] = HexaSpaces.Hexa_P1_Lagrange()
LagrangeSpaceP1[ED.Hexahedron_20] = HexaSpaces.Hexa_P1_Lagrange()
LagrangeSpaceP1[ED.Hexahedron_27] = HexaSpaces.Hexa_P1_Lagrange()
LagrangeSpaceP1[ED.Wedge_6] = WedgeSpaces.Wedge_P1_Lagrange()
LagrangeSpaceP1[ED.Wedge_15] = WedgeSpaces.Wedge_P1_Lagrange()
LagrangeSpaceP1[ED.Wedge_18] = WedgeSpaces.Wedge_P1_Lagrange()
LagrangeSpaceP1[ED.Pyramid_5] = PyrSpaces.Pyr_P1_Lagrange()
LagrangeSpaceP1[ED.Pyramid_13] = PyrSpaces.Pyr_P1_Lagrange()
LagrangeSpaceP1[ED.Pyramid_14] = PyrSpaces.Pyr_P1_Lagrange()
RegisterFESpace(LagrangeSpaceP1())
LagrangeSpaceP2 = FESpace(SpaceType.LagrangeSpaceP2)
"""Degree 2 Lagrange space. This space implement quadratic interpolation functions."""
LagrangeSpaceP2[ED.Point_1] = PointSpaces.Point_P0_Lagrange()
LagrangeSpaceP2[ED.Bar_2] = BarSpaces.Bar_P2_Lagrange()
LagrangeSpaceP2[ED.Bar_3] = BarSpaces.Bar_P2_Lagrange()
LagrangeSpaceP2[ED.Triangle_3] = TriSpaces.Tri_P2_Lagrange()
LagrangeSpaceP2[ED.Triangle_6] = TriSpaces.Tri_P2_Lagrange()
LagrangeSpaceP2[ED.Tetrahedron_4] = TetSpaces.Tet_P2_Lagrange()
LagrangeSpaceP2[ED.Tetrahedron_10] = TetSpaces.Tet_P2_Lagrange()
LagrangeSpaceP2[ED.Quadrangle_4] = QuadSpaces.Quad_P2_Lagrange()
LagrangeSpaceP2[ED.Quadrangle_8] = QuadSpaces.Quad_P2_Lagrange()
LagrangeSpaceP2[ED.Quadrangle_9] = QuadSpaces.Quad_P2_Lagrange()
LagrangeSpaceP2[ED.Hexahedron_8] = HexaSpaces.Hexa_P2_Lagrange()
LagrangeSpaceP2[ED.Hexahedron_20] = HexaSpaces.Hexa_P2_Lagrange()
LagrangeSpaceP2[ED.Hexahedron_27] = HexaSpaces.Hexa_P2_Lagrange()
LagrangeSpaceP2[ED.Wedge_6] = WedgeSpaces.Wedge_P2_Lagrange()
LagrangeSpaceP2[ED.Wedge_15] = WedgeSpaces.Wedge_P2_Lagrange()
LagrangeSpaceP2[ED.Wedge_18] = WedgeSpaces.Wedge_P2_Lagrange()
LagrangeSpaceP2[ED.Pyramid_5] = PyrSpaces.Pyr14_P2_Lagrange()
LagrangeSpaceP2[ED.Pyramid_13] = PyrSpaces.Pyr14_P2_Lagrange()
LagrangeSpaceP2[ED.Pyramid_14] = PyrSpaces.Pyr14_P2_Lagrange()
RegisterFESpace(LagrangeSpaceP2())
LagrangeSpaceP2Serendipity = FESpace(SpaceType.LagrangeSpaceP2Serendipity)
LagrangeSpaceP2Serendipity[ED.Point_1] = PointSpaces.Point_P0_Lagrange()
LagrangeSpaceP2Serendipity[ED.Bar_2] = BarSpaces.Bar_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Bar_3] = BarSpaces.Bar_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Triangle_3] = TriSpaces.Tri_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Triangle_6] = TriSpaces.Tri_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Tetrahedron_4] = TetSpaces.Tet_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Tetrahedron_10] = TetSpaces.Tet_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Quadrangle_4] = QuadSpaces.Quad_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Quadrangle_8] = QuadSpaces.Quad8_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Quadrangle_9] = QuadSpaces.Quad_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Hexahedron_8] = HexaSpaces.Hexa_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Hexahedron_20] = HexaSpaces.Hexa20_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Hexahedron_27] = HexaSpaces.Hexa_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Wedge_6] = WedgeSpaces.Wedge_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Wedge_15] = WedgeSpaces.Wedge15_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Wedge_18] = WedgeSpaces.Wedge_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Pyramid_5] = PyrSpaces.Pyr14_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Pyramid_13] = PyrSpaces.Pyr13_P2_Lagrange()
LagrangeSpaceP2Serendipity[ED.Pyramid_14] = PyrSpaces.Pyr14_P2_Lagrange()
RegisterFESpace(LagrangeSpaceP2Serendipity())
[docs]
def InitAllSpaces() -> None:
"""Function to create all the spaces, this need to be called at the beginning of the app in a multi threated app"""
for feSpace in GetListOfAvailableFESpaces():
feSpace.InitSpaces()
[docs]
def CheckIntegrity(GUI: bool = False):
InitAllSpaces()
return "ok"
if __name__ == "__main__":
print(CheckIntegrity(True)) # pragma: no cover