Coverage for src/beamme/four_c/element_beam.py: 88%

69 statements  

« 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 implements beam elements for 4C.""" 

23 

24import warnings as _warnings 

25 

26import numpy as _np 

27 

28from beamme.core.conf import bme as _bme 

29from beamme.core.element_beam import Beam as _Beam 

30from beamme.core.element_beam import Beam2 as _Beam2 

31from beamme.core.element_beam import generate_beam_class as _generate_beam_class 

32from beamme.four_c.element_data import FourCElementData as _FourCElementData 

33from beamme.four_c.four_c_types import ( 

34 BeamKirchhoffConstraintType as _BeamKirchhoffConstraintType, 

35) 

36from beamme.four_c.four_c_types import ( 

37 BeamKirchhoffParametrizationType as _BeamKirchhoffParametrizationType, 

38) 

39from beamme.four_c.four_c_types import BeamType as _BeamType 

40from beamme.four_c.input_file_mappings import ( 

41 INPUT_FILE_MAPPINGS as _INPUT_FILE_MAPPINGS, 

42) 

43 

44 

45def get_four_c_reissner_beam(n_nodes: int, is_hermite_centerline: bool) -> type[_Beam]: 

46 """Return a Simo-Reissner beam for 4C.""" 

47 

48 four_c_type = _INPUT_FILE_MAPPINGS["four_c_type_to_four_c_type"][_BeamType.reissner] 

49 four_c_cell = _INPUT_FILE_MAPPINGS["element_type_and_n_nodes_to_four_c_cell"][ 

50 _bme.element_type.beam, n_nodes 

51 ] 

52 element_technology = {"HERMITE_CENTERLINE": is_hermite_centerline} 

53 data = _FourCElementData( 

54 four_c_type=four_c_type, 

55 four_c_cell=four_c_cell, 

56 element_technology=element_technology, 

57 ) 

58 

59 if is_hermite_centerline: 

60 coupling_fix_dict = {"NUMDOF": 9, "ONOFF": [1, 1, 1, 1, 1, 1, 0, 0, 0]} 

61 coupling_joint_dict = {"NUMDOF": 9, "ONOFF": [1, 1, 1, 0, 0, 0, 0, 0, 0]} 

62 else: 

63 coupling_fix_dict = {"NUMDOF": 6, "ONOFF": [1, 1, 1, 1, 1, 1]} 

64 coupling_joint_dict = {"NUMDOF": 6, "ONOFF": [1, 1, 1, 0, 0, 0]} 

65 

66 return type( 

67 "BeamFourCSimoReissner", 

68 (_generate_beam_class(n_nodes),), 

69 { 

70 "element_type": _bme.element_type.beam, 

71 "beam_type": _BeamType.reissner, 

72 "data": data, 

73 "coupling_fix_dict": coupling_fix_dict, 

74 "coupling_joint_dict": coupling_joint_dict, 

75 }, 

76 ) 

77 

78 

79def get_four_c_kirchhoff_beam( 

80 constraint: _BeamKirchhoffConstraintType = _BeamKirchhoffConstraintType.weak, 

81 parametrization: _BeamKirchhoffParametrizationType = _BeamKirchhoffParametrizationType.rot, 

82 is_fad: bool = True, 

83) -> type[_Beam]: 

84 """Return a Kirchhoff-Love beam for 4C.""" 

85 

86 # Show warning when not using rotvec. 

87 if not parametrization == _BeamKirchhoffParametrizationType.rot: 

88 _warnings.warn( 

89 "Use tangent based parametrization with caution, especially when " 

90 " applying the boundary conditions and couplings." 

91 ) 

92 

93 n_nodes = 3 

94 

95 four_c_type = _INPUT_FILE_MAPPINGS["four_c_type_to_four_c_type"][ 

96 _BeamType.kirchhoff 

97 ] 

98 four_c_cell = _INPUT_FILE_MAPPINGS["element_type_and_n_nodes_to_four_c_cell"][ 

99 _bme.element_type.beam, n_nodes 

100 ] 

101 element_technology = { 

102 "CONSTRAINT": constraint.name, 

103 "PARAMETRIZATION": parametrization.name, 

104 "USE_FAD": is_fad, 

105 } 

106 data = _FourCElementData( 

107 four_c_type=four_c_type, 

108 four_c_cell=four_c_cell, 

109 element_technology=element_technology, 

110 ) 

111 

112 coupling_fix_dict = {"NUMDOF": 7, "ONOFF": [1, 1, 1, 1, 1, 1, 0]} 

113 coupling_joint_dict = {"NUMDOF": 7, "ONOFF": [1, 1, 1, 0, 0, 0, 0]} 

114 

115 return type( 

116 "BeamFourCKirchhoffLove", 

117 (_generate_beam_class(n_nodes),), 

118 { 

119 "element_type": _bme.element_type.beam, 

120 "beam_type": _BeamType.kirchhoff, 

121 "kirchhoff_parametrization": parametrization, 

122 "data": data, 

123 "coupling_fix_dict": coupling_fix_dict, 

124 "coupling_joint_dict": coupling_joint_dict, 

125 }, 

126 ) 

127 

128 

129class BeamFourCEulerBernoulli(_Beam2): 

130 """Represents a Euler Bernoulli beam element.""" 

131 

132 element_type = _bme.element_type.beam 

133 beam_type = _BeamType.euler_bernoulli 

134 data = _FourCElementData( 

135 four_c_type=_INPUT_FILE_MAPPINGS["four_c_type_to_four_c_type"][ 

136 _BeamType.euler_bernoulli 

137 ], 

138 four_c_cell=_INPUT_FILE_MAPPINGS["element_type_and_n_nodes_to_four_c_cell"][ 

139 _bme.element_type.beam, len(_Beam2.nodes_create) 

140 ], 

141 ) 

142 

143 def check(self) -> None: 

144 """Check that the beam is straight and that the two rotations are the 

