Skip to content

Commit

Permalink
Merge pull request #72 from sigma-epsilon/nightly
Browse files Browse the repository at this point in the history
Nightly
  • Loading branch information
BALOGHBence committed Nov 13, 2023
2 parents 4bcbce5 + e6f5870 commit 339cbdf
Show file tree
Hide file tree
Showing 75 changed files with 3,546 additions and 1,614 deletions.
103 changes: 103 additions & 0 deletions docs/source/examples/shape_functions_Q9.ipynb

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions docs/source/examples/shape_functions_T6.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sigmaepsilon.mesh"
version = "2.1.0"
version = "2.2.0"
description = "A Python package to build, manipulate and analyze polygonal meshes."
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ sigmaepsilon.deepdict >=1.2.1, < 2.0.0
sigmaepsilon.math >= 1.0.1
fsspec >= 2023.1.0 # to use awkward.to_parquet
sectionproperties >= 2.1.3
meshio
meshio
triangle
10 changes: 6 additions & 4 deletions src/sigmaepsilon/mesh/cellapproximator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ def _approximator(
if shp_source_inverse is None:
assert isinstance(x_source, Iterable)
shp_source = shp_fnc(x_source) # (nP_source, nNE)

num_rows, num_columns = shp_source.shape
rank = np.linalg.matrix_rank(shp_source)
square_and_full_rank = (num_rows == num_columns) and rank == num_columns == num_rows
square_and_full_rank = (
num_rows == num_columns
) and rank == num_columns == num_rows
if not square_and_full_rank: # pragma: no cover
warnings.warn(
"The approximation involves the calculation of a generalized inverse "
"which probably results in loss of precision.",
SigmaEpsilonPerformanceWarning
SigmaEpsilonPerformanceWarning,
)

shp_source_inverse = generalized_inverse(shp_source)

if not isinstance(values_source, ndarray):
Expand Down
2 changes: 1 addition & 1 deletion src/sigmaepsilon/mesh/cells/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .t3 import T3 as Tri
from .q4 import Q4
from .q4 import Q4 as Quad
from.q8 import Q8
from .q8 import Q8
from .q9 import Q9
from .t6 import T6
from .h8 import H8
Expand Down
25 changes: 5 additions & 20 deletions src/sigmaepsilon/mesh/cells/h27.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from typing import Tuple, List
from functools import partial

import numpy as np
from numpy import ndarray
import sympy as sy

from sigmaepsilon.math.numint import gauss_points as gp

from ..geometry import PolyCellGeometry3d
from ..data.polycell import PolyCell
from ..utils.utils import cells_coords
from ..utils.cells.h27 import (
shp_H27_multi,
dshp_H27_multi,
volumes_H27,
shape_function_matrix_H27_multi,
monoms_H27,
)
from ..utils.cells.numint import Gauss_Legendre_Hex_Grid
from ..utils.numint import Gauss_Legendre_Hex_Grid


class H27(PolyCell):
Expand Down Expand Up @@ -56,7 +54,8 @@ class Geometry(PolyCellGeometry3d):
shape_function_derivative_evaluator: dshp_H27_multi
monomial_evaluator: monoms_H27
quadrature = {
"full": Gauss_Legendre_Hex_Grid(3, 3, 3),
"full": partial(Gauss_Legendre_Hex_Grid, 3, 3, 3),
"geometry": "full",
}

@classmethod
Expand Down Expand Up @@ -155,17 +154,3 @@ def master_center(cls) -> ndarray:
numpy.ndarray
"""
return np.array([0.0, 0.0, 0.0])

def volumes(self) -> ndarray:
"""
Returns the volumes of the cells.
Returns
-------
numpy.ndarray
"""
coords = self.source_coords()
topo = self.topology().to_numpy()
ecoords = cells_coords(coords, topo)
qpos, qweight = gp(3, 3, 3)
return volumes_H27(ecoords, qpos, qweight)
24 changes: 4 additions & 20 deletions src/sigmaepsilon/mesh/cells/h8.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from typing import Tuple, List
from functools import partial

from sympy import symbols
import numpy as np
from numpy import ndarray

from sigmaepsilon.math.numint import gauss_points as gp

from ..geometry import PolyCellGeometry3d
from ..data.polycell import PolyCell
from ..utils.utils import cells_coords
from ..utils.cells.h8 import (
shp_H8_multi,
dshp_H8_multi,
volumes_H8,
shape_function_matrix_H8_multi,
monoms_H8,
)
from ..utils.cells.numint import Gauss_Legendre_Hex_Grid
from ..utils.numint import Gauss_Legendre_Hex_Grid


class H8(PolyCell):
Expand Down Expand Up @@ -46,7 +43,8 @@ class Geometry(PolyCellGeometry3d):
shape_function_derivative_evaluator: dshp_H8_multi
monomial_evaluator: monoms_H8
quadrature = {
"full": Gauss_Legendre_Hex_Grid(2, 2, 2),
"full": partial(Gauss_Legendre_Hex_Grid, 2, 2, 2),
"geometry": "full",
}

@classmethod
Expand Down Expand Up @@ -104,17 +102,3 @@ def tetmap(cls) -> np.ndarray:
[[1, 2, 0, 5], [3, 0, 2, 7], [5, 4, 7, 0], [6, 5, 7, 2], [0, 2, 7, 5]],
dtype=int,
)

def volumes(self) -> ndarray:
"""
Returns the volumes of the cells.
Returns
-------
numpy.ndarray
"""
coords = self.source_coords()
topo = self.topology().to_numpy()
ecoords = cells_coords(coords, topo)
qpos, qweight = gp(2, 2, 2)
return volumes_H8(ecoords, qpos, qweight)
7 changes: 5 additions & 2 deletions src/sigmaepsilon/mesh/cells/l2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from functools import partial

from ..geometry import PolyCellGeometry1d
from ..data.polycell import PolyCell
from ..utils.cells.l2 import (
Expand All @@ -7,7 +9,7 @@
shape_function_matrix_L2_multi,
monoms_L2,
)
from ..utils.cells.numint import Gauss_Legendre_Line_Grid
from ..utils.numint import Gauss_Legendre_Line_Grid

__all__ = ["L2"]

Expand All @@ -25,5 +27,6 @@ class Geometry(PolyCellGeometry1d):
shape_function_derivative_evaluator: dshp_L2_multi
monomial_evaluator: monoms_L2
quadrature = {
"full": Gauss_Legendre_Line_Grid(2),
"full": partial(Gauss_Legendre_Line_Grid, 2),
"geometry": "full",
}
7 changes: 5 additions & 2 deletions src/sigmaepsilon/mesh/cells/l3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from functools import partial

from ..geometry import PolyCellGeometry1d
from ..data.polycell import PolyCell
from ..utils.cells.numint import Gauss_Legendre_Line_Grid
from ..utils.numint import Gauss_Legendre_Line_Grid
from ..utils.cells.l3 import monoms_L3


Expand All @@ -18,5 +20,6 @@ class Geometry(PolyCellGeometry1d):
vtk_cell_id = 21
monomial_evaluator: monoms_L3
quadrature = {
"full": Gauss_Legendre_Line_Grid(3),
"full": partial(Gauss_Legendre_Line_Grid, 3),
"geometry": "full",
}
6 changes: 4 additions & 2 deletions src/sigmaepsilon/mesh/cells/q4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from typing import Tuple, List

import numpy as np
from numpy import ndarray
from sympy import symbols
Expand All @@ -12,7 +13,7 @@
shape_function_matrix_Q4_multi,
monoms_Q4,
)
from ..utils.cells.numint import Gauss_Legendre_Quad_4
from ..utils.numint import Gauss_Legendre_Quad_4
from ..utils.topology import Q4_to_T3


Expand All @@ -31,7 +32,8 @@ class Geometry(PolyCellGeometry2d):
shape_function_derivative_evaluator: dshp_Q4_multi
monomial_evaluator: monoms_Q4
quadrature = {
"full": Gauss_Legendre_Quad_4(),
"full": Gauss_Legendre_Quad_4,
"geometry": "full",
}

@classmethod
Expand Down
6 changes: 4 additions & 2 deletions src/sigmaepsilon/mesh/cells/q8.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Tuple, List

import numpy as np
from numpy import ndarray
from sympy import symbols
Expand All @@ -11,7 +12,7 @@
shape_function_matrix_Q8_multi,
monoms_Q8,
)
from ..utils.cells.numint import Gauss_Legendre_Quad_9
from ..utils.numint import Gauss_Legendre_Quad_9
from ..utils.topology import Q8_to_T3, trimap_Q8


Expand All @@ -30,7 +31,8 @@ class Geometry(PolyCellGeometry2d):
shape_function_derivative_evaluator: dshp_Q8_multi
monomial_evaluator: monoms_Q8
quadrature = {
"full": Gauss_Legendre_Quad_9(),
"full": Gauss_Legendre_Quad_9,
"geometry": "full",
}

@classmethod
Expand Down
6 changes: 4 additions & 2 deletions src/sigmaepsilon/mesh/cells/q9.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Tuple, List

import numpy as np
from numpy import ndarray
from sympy import symbols
Expand All @@ -11,7 +12,7 @@
shape_function_matrix_Q9_multi,
monoms_Q9,
)
from ..utils.cells.numint import Gauss_Legendre_Quad_9
from ..utils.numint import Gauss_Legendre_Quad_9
from ..utils.topology import Q4_to_T3, Q9_to_Q4


Expand All @@ -30,7 +31,8 @@ class Geometry(PolyCellGeometry2d):
shape_function_derivative_evaluator: dshp_Q9_multi
monomial_evaluator: monoms_Q9
quadrature = {
"full": Gauss_Legendre_Quad_9(),
"full": Gauss_Legendre_Quad_9,
"geometry": "full",
}

@classmethod
Expand Down
43 changes: 35 additions & 8 deletions src/sigmaepsilon/mesh/cells/t3.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from typing import Tuple, List

import numpy as np
from numpy import ndarray
from sympy import symbols

from ..geometry import PolyCellGeometry2d
from ..data.polycell import PolyCell
from ..utils.cells.numint import Gauss_Legendre_Tri_1
from ..utils.numint import Gauss_Legendre_Tri_1
from ..utils.cells.t3 import (
shp_T3_multi,
dshp_T3_multi,
Expand All @@ -20,6 +21,17 @@
class T3(PolyCell):
"""
A class to handle 3-noded triangles.
Example
-------
>>> from sigmaepsilon.mesh import TriMesh, CartesianFrame, PointData, triangulate
>>> from sigmaepsilon.mesh.cells import T3 as CellData
>>> A = CartesianFrame(dim=3)
>>> coords, topo = triangulate(size=(800, 600), shape=(10, 10))
>>> pd = PointData(coords=coords, frame=A)
>>> cd = CellData(topo=topo)
>>> trimesh = TriMesh(pd, cd)
>>> trimesh.area()
"""

label = "T3"
Expand All @@ -32,11 +44,16 @@ class Geometry(PolyCellGeometry2d):
shape_function_derivative_evaluator: dshp_T3_multi
monomial_evaluator: monoms_T3
quadrature = {
"full": Gauss_Legendre_Tri_1(),
"full": Gauss_Legendre_Tri_1,
"geometry": "full",
}

@classmethod
def trimap(cls) -> ndarray:
"""
Returns a mapping used to transform the topology to triangles.
This is only implemented here for standardization.
"""
return np.array([[0, 1, 2]], dtype=int)

@classmethod
Expand All @@ -58,36 +75,46 @@ def polybase(cls) -> Tuple[List]:
@classmethod
def master_coordinates(cls) -> ndarray:
"""
Returns local coordinates of the cell.
Returns local coordinates of the master cell relative to the origo
of the master cell.
Returns
-------
numpy.ndarray
"""
return np.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]])
return np.array([[-1 / 3, -1 / 3], [2 / 3, -1 / 3], [-1 / 3, 2 / 3]])

@classmethod
def master_center(cls) -> ndarray:
"""
Returns the local coordinates of the center of the cell.
Returns the center of the master cell relative to the origo
of the master cell.
Returns
-------
numpy.ndarray
"""
return np.array([[1 / 3, 1 / 3]])
return np.array([[0.0, 0.0]], dtype=float)

def to_triangles(self) -> ndarray:
"""
Returns the topology as triangles.
"""
return self.topology().to_numpy()

def areas(self, *args, **kwargs) -> ndarray:
def areas(self, *_, **__) -> ndarray:
"""
Returns the areas of the cells as an 1d NumPy array.
"""
coords = self.container.source().coords()
topo = self.topology().to_numpy()
ec = points_of_cells(coords, topo, local_axes=self.frames)
return area_tri_bulk(ec)

@classmethod
def from_TriMesh(cls, *args, coords=None, topo=None, **kwargs):
def from_TriMesh(
cls, *args, coords: ndarray = None, topo: ndarray = None, **__
) -> Tuple[ndarray, ndarray]:
from sigmaepsilon.mesh.data.trimesh import TriMesh

if len(args) > 0 and isinstance(args[0], TriMesh):
Expand Down
Loading

0 comments on commit 339cbdf

Please sign in to comment.