Coverage for src/meshpy/core/conf.py: 99%

75 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-14 04:22 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2018-2025 MeshPy 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 module defines a global object that manages all kind of stuff regarding 

23meshpy.""" 

24 

25from enum import Enum as _Enum 

26from enum import auto as _auto 

27 

28 

29class Geometry(_Enum): 

30 """Enum for geometry types.""" 

31 

32 point = _auto() 

33 line = _auto() 

34 surface = _auto() 

35 volume = _auto() 

36 

37 

38class BoundaryCondition(_Enum): 

39 """Enum for boundary condition types.""" 

40 

41 dirichlet = _auto() 

42 neumann = _auto() 

43 locsys = _auto() 

44 moment_euler_bernoulli = _auto() 

45 beam_to_beam_contact = _auto() 

46 beam_to_solid_volume_meshtying = _auto() 

47 beam_to_solid_surface_meshtying = _auto() 

48 beam_to_solid_surface_contact = _auto() 

49 point_coupling = _auto() 

50 point_coupling_penalty = _auto() 

51 

52 def is_point_coupling_pairwise(self) -> bool: 

53 """Check whether the point coupling condition should be applied 

54 pairwise. 

55 

56 Returns: 

57 bool: True if the coupling should be applied individually between pairs of nodes, 

58 rather than to the entire geometry set as a whole. 

59 """ 

60 if self == self.point_coupling: 

61 return False 

62 elif self == self.point_coupling_penalty: 

63 return True 

64 else: 

65 raise TypeError(f"Got unexpected coupling type: {self}") 

66 

67 

68class BeamType(_Enum): 

69 """Enum for beam types.""" 

70 

71 reissner = _auto() 

72 kirchhoff = _auto() 

73 euler_bernoulli = _auto() 

74 

75 

76class CouplingDofType(_Enum): 

77 """Enum for coupling types.""" 

78 

79 fix = _auto() 

80 joint = _auto() 

81 

82 

83class BeamToSolidInteractionType(_Enum): 

84 """Enum for beam-to-solid interaction types.""" 

85 

86 volume_meshtying = _auto() 

87 surface_meshtying = _auto() 

88 

89 

90class DoubleNodes(_Enum): 

91 """Enum for handing double nodes in Neumann conditions.""" 

92 

93 remove = _auto() 

94 keep = _auto() 

95 

96 

97class GeometricSearchAlgorithm(_Enum): 

98 """Enum for VTK value types.""" 

99 

100 automatic = _auto() 

101 brute_force_cython = _auto() 

102 binning_cython = _auto() 

103 boundary_volume_hierarchy_arborx = _auto() 

104 

105 

106class VTKGeometry(_Enum): 

107 """Enum for VTK geometry types (for now cells and points).""" 

108 

109 point = _auto() 

110 cell = _auto() 

111 

112 

113class VTKTensor(_Enum): 

114 """Enum for VTK tensor types.""" 

115 

116 scalar = _auto() 

117 vector = _auto() 

118 

119 

120class VTKType(_Enum): 

121 """Enum for VTK value types.""" 

122 

123 int = _auto() 

124 float = _auto() 

125 

126 

127class MeshPy(object): 

128 """A global object that stores options for the whole MeshPy application.""" 

129 

130 def __init__(self): 

131 self.set_default_values() 

132 

133 # Geometry types. 

134 self.geo = Geometry 

135 

136 # Boundary conditions types. 

137 self.bc = BoundaryCondition 

138 

139 # Beam types. 

140 self.beam = BeamType 

141 

142 # Beam-to-solid interaction types. 

143 self.beam_to_solid = BeamToSolidInteractionType 

144 

145 # Coupling types. 

146 self.coupling_dof = CouplingDofType 

147 

148 # Handling of multiple nodes in Neumann bcs. 

149 self.double_nodes = DoubleNodes 

150 

151 # Geometric search options. 

152 self.geometric_search_algorithm = GeometricSearchAlgorithm 

153 

154 # VTK types. 

155 # Geometry types, cell or point. 

156 self.vtk_geo = VTKGeometry 

157 # Tensor types, scalar or vector. 

158 self.vtk_tensor = VTKTensor 

159 # Data types, integer or float. 

160 self.vtk_type = VTKType 

161 

162 def set_default_values(self): 

163 """Set the configuration to the default values.""" 

164 

165 # Set the epsilons for comparison of different types of values. 

166 self.eps_quaternion = 1e-10 

167 self.eps_pos = 1e-10 

168 self.eps_knot_vector = 1e-10 

169 

170 # Allow the rotation of beams when connected and the triads do not 

171 # match. 

172 self.allow_beam_rotation = True 

173 

174 # Number of digits for node set output (this will be set in the 

175 # Mesh.get_unique_geometry_sets() method. 

176 self.vtk_node_set_format = "{:05}" 

177 # Nan values for vtk data, since we currently can't set nan explicitly. 

178 self.vtk_nan_int = -1 

179 self.vtk_nan_float = 0.0 

180 

181 # Check for overlapping elements when creating an input file. 

182 self.check_overlapping_elements = True 

183 

184 # Lines to be added to each created input file 

185 self.input_file_meshpy_header = [ 

186 "-" * 40, 

187 "This input file was created with MeshPy.", 

188 "Copyright (c) 2018-2025 MeshPy Authors", 

189 "https://imcs-compsim.github.io/meshpy/", 

190 "-" * 40, 

191 ] 

192 

193 

194mpy = MeshPy()