beamme.four_c.beam_interaction_conditions

This file contains a function to add the beam interaction conditions for 4C.

  1# The MIT License (MIT)
  2#
  3# Copyright (c) 2018-2026 BeamMe 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"""This file contains a function to add the beam interaction conditions for
 234C."""
 24
 25import beamme.core.conf as _conf
 26from beamme.core.boundary_condition import BoundaryCondition as _BoundaryCondition
 27from beamme.core.geometry_set import GeometrySet as _GeometrySet
 28from beamme.core.mesh import Mesh as _Mesh
 29
 30
 31def get_next_possible_id_for_boundary_condition(
 32    mesh: _Mesh,
 33    bc_type: _conf.BoundaryCondition,
 34    geometry_type: _conf.Geometry,
 35    condition_string: str,
 36) -> int:
 37    """Returns the next possible id, which can be used for a boundary condition
 38    based on all previous added boundary conditions within a mesh.
 39
 40    It returns the first ID which is not yet occupied within the existing boundary conditions
 41    w.r.t. to the given search_string and regex group index.
 42
 43    Args:
 44        mesh: Mesh containing already set boundary conditions.
 45        bc_type: Type of the boundary condition to be searched.
 46        geometry_type: Geometry type of the boundary condition.
 47        condition_string: String defining the condition ID tag.
 48
 49    Returns:
 50        id: Smallest available ID
 51    """
 52
 53    found_conditions = []
 54
 55    # loop through every possible geometry and find the conditions
 56    if (bc_type, geometry_type) in mesh.boundary_conditions:
 57        for bc_condition in mesh.boundary_conditions[(bc_type, geometry_type)]:
 58            found_conditions.append(bc_condition)
 59
 60    if not found_conditions:
 61        # return starting id, since no conditions of type has been added.
 62        return 0
 63    else:
 64        existing_ids = []
 65
 66        # compare string of each condition with input and store existing ids
 67        for bc in found_conditions:
 68            if condition_string in bc.data:
 69                existing_ids.append(bc.data[condition_string])
 70            else:
 71                raise KeyError(
 72                    f"The key {condition_string} is not in the data {bc.data}"
 73                )
 74
 75        # return lowest found id
 76        return min(set(range(len(existing_ids) + 1)) - set(existing_ids))
 77
 78
 79def add_beam_interaction_condition(
 80    mesh: _Mesh,
 81    geometry_set_1: _GeometrySet,
 82    geometry_set_2: _GeometrySet,
 83    bc_type: _conf.BoundaryCondition,
 84    *,
 85    id: int | None = None,
 86) -> int:
 87    """Adds a pair of beam interaction boundary conditions to the given mesh
 88    and estimates automatically the id of them based on all previously added
 89    boundary conditions of the mesh.
 90
 91    Args:
 92        mesh: Mesh to which the boundary conditions will be added.
 93        geometry_set_1: GeometrySet 1 for beam interaction boundary condition
 94        geometry_set_2: GeometrySet 2 for beam interaction boundary condition
 95        id: id of the two conditions
 96
 97    Returns:
 98        id: Used id for the created condition.
 99    """
100
101    condition_string = "COUPLING_ID"
102    if id is None:
103        id = get_next_possible_id_for_boundary_condition(
104            mesh,
105            bc_type,
106            geometry_set_1.geometry_type,
107            condition_string=condition_string,
108        )
109
110        id_2 = get_next_possible_id_for_boundary_condition(
111            mesh,
112            bc_type,
113            geometry_set_2.geometry_type,
114            condition_string=condition_string,
115        )
116
117        if not id == id_2:
118            raise ValueError(
119                f"The estimated IDs {id} and {id_2} do not match. Check Inputfile."
120            )
121
122    # Creates the two conditions with the same ID.
123    for geometry_set in [geometry_set_1, geometry_set_2]:
124        mesh.add(
125            _BoundaryCondition(
126                geometry_set, data={condition_string: id}, bc_type=bc_type
127            )
128        )
129
130    return id
def get_next_possible_id_for_boundary_condition( mesh: beamme.core.mesh.Mesh, bc_type: beamme.core.conf.BoundaryCondition, geometry_type: beamme.core.conf.Geometry, condition_string: str) -> int:
32def get_next_possible_id_for_boundary_condition(
33    mesh: _Mesh,
34    bc_type: _conf.BoundaryCondition,
35    geometry_type: _conf.Geometry,
36    condition_string: str,
37) -> int:
38    """Returns the next possible id, which can be used for a boundary condition
39    based on all previous added boundary conditions within a mesh.
40
41    It returns the first ID which is not yet occupied within the existing boundary conditions
42    w.r.t. to the given search_string and regex group index.
43
44    Args:
45        mesh: Mesh containing already set boundary conditions.
46        bc_type: Type of the boundary condition to be searched.
47        geometry_type: Geometry type of the boundary condition.
48        condition_string: String defining the condition ID tag.
49
50    Returns:
51        id: Smallest available ID
52    """
53
54    found_conditions = []
55
56    # loop through every possible geometry and find the conditions
57    if (bc_type, geometry_type) in mesh.boundary_conditions:
58        for bc_condition in mesh.boundary_conditions[(bc_type, geometry_type)]:
59            found_conditions.append(bc_condition)
60
61    if not found_conditions:
62        # return starting id, since no conditions of type has been added.
63        return 0
64    else:
65        existing_ids = []
66
67        # compare string of each condition with input and store existing ids
68        for bc in found_conditions:
69            if condition_string in bc.data:
70                existing_ids.append(bc.data[condition_string])
71            else:
72                raise KeyError(
73                    f"The key {condition_string} is not in the data {bc.data}"
74                )
75
76        # return lowest found id
77        return min(set(range(len(existing_ids) + 1)) - set(existing_ids))

Returns the next possible id, which can be used for a boundary condition based on all previous added boundary conditions within a mesh.

It returns the first ID which is not yet occupied within the existing boundary conditions w.r.t. to the given search_string and regex group index.

Arguments:
  • mesh: Mesh containing already set boundary conditions.
  • bc_type: Type of the boundary condition to be searched.
  • geometry_type: Geometry type of the boundary condition.
  • condition_string: String defining the condition ID tag.
Returns:

id: Smallest available ID

def add_beam_interaction_condition( mesh: beamme.core.mesh.Mesh, geometry_set_1: beamme.core.geometry_set.GeometrySet, geometry_set_2: beamme.core.geometry_set.GeometrySet, bc_type: beamme.core.conf.BoundaryCondition, *, id: int | None = None) -> int:
 80def add_beam_interaction_condition(
 81    mesh: _Mesh,
 82    geometry_set_1: _GeometrySet,
 83    geometry_set_2: _GeometrySet,
 84    bc_type: _conf.BoundaryCondition,
 85    *,
 86    id: int | None = None,
 87) -> int:
 88    """Adds a pair of beam interaction boundary conditions to the given mesh
 89    and estimates automatically the id of them based on all previously added
 90    boundary conditions of the mesh.
 91
 92    Args:
 93        mesh: Mesh to which the boundary conditions will be added.
 94        geometry_set_1: GeometrySet 1 for beam interaction boundary condition
 95        geometry_set_2: GeometrySet 2 for beam interaction boundary condition
 96        id: id of the two conditions
 97
 98    Returns:
 99        id: Used id for the created condition.
