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

Merged
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
8 changes: 4 additions & 4 deletions src/meshpy/four_c/dbc_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ def add_point_neuman_condition_to_input_file(

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

# Create GeometrySet with nodes.
mesh_nodes = [input_file.nodes[i_node] for i_node in nodes]
mesh_nodes = [input_file.mesh.nodes[i_node] for i_node in nodes]
geo = _GeometrySet(mesh_nodes)

# Create the Boundary Condition.
Expand All @@ -200,7 +200,7 @@ def add_point_neuman_condition_to_input_file(
},
bc_type=_mpy.bc.neumann,
)
input_file.add(bc)
input_file.mesh.add(bc)


def dbc_monitor_to_input_all_values(
Expand Down Expand Up @@ -322,7 +322,7 @@ def dbc_monitor_to_input_all_values(
)

# add the function to the input array
input_file.add(fun)
input_file.mesh.add(fun)

# store function
functions.append(fun)
Expand Down
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 @@ -128,7 +128,7 @@ def _get_yaml_geometry_sets(
return geometry_sets_in_this_section


class InputFile(_Mesh):
class InputFile:
"""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 @@ -206,7 +206,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 @@ -345,7 +345,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 @@ -462,7 +462,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 @@ -619,36 +619,36 @@ def _dump_mesh_items(yaml_dict, section_name, data_list):
raise TypeError(f"Could not dump {item}")

# 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 @@ -657,10 +657,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 @@ -670,7 +670,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 @@ -679,8 +679,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
17 changes: 14 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from vtk_utils.compare_grids import compare_grids

from meshpy.core.conf import mpy
from meshpy.core.mesh import Mesh
from meshpy.four_c.input_file import InputFile
from meshpy.four_c.yaml_dumper import MeshPyDumper as _MeshPyDumper
from meshpy.utils.environment import fourcipp_is_available
Expand Down Expand Up @@ -274,8 +275,8 @@ def assert_results_equal(get_string, tmp_path, current_test_name) -> Callable:
"""

def _assert_results_equal(
reference: Union[Path, str, dict],
result: Union[Path, str, dict, InputFile],
reference: Union[Path, str, dict, InputFile, Mesh],
result: Union[Path, str, dict, InputFile, Mesh],
rtol: Optional[float] = None,
atol: Optional[float] = None,
input_file_kwargs: dict = {"add_header_information": False, "check_nox": False},
Expand Down Expand Up @@ -331,10 +332,20 @@ def get_dictionary(data) -> dict:
compare_dicts(reference_dict, result_dict, rtol=rtol, atol=atol)
return

if isinstance(reference, InputFile) or isinstance(result, InputFile):
if isinstance(reference, (InputFile, Mesh)) or isinstance(
result, (InputFile, Mesh)
):

def get_dictionary(data) -> dict:
"""Get the dictionary representation of the data object."""

# Internally convert Mesh to InputFile to allow for simple comparison via dictionary
# TODO this should be improved in the future
if isinstance(data, Mesh):
input_file = InputFile()
input_file.add(data)
data = input_file

if isinstance(data, InputFile):
if fourcipp_is_available():
raise ValueError(
Expand Down
159 changes: 0 additions & 159 deletions tests/reference-files/test_meshpy_comments_in_solid.4C.yaml

This file was deleted.

Loading