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

15 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-23 08:08 +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 beam filament from a curve represented with splinepy.""" 

23 

24import numpy as _np 

25 

26from beamme.mesh_creation_functions.beam_parametric_curve import ( 

27 create_beam_mesh_parametric_curve as _create_beam_mesh_parametric_curve, 

28) 

29 

30 

31def get_curve_function_and_jacobian_for_integration(curve): 

32 """Return function objects for evaluating the curve and the derivative. 

33 These functions are used in the curve integration. 

34 

35 Args 

36 ---- 

37 curve: splinepy object 

38 Curve that is used to describe the beam centerline. 

39 

40 Return 

41 ---- 

42 (function, jacobian, curve_start, curve_end): 

43 function: 

44 Function for evaluating a position on the curve 

45 jacobian: 

46 Function for evaluating the tangent along the curve 

47 curve_start: 

48 Parameter coordinate for the start for the curve 

49 curve_end: 

50 Parameter coordinate for the end for the curve 

51 """ 

52 

53 curve_start = curve.parametric_bounds[0][0] 

54 curve_end = curve.parametric_bounds[1][0] 

55 

56 def eval_r(t): 

57 """Evaluate the position along the curve. 

58 

59 We need to pass an array with shape (n, 1) to the splinepy 

60 function, we do this by passing a reordered view of t. 

61 """ 

62 t = _np.asarray(t) 

63 return curve.evaluate(t[:, None]) 

64 

65 def eval_rp(t): 

66 """Evaluate the derivative along the curve. 

67 

68 We need to pass an array with shape (n, 1) to the splinepy 

69 function, we do this by passing a reordered view of t. 

70 """ 

71 t = _np.asarray(t) 

72 return curve.derivative(t[:, None], orders=[1]) 

73 

74 return eval_r, eval_rp, curve_start, curve_end 

75 

76 

77def create_beam_mesh_from_splinepy(mesh, beam_class, material, curve, **kwargs): 

78 """Generate a beam from a splinepy curve. 

79 

80 Args 

81 ---- 

82 mesh: Mesh 

83 Mesh that the curve will be added to. 

84 beam_class: Beam 

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

86 material: Material 

87 Material for this line. 

88 curve: splinepy object 

89 Curve that is used to describe the beam centerline. 

90 

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

92 ---- 

93 n_el: int 

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

95 Mutually exclusive with l_el. 

96 l_el: float 

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

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

99 warped after they are created. 

100 

101 Return: 

102 Return value from create_beam_mesh_function 

103 """ 

104 

105 ( 

106 function, 

107 jacobian, 

108 curve_start, 

109 curve_end, 

110 ) = get_curve_function_and_jacobian_for_integration(curve) 

111 

112 # Create the beams 

113 return _create_beam_mesh_parametric_curve( 

114 mesh, 

115 beam_class, 

116 material, 

117 function, 

118 [curve_start, curve_end], 

119 function_derivative=jacobian, 

120 vectorized=True, 

121 **kwargs, 

122 )