Coverage for src/beamme/core/element_volume.py: 98%
49 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-08 11:03 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-08 11:03 +0000
1# The MIT License (MIT)
2#
3# Copyright (c) 2018-2026 BeamMe Authors
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22"""This file defines the base volume element."""
24import numpy as _np
25import pyvista as _pv
26import vtk as _vtk
28from beamme.core.element import Element as _Element
29from beamme.core.vtk_writer import add_point_data_node_sets as _add_point_data_node_sets
32class VolumeElement(_Element):
33 """A base class for a volume element."""
35 # This class variables stores the information about the element shape in
36 # vtk. And the connectivity to the nodes.
37 vtk_cell_type = None
38 vtk_cell_type_legacy = None
39 vtk_topology: list = []
41 def __init__(self, nodes=None, data={}, **kwargs):
42 super().__init__(nodes=nodes, **kwargs)
43 self.data = data
45 def get_vtk(self, vtk_writer_beam, vtk_writer_solid, **kwargs):
46 """Add the representation of this element to the VTK writer as a
47 quad."""
49 # Check that the element has a valid vtk cell type.
50 if self.vtk_cell_type_legacy is None:
51 raise TypeError(f"vtk_cell_type_legacy for {type(self)} not set!")
53 # Dictionary with cell data.
54 cell_data = {}
56 # Dictionary with point data.
57 point_data = {}
59 # Array with nodal coordinates.
60 coordinates = _np.zeros([len(self.nodes), 3])
61 for i, node in enumerate(self.nodes):
62 coordinates[i, :] = node.coordinates
64 # Add the node sets connected to this element.
65 _add_point_data_node_sets(point_data, self.nodes)
67 # Add cell to writer.
68 indices = vtk_writer_solid.add_points(coordinates, point_data=point_data)
69 vtk_writer_solid.add_cell(
70 self.vtk_cell_type_legacy, indices[self.vtk_topology], cell_data=cell_data
71 )
74class VolumePoint(VolumeElement):
75 """A point volume element, e.g., for spheres."""
77 vtk_cell_type = _pv.CellType.VERTEX
80class VolumeWEDGE6(VolumeElement):
81 """A WEDGE6 volume element."""
83 vtk_cell_type_legacy = _vtk.vtkWedge
84 vtk_cell_type = _pv.CellType.WEDGE
85 vtk_topology = list(range(6))
88class VolumeHEX8(VolumeElement):
89 """A HEX8 volume element."""
91 vtk_cell_type_legacy = _vtk.vtkHexahedron
92 vtk_cell_type = _pv.CellType.HEXAHEDRON
93 vtk_topology = list(range(8))
96class VolumeTET4(VolumeElement):
97 """A TET4 volume element."""
99 vtk_cell_type_legacy = _vtk.vtkTetra
100 vtk_cell_type = _pv.CellType.TETRA
101 vtk_topology = list(range(4))
104class VolumeTET10(VolumeElement):
105 """A TET10 volume element."""
107 vtk_cell_type_legacy = _vtk.vtkQuadraticTetra
108 vtk_cell_type = _pv.CellType.QUADRATIC_TETRA
109 vtk_topology = list(range(10))
112class VolumeHEX20(VolumeElement):
113 """A HEX20 volume element."""
115 vtk_cell_type_legacy = _vtk.vtkQuadraticHexahedron
116 vtk_cell_type = _pv.CellType.QUADRATIC_HEXAHEDRON
117 vtk_topology = [
118 0,
119 1,
120 2,
121 3,
122 4,
123 5,
124 6,
125 7,
126 8,
127 9,
128 10,
129 11,
130 16,
131 17,
132 18,
133 19,
134 12,
135 13,
136 14,
137 15,
138 ]
141class VolumeHEX27(VolumeElement):
142 """A HEX27 volume element."""
144 vtk_cell_type_legacy = _vtk.vtkTriQuadraticHexahedron
145 vtk_cell_type = _pv.CellType.TRIQUADRATIC_HEXAHEDRON
146 vtk_topology = [
147 0,
148 1,
149 2,
150 3,
151 4,
152 5,
153 6,
154 7,
155 8,
156 9,
157 10,
158 11,
159 16,
160 17,
161 18,
162 19,
163 12,
164 13,
165 14,
166 15,
167 24,
168 22,
169 21,
170 23,
171 20,
172 25,
173 26,
174 ]