Coverage for lasso/femzip/fz_config.py: 95%

113 statements  

« prev     ^ index     » next       coverage.py v7.2.4, created at 2023-04-28 18:42 +0100

1from typing import Dict, Union, Tuple 

2 

3import enum 

4 

5 

6def get_last_int_of_line(line: str) -> Tuple[str, Union[None, int]]: 

7 """Searches an integer in the line 

8 

9 Parameters 

10 ---------- 

11 line: str 

12 line to be searched 

13 

14 Returns 

15 ------- 

16 rest_line: str 

17 rest of line before match 

18 number: Union[int, None] 

19 number or None if not found 

20 """ 

21 for entry in line.split(): 

22 if entry.isdigit(): 

23 return line[: line.rfind(entry)], int(entry) 

24 return line, None 

25 

26 

27class FemzipVariableCategory(enum.Enum): 

28 """Enum for femzip variable categories 

29 

30 Attributes 

31 ---------- 

32 GEOMETRY: int 

33 -5 

34 PART: int 

35 -2 

36 GLOBAL: int 

37 -1 

38 NODE: int 

39 0 

40 SOLID: int 

41 1 

42 THICK_SHELL: int 

43 2 

44 BEAM: int 

45 3 

46 TOOLS: int 

47 4 

48 SHELL: int 

49 5 

50 SPH: int 

51 6 

52 FPM: int 

53 7 

54 CFD: int 

55 8 

56 CPM_FLOAT_VAR: int 

57 9 

58 CPM_AIRBAG: int 

59 10 

60 CPM_INT_VAR: int 

61 11 

62 RADIOSS_STATE_DATA: int 

63 12 

64 HEXA20: int 

65 13 

66 """ 

67 

68 GEOMETRY = -5 

69 # REST_OF_HEADER_AND_GEOMETRY_UNCOMPRESSED = -3 

70 # ALL_STATE_EXCEPT_GEOMETRY_POSITION = -2 

71 # REST_OF_HEADER_AND_GEOMETRY_COMPRESSED = -1 

72 # EXTERNAL_NODE_IDS = 1 

73 # NODE_COORDINATES = 2 

74 # SOLID_ELEMENT_IDS = 3 

75 # SOLID_NEIGHBORS = 4 

76 # SOLID_MATERIALS = 5 

77 # THICK_SHELLS = (6, 7, 8) 

78 # BEAMS = (9, 10, 11) 

79 # TOOL_ELEMENTS = (12, 13, 14) 

80 # SHELL_ELEMENTS = (15, 16, 17) 

81 # HEADER_AND_PART_TITLES = -4 

82 # TIME = -3 

83 PART = -2 

84 GLOBAL = -1 

85 NODE = 0 

86 SOLID = 1 

87 THICK_SHELL = 2 

88 BEAM = 3 

89 TOOLS = 4 

90 SHELL = 5 

91 SPH = 6 

92 FPM = 7 

93 CFD = 8 

94 CPM_FLOAT_VAR = 9 

95 CPM_AIRBAG = 10 

96 CPM_INT_VAR = 11 

97 RADIOSS_STATE_DATA = 12 

98 HEXA20 = 13 

99 

100 @staticmethod 

101 def from_int(number: int) -> "FemzipVariableCategory": 

102 """Deserializes an integer into an enum 

103 

104 Parameters 

105 ---------- 

106 number: int 

107 number to turn into an enum 

108 

109 Returns 

110 ------- 

111 enum_value: FemzipVariableCategory 

112 """ 

113 if number not in FEMZIP_CATEGORY_TRANSL_DICT: 

114 err_msg = f"Error: Unknown femzip variable category: '{number}'" 

115 raise RuntimeError(err_msg) 

116 

117 return FEMZIP_CATEGORY_TRANSL_DICT[number] 

118 

119 

120FEMZIP_CATEGORY_TRANSL_DICT: Dict[int, FemzipVariableCategory] = { 

121 entry.value: entry for entry in FemzipVariableCategory.__members__.values() 

122} 

123 

124 

125class FemzipArrayType(enum.Enum): 

126 """Enum for femzip array types""" 

127 

128 GLOBAL_DATA = "global" 

129 PART_RESULTS = "Parts: Energies and others" 

130 # nodes 

131 NODE_DISPLACEMENT = "coordinates" 

132 NODE_TEMPERATURES = "temperatures" 

133 NODE_ACCELERATIONS = "accelerations" 

134 NODE_HEAT_FLUX = "heat_flux" 

135 NODE_MASS_SCALING = "mass_scaling" 

136 NODE_TEMPERATURE_GRADIENT = "dtdt" 

137 NODE_VELOCITIES = "velocities" 

138 

139 # beam 

140 BEAM_S_SHEAR_RESULTANT = "s_shear_resultant" 

141 BEAM_T_SHEAR_RESULTANT = "t_shear_resultant" 

142 BEAM_S_BENDING_MOMENT = "s_bending_moment" 

143 BEAM_T_BENDING_MOMENT = "t_bending_moment" 

