Coverage for src/beamme/core/element_volume.py: 97%

39 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-09-29 11:30 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2018-2025 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.""" 

23 

24import numpy as _np 

25import vtk as _vtk 

26 

27from beamme.core.element import Element as _Element 

28from beamme.core.vtk_writer import add_point_data_node_sets as _add_point_data_node_sets 

29 

30 

31class VolumeElement(_Element): 

32 """A base class for a volume element.""" 

33 

34 # This class variables stores the information about the element shape in 

35 # vtk. And the connectivity to the nodes. 

36 vtk_cell_type = None 

37 vtk_topology: list = [] 

38 

39 def __init__(self, nodes=None, data={}, **kwargs): 

40 super().__init__(nodes=nodes, material=None, **kwargs) 

41 self.data = data 

42 

43 def get_vtk(self, vtk_writer_beam, vtk_writer_solid, **kwargs): 

44 """Add the representation of this element to the VTK writer as a 

45 quad.""" 

46 

47 # Check that the element has a valid vtk cell type. 

48 if self.vtk_cell_type is None: 

49 raise TypeError(f"vtk_cell_type for {type(self)} not set!") 

50 

51 # Dictionary with cell data. 

52 cell_data = {} 

53 

54 # Dictionary with point data. 

55 point_data = {} 

56 

57 # Array with nodal coordinates. 

58 coordinates = _np.zeros([len(self.nodes), 3]) 

59 for i, node in enumerate(self.nodes): 

60 coordinates[i, :] = node.coordinates 

61 

62 # Add the node sets connected to this element. 

63 _add_point_data_node_sets(point_data, self.nodes) 

64 

65 # Add cell to writer. 

66 indices = vtk_writer_solid.add_points(coordinates, point_data=point_data) 

67 vtk_writer_solid.add_cell( 

68 self.vtk_cell_type, indices[self.vtk_topology], cell_data=cell_data 

69 ) 

70 

71 

72class VolumeWEDGE6(VolumeElement): 

73 """A WEDGE6 volume element.""" 

74 

75 vtk_cell_type = _vtk.vtkWedge 

76 vtk_topology = list(range(6)) 

77 

78 

79class VolumeHEX8(VolumeElement): 

80 """A HEX8 volume element.""" 

81 

82 vtk_cell_type = _vtk.vtkHexahedron 

83 vtk_topology = list(range(8)) 

84 

85 

86class VolumeTET4(VolumeElement): 

87 """A TET4 volume element.""" 

88 

89 vtk_cell_type = _vtk.vtkTetra 

90 vtk_topology = list(range(4)) 

91 

92 

93class VolumeTET10(VolumeElement): 

94 """A TET10 volume element.""" 

95 

96 vtk_cell_type = _vtk.vtkQuadraticTetra 

97 vtk_topology = list(range(10)) 

98 

99 

100class VolumeHEX20(VolumeElement): 

101 """A HEX20 volume element.""" 

102 

103 vtk_cell_type = _vtk.vtkQuadraticHexahedron 

104 vtk_topology = [ 

105 0, 

106 1, 

107 2, 

108 3, 

109 4, 

110 5, 

111 6, 

112 7, 

113 8, 

114 9, 

115 10, 

116 11, 

117 16, 

118 17, 

119 18, 

120 19, 

121 12, 

122 13, 

123 14, 

124 15, 

125 ] 

126 

127 

128class VolumeHEX27(VolumeElement): 

129 """A HEX27 volume element.""" 

130 

131 vtk_cell_type = _vtk.vtkTriQuadraticHexahedron 

132 vtk_topology = [ 

133 0, 

134 1, 

135 2, 

136 3, 

137 4, 

138 5, 

139 6, 

140 7, 

141 8, 

142 9, 

143 10, 

144 11, 

145 16, 

146 17, 

147 18, 

148 19, 

149 12, 

150 13, 

151 14, 

152 15, 

153 24, 

154 22, 

155 21, 

156 23, 

157 20, 

158 25, 

159 26, 

160 ]