Coverage for src/beamme/four_c/material.py: 89%

88 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 implements materials for 4C beams and solids.""" 

23 

24import numpy as _np 

25 

26from beamme.core.material import MaterialBeamBase as _MaterialBeamBase 

27from beamme.core.material import MaterialSolidBase as _MaterialSolidBase 

28 

29 

30class MaterialReissner(_MaterialBeamBase): 

31 """Holds material definition for Reissner beams.""" 

32 

33 def __init__( 

34 self, 

35 shear_correction=1, 

36 *, 

37 by_modes=False, 

38 scale_axial_rigidity=1.0, 

39 scale_shear_rigidity=1.0, 

40 scale_torsional_rigidity=1.0, 

41 scale_bending_rigidity=1.0, 

42 **kwargs, 

43 ): 

44 if by_modes: 

45 mat_string = "MAT_BeamReissnerElastHyper_ByModes" 

46 else: 

47 mat_string = "MAT_BeamReissnerElastHyper" 

48 

49 super().__init__(material_string=mat_string, **kwargs) 

50 

51 # Shear factor for Reissner beam. 

52 self.shear_correction = shear_correction 

53 

54 self.by_modes = by_modes 

55 

56 # Scaling factors to influence a single stiffness independently 

57 self.scale_axial_rigidity = scale_axial_rigidity 

58 self.scale_shear_rigidity = scale_shear_rigidity 

59 self.scale_torsional_rigidity = scale_torsional_rigidity 

60 self.scale_bending_rigidity = scale_bending_rigidity 

61 

62 if not by_modes and not all( 

63 _np.isclose(x, 1.0) 

64 for x in ( 

65 scale_axial_rigidity, 

66 scale_shear_rigidity, 

67 scale_torsional_rigidity, 

68 scale_bending_rigidity, 

69 ) 

70 ): 

71 raise ValueError( 

72 "Scaling factors are only supported for MAT_BeamReissnerElastHyper_ByModes" 

73 ) 

74 

75 def dump_to_list(self): 

76 """Return a list with the (single) item representing this material.""" 

77 if ( 

78 self.area is None 

79 and self.mom2 is None 

80 and self.mom3 is None 

81 and self.polar is None 

82 ): 

83 area, mom2, mom3, polar = self.calc_area_stiffness() 

84 elif ( 

85 self.area is not None 

86 and self.mom2 is not None 

87 and self.mom3 is not None 

88 and self.polar is not None 

89 ): 

90 area = self.area 

91 mom2 = self.mom2 

92 mom3 = self.mom3 

93 polar = self.polar 

94 else: 

95 raise ValueError( 

96 "Either all relevant material parameters are set " 

97 "by the user, or a circular cross-section will be assumed. " 

98 "A combination is not possible" 

99 ) 

100 

101 if self.by_modes: 

102 shear_modulus = self.youngs_modulus / (2.0 * (1.0 + self.nu)) 

103 

104 data = { 

105 "EA": (self.youngs_modulus * area) * self.scale_axial_rigidity, 

106 "GA2": (shear_modulus * area * self.shear_correction) 

107 * self.scale_shear_rigidity, 

108 "GA3": (shear_modulus * area * self.shear_correction) 

109 * self.scale_shear_rigidity, 

110 "GI_T": (shear_modulus * polar) * self.scale_torsional_rigidity, 

111 "EI2": (self.youngs_modulus * mom2) * self.scale_bending_rigidity, 

112 "EI3": (self.youngs_modulus * mom3) * self.scale_bending_rigidity, 

113 "RhoA": self.density * area, 

114 "MASSMOMINPOL": self.density * (mom2 + mom3), 

115 "MASSMOMIN2": self.density * mom2, 

116 "MASSMOMIN3": self.density * mom3, 

117 } 

118 

119 else: 

120 data = { 

121 "YOUNG": self.youngs_modulus, 

122 "POISSONRATIO": self.nu, 

123 "DENS": self.density, 

124 "CROSSAREA": area, 

125 "SHEARCORR": self.shear_correction, 

126 "MOMINPOL": polar, 

127 "MOMIN2": mom2, 

128 "MOMIN3": mom3, 

129 } 

130 

131 if self.interaction_radius is not None: 

132 data["INTERACTIONRADIUS"] = self.interaction_radius 

133 

134 return {"MAT": self.i_global + 1, self.material_string: data} 

135 

136 

137class MaterialReissnerElastoplastic(MaterialReissner): 

138 """Holds elasto-plastic material definition for Reissner beams.""" 

139 

140 def __init__( 

141 self, 

142 *, 

143 yield_moment=None, 

144 isohardening_modulus_moment=None, 

145 torsion_plasticity=False, 

146 **kwargs, 

147 ): 

148 super().__init__(**kwargs) 

149 self.material_string = "MAT_BeamReissnerElastPlastic" 

150 

151 if yield_moment is None or isohardening_modulus_moment is None: 

152 raise ValueError( 

153 "The yield moment and the isohardening modulus for moments must be specified " 

154 "for plasticity." 

155 ) 

156 

157 self.yield_moment = yield_moment 

158 self.isohardening_modulus_moment = isohardening_modulus_moment 

159 self.torsion_plasticity = torsion_plasticity 

160 

161 def dump_to_list(self): 

162 """Return a list with the (single) item representing this material.""" 

163 super_list = super().dump_to_list() 

164 mat_dict = super_list[self.material_string] 

165 mat_dict["YIELDM"] = self.yield_moment 

166 mat_dict["ISOHARDM"] = self.isohardening_modulus_moment 

167 mat_dict["TORSIONPLAST"] = self.torsion_plasticity 

168 return super_list 

169 

170 

171class MaterialKirchhoff(_MaterialBeamBase): 

172 """Holds material definition for Kirchhoff beams.""" 

173 

174 def __init__(self, is_fad=False, **kwargs): 

175 super().__init__(material_string="MAT_BeamKirchhoffElastHyper", **kwargs) 

176 self.is_fad = is_fad 

177 

178 def dump_to_list(self): 

179 """Return a list with the (single) item representing this material.""" 

180 if ( 

181 self.area is None 

182 and self.mom2 is None 

183 and self.mom3 is None 

184 and self.polar is None 

185 ): 

186 area, mom2, mom3, polar = self.calc_area_stiffness() 

187 elif ( 

188 self.area is not None 

189 and self.mom2 is not None 

190 and self.mom3 is not None 

191 and self.polar is not None 

192 ): 

193 area = self.area 

194 mom2 = self.mom2 

195 mom3 = self.mom3 

196 polar = self.polar 

197 else: 

198 raise ValueError( 

199 "Either all relevant material parameters are set " 

200 "by the user, or a circular cross-section will be assumed. " 

201 "A combination is not possible" 

202 ) 

203 data = { 

204 "YOUNG": self.youngs_modulus, 

205 "SHEARMOD": self.youngs_modulus / (2.0 * (1.0 + self.nu)), 

206 "DENS": self.density, 

207 "CROSSAREA": area, 

208 "MOMINPOL": polar, 

209 "MOMIN2": mom2, 

210 "MOMIN3": mom3, 

211 "FAD": self.is_fad, 

212 } 

213 if self.interaction_radius is not None: 

214 data["INTERACTIONRADIUS"] = self.interaction_radius 

215 return {"MAT": self.i_global + 1, self.material_string: data} 

216 

217 

218class MaterialEulerBernoulli(_MaterialBeamBase): 

219 """Holds material definition for Euler Bernoulli beams.""" 

220 

221 def __init__(self, **kwargs): 

222 super().__init__( 

223 material_string="MAT_BeamKirchhoffTorsionFreeElastHyper", **kwargs 

224 ) 

225 

226 def dump_to_list(self): 

227 """Return a list with the (single) item representing this material.""" 

228 area, mom2, _mom3, _polar = self.calc_area_stiffness() 

229 if self.area is None and self.mom2 is None: 

230 area, mom2, _mom3, _polar = self.calc_area_stiffness() 

231 elif self.area is not None and self.mom2 is not None: 

232 area = self.area 

233 mom2 = self.mom2 

234 else: 

235 raise ValueError( 

236 "Either all relevant material parameters are set " 

237 "by the user, or a circular cross-section will be assumed. " 

238 "A combination is not possible" 

239 ) 

240 data = { 

241 "YOUNG": self.youngs_modulus, 

242 "DENS": self.density, 

243 "CROSSAREA": area, 

244 "MOMIN": mom2, 

245 } 

246 return {"MAT": self.i_global + 1, self.material_string: data} 

247 

248 

249class MaterialSolid(_MaterialSolidBase): 

250 """Base class for a material for solids.""" 

251 

252 def __init__(self, material_string=None, **kwargs): 

253 """Set the material values for a solid.""" 

254 self.material_string = material_string 

255 super().__init__(**kwargs) 

256 

257 def dump_to_list(self): 

258 """Return a list with the (single) item representing this material.""" 

259 

260 return {"MAT": self.i_global + 1, self.material_string: self.data} 

261 

262 

263class MaterialStVenantKirchhoff(MaterialSolid): 

264 """Holds material definition for StVenant Kirchhoff solids.""" 

265 

266 def __init__(self, youngs_modulus=-1.0, nu=0.0, density=0.0): 

267 super().__init__( 

268 material_string="MAT_Struct_StVenantKirchhoff", 

269 data={"YOUNG": youngs_modulus, "NUE": nu, "DENS": density}, 

270 )