Skip to content

Commit

Permalink
Add MeshContainer.as_vertex_mesh()
Browse files Browse the repository at this point in the history
  • Loading branch information
adtzlr committed Feb 15, 2025
1 parent 46b5093 commit 76eba51
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/felupe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
RegionTriangleMINI,
RegionTriQuadraticHexahedron,
RegionTriQuadraticHexahedronBoundary,
RegionVertex,
)
from .tools import hello_world, newtonrhapson, project, runs_on, save, topoints
from .view import ViewField, ViewMesh
Expand Down Expand Up @@ -235,6 +236,7 @@
"RegionTriangleMINI",
"RegionTriQuadraticHexahedron",
"RegionTriQuadraticHexahedronBoundary",
"RegionVertex",
"newtonrhapson",
"project",
"save",
Expand Down
2 changes: 2 additions & 0 deletions src/felupe/element/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ._quad import BiQuadraticQuad, ConstantQuad, Quad, QuadraticQuad
from ._tetra import QuadraticTetra, Tetra, TetraMINI
from ._triangle import QuadraticTriangle, Triangle, TriangleMINI
from ._vertex import Vertex

__all__ = [
"Element",
Expand All @@ -37,4 +38,5 @@
"lagrange_line",
"lagrange_quad",
"lagrange_hexahedron",
"Vertex",
]
47 changes: 47 additions & 0 deletions src/felupe/element/_vertex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
"""
This file is part of FElupe.
FElupe is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FElupe is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FElupe. If not, see <http://www.gnu.org/licenses/>.
"""

import numpy as np

from ._base import Element


class Vertex(Element):
r"""A vertex element formulation with constant shape functions.
Notes
-----
The vertex element is defined by one point.
"""

def __init__(self):
self.points = np.array([[0.0]])
self.cells = np.arange(len(self.points)).reshape(1, -1)
self.cell_type = "vertex"

Check warning on line 35 in src/felupe/element/_vertex.py

View check run for this annotation

Codecov / codecov/patch

src/felupe/element/_vertex.py#L33-L35

Added lines #L33 - L35 were not covered by tests

def function(self, r):
"Return the shape functions at given coordinate (r)."
return np.ones(1)

Check warning on line 39 in src/felupe/element/_vertex.py

View check run for this annotation

Codecov / codecov/patch

src/felupe/element/_vertex.py#L39

Added line #L39 was not covered by tests

def gradient(self, r):
"Return the gradient of shape functions at given coordinate (r)."
return np.zeros((1, 1))

Check warning on line 43 in src/felupe/element/_vertex.py

View check run for this annotation

Codecov / codecov/patch

src/felupe/element/_vertex.py#L43

Added line #L43 was not covered by tests

def hessian(self, rs):
"Return the hessian of shape functions at given coordinate (r)."
return np.zeros((1, 1, 1))

Check warning on line 47 in src/felupe/element/_vertex.py

View check run for this annotation

Codecov / codecov/patch

src/felupe/element/_vertex.py#L47

Added line #L47 was not covered by tests
5 changes: 5 additions & 0 deletions src/felupe/mesh/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ def as_meshio(self, combined=True, **kwargs):

return meshio.Mesh(self.points, cells, **kwargs)

def as_vertex_mesh(self):
"Return a merged vertex-mesh."
cells = np.unique([mesh.cells.ravel() for mesh in self.meshes]).reshape(-1, 1)
return Mesh(self.points, cells, cell_type=None)

Check warning on line 285 in src/felupe/mesh/_container.py

View check run for this annotation

Codecov / codecov/patch

src/felupe/mesh/_container.py#L284-L285

Added lines #L284 - L285 were not covered by tests

def copy(self):
"Return a deepcopy of the mesh container."
return deepcopy(self)
Expand Down
2 changes: 2 additions & 0 deletions src/felupe/region/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
RegionTriangleMINI,
RegionTriQuadraticHexahedron,
RegionTriQuadraticHexahedronBoundary,
RegionVertex,
)

__all__ = [
Expand All @@ -48,4 +49,5 @@
"RegionTriangleMINI",
"RegionTriQuadraticHexahedron",
"RegionTriQuadraticHexahedronBoundary",
"RegionVertex",
]
11 changes: 11 additions & 0 deletions src/felupe/region/_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
Triangle,
TriangleMINI,
TriQuadraticHexahedron,
Vertex,
)
from ..mesh import Mesh
from ..quadrature import GaussLegendre, GaussLegendreBoundary
Expand Down Expand Up @@ -852,3 +853,13 @@ class RegionQuadraticTetra(Region):
def __init__(self, mesh, quadrature=TetraQuadrature(order=2), grad=True, **kwargs):
element = QuadraticTetra()
super().__init__(mesh, element, quadrature, grad=grad, **kwargs)


class RegionVertex(Region):
"A region with a vertex element."

def __init__(
self, mesh, quadrature=GaussLegendre(order=0, dim=1), grad=False, **kwargs
):
element = Vertex()
super().__init__(mesh, element, quadrature, grad=grad, **kwargs)

Check warning on line 865 in src/felupe/region/_templates.py

View check run for this annotation

Codecov / codecov/patch

src/felupe/region/_templates.py#L864-L865

Added lines #L864 - L865 were not covered by tests

0 comments on commit 76eba51

Please sign in to comment.