Skip to content

Commit fa31632

Browse files
Merge pull request #321 from davidrudlstorfer/remove_inheritance_of_inputfile_on_mesh
Remove inheritance of InputFile on Mesh
2 parents 48ec144 + 78788ff commit fa31632

12 files changed

+496
-735
lines changed

src/meshpy/four_c/dbc_monitor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ def add_point_neuman_condition_to_input_file(
183183

184184
# Add the function to the input file, if they are not previously added.
185185
for function in function_array:
186-
input_file.add(function)
186+
input_file.mesh.add(function)
187187

188188
# Create GeometrySet with nodes.
189-
mesh_nodes = [input_file.nodes[i_node] for i_node in nodes]
189+
mesh_nodes = [input_file.mesh.nodes[i_node] for i_node in nodes]
190190
geo = _GeometrySet(mesh_nodes)
191191

192192
# Create the Boundary Condition.
@@ -200,7 +200,7 @@ def add_point_neuman_condition_to_input_file(
200200
},
201201
bc_type=_mpy.bc.neumann,
202202
)
203-
input_file.add(bc)
203+
input_file.mesh.add(bc)
204204

205205

206206
def dbc_monitor_to_input_all_values(
@@ -322,7 +322,7 @@ def dbc_monitor_to_input_all_values(
322322
)
323323

324324
# add the function to the input array
325-
input_file.add(fun)
325+
input_file.mesh.add(fun)
326326

327327
# store function
328328
functions.append(fun)

src/meshpy/four_c/input_file.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def _get_yaml_geometry_sets(
128128
return geometry_sets_in_this_section
129129

130130

131-
class InputFile(_Mesh):
131+
class InputFile:
132132
"""An item that represents a complete 4C input file."""
133133

134134
# Define the names of sections and boundary conditions in the input file.
@@ -206,7 +206,7 @@ def __init__(self, *, yaml_file: _Optional[_Path] = None, cubit=None):
206206
into this input file.
207207
"""
208208

209-
super().__init__()
209+
self.mesh = _Mesh()
210210

211211
# Everything that is not a full MeshPy object is stored here, e.g., parameters
212212
# and imported nodes/elements/materials/...
@@ -345,7 +345,7 @@ def add(self, *args, **kwargs):
345345
self.add_section(args[0], **kwargs)
346346
return
347347

348-
super().add(*args, **kwargs)
348+
self.mesh.add(*args, **kwargs)
349349

350350
def add_section(self, section, *, option_overwrite=False):
351351
"""Add a section to the object.
@@ -462,7 +462,7 @@ def get_dict_to_dump(
462462

463463
# Perform some checks on the mesh.
464464
if _mpy.check_overlapping_elements:
465-
self.check_overlapping_elements()
465+
self.mesh.check_overlapping_elements()
466466

467467
# The base dictionary we use here is the one that already exists.
468468
# This one might already contain mesh sections - stored in pure
@@ -619,36 +619,36 @@ def _dump_mesh_items(yaml_dict, section_name, data_list):
619619
raise TypeError(f"Could not dump {item}")
620620

621621
# Add sets from couplings and boundary conditions to a temp container.
622-
self.unlink_nodes()
622+
self.mesh.unlink_nodes()
623623
start_indices_geometry_set = _get_global_start_geometry_set(yaml_dict)
624-
mesh_sets = self.get_unique_geometry_sets(
624+
mesh_sets = self.mesh.get_unique_geometry_sets(
625625
geometry_set_start_indices=start_indices_geometry_set
626626
)
627627

628628
# Assign global indices to all entries.
629629
start_index_nodes = _get_global_start_node(yaml_dict)
630-
_set_i_global(self.nodes, start_index=start_index_nodes)
630+
_set_i_global(self.mesh.nodes, start_index=start_index_nodes)
631631
start_index_elements = _get_global_start_element(yaml_dict)
632-
_set_i_global_elements(self.elements, start_index=start_index_elements)
632+
_set_i_global_elements(self.mesh.elements, start_index=start_index_elements)
633633
start_index_materials = _get_global_start_material(yaml_dict)
634-
_set_i_global(self.materials, start_index=start_index_materials)
634+
_set_i_global(self.mesh.materials, start_index=start_index_materials)
635635
start_index_functions = _get_global_start_function(yaml_dict)
636-
_set_i_global(self.functions, start_index=start_index_functions)
636+
_set_i_global(self.mesh.functions, start_index=start_index_functions)
637637

638638
# Add material data to the input file.
639-
_dump_mesh_items(yaml_dict, "MATERIALS", self.materials)
639+
_dump_mesh_items(yaml_dict, "MATERIALS", self.mesh.materials)
640640

641641
# Add the functions.
642-
for function in self.functions:
642+
for function in self.mesh.functions:
643643
yaml_dict[f"FUNCT{function.i_global}"] = function.dump_to_list()
644644

645645
# If there are couplings in the mesh, set the link between the nodes
646646
# and elements, so the couplings can decide which DOFs they couple,
647647
# depending on the type of the connected beam element.
648648
def get_number_of_coupling_conditions(key):
649649
"""Return the number of coupling conditions in the mesh."""
650-
if (key, _mpy.geo.point) in self.boundary_conditions.keys():
651-
return len(self.boundary_conditions[key, _mpy.geo.point])
650+
if (key, _mpy.geo.point) in self.mesh.boundary_conditions.keys():
651+
return len(self.mesh.boundary_conditions[key, _mpy.geo.point])
652652
else:
653653
return 0
654654

@@ -657,10 +657,10 @@ def get_number_of_coupling_conditions(key):
657657
+ get_number_of_coupling_conditions(_mpy.bc.point_coupling_penalty)
658658
> 0
659659
):
660-
self.set_node_links()
660+
self.mesh.set_node_links()
661661

662662
# Add the boundary conditions.
663-
for (bc_key, geom_key), bc_list in self.boundary_conditions.items():
663+
for (bc_key, geom_key), bc_list in self.mesh.boundary_conditions.items():
664664
if len(bc_list) > 0:
665665
section_name = (
666666
bc_key
@@ -670,7 +670,7 @@ def get_number_of_coupling_conditions(key):
670670
_dump_mesh_items(yaml_dict, section_name, bc_list)
671671

672672
# Add additional element sections, e.g., for NURBS knot vectors.
673-
for element in self.elements:
673+
for element in self.mesh.elements:
674674
element.dump_element_specific_section(yaml_dict)
675675

676676
# Add the geometry sets.
@@ -679,8 +679,8 @@ def get_number_of_coupling_conditions(key):
679679
_dump_mesh_items(yaml_dict, self.geometry_set_names[geom_key], item)
680680

681681
# Add the nodes and elements.
682-
_dump_mesh_items(yaml_dict, "NODE COORDS", self.nodes)
683-
_dump_mesh_items(yaml_dict, "STRUCTURE ELEMENTS", self.elements)
682+
_dump_mesh_items(yaml_dict, "NODE COORDS", self.mesh.nodes)
683+
_dump_mesh_items(yaml_dict, "STRUCTURE ELEMENTS", self.mesh.elements)
684684

685685
return yaml_dict
686686

tests/conftest.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from vtk_utils.compare_grids import compare_grids
3939

4040
from meshpy.core.conf import mpy
41+
from meshpy.core.mesh import Mesh
4142
from meshpy.four_c.input_file import InputFile
4243
from meshpy.four_c.yaml_dumper import MeshPyDumper as _MeshPyDumper
4344
from meshpy.utils.environment import fourcipp_is_available
@@ -274,8 +275,8 @@ def assert_results_equal(get_string, tmp_path, current_test_name) -> Callable:
274275
"""
275276

276277
def _assert_results_equal(
277-
reference: Union[Path, str, dict],
278-
result: Union[Path, str, dict, InputFile],
278+
reference: Union[Path, str, dict, InputFile, Mesh],
279+
result: Union[Path, str, dict, InputFile, Mesh],
279280
rtol: Optional[float] = None,
280281
atol: Optional[float] = None,
281282
input_file_kwargs: dict = {"add_header_information": False, "check_nox": False},
@@ -331,10 +332,20 @@ def get_dictionary(data) -> dict:
331332
compare_dicts(reference_dict, result_dict, rtol=rtol, atol=atol)
332333
return
333334

334-
if isinstance(reference, InputFile) or isinstance(result, InputFile):
335+
if isinstance(reference, (InputFile, Mesh)) or isinstance(
336+
result, (InputFile, Mesh)
337+
):
335338

336339
def get_dictionary(data) -> dict:
337340
"""Get the dictionary representation of the data object."""
341+
342+
# Internally convert Mesh to InputFile to allow for simple comparison via dictionary
343+
# TODO this should be improved in the future
344+
if isinstance(data, Mesh):
345+
input_file = InputFile()
346+
input_file.add(data)
347+
data = input_file
348+
338349
if isinstance(data, InputFile):
339350
if fourcipp_is_available():
340351
raise ValueError(

tests/reference-files/test_meshpy_comments_in_solid.4C.yaml

-159
This file was deleted.

0 commit comments

Comments
 (0)