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