Skip to content

Remove inheritance of InputFile on Mesh #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/meshpy/four_c/input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _get_yaml_geometry_sets(
return geometry_sets_in_this_section


class InputFile(_Mesh):
class InputFile:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And as a final note: I tested the overall working with my minimal example from #318 and everything worked out of the box as we discussed it.

"""An item that represents a complete 4C input file."""

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

super().__init__()
self.mesh = _Mesh()

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

super().add(*args, **kwargs)
self.mesh.add(*args, **kwargs)

def add_section(self, section, *, option_overwrite=False):
"""Add a section to the object.
Expand Down Expand Up @@ -428,7 +428,7 @@ def get_dict_to_dump(

# Perform some checks on the mesh.
if _mpy.check_overlapping_elements:
self.check_overlapping_elements()
self.mesh.check_overlapping_elements()

# The base dictionary we use here is the one that already exists.
# This one might already contain mesh sections - stored in pure
Expand Down Expand Up @@ -578,36 +578,36 @@ def _dump_mesh_items(yaml_dict, section_name, data_list):
item_dict_list.extend(item.dump_to_list())

# Add sets from couplings and boundary conditions to a temp container.
self.unlink_nodes()
self.mesh.unlink_nodes()
start_indices_geometry_set = _get_global_start_geometry_set(yaml_dict)
mesh_sets = self.get_unique_geometry_sets(
mesh_sets = self.mesh.get_unique_geometry_sets(
geometry_set_start_indices=start_indices_geometry_set
)

# Assign global indices to all entries.
start_index_nodes = _get_global_start_node(yaml_dict)
_set_i_global(self.nodes, start_index=start_index_nodes)
_set_i_global(self.mesh.nodes, start_index=start_index_nodes)
start_index_elements = _get_global_start_element(yaml_dict)
_set_i_global_elements(self.elements, start_index=start_index_elements)
_set_i_global_elements(self.mesh.elements, start_index=start_index_elements)
start_index_materials = _get_global_start_material(yaml_dict)
_set_i_global(self.materials, start_index=start_index_materials)
_set_i_global(self.mesh.materials, start_index=start_index_materials)
start_index_functions = _get_global_start_function(yaml_dict)
_set_i_global(self.functions, start_index=start_index_functions)
_set_i_global(self.mesh.functions, start_index=start_index_functions)

# Add material data to the input file.
_dump_mesh_items(yaml_dict, "MATERIALS", self.materials)
_dump_mesh_items(yaml_dict, "MATERIALS", self.mesh.materials)

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

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

Expand All @@ -616,10 +616,10 @@ def get_number_of_coupling_conditions(key):
+ get_number_of_coupling_conditions(_mpy.bc.point_coupling_penalty)
> 0
):
self.set_node_links()
self.mesh.set_node_links()

# Add the boundary conditions.
for (bc_key, geom_key), bc_list in self.boundary_conditions.items():
for (bc_key, geom_key), bc_list in self.mesh.boundary_conditions.items():
if len(bc_list) > 0:
section_name = (
bc_key
Expand All @@ -629,7 +629,7 @@ def get_number_of_coupling_conditions(key):
_dump_mesh_items(yaml_dict, section_name, bc_list)

# Add additional element sections, e.g., for NURBS knot vectors.
for element in self.elements:
for element in self.mesh.elements:
element.dump_element_specific_section(yaml_dict)

# Add the geometry sets.
Expand All @@ -638,8 +638,8 @@ def get_number_of_coupling_conditions(key):
_dump_mesh_items(yaml_dict, self.geometry_set_names[geom_key], item)

# Add the nodes and elements.
_dump_mesh_items(yaml_dict, "NODE COORDS", self.nodes)
_dump_mesh_items(yaml_dict, "STRUCTURE ELEMENTS", self.elements)
_dump_mesh_items(yaml_dict, "NODE COORDS", self.mesh.nodes)
_dump_mesh_items(yaml_dict, "STRUCTURE ELEMENTS", self.mesh.elements)

return yaml_dict

Expand Down
3 changes: 2 additions & 1 deletion tests/test_cosserat_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def create_beam_solid_input_file(get_corresponding_reference_file_path):
yaml_file=get_corresponding_reference_file_path(
reference_file_base_name="test_cosserat_curve_mesh"
)
)
).mesh

create_beam_mesh_helix(
mesh,
Beam3rHerm2Line3,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_meshpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def test_meshpy_rotations(assert_results_equal):
"""Check if the Mesh function rotation gives the same results as rotating
each node it self."""

mesh_1 = InputFile()
mesh_1 = Mesh()
create_test_mesh(mesh_1)

mesh_2 = InputFile()
mesh_2 = Mesh()
create_test_mesh(mesh_2)
Comment on lines -115 to 119
Copy link
Collaborator Author

@davidrudlstorfer davidrudlstorfer Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isteinbrecher one general question I wanted to discuss before proceeding to adjust the tests

In my opinion, in the future MeshPy should work without fourcipp, i.e., a 4C input file. For that it would be ideal if we could run tests on Meshes.

Currently we are not able to compare meshes within the testing framework. Do you share this opinion that we should test it without any overhead?

Maybe you have additional ideas, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we share this opinion I would add an option that we can compare individual Meshes in our testing suite.

This somehow contradicts our discussion we had yesterday - we said we mainly wanted to focus on tests with reference files.

But in my opinion it's not that nice that we will always depend on fourcipp.

Maybe create a really generic input file which just dumps the raw data to yaml/json files and compare these?


# Set the seed for the pseudo random numbers
Expand Down
Loading