Coverage for src/beamme/mesh_creation_functions/beam_node_continuation.py: 92%
25 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"""Functions to create meshed beam geometries at a node."""
24import numpy as _np
26from beamme.core.conf import bme as _bme
27from beamme.mesh_creation_functions.beam_arc import (
28 create_beam_mesh_arc_segment_via_axis as _create_beam_mesh_arc_segment_via_axis,
29)
30from beamme.mesh_creation_functions.beam_line import (
31 create_beam_mesh_line as _create_beam_mesh_line,
32)
33from beamme.utils.nodes import get_single_node as _get_single_node
36def create_beam_mesh_line_at_node(
37 mesh, beam_class, material, start_node, length, **kwargs
38):
39 """Generate a straight line at a given node.
41 The tangent will be the same as at that node.
43 Args
44 ----
45 mesh: Mesh
46 Mesh that the arc segment will be added to.
47 beam_class: Beam
48 Class of beam that will be used for this line.
49 material: Material
50 Material for this segment.
51 start_node: _np.array, list
52 Point where the arc will continue.
53 length: float
54 Length of the line.
56 **kwargs (for all of them look into create_beam_mesh_function)
57 ----
58 n_el: int
59 Number of equally spaced beam elements along the line. Defaults to 1.
60 Mutually exclusive with l_el.
61 l_el: float
62 Desired length of beam elements. Mutually exclusive with n_el.
63 Be aware, that this length might not be achieved, if the elements are
64 warped after they are created.
66 Return
67 ----
68 return_set: GeometryName
69 Set with the 'start' and 'end' node of the line. Also a 'line' set
70 with all nodes of the line.
71 """
72 if length < 0:
73 raise ValueError("Length has to be positive!")
75 # Create the line starting from the given node
76 start_node = _get_single_node(start_node)
77 tangent = start_node.rotation * [1, 0, 0]
78 start_position = start_node.coordinates
79 end_position = start_position + tangent * length
81 return _create_beam_mesh_line(
82 mesh,
83 beam_class,
84 material,
85 start_position,
86 end_position,
87 start_node=start_node,
88 **kwargs,
89 )
92def create_beam_mesh_arc_at_node(
93 mesh, beam_class, material, start_node, arc_axis_normal, radius, angle, **kwargs
94):
95 """Generate a circular segment starting at a given node.
97 The arc will be tangent to the given node.
99 Args
100 ----
101 mesh: Mesh
102 Mesh that the arc segment will be added to.
103 beam_class: Beam
104 Class of beam that will be used for this line.
105 material: Material
106 Material for this segment.
107 start_node: _np.array, list
108 Point where the arc will continue.
109 arc_axis_normal: 3d-vector
110 Rotation axis for the created arc.
111 radius: float
112 The radius of the arc segment.
113 angle: float
114 Angle of the arc. If the angle is negative, the arc will point in the
115 opposite direction, i.e., as if the arc_axis_normal would change sign.
117 **kwargs (for all of them look into create_beam_mesh_function)
118 ----
119 n_el: int
120 Number of equally spaced beam elements along the line. Defaults to 1.
121 Mutually exclusive with l_el.
122 l_el: float
123 Desired length of beam elements. Mutually exclusive with n_el.
124 Be aware, that this length might not be achieved, if the elements are
125 warped after they are created.
127 Return
128 ----
129 return_set: GeometryName
130 Set with the 'start' and 'end' node of the line. Also a 'line' set
131 with all nodes of the line.
132 """
133 # If the angle is negative, the normal is switched
134 arc_axis_normal = _np.asarray(arc_axis_normal)
135 if angle < 0:
136 arc_axis_normal = -1.0 * arc_axis_normal
138 # The normal has to be perpendicular to the start point tangent
139 start_node = _get_single_node(start_node)
140 tangent = start_node.rotation * [1, 0, 0]
141 if _np.abs(_np.dot(tangent, arc_axis_normal)) > _bme.eps_pos:
142 raise ValueError(
143 "The normal has to be perpendicular to the tangent in the start node!"
144 )
146 # Get the center of the arc
147 center_direction = _np.cross(tangent, arc_axis_normal)
148 center_direction *= 1.0 / _np.linalg.norm(center_direction)
149 center = start_node.coordinates - center_direction * radius
151 return _create_beam_mesh_arc_segment_via_axis(
152 mesh,
153 beam_class,
154 material,
155 arc_axis_normal,
156 center,
157 start_node.coordinates,
158 _np.abs(angle),
159 start_node=start_node,
160 **kwargs,
161 )