Coverage for src/beamme/mesh_creation_functions/beam_line.py: 100%

23 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"""Functions to create beam meshes along straight lines.""" 

23 

24import numpy as _np 

25 

26from beamme.core.conf import bme as _bme 

27from beamme.core.rotation import Rotation as _Rotation 

28from beamme.mesh_creation_functions.beam_generic import ( 

29 create_beam_mesh_generic as _create_beam_mesh_generic, 

30) 

31 

32 

33def create_beam_mesh_line(mesh, beam_class, material, start_point, end_point, **kwargs): 

34 """Generate a straight line of beam elements. 

35 

36 Args 

37 ---- 

38 mesh: Mesh 

39 Mesh that the line will be added to. 

40 beam_class: Beam 

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

42 material: Material 

43 Material for this line. 

44 start_point, end_point: _np.array, list 

45 3D-coordinates for the start and end point of the line. 

46 

47 **kwargs (for all of them look into create_beam_mesh_function) 

48 ---- 

49 n_el: int 

50 Number of equally spaced beam elements along the line. Defaults to 1. 

51 Mutually exclusive with l_el. 

52 l_el: float 

53 Desired length of beam elements. Mutually exclusive with n_el. 

54 Be aware, that this length might not be achieved, if the elements are 

55 warped after they are created. 

56 start_node: Node, GeometrySet 

57 Node to use as the first node for this line. Use this if the line 

58 is connected to other lines (angles have to be the same, otherwise 

59 connections should be used). If a geometry set is given, it can 

60 contain one, and one node only. 

61 

62 Return 

63 ---- 

64 return_set: GeometryName 

65 Set with the 'start' and 'end' node of the line. Also a 'line' set 

66 with all nodes of the line. 

67 """ 

68 

69 # Get geometrical values for this line. 

70 start_point = _np.asarray(start_point) 

71 end_point = _np.asarray(end_point) 

72 direction = end_point - start_point 

73 line_length = _np.linalg.norm(direction) 

74 t1 = direction / line_length 

75 

76 # Check if the z or y axis are larger projected onto the direction. 

77 # The tolerance is used here to ensure that round-off changes in the last digits of 

78 # the floating point values don't switch the case. This increases the robustness in 

79 # testing. 

80 if abs(_np.dot(t1, [0, 0, 1])) < abs(_np.dot(t1, [0, 1, 0])) - _bme.eps_quaternion: 

81 t2 = [0, 0, 1] 

82 else: 

83 t2 = [0, 1, 0] 

84 rotation = _Rotation.from_basis(t1, t2) 

85 

86 def get_beam_geometry(parameter_a, parameter_b): 

87 """Return a function for the position along the beams axis.""" 

88 

89 def beam_function(xi): 

90 """Return a point on the beams axis for a given parameter 

91 coordinate xi.""" 

92 point_a = start_point + parameter_a * direction 

93 point_b = start_point + parameter_b * direction 

94 pos = 0.5 * (1 - xi) * point_a + 0.5 * (1 + xi) * point_b 

95 arc_length = ( 

96 0.5 * (1 - xi) * parameter_a + 0.5 * (1 + xi) * parameter_b 

97 ) * line_length 

98 return (pos, rotation, arc_length) 

99 

100 return beam_function 

101 

102 # Create the beam in the mesh 

103 return _create_beam_mesh_generic( 

104 mesh, 

105 beam_class=beam_class, 

106 material=material, 

107 function_generator=get_beam_geometry, 

108 interval=[0.0, 1.0], 

109 interval_length=line_length, 

110 **kwargs, 

111 )