Coverage for src/beamme/mesh_creation_functions/beam_splinepy.py: 100%
15 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-28 15:20 +0000
« 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 beam filament from a curve represented with splinepy."""
24import numpy as _np
26from beamme.mesh_creation_functions.beam_parametric_curve import (
27 create_beam_mesh_parametric_curve as _create_beam_mesh_parametric_curve,
28)
31def get_curve_function_and_jacobian_for_integration(curve):
32 """Return function objects for evaluating the curve and the derivative.
34 These functions are used in the curve integration.
36 Args
37 ----
38 curve: splinepy object
39 Curve that is used to describe the beam centerline.
41 Return
42 ----
43 (function, jacobian, curve_start, curve_end):
44 function:
45 Function for evaluating a position on the curve
46 jacobian:
47 Function for evaluating the tangent along the curve
48 curve_start:
49 Parameter coordinate for the start for the curve
50 curve_end:
51 Parameter coordinate for the end for the curve
52 """
53 curve_start = curve.parametric_bounds[0][0]
54 curve_end = curve.parametric_bounds[1][0]
56 def eval_r(t):
57 """Evaluate the position along the curve.
59 We need to pass an array with shape (n, 1) to the splinepy function, we do this
60 by passing a reordered view of t.
61 """
62 t = _np.asarray(t)
63 return curve.evaluate(t[:, None])
65 def eval_rp(t):
66 """Evaluate the derivative along the curve.
68 We need to pass an array with shape (n, 1) to the splinepy function, we do this
69 by passing a reordered view of t.
70 """
71 t = _np.asarray(t)
72 return curve.derivative(t[:, None], orders=[1])
74 return eval_r, eval_rp, curve_start, curve_end
77def create_beam_mesh_from_splinepy(mesh, beam_class, material, curve, **kwargs):
78 """Generate a beam from a splinepy curve.
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.
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.
101 Return:
102 Return value from create_beam_mesh_function
103 """
104 (
105 function,
106 jacobian,
107 curve_start,
108 curve_end,
109 ) = get_curve_function_and_jacobian_for_integration(curve)
111 # Create the beams
112 return _create_beam_mesh_parametric_curve(
113 mesh,
114 beam_class,
115 material,
116 function,
117 [curve_start, curve_end],
118 function_derivative=jacobian,
119 vectorized=True,
120 **kwargs,
121 )