Skip to content

Commit

Permalink
Add element geometry return option.
Browse files Browse the repository at this point in the history
- provide test case to show how it can be used.
  • Loading branch information
knarfnitram committed Dec 19, 2024
1 parent 8b26fef commit 40bb5ef
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions meshpy/geometry_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ def get_all_nodes(self):
"Currently GeometrySet are only implemented for points and lines"
)

def get_geometry_objects(self):
"""Return the objects of the specified geometry type."""
return self.geometry_objects[self.geometry_type]


class GeometrySetNodes(GeometrySetBase):
"""Geometry set which is defined by nodes and not explicit geometry."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -----------------------------------------------------------------------------
// This input file was created with MeshPy.
// Copyright (c) 2018-2024
// Ivo Steinbrecher
// Institute for Mathematics and Computer-Based Simulation
// Universitaet der Bundeswehr Muenchen
// https://www.unibw.de/imcs-en
// -----------------------------------------------------------------------------
-----------------------------------------------------------------------MATERIALS
MAT 1 MAT_BeamReissnerElastHyper YOUNG 1 POISSONRATIO 0.0 DENS 0.0 CROSSAREA 0.031415926535897934 SHEARCORR 1 MOMINPOL 0.00015707963267948968 MOMIN2 7.853981633974484e-05 MOMIN3 7.853981633974484e-05
---------------------------------------------------DESIGN LINE DIRICH CONDITIONS
DLINE 1
E 1 - NUMDOF 9 ONOFF 1 1 1 0 0 0 0 0 0 VAL 0 0 0 0 0 0 0 0 0 FUNCT 0 0 0 0 0 0 0 0 0
-------------------------------------------------------------DLINE-NODE TOPOLOGY
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 COORDS
NODE 1 COORD 0 0 0
NODE 2 COORD 0.2 0 0
NODE 3 COORD 0.4 0 0
NODE 4 COORD 0.6 0 0
NODE 5 COORD 0.8 0 0
NODE 6 COORD 1 0 0
NODE 7 COORD 1.2 0 0
NODE 8 COORD 1.4 0 0
NODE 9 COORD 1.6 0 0
NODE 10 COORD 1.8 0 0
NODE 11 COORD 2 0 0
--------------------------------------------------------------STRUCTURE ELEMENTS
1 BEAM3R HERM2LINE3 1 3 2 MAT 1 TRIADS 0 0 0 0 0 0 0 0 0
2 BEAM3R HERM2LINE3 3 5 4 MAT 1 TRIADS 0 0 0 0 0 0 0 0 0
3 BEAM3R HERM2LINE3 5 7 6 MAT 1 TRIADS 0 0 0 0 0 0 0 0 0
4 BEAM3R HERM2LINE3 7 9 8 MAT 1 TRIADS 0 0 0 0 0 0 0 0 0
5 BEAM3R HERM2LINE3 9 11 10 MAT 1 TRIADS 0 0 0 0 0 0 0 0 0
37 changes: 37 additions & 0 deletions tests/testing_meshpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,43 @@ def get_arguments_curve(circle_type):
additional_identifier=additional_identifier,
)

def test_get_geometry_set_to_boundary_conditions(self):
"""Test if the geometry set returns the objects(elements) and if they
can be forwarded to a GeometrySet."""

# Initialize material and input file.
mat = MaterialReissner(radius=0.1, youngs_modulus=1)
mesh = InputFile()

# number of elements
n_el = 5

# Create a simple beam.
geometry = create_beam_mesh_line(
mesh, Beam3rHerm2Line3, mat, [0, 0, 0], [2, 0, 0], n_el=n_el
)

# Check if all objects elements are returned.
elements_of_geometry = list(geometry["line"].get_geometry_objects().keys())

# First check type.
self.assertEqual(type(elements_of_geometry[0]), Beam3rHerm2Line3)

# Check number of elements.
self.assertEqual(len(elements_of_geometry), n_el)

# Add boundary condition to all elements except the first and last element.
mesh.add(
BoundaryCondition(
GeometrySet(elements_of_geometry[1:-1]),
"NUMDOF 9 ONOFF 1 1 1 0 0 0 0 0 0 VAL 0 0 0 0 0 0 0 0 0 FUNCT 0 0 0 0 0 0 0 0 0",
bc_type=mpy.bc.dirichlet,
)
)

# Compare with the reference file.
compare_test_result(self, mesh.get_string(header=False))

def test_meshpy_replace_nodes_geometry_set(self):
"""Test case for coupling of nodes, and reusing the identical nodes.
Expand Down

0 comments on commit 40bb5ef

Please sign in to comment.