diff --git a/applications/MedApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/MedApplication/custom_python/add_custom_utilities_to_python.cpp index ada143f12d64..70d6a57d8260 100644 --- a/applications/MedApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/MedApplication/custom_python/add_custom_utilities_to_python.cpp @@ -27,7 +27,10 @@ void AddCustomUtilitiesToPython(pybind11::module& m) namespace py = pybind11; py::class_(m,"MedTestingUtilities") - .def_static("CheckModelPartsAreEqual", &MedTestingUtilities::CheckModelPartsAreEqual) + .def_static("CheckModelPartsAreEqual", &MedTestingUtilities::CheckModelPartsAreEqual, + py::arg("model_part_1"), + py::arg("model_part_2"), + py::arg("check_sub_model_parts")=true) .def_static("AddGeometriesFromElements", &MedTestingUtilities::AddGeometriesFromElements) .def_static("ComputeLength", &MedTestingUtilities::ComputeLength) .def_static("ComputeArea", &MedTestingUtilities::ComputeArea) diff --git a/applications/MedApplication/custom_utilities/med_testing_utilities.cpp b/applications/MedApplication/custom_utilities/med_testing_utilities.cpp index 3d76d2c20abe..0a1b9b55fe21 100644 --- a/applications/MedApplication/custom_utilities/med_testing_utilities.cpp +++ b/applications/MedApplication/custom_utilities/med_testing_utilities.cpp @@ -198,7 +198,8 @@ double ComputeGeometricalQuantity( void MedTestingUtilities::CheckModelPartsAreEqual( const ModelPart& rModelPart1, - const ModelPart& rModelPart2) + const ModelPart& rModelPart2, + const bool CheckSubModelParts) { KRATOS_TRY @@ -223,13 +224,17 @@ void MedTestingUtilities::CheckModelPartsAreEqual( // check geometries CheckGeometriesAreEqual(rModelPart1, rModelPart2); + if (!CheckSubModelParts) { + return; + } + KRATOS_CHECK_EQUAL(rModelPart1.NumberOfSubModelParts(), rModelPart2.NumberOfSubModelParts()); const auto& r_smp2_names = rModelPart2.GetSubModelPartNames(); for (const auto& r_smp_name : rModelPart1.GetSubModelPartNames()) { KRATOS_CHECK(contains(r_smp2_names, r_smp_name)); - CheckModelPartsAreEqual(rModelPart1.GetSubModelPart(r_smp_name), rModelPart1.GetSubModelPart(r_smp_name)); + CheckModelPartsAreEqual(rModelPart1.GetSubModelPart(r_smp_name), rModelPart2.GetSubModelPart(r_smp_name)); } KRATOS_CATCH("") diff --git a/applications/MedApplication/custom_utilities/med_testing_utilities.h b/applications/MedApplication/custom_utilities/med_testing_utilities.h index cc713174b3a2..e971f4a14a29 100644 --- a/applications/MedApplication/custom_utilities/med_testing_utilities.h +++ b/applications/MedApplication/custom_utilities/med_testing_utilities.h @@ -63,7 +63,8 @@ class KRATOS_API(MED_APPLICATION) MedTestingUtilities static void CheckModelPartsAreEqual( const ModelPart& rModelPart1, - const ModelPart& rModelPart2); + const ModelPart& rModelPart2, + const bool CheckSubModelParts=true); static void AddGeometriesFromElements( ModelPart& rModelPart); diff --git a/applications/MedApplication/tests/med_files/empty/mesh.med b/applications/MedApplication/tests/med_files/empty.med similarity index 100% rename from applications/MedApplication/tests/med_files/empty/mesh.med rename to applications/MedApplication/tests/med_files/empty.med diff --git a/applications/MedApplication/tests/med_files/hexahedral_20N/mesh.med b/applications/MedApplication/tests/med_files/hexahedral_20N.med similarity index 100% rename from applications/MedApplication/tests/med_files/hexahedral_20N/mesh.med rename to applications/MedApplication/tests/med_files/hexahedral_20N.med diff --git a/applications/MedApplication/tests/med_files/hexahedral_27N/mesh.med b/applications/MedApplication/tests/med_files/hexahedral_27N.med similarity index 100% rename from applications/MedApplication/tests/med_files/hexahedral_27N/mesh.med rename to applications/MedApplication/tests/med_files/hexahedral_27N.med diff --git a/applications/MedApplication/tests/med_files/hexahedral_8N/mesh.med b/applications/MedApplication/tests/med_files/hexahedral_8N.med similarity index 100% rename from applications/MedApplication/tests/med_files/hexahedral_8N/mesh.med rename to applications/MedApplication/tests/med_files/hexahedral_8N.med diff --git a/applications/MedApplication/tests/med_files/only_nodes/mesh.med b/applications/MedApplication/tests/med_files/only_nodes.med similarity index 100% rename from applications/MedApplication/tests/med_files/only_nodes/mesh.med rename to applications/MedApplication/tests/med_files/only_nodes.med diff --git a/applications/MedApplication/tests/med_files/quadrilateral_4N_2d/create_mesh.py b/applications/MedApplication/tests/med_files/quadrilateral_4N_2d/create_mesh.py deleted file mode 100644 index 8713b45370cd..000000000000 --- a/applications/MedApplication/tests/med_files/quadrilateral_4N_2d/create_mesh.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python - -### -### This file is generated automatically by SALOME v9.6.0 with dump python functionality -### - -import salome - -salome.salome_init() -import salome_notebook -notebook = salome_notebook.NoteBook() - -### -### GEOM component -### - -import GEOM -from salome.geom import geomBuilder -import math -import SALOMEDS - - -geompy = geomBuilder.New() - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) -Face_1 = geompy.MakeFaceHW(100, 100, 1) -geompy.addToStudy( O, 'O' ) -geompy.addToStudy( OX, 'OX' ) -geompy.addToStudy( OY, 'OY' ) -geompy.addToStudy( OZ, 'OZ' ) -geompy.addToStudy( Face_1, 'Face_1' ) - -### -### SMESH component -### - -import SMESH, SALOMEDS -from salome.smesh import smeshBuilder - -smesh = smeshBuilder.New() -#smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations: - # multiples meshes built in parallel, complex and numerous mesh edition (performance) - -#hyp_8.SetLength( 14.1421 ) ### not created Object -NETGEN_2D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters_2D', 'NETGENEngine', 14.1421, 1 ) -Mesh_1 = smesh.Mesh(Face_1) -status = Mesh_1.AddHypothesis( Face_1, NETGEN_2D_Parameters_1 ) -NETGEN_1D_2D = Mesh_1.Triangle(algo=smeshBuilder.NETGEN_1D2D) -isDone = Mesh_1.Compute() - - -## Set names of Mesh objects -smesh.SetName(NETGEN_1D_2D.GetAlgorithm(), 'NETGEN 1D-2D') -smesh.SetName(NETGEN_2D_Parameters_1, 'NETGEN 2D Parameters_1') -smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') - - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser() diff --git a/applications/MedApplication/tests/med_files/quadrilateral_4N_2d/mesh.med b/applications/MedApplication/tests/med_files/quadrilateral_4N_2d/mesh.med deleted file mode 100644 index 1a45e8ef3b28..000000000000 Binary files a/applications/MedApplication/tests/med_files/quadrilateral_4N_2d/mesh.med and /dev/null differ diff --git a/applications/MedApplication/tests/med_files/tetrahedral_10N/mesh.med b/applications/MedApplication/tests/med_files/tetrahedral_10N.med similarity index 100% rename from applications/MedApplication/tests/med_files/tetrahedral_10N/mesh.med rename to applications/MedApplication/tests/med_files/tetrahedral_10N.med diff --git a/applications/MedApplication/tests/med_files/tetrahedral_4N/mesh.med b/applications/MedApplication/tests/med_files/tetrahedral_4N.med similarity index 100% rename from applications/MedApplication/tests/med_files/tetrahedral_4N/mesh.med rename to applications/MedApplication/tests/med_files/tetrahedral_4N.med diff --git a/applications/MedApplication/tests/med_files/triangle_3N_2d/create_mesh.py b/applications/MedApplication/tests/med_files/triangle_3N_2d/create_mesh.py deleted file mode 100644 index 86e9d0c4e8b1..000000000000 --- a/applications/MedApplication/tests/med_files/triangle_3N_2d/create_mesh.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python - -### -### This file is generated automatically by SALOME v9.6.0 with dump python functionality -### - -import salome - -salome.salome_init() -import salome_notebook -notebook = salome_notebook.NoteBook() - -### -### GEOM component -### - -import GEOM -from salome.geom import geomBuilder -import math -import SALOMEDS - - -geompy = geomBuilder.New() - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) -Face_1 = geompy.MakeFaceHW(100, 100, 1) -geompy.addToStudy( O, 'O' ) -geompy.addToStudy( OX, 'OX' ) -geompy.addToStudy( OY, 'OY' ) -geompy.addToStudy( OZ, 'OZ' ) -geompy.addToStudy( Face_1, 'Face_1' ) - -### -### SMESH component -### - -import SMESH, SALOMEDS -from salome.smesh import smeshBuilder - -smesh = smeshBuilder.New() -#smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations: - # multiples meshes built in parallel, complex and numerous mesh edition (performance) - -#hyp_0.SetLength( 14.1421 ) ### not created Object -NETGEN_2D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters_2D', 'NETGENEngine', 14.1421, 0 ) -Mesh_1 = smesh.Mesh(Face_1) -status = Mesh_1.AddHypothesis( Face_1, NETGEN_2D_Parameters_1 ) -NETGEN_1D_2D = Mesh_1.Triangle(algo=smeshBuilder.NETGEN_1D2D) -isDone = Mesh_1.Compute() - - -## Set names of Mesh objects -smesh.SetName(NETGEN_1D_2D.GetAlgorithm(), 'NETGEN 1D-2D') -smesh.SetName(NETGEN_2D_Parameters_1, 'NETGEN 2D Parameters_1') -smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') - - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser() diff --git a/applications/MedApplication/tests/med_files/triangle_3N_2d/mesh.med b/applications/MedApplication/tests/med_files/triangle_3N_2d/mesh.med deleted file mode 100644 index c16e5287a8d9..000000000000 Binary files a/applications/MedApplication/tests/med_files/triangle_3N_2d/mesh.med and /dev/null differ diff --git a/applications/MedApplication/tests/med_files/triangle_3N_3d/create_mesh.py b/applications/MedApplication/tests/med_files/triangle_3N_3d/create_mesh.py deleted file mode 100644 index b51ceafe260b..000000000000 --- a/applications/MedApplication/tests/med_files/triangle_3N_3d/create_mesh.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -### -### This file is generated automatically by SALOME v9.6.0 with dump python functionality -### - -import salome - -salome.salome_init() -import salome_notebook -notebook = salome_notebook.NoteBook() - -### -### GEOM component -### - -import GEOM -from salome.geom import geomBuilder -import math -import SALOMEDS - - -geompy = geomBuilder.New() - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) -Vertex_1 = geompy.MakeVertex(1, 0, 0.1) -Vertex_2 = geompy.MakeVertex(0, 1, 0) -Line_1 = geompy.MakeLineTwoPnt(Vertex_2, Vertex_1) -Line_2 = geompy.MakeLineTwoPnt(O, Vertex_2) -Line_3 = geompy.MakeLineTwoPnt(O, Vertex_1) -Face_1 = geompy.MakeFaceWires([Line_1, Line_2, Line_3], 1) -geompy.addToStudy( O, 'O' ) -geompy.addToStudy( OX, 'OX' ) -geompy.addToStudy( OY, 'OY' ) -geompy.addToStudy( OZ, 'OZ' ) -geompy.addToStudy( Vertex_1, 'Vertex_1' ) -geompy.addToStudy( Vertex_2, 'Vertex_2' ) -geompy.addToStudy( Line_1, 'Line_1' ) -geompy.addToStudy( Line_2, 'Line_2' ) -geompy.addToStudy( Line_3, 'Line_3' ) -geompy.addToStudy( Face_1, 'Face_1' ) - -### -### SMESH component -### - -import SMESH, SALOMEDS -from salome.smesh import smeshBuilder - -smesh = smeshBuilder.New() -#smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations: - # multiples meshes built in parallel, complex and numerous mesh edition (performance) - -#hyp_12.SetLength( 0.141774 ) ### not created Object -NETGEN_2D_Parameters_1 = smesh.CreateHypothesisByAverageLength( 'NETGEN_Parameters_2D', 'NETGENEngine', 0.141774, 0 ) -Mesh_1 = smesh.Mesh(Face_1) -status = Mesh_1.AddHypothesis( Face_1, NETGEN_2D_Parameters_1 ) -NETGEN_1D_2D = Mesh_1.Triangle(algo=smeshBuilder.NETGEN_1D2D) -isDone = Mesh_1.Compute() - - -## Set names of Mesh objects -smesh.SetName(NETGEN_1D_2D.GetAlgorithm(), 'NETGEN 1D-2D') -smesh.SetName(NETGEN_2D_Parameters_1, 'NETGEN 2D Parameters_1') -smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') - - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser() diff --git a/applications/MedApplication/tests/med_files/triangle_3N_3d/mesh.med b/applications/MedApplication/tests/med_files/triangle_3N_3d/mesh.med deleted file mode 100644 index f78cd1488267..000000000000 Binary files a/applications/MedApplication/tests/med_files/triangle_3N_3d/mesh.med and /dev/null differ diff --git a/applications/MedApplication/tests/test_med_model_part_io.py b/applications/MedApplication/tests/test_med_model_part_io.py index 852963c17b4c..2a5215dd6f84 100644 --- a/applications/MedApplication/tests/test_med_model_part_io.py +++ b/applications/MedApplication/tests/test_med_model_part_io.py @@ -6,6 +6,8 @@ from KratosMultiphysics.kratos_utilities import DeleteFileIfExisting from testing_utilities import MedModelPartIOTestCase, GetMedPath, get_num_geometries_by_type +from pathlib import Path + class TestMedModelPartIO(MedModelPartIOTestCase): def setUp(self): @@ -26,7 +28,7 @@ def _execute_tests(self, med_path, check_fct, print_vtk=False): check_fct(self.mp_read_1) with self.subTest("read_write_read"): - med_temp_path = GetMedPath(med_path, "temp.med") + med_temp_path = GetMedPath(med_path).with_suffix(".med.tmp") DeleteFileIfExisting(med_temp_path) # make sure there are no leftovers from previous tests self.addCleanup(DeleteFileIfExisting, med_temp_path) # clean up after test @@ -36,13 +38,17 @@ def _execute_tests(self, med_path, check_fct, print_vtk=False): med_io_read_2 = KratosMed.MedModelPartIO(med_temp_path, KM.IO.READ) med_io_read_2.ReadModelPart(self.mp_read_2) - KratosMed.MedTestingUtilities.CheckModelPartsAreEqual(self.mp_read_1, self.mp_read_2) + KratosMed.MedTestingUtilities.CheckModelPartsAreEqual( + self.mp_read_1, + self.mp_read_2, + check_sub_model_parts=False # until writing of SMPs is implemented + ) def test_empty_med_file(self): def mp_check_fct(model_part): self.assertEqual(model_part.NumberOfNodes(), 0) - self._execute_tests("empty", mp_check_fct) + self._execute_tests(Path("empty"), mp_check_fct) def test_only_nodes(self): def mp_check_fct(model_part): @@ -58,7 +64,7 @@ def mp_check_fct(model_part): self.assertAlmostEqual(node.Z, coords[2]) self.assertAlmostEqual(node.Z0, coords[2]) - self._execute_tests("only_nodes", mp_check_fct) + self._execute_tests(Path("only_nodes"), mp_check_fct) def test_nodes_with_sub_meshes(self): self.skipTest("This test is not yet implemented") @@ -125,7 +131,7 @@ def mp_check_fct(model_part): self.assertTrue(0.0 <= node.Z <= 200.0) self.assertTrue(0.0 <= node.Z0 <= 200.0) - self._execute_tests("tetrahedral_4N", mp_check_fct) + self._execute_tests(Path("tetrahedral_4N"), mp_check_fct) def test_tetrahedra_10N_quadratic_mesh(self): def mp_check_fct(model_part): @@ -152,7 +158,7 @@ def mp_check_fct(model_part): self.assertTrue(0.0 <= node.Z <= 200.0) self.assertTrue(0.0 <= node.Z0 <= 200.0) - self._execute_tests("tetrahedral_10N", mp_check_fct) + self._execute_tests(Path("tetrahedral_10N"), mp_check_fct) def test_hexahedra_8N_linear_mesh(self): def mp_check_fct(model_part): @@ -179,7 +185,7 @@ def mp_check_fct(model_part): self.assertTrue(0.0 <= node.Z <= 200.0) self.assertTrue(0.0 <= node.Z0 <= 200.0) - self._execute_tests("hexahedral_8N", mp_check_fct) + self._execute_tests(Path("hexahedral_8N"), mp_check_fct) def test_hexahedra_20N_quadratic_mesh(self): self.skipTest("The connectivity conversion is not yet fully implemented") @@ -208,7 +214,7 @@ def mp_check_fct(model_part): self.assertTrue(0.0 <= node.Z <= 200.0) self.assertTrue(0.0 <= node.Z0 <= 200.0) - self._execute_tests("hexahedral_20N", mp_check_fct) + self._execute_tests(Path("hexahedral_20N"), mp_check_fct) def test_hexahedra_27N_biquadratic_mesh(self): self.skipTest("The connectivity conversion is not yet fully implemented") @@ -237,7 +243,7 @@ def mp_check_fct(model_part): self.assertTrue(0.0 <= node.Z <= 200.0) self.assertTrue(0.0 <= node.Z0 <= 200.0) - self._execute_tests("hexahedral_27N", mp_check_fct) + self._execute_tests(Path("hexahedral_27N"), mp_check_fct) def write_vtk(model_part, name): @@ -271,4 +277,5 @@ def write_vtk(model_part, name): if __name__ == "__main__": + KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING) KratosUnittest.main() diff --git a/applications/MedApplication/tests/testing_utilities.py b/applications/MedApplication/tests/testing_utilities.py index 1fc3e5237064..4b19f2459faf 100644 --- a/applications/MedApplication/tests/testing_utilities.py +++ b/applications/MedApplication/tests/testing_utilities.py @@ -7,8 +7,8 @@ from typing import Any, Dict, List, Set -def GetMedPath(med_path, med_name="mesh.med"): - return Path(__file__).absolute().parent / "med_files" / med_path / med_name +def GetMedPath(med_file_name: Path) -> Path: + return Path(__file__).absolute().parent / "med_files" / med_file_name.with_suffix(".med") class MedModelPartIOTestCase(KratosUnittest.TestCase):