Coverage for src/meshpy/mesh_creation_functions/beam_wire.py: 97%
30 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-28 04:21 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-28 04:21 +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"""Create a steel wire."""
24import numpy as _np
26from meshpy.core.geometry_set import GeometryName as _GeometryName
27from meshpy.core.geometry_set import GeometrySet as _GeometrySet
28from meshpy.mesh_creation_functions.beam_basic_geometry import (
29 create_beam_mesh_line as _create_beam_mesh_line,
30)
31from meshpy.utils.nodes import check_node_by_coordinate as _check_node_by_coordinate
34def create_wire_fibers(
35 mesh, beam_class, material, length, *, radius=None, layers=1, n_el=1
36):
37 """Create a steel wire consisting of multiple filaments. The wire will be
38 oriented in x-direction.
40 Args
41 ----
42 mesh: Mesh
43 Mesh that the line will be added to.
44 beam_class: Beam
45 Class of beam that will be used for this line.
46 material: Material
47 Material for this line.
48 length: float
49 Length of the wire.
50 radius: float
51 If this parameter is given, not the beam cross section radius will be
52 taken, but this one.
53 layers: int
54 Number of layers to be used for the wire.
55 n_el: int
56 Number of beam elements per filament.
58 Return
59 ----
60 return_set: GeometryName
61 Set with the 'start' and 'end' nodes of the wire. Also a 'all' set
62 with all nodes of the wire.
63 """
65 if len(mesh.nodes) != 0:
66 raise ValueError(
67 "The create_wire_fibers function can only be used with an empty mesh."
68 )
70 if radius is None:
71 wire_beam_radius = material.radius
72 else:
73 wire_beam_radius = radius
75 def create_line(pos_yz):
76 """Create a line starting at the yz-plane with the 2D coordinates
77 pos_yz."""
78 _create_beam_mesh_line(
79 mesh,
80 beam_class,
81 material,
82 [0.0, pos_yz[0], pos_yz[1]],
83 [length, pos_yz[0], pos_yz[1]],
84 n_el=n_el,
85 )
87 # Create the center filament.
88 create_line([0.0, 0.0])
90 # Create the filaments in the layers.
91 for i_angle in range(6):
92 angle = i_angle * _np.pi / 3.0
93 direction_radial = _np.array([_np.cos(angle), _np.sin(angle)])
94 angle = i_angle * _np.pi / 3.0 + 2.0 * _np.pi / 3.0
95 direction_tangential = _np.array([_np.cos(angle), _np.sin(angle)])
96 for i_layer in range(layers):
97 for i_tangent in range(i_layer + 1):
98 pos = (
99 2.0
100 * wire_beam_radius
101 * (
102 direction_radial * (i_layer + 1)
103 + direction_tangential * i_tangent
104 )
105 )
106 create_line(pos)
108 # Create the sets to return.
109 return_set = _GeometryName()
110 start_nodes = mesh.get_nodes_by_function(_check_node_by_coordinate, 0, 0.0)
111 end_nodes = mesh.get_nodes_by_function(_check_node_by_coordinate, 0, length)
112 return_set["start"] = _GeometrySet(start_nodes)
113 return_set["end"] = _GeometrySet(end_nodes)
114 return_set["all"] = _GeometrySet(mesh.elements)
115 return return_set