144 BEAM_AXIAL_FORCE = "axial_force" 

145 BEAM_TORSIONAL_MOMENT = "torsional_resultant" 

146 BEAM_AXIAL_STRESS = "axial_stress" 

147 BEAM_SHEAR_STRESS_RS = "RS_shear_stress" 

148 BEAM_SHEAR_STRESS_TR = "TR_shear_stress" 

149 BEAM_PLASTIC_STRAIN = "plastic_strain" 

150 BEAM_AXIAL_STRAIN = "axial_strain" 

151 

152 # airbag 

153 AIRBAG_STATE_GEOM = "CPMs_state_geometry" 

154 AIRBAG_PARTICLE_POS_X = "Pos x" 

155 AIRBAG_PARTICLE_POS_Y = "Pos y" 

156 AIRBAG_PARTICLE_POS_Z = "Pos z" 

157 AIRBAG_PARTICLE_VEL_X = "Vel x" 

158 AIRBAG_PARTICLE_VEL_Y = "Vel y" 

159 AIRBAG_PARTICLE_VEL_Z = "Vel z" 

160 AIRBAG_PARTICLE_MASS = "Mass" 

161 AIRBAG_PARTICLE_RADIUS = "Radius" 

162 AIRBAG_PARTICLE_SPIN_ENERGY = "Spin En" 

163 AIRBAG_PARTICLE_TRAN_ENERGY = "Tran En" 

164 AIRBAG_PARTICLE_NEIGHBOR_DIST = "NS dist" 

165 AIRBAG_PARTICLE_GAS_CHAMBER_ID = "GasC ID" 

166 AIRBAG_PARTICLE_CHAMBER_ID = "Cham ID" 

167 AIRBAG_PARTICLE_LEAKAGE = "Leakage" 

168 

169 STRESS_X = "Sigma-x" 

170 STRESS_Y = "Sigma-y" 

171 STRESS_Z = "Sigma-z" 

172 STRESS_XY = "Sigma-xy" 

173 STRESS_YZ = "Sigma-yz" 

174 STRESS_XZ = "Sigma-zx" 

175 EFF_PSTRAIN = "Effective plastic strain" 

176 HISTORY_VARS = "extra_value_per_element" 

177 BENDING_MOMENT_MX = "bending_moment Mx" 

178 BENDING_MOMENT_MY = "bending_moment My" 

179 BENDING_MOMENT_MXY = "bending_moment Mxy" 

180 SHEAR_FORCE_X = "shear_resultant Qx" 

181 SHEAR_FORCE_Y = "shear_resultant Qy" 

182 NORMAL_FORCE_X = "normal_resultant Nx" 

183 NORMAL_FORCE_Y = "normal_resultant Ny" 

184 NORMAL_FORCE_XY = "normal_resultant Nxy" 

185 THICKNESS = "thickness" 

186 UNKNOWN_1 = "element_dependent_variable_1" 

187 UNKNOWN_2 = "element_dependent_variable_2" 

188 STRAIN_INNER_X = "Epsilon-x (inner)" 

189 STRAIN_INNER_Y = "Epsilon-y (inner)" 

190 STRAIN_INNER_Z = "Epsilon-z (inner)" 

191 STRAIN_INNER_XY = "Epsilon-xy (inner)" 

192 STRAIN_INNER_YZ = "Epsilon-yz (inner)" 

193 STRAIN_INNER_XZ = "Epsilon-zx (inner)" 

194 STRAIN_OUTER_X = "Epsilon-x (outer)" 

195 STRAIN_OUTER_Y = "Epsilon-y (outer)" 

196 STRAIN_OUTER_Z = "Epsilon-z (outer)" 

197 STRAIN_OUTER_XY = "Epsilon-xy (outer)" 

198 STRAIN_OUTER_YZ = "Epsilon-yz (outer)" 

199 STRAIN_OUTER_XZ = "Epsilon-zx (outer)" 

200 INTERNAL_ENERGY = "internal_energy" 

201 

202 STRAIN_X = "Epsilon-x (IP 1)" 

203 STRAIN_Y = "Epsilon-y (IP 1)" 

204 STRAIN_Z = "Epsilon-z (IP 1)" 

205 STRAIN_XY = "Epsilon-xy (IP 1)" 

206 STRAIN_YZ = "Epsilon-yz (IP 1)" 

207 STRAIN_XZ = "Epsilon-zx (IP 1)" 

208 

209 @staticmethod 

210 def from_string(femzip_name: str) -> "FemzipArrayType": 

211 """Converts a variable name to an array type string 

212 

213 Parameters 

214 ---------- 

215 femzip_name: str 

216 name of the variable given by femzip 

217 

218 Returns 

219 ------- 

220 femzip_array_type: FemzipArrayType 

221 """ 

222 for fz_array_type in FemzipArrayType.__members__.values(): 

223 if fz_array_type.value in femzip_name.strip(): 

224 return fz_array_type 

225 

226 err_msg = "Unknown femzip variable name: '{0}'" 

227 raise ValueError(err_msg.format(femzip_name))