Coverage for src/meshpy/mesh_creation_functions/beam_node_continuation.py: 92%
25 statements
« prev ^ index » next coverage.py v7.9.0, created at 2025-06-13 04:26 +0000
« prev ^ index » next coverage.py v7.9.0, created at 2025-06-13 04:26 +0000
1# The MIT License (MIT)
2#
3# Copyright (c) 2018-2025 MeshPy 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 meshpy.core.conf import mpy as _mpy
27from meshpy.mesh_creation_functions.beam_arc import (
28 create_beam_mesh_arc_segment_via_axis as _create_beam_mesh_arc_segment_via_axis,
29)
30from meshpy.mesh_creation_functions.beam_line import (
31 create_beam_mesh_line as _create_beam_mesh_line,
32)
33from meshpy.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. The tangent will be the same
40 as at that node.
42 Args
43 ----
44 mesh: Mesh
45 Mesh that the arc segment will be added to.
46 beam_class: Beam
47 Class of beam that will be used for this line.
48 material: Material
49 Material for this segment.
50 start_node: _np.array, list
51 Point where the arc will continue.
52 length: float
53 Length of the line.
55 **kwargs (for all of them look into create_beam_mesh_function)
56 ----
57 n_el: int
58 Number of equally spaced beam elements along the line. Defaults to 1.
59 Mutually exclusive with l_el.
60 l_el: float
61 Desired length of beam elements. Mutually exclusive with n_el.
62 Be aware, that this length might not be achieved, if the elements are
63 warped after they are created.
65 Return
66 ----
67 return_set: GeometryName
68 Set with the 'start' and 'end' node of the line. Also a 'line' set
69 with all nodes of the line.
70 """
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. The arc will be
96 tangent to the given node.
98 Args
99 ----
100 mesh: Mesh
101 Mesh that the arc segment will be added to.
102 beam_class: Beam
103 Class of beam that will be used for this line.
104 material: Material
105 Material for this segment.
106 start_node: _np.array, list
107 Point where the arc will continue.
108 arc_axis_normal: 3d-vector
109 Rotation axis for the created arc.
110 radius: float
111 The radius of the arc segment.
112 angle: float
113 Angle of the arc. If the angle is negative, the arc will point in the
114 opposite direction, i.e., as if the arc_axis_normal would change sign.
116 **kwargs (for all of them look into create_beam_mesh_function)
117 ----
118 n_el: int
119 Number of equally spaced beam elements along the line. Defaults to 1.
120 Mutually exclusive with l_el.
121 l_el: float
122 Desired length of beam elements. Mutually exclusive with n_el.
123 Be aware, that this length might not be achieved, if the elements are
124 warped after they are created.
126 Return
127 ----
128 return_set: GeometryName
129 Set with the 'start' and 'end' node of the line. Also a 'line' set
130 with all nodes of the line.
131 """
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)) > _mpy.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 )