145 same.""" 

146 

147 # Perform checks from the parent class. 

148 super().check() 

149 

150 # The two rotations must be the same and the x1 vector must point from 

151 # the start point to the end point. 

152 if not self.nodes[0].rotation == self.nodes[1].rotation: 

153 raise ValueError( 

154 "The two nodal rotations in Euler Bernoulli beams must be the same," 

155 "i.e., the beam has to be straight!" 

156 ) 

157 direction = self.nodes[1].coordinates - self.nodes[0].coordinates 

158 t1 = self.nodes[0].rotation * [1, 0, 0] 

159 if _np.linalg.norm(direction / _np.linalg.norm(direction) - t1) >= _bme.eps_pos: 

160 raise ValueError( 

161 "The rotations do not match the direction of the Euler Bernoulli beam!" 

162 ) 

163 

164 

165def get_four_c_beam( 

166 beam_type: _BeamType, 

167 *, 

168 n_nodes: int | None = None, 

169 is_hermite_centerline: bool | None = None, 

170 **kwargs, 

171) -> type[_Beam]: 

172 """Return an object that can be used to create beams with 4C.""" 

173 

174 def _check_arguments(name, value, expected): 

175 """Check that if an argument is given, it has the expected value.""" 

176 if value is not None and not value == expected: 

177 raise ValueError( 

178 f"Parameter {name} with the value {value} does not match the expected value {expected}" 

179 ) 

180 

181 match beam_type: 

182 case _BeamType.reissner: 

183 # Set default values for centerline interpolation 

184 if n_nodes is None: 

185 n_nodes = 3 

186 if is_hermite_centerline is None: 

187 is_hermite_centerline = True 

188 return get_four_c_reissner_beam( 

189 n_nodes=n_nodes, is_hermite_centerline=is_hermite_centerline, **kwargs 

190 ) 

191 case _BeamType.kirchhoff: 

192 _check_arguments("n_nodes", n_nodes, 3) 

193 _check_arguments("is_hermite_centerline", is_hermite_centerline, True) 

194 return get_four_c_kirchhoff_beam(**kwargs) 

195 case _BeamType.euler_bernoulli: 

196 _check_arguments("n_nodes", n_nodes, 2) 

197 _check_arguments("is_hermite_centerline", is_hermite_centerline, True) 

198 return BeamFourCEulerBernoulli 

199 case _: 

200 raise ValueError("Got unexpected beam type.") 

201 

202 

203# Provide shortcuts for backwards compatibility 

204Beam3rHerm2Line3 = get_four_c_beam( 

205 _BeamType.reissner, n_nodes=3, is_hermite_centerline=True 

206) 

207Beam3rLine2Line2 = get_four_c_beam( 

208 _BeamType.reissner, n_nodes=2, is_hermite_centerline=False 

209) 

210Beam3eb = get_four_c_beam(_BeamType.euler_bernoulli)