Coverage for src/beamme/mesh_creation_functions/applications/beam_wire.py: 93%

30 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"""Create a steel wire.""" 

23 

24import numpy as _np 

25 

26from beamme.core.geometry_set import GeometryName as _GeometryName 

27from beamme.core.geometry_set import GeometrySet as _GeometrySet 

28from beamme.mesh_creation_functions.beam_line import ( 

29 create_beam_mesh_line as _create_beam_mesh_line, 

30) 

31from beamme.utils.nodes import check_node_by_coordinate as _check_node_by_coordinate 

32 

33 

34def create_wire_fibers( 

35 mesh, beam_class, material, length, *, radius=None, layers=1, n_el=1 

36): 

37 """Create a steel wire consisting of multiple filaments. 

38 

39 The wire will be oriented in x-direction. 

40 

41 Args 

42 ---- 

43 mesh: Mesh 

44 Mesh that the line will be added to. 

45 beam_class: Beam 

46 Class of beam that will be used for this line. 

47 material: Material 

48 Material for this line. 

49 length: float 

50 Length of the wire. 

51 radius: float 

52 If this parameter is given, not the beam cross section radius will be 

53 taken, but this one. 

54 layers: int 

55 Number of layers to be used for the wire. 

56 n_el: int 

57 Number of beam elements per filament. 

58 

59 Return 

60 ---- 

61 return_set: GeometryName 

62 Set with the 'start' and 'end' nodes of the wire. Also a 'all' set 

63 with all nodes of the wire. 

64 """ 

65 if len(mesh.nodes) != 0: 

66 raise ValueError( 

67 "The create_wire_fibers function can only be used with an empty mesh." 

68 ) 

69 

70 if radius is None: 

71 wire_beam_radius = material.radius 

72 else: 

73 wire_beam_radius = radius 

74 

75 def create_line(pos_yz): 

76 """Create a line starting at the yz-plane with the 2D coordinates pos_yz.""" 

77 _create_beam_mesh_line( 

78 mesh, 

79 beam_class, 

80 material, 

81 [0.0, pos_yz[0], pos_yz[1]], 

82 [length, pos_yz[0], pos_yz[1]], 

83 n_el=n_el, 

84 ) 

85 

86 # Create the center filament. 

87 create_line([0.0, 0.0]) 

88 

89 # Create the filaments in the layers. 

90 for i_angle in range(6): 

91 angle = i_angle * _np.pi / 3.0 

92 direction_radial = _np.array([_np.cos(angle), _np.sin(angle)]) 

93 angle = i_angle * _np.pi / 3.0 + 2.0 * _np.pi / 3.0 

94 direction_tangential = _np.array([_np.cos(angle), _np.sin(angle)]) 

95 for i_layer in range(layers): 

96 for i_tangent in range(i_layer + 1): 

97 pos = ( 

98 2.0 

99 * wire_beam_radius 

100 * ( 

101 direction_radial * (i_layer + 1) 

102 + direction_tangential * i_tangent 

103 ) 

104 ) 

105 create_line(pos) 

106 

107 # Create the sets to return. 

108 return_set = _GeometryName() 

109 start_nodes = mesh.get_nodes_by_function(_check_node_by_coordinate, 0, 0.0) 

110 end_nodes = mesh.get_nodes_by_function(_check_node_by_coordinate, 0, length) 

111 return_set["start"] = _GeometrySet(start_nodes) 

112 return_set["end"] = _GeometrySet(end_nodes) 

113 return_set["all"] = _GeometrySet(mesh.elements) 

114 return return_set