Skip to content

Commit

Permalink
Create beam to beam contact factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
knarfnitram committed Feb 4, 2025
1 parent 1536cee commit 474b4b8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 23 deletions.
65 changes: 58 additions & 7 deletions meshpy/four_c/beam_to_beam_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,62 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -----------------------------------------------------------------------------
"""This file contains the definition of the beam to beam contact condition for
4c."""
"""This file contains the definition of the beam to beam contact condition and
the corresponding factory for 4c."""

# MeshPy modules
from ..boundary_condition import BoundaryCondition
from ..conf import mpy
from ..geometry_set import GeometrySet
from ..inputfile import InputFile


class BeamtoBeamContactBoundaryConditionFactory:
"""The beam to beam boundary condition contact factory allows to add two
GeometrySets with the contact condition to an input file and tracks
automatically the unique id of all previously set beam to beam contact
boundary conditions."""

condition_id_ = 0
inputfile = None

# Initialization of the object
def __init__(self, inputfile=InputFile):
# Store a reference to the input file.
self.inputfile = inputfile

# Start by 1 as id.
self.condition_id_ = 1

def add_contact_geometries(
self, geometryset_1=GeometrySet, geometryset_2=GeometrySet
):
"""Creates the contact boundary conditions for two GeometrySets and
adds them to the inputfile.
Automatically keeps track of the ids.
:param geometryset_1: GeometrySet for nodes of body 1
:param geometryset_2: GeometrySet for nodes of body 2
"""

# Creates the two conditions with the same ID.
cond1 = BeamtoBeamContactCondition(geometryset_1, self.condition_id_)
cond2 = BeamtoBeamContactCondition(geometryset_2, self.condition_id_)

# Increment the id.
self.condition_id_ += 1

# Add the new boundary conditions to the input file.
self.inputfile.add(cond1)
self.inputfile.add(cond2)

def get_next_condition_id(self):
"""Return the id of the next condition."""
return self.condition_id_

def get_previous_condition_id(self):
"""Return the id of the last set condition."""
return self.condition_id_ - 1


class BeamtoBeamContactCondition(BoundaryCondition):
Expand All @@ -72,21 +121,23 @@ class BeamtoBeamContactCondition(BoundaryCondition):

def __init__(
self,
geometry_set,
ID,
geometry_set=GeometrySet,
id=int,
**kwargs,
):
"""Initialize the object.
"""
Args
----
geometry_set: GeometrySet
Geometry that this boundary condition acts on.
id: int
Identification number of the boundary condition.
"""

# Initialize the object.
super().__init__(
geometry_set,
"COUPLING_ID {}".format(ID),
"COUPLING_ID {}".format(id),
bc_type=mpy.bc.beam_to_beam_interaction,
**kwargs,
)
24 changes: 8 additions & 16 deletions tests/test_four_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
set_runtime_output,
)
from meshpy.four_c.beam_potential import BeamPotential
from meshpy.four_c.beam_to_beam_contact import BeamtoBeamContactCondition
from meshpy.four_c.beam_to_beam_contact import BeamtoBeamContactBoundaryConditionFactory
from meshpy.four_c.dbc_monitor import linear_time_transformation
from meshpy.four_c.locsys_condition import LocSysCondition
from meshpy.four_c.solid_shell_thickness_direction import (
Expand Down Expand Up @@ -479,21 +479,14 @@ def test_meshpy_beam_contact_example(
)
)

# Add nodes of beam 1 with Coupling ID 1.
mesh.add(
BeamtoBeamContactCondition(
beam_x["line"],
1,
)
)
# Create a beam to beam contact boundary condition factory.
btbc_condition_handler = BeamtoBeamContactBoundaryConditionFactory(mesh)

# Add nodes of beam 2 with same Coupling ID.
mesh.add(
BeamtoBeamContactCondition(
beam_y["line"],
1,
)
)
# Add the two contact node sets.
btbc_condition_handler.add_contact_geometries(beam_x["line"], beam_y["line"])

# check that the id was correctly increased.
assert btbc_condition_handler.get_next_condition_id() == 2

# Add the standard,static header.
set_header_static(
Expand Down Expand Up @@ -522,5 +515,4 @@ def test_meshpy_beam_contact_example(
set_beam_contact_runtime_output(mesh, every_iteration=False)

# Compare with the reference solution.
# compare_test_result(self, mesh.get_string(header=False, check_nox=False))
assert_results_equal(get_corresponding_reference_file_path(), mesh)

0 comments on commit 474b4b8

Please sign in to comment.