Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nightly #72

Merged
merged 48 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
bd491f2
fixed typo in docs
BALOGHBence Oct 23, 2023
83c4362
added missing type hints
BALOGHBence Oct 24, 2023
0b805a8
moved origo to cell center
BALOGHBence Oct 24, 2023
00d6f7f
added new tests
BALOGHBence Oct 24, 2023
efed799
added more tests
BALOGHBence Oct 25, 2023
91984b1
fixed utility functions
BALOGHBence Oct 25, 2023
d463208
added "geometry" to quadratures
BALOGHBence Oct 25, 2023
6ec53b7
added docstrings, type hints and new utilities
BALOGHBence Oct 25, 2023
b5e33cf
fixed docstrings
BALOGHBence Oct 25, 2023
c788882
moved module to new location
BALOGHBence Oct 25, 2023
6533c5f
removed duplicate item
BALOGHBence Oct 25, 2023
7a7c156
added tests for pointdata
BALOGHBence Oct 25, 2023
dc4ada6
added type and value checks for setters, docstrings and type hints
BALOGHBence Oct 25, 2023
92ef446
added Quadrature class to module
BALOGHBence Oct 25, 2023
f13ea87
added gauss point parser utility
BALOGHBence Oct 25, 2023
eef4243
fixed missing default value for argument
BALOGHBence Oct 25, 2023
1310d61
added example to docstring
BALOGHBence Oct 25, 2023
f623b9a
removed duplicate import
BALOGHBence Oct 25, 2023
8577f15
code formatting
BALOGHBence Oct 25, 2023
6f8fc53
added __init__.py
BALOGHBence Oct 25, 2023
40b21f9
fixed T6 shape functions
BALOGHBence Oct 30, 2023
98b5d91
added tests for T6 cell
BALOGHBence Oct 30, 2023
fb8180f
blacked
BALOGHBence Oct 30, 2023
7d18006
changed implementation order
BALOGHBence Nov 1, 2023
89e94f8
added triangle library
BALOGHBence Nov 1, 2023
d98000c
better type hints
BALOGHBence Nov 1, 2023
bd4632d
type hints and formatting
BALOGHBence Nov 1, 2023
13e3fd6
added type hint
BALOGHBence Nov 1, 2023
92fefb6
added new assertions
BALOGHBence Nov 1, 2023
a3b2862
added new examples
BALOGHBence Nov 1, 2023
69ac158
formatting with black
BALOGHBence Nov 1, 2023
c3bfb03
refactored Quadrature class
BALOGHBence Nov 1, 2023
2a4cf45
refactored area and volume calculations
BALOGHBence Nov 1, 2023
2803d32
refactored polycell class
BALOGHBence Nov 1, 2023
ce9954d
fixed 1d grid generation
BALOGHBence Nov 1, 2023
d8cd68d
bugfix, typehints and docstrings
BALOGHBence Nov 1, 2023
f031b3d
renamed function
BALOGHBence Nov 1, 2023
27e5007
renamed function
BALOGHBence Nov 1, 2023
0a1f31b
added tests
BALOGHBence Nov 1, 2023
de9bd8b
added abstract class
BALOGHBence Nov 1, 2023
0ca0856
updated numerical integration
BALOGHBence Nov 2, 2023
4348022
increased version number
BALOGHBence Nov 2, 2023
c44080c
added more tests
BALOGHBence Nov 3, 2023
367227f
improved data classes
BALOGHBence Nov 3, 2023
ea6a848
added 'natural' option to some quadratures
BALOGHBence Nov 3, 2023
4c78d9d
fixed positional arguments
BALOGHBence Nov 12, 2023
53cac86
fixed positional arguments
BALOGHBence Nov 12, 2023
e6f5870
Merge branch 'main' into nightly
BALOGHBence Nov 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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