Coverage for src/beamme/four_c/boundary_condition_data.py: 100%
14 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-28 15:20 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-28 15:20 +0000
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 provides a data class to handle boundary conditions dumped to 4C input
23files."""
25from dataclasses import dataclass as _dataclass
26from typing import Any as _Any
28from beamme.core.mesh_representation import GeometrySetInfo as _GeometrySetInfo
31@_dataclass
32class FourCBoundaryConditionData:
33 """Class that contains the data for a 4C boundary condition."""
35 geometry_set_id: int
36 data: dict
38 def dump_to_input_file_yaml(self) -> dict:
39 """Dump the boundary condition data to a dictionary that can be written to a 4C
40 input file with the mesh in yaml format."""
41 return {"E": self.geometry_set_id, **self.data}
43 def dump_to_input_file_vtu(
44 self, geometry_sets_in_mr: dict[int, _GeometrySetInfo]
45 ) -> dict:
46 """Dump the boundary condition data to a dictionary that can be written to a 4C
47 input file with the mesh in vtu format."""
48 # For geometry sets in vtu format, 4C starts counting from 0. Also, the entries in geometry_sets_in_mr are indexed from 0.
49 geometry_set_id = self.geometry_set_id - 1
50 geometry_set_info = geometry_sets_in_mr[geometry_set_id]
52 boundary_condition_geometry_info: dict[str, _Any]
53 if geometry_set_info.name is not None:
54 boundary_condition_geometry_info = {"NODE_SET_NAME": geometry_set_info.name}
55 else:
56 boundary_condition_geometry_info = {
57 "E": geometry_set_id,
58 "ENTITY_TYPE": "node_set_id",
59 }
60 return {**boundary_condition_geometry_info, **self.data}