Skip to content
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

[Med] minor cleanup in tests #11700

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ void AddCustomUtilitiesToPython(pybind11::module& m)
namespace py = pybind11;

py::class_<MedTestingUtilities>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ double ComputeGeometricalQuantity(

void MedTestingUtilities::CheckModelPartsAreEqual(
const ModelPart& rModelPart1,
const ModelPart& rModelPart2)
const ModelPart& rModelPart2,
const bool CheckSubModelParts)
{
KRATOS_TRY

Expand All @@ -223,6 +224,10 @@ 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
25 changes: 16 additions & 9 deletions applications/MedApplication/tests/test_med_model_part_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -271,4 +277,5 @@ def write_vtk(model_part, name):


if __name__ == "__main__":
KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING)
KratosUnittest.main()
4 changes: 2 additions & 2 deletions applications/MedApplication/tests/testing_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down