# -*- 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.
#
"""Zset tools
"""
from typing import Dict
import numpy as np
from Muscat.Helpers.Logger import Warning, Info
import Muscat.Containers.ElementsDescription as ED
from Muscat.Containers.Mesh import Mesh
import Muscat.IO.ZsetCatalog as ZSC
from Muscat.IO.ZsetCatalog import get_integration_for_element
from Muscat.IO.ZsetCatalog import get_shapes_at_ip_for_element
GetIntegrationForElement = get_integration_for_element
GetShapesAtIpForElement = get_shapes_at_ip_for_element
GeofNumber = {}
PermutationZSetToMuscat = {}
nbIntegrationsPoints = {}
GeofNumber["l2d1"] = ED.Point_1
GeofNumber["l2d2"] = ED.Bar_2
GeofNumber["line"] = ED.Bar_2
GeofNumber["quad"] = ED.Bar_3
GeofNumber["q4"] = ED.Quadrangle_4
GeofNumber["quad4"] = ED.Quadrangle_4
GeofNumber["c2d4"] = ED.Quadrangle_4
GeofNumber["cax8"] = ED.Quadrangle_4
GeofNumber["c2d8"] = ED.Quadrangle_8
PermutationZSetToMuscat["c2d8"] = [0, 2, 4, 6, 1, 3, 5, 7]
GeofNumber["c2d3"] = ED.Triangle_3
GeofNumber["s3d3"] = ED.Triangle_3
GeofNumber["s3d3r"] = ED.Triangle_3
GeofNumber["c2d6"] = ED.Triangle_6
PermutationZSetToMuscat["c2d6"] = [0, 2, 4, 1, 3, 5]
GeofNumber["c3d4"] = ED.Tetrahedron_4
GeofNumber["c3d4r"] = ED.Tetrahedron_4
GeofNumber["c3d5"] = ED.Pyramid_5
GeofNumber["c3d6"] = ED.Wedge_6
GeofNumber["c3d6r"] = ED.Wedge_6
GeofNumber["c3d8"] = ED.Hexahedron_8
GeofNumber["c3d8r"] = ED.Hexahedron_8
GeofNumber["c3d10"] = ED.Tetrahedron_10
PermutationZSetToMuscat["c3d10"] = [2, 0, 1, 9, 5, 3, 4, 8, 6, 7]
GeofNumber["c3d10r"] = ED.Tetrahedron_10
PermutationZSetToMuscat["c3d10r"] = [2, 0, 1, 9, 5, 3, 4, 8, 6, 7]
GeofNumber["c3d10_4"] = ED.Tetrahedron_10
PermutationZSetToMuscat["c3d10_4"] = [2, 0, 1, 9, 5, 3, 4, 8, 6, 7]
GeofNumber["c3d20"] = ED.Hexahedron_20
PermutationZSetToMuscat["c3d20"] = [0, 2, 4, 6, 12, 14, 16, 18, 1, 3, 5, 7, 13, 15, 17, 19, 8, 9, 10, 11]
GeofNumber["c3d20r"] = ED.Hexahedron_20
PermutationZSetToMuscat["c3d20r"] = [0, 2, 4, 6, 12, 14, 16, 18, 1, 3, 5, 7, 13, 15, 17, 19, 8, 9, 10, 11]
GeofNumber["t3"] = ED.Triangle_3
GeofNumber["t6"] = ED.Triangle_6
PermutationZSetToMuscat["t6"] = PermutationZSetToMuscat["c2d6"]
GeofNumber["s3d6"] = ED.Triangle_6
PermutationZSetToMuscat["s3d6"] = PermutationZSetToMuscat["c2d6"]
GeofNumber["q8"] = ED.Quadrangle_8
PermutationZSetToMuscat["q8"] = [0, 2, 4, 6, 1, 3, 5, 7]
GeofNumber["c3d15"] = ED.Wedge_15
PermutationZSetToMuscat["c3d15"] = [0, 2, 4, 9, 11, 13, 1, 3, 5, 10, 12, 14, 6, 7, 8]
GeofNumber["c3d15r"] = ED.Wedge_15
PermutationZSetToMuscat["c3d15r"] = [0, 2, 4, 9, 11, 13, 1, 3, 5, 10, 12, 14, 6, 7, 8]
GeofNumber["c3d13"] = ED.Pyramid_13
from Muscat.FE.IntegrationRules import MeshQuadrature, ElementaryQuadrature
[docs]def GetIntegrationRuleForZsetMesh(mesh: Mesh) -> MeshQuadrature:
"""Function the generate a integration rules for given unstructured mesh.
The mesh must contain the element field named "FE Names" with the zset element names
Parameters
----------
mesh : UnstructuredMesh
A mesh with a element filed named "FE Names"
Returns
-------
MeshQuadrature
containing the integration rule for the current mesh.
"""
from Muscat.FE.IntegrationRules import LagrangeIsoParamQuadrature
import copy
# res = copy.deepcopy(LagrangeIsoParam)
res = MeshQuadrature("ZsetLocalQuadrature")
if "FE Names" in mesh.elemFields:
elementTypeInTheMesh = np.unique(mesh.elemFields["FE Names"])
for zsetEType in elementTypeInTheMesh:
if zsetEType not in GeofNumber: # pragma: no cover
Warning(f"Cant find a ElementaryQuadrature for element {GeofNumber} using")
continue
pAntW = GetIntegrationForElement(zsetEType)
if pAntW:
points, weights = pAntW
res.AddElementaryQuadrature(ElementaryQuadrature(elementType=GeofNumber[zsetEType], points=points, weights=weights))
else:
Info(f"Element ({zsetEType}) does not have zset integration rule")
return res
for en in ZSC.element_names:
try:
nbIntegrationsPoints[en] = eval("ZSC." + en + "_ngp")
except:
nbIntegrationsPoints[en] = -1
[docs]def CheckIntegrity(GUI: bool = False) -> str:
from Muscat.TestData import GetTestDataPath
from Muscat.IO.GeofReader import ReadGeof
mesh = ReadGeof(GetTestDataPath() + "cube.geof")
print(GetIntegrationRuleForZsetMesh(mesh))
return "OK"
if __name__ == "__main__": # pragma: no cover
print(CheckIntegrity())