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

69 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-28 15:20 +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 four_c_type = _INPUT_FILE_MAPPINGS["four_c_type_to_four_c_type"][_BeamType.reissner] 

48 four_c_cell = _INPUT_FILE_MAPPINGS["element_type_and_n_nodes_to_four_c_cell"][ 

49 _bme.element_type.beam, n_nodes 

50 ] 

51 element_technology = {"HERMITE_CENTERLINE": is_hermite_centerline} 

52 data = _FourCElementData( 

53 four_c_type=four_c_type, 

54 four_c_cell=four_c_cell, 

55 element_technology=element_technology, 

56 ) 

57 

58 if is_hermite_centerline: 

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

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

61 else: 

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

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

64 

65 return type( 

66 "BeamFourCSimoReissner", 

67 (_generate_beam_class(n_nodes),), 

68 { 

69 "element_type": _bme.element_type.beam, 

70 "beam_type": _BeamType.reissner, 

71 "data": data, 

72 "coupling_fix_dict": coupling_fix_dict, 

73 "coupling_joint_dict": coupling_joint_dict, 

74 }, 

75 ) 

76 

77 

78def get_four_c_kirchhoff_beam( 

79 constraint: _BeamKirchhoffConstraintType = _BeamKirchhoffConstraintType.weak, 

80 parametrization: _BeamKirchhoffParametrizationType = _BeamKirchhoffParametrizationType.rot, 

81 is_fad: bool = True, 

82) -> type[_Beam]: 

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

84 # Show warning when not using rotvec. 

85 if not parametrization == _BeamKirchhoffParametrizationType.rot: 

86 _warnings.warn( 

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

88 " applying the boundary conditions and couplings." 

89 ) 

90 

91 n_nodes = 3 

92 

93 four_c_type = _INPUT_FILE_MAPPINGS["four_c_type_to_four_c_type"][ 

94 _BeamType.kirchhoff 

95 ] 

96 four_c_cell = _INPUT_FILE_MAPPINGS["element_type_and_n_nodes_to_four_c_cell"][ 

97 _bme.element_type.beam, n_nodes 

98 ] 

99 element_technology = { 

100 "CONSTRAINT": constraint.name, 

101 "PARAMETRIZATION": parametrization.name, 

102 "USE_FAD": is_fad, 

103 } 

104 data = _FourCElementData( 

105 four_c_type=four_c_type, 

106 four_c_cell=four_c_cell, 

107 element_technology=element_technology, 

108 ) 

109 

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

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

112 

113 return type( 

114 "BeamFourCKirchhoffLove", 

115 (_generate_beam_class(n_nodes),), 

116 { 

117 "element_type": _bme.element_type.beam, 

118 "beam_type": _BeamType.kirchhoff, 

119 "kirchhoff_parametrization": parametrization, 

120 "data": data, 

121 "coupling_fix_dict": coupling_fix_dict, 

122 "coupling_joint_dict": coupling_joint_dict, 

123 }, 

124 ) 

125 

126 

127class BeamFourCEulerBernoulli(_Beam2): 

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

129 

130 element_type = _bme.element_type.beam 

131 beam_type = _BeamType.euler_bernoulli 

132 data = _FourCElementData( 

133 four_c_type=_INPUT_FILE_MAPPINGS["four_c_type_to_four_c_type"][ 

134 _BeamType.euler_bernoulli 

135 ], 

136 four_c_cell=_INPUT_FILE_MAPPINGS["element_type_and_n_nodes_to_four_c_cell"][ 

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

138 ], 

139 ) 

140 

141 def check(self) -> None: 

142 """Check that the beam is straight and that the two rotations are the same.""" 

143 # Perform checks from the parent class. 

144 super().check() 

145 

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

147 # the start point to the end point. 

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

149 raise ValueError( 

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

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

152 ) 

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

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

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

156 raise ValueError( 

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

158 ) 

159 

160 

161def get_four_c_beam( 

162 beam_type: _BeamType, 

163 *, 

164 n_nodes: int | None = None, 

165 is_hermite_centerline: bool | None = None, 

166 **kwargs, 

167) -> type[_Beam]: 

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

169 

170 def _check_arguments(name, value, expected): 

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

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

173 raise ValueError( 

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

175 ) 

176 

177 match beam_type: 

178 case _BeamType.reissner: 

179 # Set default values for centerline interpolation 

180 if n_nodes is None: 

181 n_nodes = 3 

182 if is_hermite_centerline is None: 

183 is_hermite_centerline = True 

184 return get_four_c_reissner_beam( 

185 n_nodes=n_nodes, is_hermite_centerline=is_hermite_centerline, **kwargs 

186 ) 

187 case _BeamType.kirchhoff: 

188 _check_arguments("n_nodes", n_nodes, 3) 

189 _check_arguments("is_hermite_centerline", is_hermite_centerline, True) 

190 return get_four_c_kirchhoff_beam(**kwargs) 

191 case _BeamType.euler_bernoulli: 

192 _check_arguments("n_nodes", n_nodes, 2) 

193 _check_arguments("is_hermite_centerline", is_hermite_centerline, True) 

194 return BeamFourCEulerBernoulli 

195 case _: 

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

197 

198 

199# Provide shortcuts for backwards compatibility 

200Beam3rHerm2Line3 = get_four_c_beam( 

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

202) 

203Beam3rLine2Line2 = get_four_c_beam( 

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

205) 

206Beam3eb = get_four_c_beam(_BeamType.euler_bernoulli)