Skip to content

Commit

Permalink
Merge pull request #73 from davidrudlstorfer/fix_helix_mesh
Browse files Browse the repository at this point in the history
Fix mesh creation for helical geometries
  • Loading branch information
isteinbrecher authored May 3, 2024
2 parents 5cfbee6 + 96af429 commit 30f7a81
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 71 deletions.
28 changes: 20 additions & 8 deletions meshpy/mesh_creation_functions/beam_basic_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

# Meshpy modules.
from ..conf import mpy
from ..mesh import Mesh
from ..rotation import Rotation
from ..utility import get_single_node
from .beam_generic import create_beam_mesh_function
Expand Down Expand Up @@ -561,6 +562,9 @@ def create_beam_mesh_helix(
start_point_origin_vec = start_point - origin
radius = np.linalg.norm(start_point_origin_vec)

# create temporary mesh to not alter original mesh
mesh_temp = Mesh()

# return line if radius of helix is 0 or twist angle is np.pi/2
if np.isclose(radius, 0) or np.isclose(np.cos(twist_angle), 0.0):
if turns:
Expand All @@ -576,15 +580,20 @@ def create_beam_mesh_helix(
+ "Simple line geometry is returned!"
)

return create_beam_mesh_line(
mesh,
line_sets = create_beam_mesh_line(
mesh_temp,
beam_object,
material,
start_point=start_point,
end_point=start_point + height_helix * axis * np.sign(np.sin(twist_angle)),
**kwargs,
)

# add line to mesh
mesh.add_mesh(mesh_temp)

return line_sets

# generate simple helix
if height_helix:
end_point = np.array(
Expand All @@ -608,22 +617,25 @@ def create_beam_mesh_helix(
]
)

helix = create_beam_mesh_line(
mesh,
helix_sets = create_beam_mesh_line(
mesh_temp,
beam_object,
material,
start_point=[radius, 0, 0],
end_point=end_point,
**kwargs,
)

mesh.wrap_around_cylinder()
mesh_temp.wrap_around_cylinder()

# rotate and translate simple helix to align with neccessary axis and starting point
mesh.rotate(
mesh_temp.rotate(
Rotation.from_basis(start_point_origin_vec, axis)
* Rotation([1, 0, 0], -np.pi * 0.5)
)
mesh.translate(-mesh.nodes[0].coordinates + start_point)
mesh_temp.translate(-mesh_temp.nodes[0].coordinates + start_point)

# add helix to mesh
mesh.add_mesh(mesh_temp)

return helix
return helix_sets
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@
-----------------------------------------------------------------------MATERIALS
MAT 1 MAT_BeamReissnerElastHyper YOUNG 100000.0 POISSONRATIO 0.0 DENS 0.0 CROSSAREA 0.7853981633974483 SHEARCORR 1.0 MOMINPOL 0.09817477042468103 MOMIN2 0.04908738521234052 MOMIN3 0.04908738521234052
-------------------------------------------------------------DNODE-NODE TOPOLOGY
NODE 7 DNODE 1
NODE 1 DNODE 2
NODE 10 DNODE 1
NODE 4 DNODE 2
-------------------------------------------------------------DLINE-NODE TOPOLOGY
NODE 1 DLINE 1
NODE 2 DLINE 1
NODE 3 DLINE 1
NODE 4 DLINE 1
NODE 5 DLINE 1
NODE 6 DLINE 1
NODE 7 DLINE 1
NODE 8 DLINE 1
NODE 9 DLINE 1
NODE 10 DLINE 1
---------------------------------------------------------------------NODE COORDS
NODE 1 COORD 2 0 0
NODE 2 COORD 1.34482448817 1.48035370639 1.66666666667
NODE 3 COORD -0.191447096029 1.9908159155 3.33333333333
NODE 4 COORD -1.60228723109 1.19694428821 5
NODE 5 COORD -1.96334800942 -0.381135925751 6.66666666667
NODE 6 COORD -1.03807125077 -1.70950521448 8.33333333333
NODE 7 COORD 0.567324370926 -1.91784854933 10
NODE 1 COORD 0 0 0
NODE 2 COORD -0.5 -0.5 -0.5
NODE 3 COORD -1 -1 -1
NODE 4 COORD 2 0 0
NODE 5 COORD 1.34482448817 1.48035370639 1.66666666667
NODE 6 COORD -0.191447096029 1.9908159155 3.33333333333
NODE 7 COORD -1.60228723109 1.19694428821 5
NODE 8 COORD -1.96334800942 -0.381135925751 6.66666666667
NODE 9 COORD -1.03807125077 -1.70950521448 8.33333333333
NODE 10 COORD 0.567324370926 -1.91784854933 10
--------------------------------------------------------------STRUCTURE ELEMENTS
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.613943125569 -1.48218982027 0.613943125569 0.825845001377 -1.75132059139 1.82233126689 0.0412003090647 -1.71867210284 1.24441771648
2 BEAM3R HERM2LINE3 3 5 4 MAT 1 TRIADS 0.825845001377 -1.75132059139 1.82233126689 -1.76693362712 0.540443031687 -1.63156168219 -1.62734522345 1.40867035905 -2.14678720617
3 BEAM3R HERM2LINE3 5 7 6 MAT 1 TRIADS -1.76693362712 0.540443031687 -1.63156168219 -1.36158461459 -0.809718268376 -0.390228435716 -1.6574070681 -0.199576520935 -1.03084186572
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544
2 BEAM3R HERM2LINE3 4 6 5 MAT 1 TRIADS -0.613943125569 -1.48218982027 0.613943125569 0.825845001377 -1.75132059139 1.82233126689 0.0412003090647 -1.71867210284 1.24441771648
3 BEAM3R HERM2LINE3 6 8 7 MAT 1 TRIADS 0.825845001377 -1.75132059139 1.82233126689 -1.76693362712 0.540443031687 -1.63156168219 -1.62734522345 1.40867035905 -2.14678720617
4 BEAM3R HERM2LINE3 8 10 9 MAT 1 TRIADS -1.76693362712 0.540443031687 -1.63156168219 -1.36158461459 -0.809718268376 -0.390228435716 -1.6574070681 -0.199576520935 -1.03084186572
-----------------------------------------------------------------------------END
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@
-----------------------------------------------------------------------MATERIALS
MAT 1 MAT_BeamReissnerElastHyper YOUNG 100000.0 POISSONRATIO 0.0 DENS 0.0 CROSSAREA 0.7853981633974483 SHEARCORR 1.0 MOMINPOL 0.09817477042468103 MOMIN2 0.04908738521234052 MOMIN3 0.04908738521234052
-------------------------------------------------------------DNODE-NODE TOPOLOGY
NODE 9 DNODE 1
NODE 1 DNODE 2
NODE 12 DNODE 1
NODE 4 DNODE 2
-------------------------------------------------------------DLINE-NODE TOPOLOGY
NODE 1 DLINE 1
NODE 2 DLINE 1
NODE 3 DLINE 1
NODE 4 DLINE 1
NODE 5 DLINE 1
NODE 6 DLINE 1
NODE 7 DLINE 1
NODE 8 DLINE 1
NODE 9 DLINE 1
NODE 10 DLINE 1
NODE 11 DLINE 1
NODE 12 DLINE 1
---------------------------------------------------------------------NODE COORDS
NODE 1 COORD 1 1 1
NODE 2 COORD 6.7735026919 6.7735026919 6.7735026919
NODE 3 COORD 12.5470053838 12.5470053838 12.5470053838
NODE 4 COORD 18.3205080757 18.3205080757 18.3205080757
NODE 5 COORD 24.0940107676 24.0940107676 24.0940107676
NODE 6 COORD 29.8675134595 29.8675134595 29.8675134595
NODE 7 COORD 35.6410161514 35.6410161514 35.6410161514
NODE 8 COORD 41.4145188433 41.4145188433 41.4145188433
NODE 9 COORD 47.1880215352 47.1880215352 47.1880215352
NODE 1 COORD 0 0 0
NODE 2 COORD -0.5 -0.5 -0.5
NODE 3 COORD -1 -1 -1
NODE 4 COORD 1 1 1
NODE 5 COORD 6.7735026919 6.7735026919 6.7735026919
NODE 6 COORD 12.5470053838 12.5470053838 12.5470053838
NODE 7 COORD 18.3205080757 18.3205080757 18.3205080757
NODE 8 COORD 24.0940107676 24.0940107676 24.0940107676
NODE 9 COORD 29.8675134595 29.8675134595 29.8675134595
NODE 10 COORD 35.6410161514 35.6410161514 35.6410161514
NODE 11 COORD 41.4145188433 41.4145188433 41.4145188433
NODE 12 COORD 47.1880215352 47.1880215352 47.1880215352
--------------------------------------------------------------STRUCTURE ELEMENTS
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
2 BEAM3R HERM2LINE3 3 5 4 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
3 BEAM3R HERM2LINE3 5 7 6 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
4 BEAM3R HERM2LINE3 7 9 8 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544
2 BEAM3R HERM2LINE3 4 6 5 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
3 BEAM3R HERM2LINE3 6 8 7 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
4 BEAM3R HERM2LINE3 8 10 9 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
5 BEAM3R HERM2LINE3 10 12 11 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
-----------------------------------------------------------------------------END
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@
-----------------------------------------------------------------------MATERIALS
MAT 1 MAT_BeamReissnerElastHyper YOUNG 100000.0 POISSONRATIO 0.0 DENS 0.0 CROSSAREA 0.7853981633974483 SHEARCORR 1.0 MOMINPOL 0.09817477042468103 MOMIN2 0.04908738521234052 MOMIN3 0.04908738521234052
-------------------------------------------------------------DNODE-NODE TOPOLOGY
NODE 9 DNODE 1
NODE 1 DNODE 2
NODE 12 DNODE 1
NODE 4 DNODE 2
-------------------------------------------------------------DLINE-NODE TOPOLOGY
NODE 1 DLINE 1
NODE 2 DLINE 1
NODE 3 DLINE 1
NODE 4 DLINE 1
NODE 5 DLINE 1
NODE 6 DLINE 1
NODE 7 DLINE 1
NODE 8 DLINE 1
NODE 9 DLINE 1
NODE 10 DLINE 1
NODE 11 DLINE 1
NODE 12 DLINE 1
---------------------------------------------------------------------NODE COORDS
NODE 1 COORD 3 0 0
NODE 2 COORD 2.9899942382 2.42676917578 -0.25169990452
NODE 3 COORD 2.05197680159 4.33763484933 0.940515367999
NODE 4 COORD 1.40034341356 4.86248321003 3.23236390479
NODE 5 COORD 2.03994442247 4.14534044222 5.47496917316
NODE 6 COORD 4.03084223457 3.23898968807 6.55548562467
NODE 7 COORD 6.44436403582 3.33465636213 6.21136065882
NODE 8 COORD 8.04260574482 4.89039614134 5.22244268006
NODE 9 COORD 8.18419850451 7.29593855857 4.84037101261
NODE 1 COORD 0 0 0
NODE 2 COORD -0.5 -0.5 -0.5
NODE 3 COORD -1 -1 -1
NODE 4 COORD 3 0 0
NODE 5 COORD 2.9899942382 2.42676917578 -0.25169990452
NODE 6 COORD 2.05197680159 4.33763484933 0.940515367999
NODE 7 COORD 1.40034341356 4.86248321003 3.23236390479
NODE 8 COORD 2.03994442247 4.14534044222 5.47496917316
NODE 9 COORD 4.03084223457 3.23898968807 6.55548562467
NODE 10 COORD 6.44436403582 3.33465636213 6.21136065882
NODE 11 COORD 8.04260574482 4.89039614134 5.22244268006
NODE 12 COORD 8.18419850451 7.29593855857 4.84037101261
--------------------------------------------------------------STRUCTURE ELEMENTS
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS 1.50130718108 1.35661672402 0.477171338627 -1.21863105979 -2.05469395851 -0.864081375082 1.75047263615 2.16242430293 0.846693286851
2 BEAM3R HERM2LINE3 3 5 4 MAT 1 TRIADS -1.21863105979 -2.05469395851 -0.864081375082 0.0863366257001 -0.868861065578 -0.445997447356 -0.52331096555 -1.49406240657 -0.676920827978
3 BEAM3R HERM2LINE3 5 7 6 MAT 1 TRIADS 0.0863366257001 -0.868861065578 -0.445997447356 1.08651489404 0.517671463843 0.11327033771 0.622783907829 -0.196088893105 -0.181481669134
4 BEAM3R HERM2LINE3 7 9 8 MAT 1 TRIADS 1.08651489404 0.517671463843 0.11327033771 1.73107566054 2.07231804729 0.804238861004 1.46615833297 1.27206928616 0.439606672431
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544
2 BEAM3R HERM2LINE3 4 6 5 MAT 1 TRIADS 1.50130718108 1.35661672402 0.477171338627 -1.21863105979 -2.05469395851 -0.864081375082 1.75047263615 2.16242430293 0.846693286851
3 BEAM3R HERM2LINE3 6 8 7 MAT 1 TRIADS -1.21863105979 -2.05469395851 -0.864081375082 0.0863366257001 -0.868861065578 -0.445997447356 -0.52331096555 -1.49406240657 -0.676920827978
4 BEAM3R HERM2LINE3 8 10 9 MAT 1 TRIADS 0.0863366257001 -0.868861065578 -0.445997447356 1.08651489404 0.517671463843 0.11327033771 0.622783907829 -0.196088893105 -0.181481669134
5 BEAM3R HERM2LINE3 10 12 11 MAT 1 TRIADS 1.08651489404 0.517671463843 0.11327033771 1.73107566054 2.07231804729 0.804238861004 1.46615833297 1.27206928616 0.439606672431
-----------------------------------------------------------------------------END
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
-----------------------------------------------------------------------MATERIALS
MAT 1 MAT_BeamReissnerElastHyper YOUNG 100000.0 POISSONRATIO 0.0 DENS 0.0 CROSSAREA 0.7853981633974483 SHEARCORR 1.0 MOMINPOL 0.09817477042468103 MOMIN2 0.04908738521234052 MOMIN3 0.04908738521234052
-------------------------------------------------------------DNODE-NODE TOPOLOGY
NODE 5 DNODE 1
NODE 1 DNODE 2
NODE 8 DNODE 1
NODE 4 DNODE 2
-------------------------------------------------------------DLINE-NODE TOPOLOGY
NODE 1 DLINE 1
NODE 2 DLINE 1
NODE 3 DLINE 1
NODE 4 DLINE 1
NODE 5 DLINE 1
NODE 6 DLINE 1
NODE 7 DLINE 1
NODE 8 DLINE 1
---------------------------------------------------------------------NODE COORDS
NODE 1 COORD 2 2 1
NODE 2 COORD 3.44337567297 3.44337567297 2.44337567297
NODE 3 COORD 4.88675134595 4.88675134595 3.88675134595
NODE 4 COORD 6.33012701892 6.33012701892 5.33012701892
NODE 5 COORD 7.7735026919 7.7735026919 6.7735026919
NODE 1 COORD 0 0 0
NODE 2 COORD -0.5 -0.5 -0.5
NODE 3 COORD -1 -1 -1
NODE 4 COORD 2 2 1
NODE 5 COORD 3.44337567297 3.44337567297 2.44337567297
NODE 6 COORD 4.88675134595 4.88675134595 3.88675134595
NODE 7 COORD 6.33012701892 6.33012701892 5.33012701892
NODE 8 COORD 7.7735026919 7.7735026919 6.7735026919
--------------------------------------------------------------STRUCTURE ELEMENTS
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
2 BEAM3R HERM2LINE3 3 5 4 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544 -0.719803035506 2.26469064399 -0.298152179544
2 BEAM3R HERM2LINE3 4 6 5 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
3 BEAM3R HERM2LINE3 6 8 7 MAT 1 TRIADS -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894 -0.241535826833 -0.75993556603 0.58311906894
-----------------------------------------------------------------------------END
20 changes: 20 additions & 0 deletions tests/testing_mesh_creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,11 @@ def test_mesh_creation_functions_helix_no_rotation(self):
# Add material and function.
mat = MaterialReissner(youngs_modulus=1e5, radius=0.5, shear_correction=1.0)

# Add simple line to verify that the helix creation does not alter additional meshes
create_beam_mesh_line(
input_file, Beam3rHerm2Line3, mat, [0.0, 0.0, 0.0], [-1.0, -1.0, -1.0]
)

# Create helix.
helix_set = create_beam_mesh_helix(
input_file,
Expand All @@ -773,6 +778,11 @@ def test_mesh_creation_functions_helix_rotation_offset(self):
# Add material and function.
mat = MaterialReissner(youngs_modulus=1e5, radius=0.5, shear_correction=1.0)

# Add simple line to verify that the helix creation does not alter additional meshes
create_beam_mesh_line(
input_file, Beam3rHerm2Line3, mat, [0.0, 0.0, 0.0], [-1.0, -1.0, -1.0]
)

# Create helix.
helix_set = create_beam_mesh_helix(
input_file,
Expand All @@ -799,6 +809,11 @@ def test_mesh_creation_functions_helix_radius_zero(self):
# Add material and function.
mat = MaterialReissner(youngs_modulus=1e5, radius=0.5, shear_correction=1.0)

# Add simple line to verify that the helix creation does not alter additional meshes
create_beam_mesh_line(
input_file, Beam3rHerm2Line3, mat, [0.0, 0.0, 0.0], [-1.0, -1.0, -1.0]
)

# Create helix.
helix_set = create_beam_mesh_helix(
input_file,
Expand Down Expand Up @@ -826,6 +841,11 @@ def test_mesh_creation_functions_helix_twist_angle_right_angle(self):
# Add material and function.
mat = MaterialReissner(youngs_modulus=1e5, radius=0.5, shear_correction=1.0)

# Add simple line to verify that the helix creation does not alter additional meshes
create_beam_mesh_line(
input_file, Beam3rHerm2Line3, mat, [0.0, 0.0, 0.0], [-1.0, -1.0, -1.0]
)

# Create helix.
helix_set = create_beam_mesh_helix(
input_file,
Expand Down

0 comments on commit 30f7a81

Please sign in to comment.