100    """
101
102    condition_string = "COUPLING_ID"
103    if id is None:
104        id = get_next_possible_id_for_boundary_condition(
105            mesh,
106            bc_type,
107            geometry_set_1.geometry_type,
108            condition_string=condition_string,
109        )
110
111        id_2 = get_next_possible_id_for_boundary_condition(
112            mesh,
113            bc_type,
114            geometry_set_2.geometry_type,
115            condition_string=condition_string,
116        )
117
118        if not id == id_2:
119            raise ValueError(
120                f"The estimated IDs {id} and {id_2} do not match. Check Inputfile."
121            )
122
123    # Creates the two conditions with the same ID.
124    for geometry_set in [geometry_set_1, geometry_set_2]:
125        mesh.add(
126            _BoundaryCondition(
127                geometry_set, data={condition_string: id}, bc_type=bc_type
128            )
129        )
130
131    return id

Adds a pair of beam interaction boundary conditions to the given mesh and estimates automatically the id of them based on all previously added boundary conditions of the mesh.

Arguments:
  • mesh: Mesh to which the boundary conditions will be added.
  • geometry_set_1: GeometrySet 1 for beam interaction boundary condition
  • geometry_set_2: GeometrySet 2 for beam interaction boundary condition
  • id: id of the two conditions
Returns:

id: Used id for the created condition.