From ff60de294719f49f45c0033236294ccfca790b05 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 16 Oct 2023 22:50:52 +0200 Subject: [PATCH 1/4] add ImportMedModeler --- .../modelers/import_med_modeler.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 applications/MedApplication/python_scripts/modelers/import_med_modeler.py diff --git a/applications/MedApplication/python_scripts/modelers/import_med_modeler.py b/applications/MedApplication/python_scripts/modelers/import_med_modeler.py new file mode 100644 index 000000000000..007920c895de --- /dev/null +++ b/applications/MedApplication/python_scripts/modelers/import_med_modeler.py @@ -0,0 +1,48 @@ +import KratosMultiphysics as KM +import KratosMultiphysics.MedApplication as KratosMed + + +class ImportMedModeler(KM.Modeler): + def __init__(self, model, settings): + super().__init__(model, settings) + + # Cannot validate as settings may differ among input types + settings.AddMissingParameters(self.__GetDefaultSettings()) + + self.input_filename: str = settings["input_filename"].GetString() + + # Create the import destination model part + # It is mandatory to do this when the modeler is instantiated to have the model part created before the solvers add the variables + model_part_name: str = settings["model_part_name"].GetString() + if not model_part_name: + raise Exception( + "Missing 'model_part_name' in input settings. This is where the imported model part is to be stored." + ) + + self.model_part: KM.ModelPart = model.CreateModelPart(model_part_name) + + def SetupGeometryModel(self): + super().SetupGeometryModel() + + KratosMed.MedModelPartIO(self.input_filename, KM.IO.READ).ReadModelPart(self.model_part) + + def PrepareGeometryModel(self): + super().PrepareGeometryModel() + + def SetupModelPart(self): + super().SetupModelPart() + + @classmethod + def __GetDefaultSettings(cls): + default_settings = KM.Parameters( + """{ + "echo_level" : 0, + "input_filename" : "", + "model_part_name" : "" + }""" + ) + return default_settings + + +def Factory(model, settings): + return ImportMedModeler(model, settings) From c9508a9d81a3776189d797feeb7837f18d183bca Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 20 Oct 2023 21:08:40 +0200 Subject: [PATCH 2/4] WIP test --- .../tests/test_MedApplication.py | 17 +- .../tests/test_import_med_modeler.py | 183 ++++++++++++++++++ 2 files changed, 194 insertions(+), 6 deletions(-) create mode 100644 applications/MedApplication/tests/test_import_med_modeler.py diff --git a/applications/MedApplication/tests/test_MedApplication.py b/applications/MedApplication/tests/test_MedApplication.py index 068e617fe356..2b10fd953c0c 100644 --- a/applications/MedApplication/tests/test_MedApplication.py +++ b/applications/MedApplication/tests/test_MedApplication.py @@ -2,9 +2,11 @@ # Import the tests of test-classes to create the suites import test_med_model_part_io +import test_import_med_modeler + def AssembleTestSuites(): - ''' Populates the test suites to run. + """Populates the test suites to run. Populates the test suites to run. At least, it should pupulate the suites: "small", "nighlty" and "all" @@ -14,31 +16,34 @@ def AssembleTestSuites(): suites: A dictionary of suites The set of suites with its test_cases added. - ''' + """ suites = KratosUnittest.KratosSuites # Create a test suit with the selected tests (Small tests): # smallSuite will contain the following tests: # - testSmallExample - smallSuite = suites['small'] + smallSuite = suites["small"] smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases([test_med_model_part_io.TestMedModelPartIO])) + smallSuite.addTests( + KratosUnittest.TestLoader().loadTestsFromTestCases([test_import_med_modeler.TestImportMedModeler]) + ) # Create a test suit with the selected tests # nightSuite will contain the following tests: # - testSmallExample # - testNightlyFirstExample # - testNightlySecondExample - nightSuite = suites['nightly'] + nightSuite = suites["nightly"] nightSuite.addTests(smallSuite) # Create a test suit that contains all the tests from every testCase # in the list: - allSuite = suites['all'] + allSuite = suites["all"] allSuite.addTests(nightSuite) return suites -if __name__ == '__main__': +if __name__ == "__main__": KratosUnittest.runTests(AssembleTestSuites()) diff --git a/applications/MedApplication/tests/test_import_med_modeler.py b/applications/MedApplication/tests/test_import_med_modeler.py new file mode 100644 index 000000000000..5dc0290cc9fe --- /dev/null +++ b/applications/MedApplication/tests/test_import_med_modeler.py @@ -0,0 +1,183 @@ +# Importing the Kratos Library +import KratosMultiphysics +import KratosMultiphysics.KratosUnittest as KratosUnittest +from KratosMultiphysics.MedApplication.modelers.import_med_modeler import ImportMedModeler +from pathlib import Path +from testing_utilities import MedModelPartIOTestCase, GetMedPath + + +class TestImportMedModeler(MedModelPartIOTestCase): + def test_import_med_modeler(self): + # Set up the import model part modeler + model = KratosMultiphysics.Model() + settings = KratosMultiphysics.Parameters( + """{ + "echo_level" : 0, + "input_filename" : "", + "model_part_name" : "Main" + }""" + ) + settings["input_filename"].SetString(str(GetMedPath(Path("hexahedral_8N")))) + import_mdpa_modeler = ImportMedModeler(model, settings) + + # Get the model part created by the modeler + model_part = model.GetModelPart(settings["model_part_name"].GetString()) + + # Call the modeler methods + import_mdpa_modeler.SetupGeometryModel() + import_mdpa_modeler.PrepareGeometryModel() + import_mdpa_modeler.SetupModelPart() + + self._basic_checks(model_part) + + # Check results + + return + + self.assertEqual(model_part.NumberOfSubModelParts(), 2) + + self.assertEqual(model_part.NumberOfTables(), 0) + self.assertEqual(model_part.NumberOfProperties(), 0) + self.assertEqual(model_part.NumberOfNodes(), 6) + self.assertEqual(model_part.NumberOfGeometries(), 9) + self.assertEqual(model_part.NumberOfElements(), 0) + self.assertEqual(model_part.NumberOfConditions(), 5) + + self.assertEqual(model_part[KratosMultiphysics.AMBIENT_TEMPERATURE], 250.0) + self.assertEqual(model_part[KratosMultiphysics.DISPLACEMENT_X], 2.1) + self.assertEqual(model_part[KratosMultiphysics.DISPLACEMENT_Y], 3.2) + self.assertEqual(model_part[KratosMultiphysics.DISPLACEMENT_Z], 4.3) + self.assertEqual(model_part[KratosMultiphysics.VELOCITY_X], 3.8) + self.assertEqual(model_part[KratosMultiphysics.VELOCITY_Y], 4.9) + self.assertEqual(model_part[KratosMultiphysics.VELOCITY_Z], 0.0) + + self.assertTrue(model_part.GetNode(1).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) + self.assertTrue(model_part.GetNode(2).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) + self.assertFalse(model_part.GetNode(3).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) + self.assertFalse(model_part.GetNode(972).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) + self.assertTrue(model_part.GetNode(973).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) + self.assertTrue(model_part.GetNode(974).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) + + self.assertTrue(model_part.GetNode(1).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) + self.assertTrue(model_part.GetNode(2).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) + self.assertFalse(model_part.GetNode(3).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) + self.assertFalse(model_part.GetNode(972).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) + self.assertTrue(model_part.GetNode(973).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) + self.assertTrue(model_part.GetNode(974).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) + + self.assertTrue(model_part.GetNode(1).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) + self.assertTrue(model_part.GetNode(2).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) + self.assertFalse(model_part.GetNode(3).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) + self.assertFalse(model_part.GetNode(972).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) + self.assertTrue(model_part.GetNode(973).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) + self.assertTrue(model_part.GetNode(974).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) + + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.1) + self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.2) + self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) + self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) + self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) + self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) + + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) + self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) + self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) + self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) + self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.000973) + self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.000974) + + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) + self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) + self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) + self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) + self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) + self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) + + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) + self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) + self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.0) + self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.0) + self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) + self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) + + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VELOCITY_X), 1.1) + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VELOCITY_Y), 2.2) + self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VELOCITY_Z), 3.3) + + self.assertTrue(model_part.HasSubModelPart("Inlets")) + + inlets_model_part = model_part.GetSubModelPart("Inlets") + + self.assertEqual(inlets_model_part.NumberOfTables(), 1) + self.assertEqual(inlets_model_part.NumberOfProperties(), 0) + self.assertEqual(inlets_model_part.NumberOfNodes(), 3) + self.assertEqual(inlets_model_part.NumberOfGeometries(), 0) + self.assertEqual(inlets_model_part.NumberOfElements(), 1) + self.assertEqual(inlets_model_part.NumberOfConditions(), 3) + self.assertEqual(inlets_model_part.NumberOfSubModelParts(), 2) + self.assertTrue(inlets_model_part.HasSubModelPart("Inlet1")) + self.assertTrue(inlets_model_part.HasSubModelPart("Inlet2")) + + inlet1_model_part = inlets_model_part.GetSubModelPart("Inlet1") + + self.assertEqual(inlet1_model_part.NumberOfTables(), 0) + self.assertEqual(inlet1_model_part.NumberOfProperties(), 0) + self.assertEqual(inlet1_model_part.NumberOfNodes(), 2) + self.assertEqual(inlet1_model_part.NumberOfGeometries(), 0) + self.assertEqual(inlet1_model_part.NumberOfElements(), 0) + self.assertEqual(inlet1_model_part.NumberOfConditions(), 2) + self.assertEqual(inlet1_model_part.NumberOfSubModelParts(), 0) + + inlet2_model_part = inlets_model_part.GetSubModelPart("Inlet2") + + self.assertEqual(inlet2_model_part.NumberOfTables(), 0) + self.assertEqual(inlet2_model_part.NumberOfProperties(), 0) + self.assertEqual(inlet2_model_part.NumberOfNodes(), 0) + self.assertEqual(inlet2_model_part.NumberOfGeometries(), 0) + self.assertEqual(inlet2_model_part.NumberOfElements(), 0) + self.assertEqual(inlet2_model_part.NumberOfConditions(), 2) + self.assertEqual(inlet2_model_part.NumberOfSubModelParts(), 0) + + self.assertTrue(model_part.HasSubModelPart("Outlet")) + + outlet_model_part = model_part.GetSubModelPart("Outlet") + + self.assertEqual(outlet_model_part.NumberOfTables(), 0) + self.assertEqual(outlet_model_part.NumberOfProperties(), 1) + self.assertEqual(outlet_model_part.NumberOfNodes(), 0) + self.assertEqual(outlet_model_part.NumberOfGeometries(), 0) + self.assertEqual(outlet_model_part.NumberOfElements(), 0) + self.assertEqual(outlet_model_part.NumberOfConditions(), 1) + self.assertEqual(outlet_model_part.NumberOfSubModelParts(), 0) + + properties_1 = model_part.GetProperties()[1] + # Bools + self.assertTrue(properties_1[KratosMultiphysics.IS_RESTARTED]) + self.assertFalse(properties_1[KratosMultiphysics.COMPUTE_DYNAMIC_TANGENT]) + self.assertFalse(properties_1[KratosMultiphysics.COMPUTE_LUMPED_MASS_MATRIX]) + # Double + self.assertEqual(properties_1[KratosMultiphysics.DENSITY], 3.4e-5) + # Array3 + self.assertEqual(properties_1[KratosMultiphysics.VOLUME_ACCELERATION][0], 0.00) + self.assertEqual(properties_1[KratosMultiphysics.VOLUME_ACCELERATION][1], 0.00) + self.assertEqual(properties_1[KratosMultiphysics.VOLUME_ACCELERATION][2], 9.8) + # Matrix3x3 + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][0, 0], 0) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][0, 1], 0.27) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][0, 2], 0.27) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][1, 0], 0.087) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][1, 1], 0) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][1, 2], 0.27) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][2, 0], 0.075) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][2, 1], 0.23) + self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][2, 2], 0) + + # SubModelPartData + self.assertTrue(inlets_model_part[KratosMultiphysics.IS_RESTARTED]) + self.assertTrue(inlets_model_part[KratosMultiphysics.COMPUTE_LUMPED_MASS_MATRIX]) + self.assertFalse(inlets_model_part[KratosMultiphysics.COMPUTE_DYNAMIC_TANGENT]) + + +if __name__ == "__main__": + KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING) + KratosUnittest.main() From 6b08c5e31923d5a4fce5e015de437fa5ec55da38 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 20 Oct 2023 21:10:41 +0200 Subject: [PATCH 3/4] finished test --- .../tests/test_import_med_modeler.py | 170 +++--------------- 1 file changed, 24 insertions(+), 146 deletions(-) diff --git a/applications/MedApplication/tests/test_import_med_modeler.py b/applications/MedApplication/tests/test_import_med_modeler.py index 5dc0290cc9fe..e79ca5ee78fb 100644 --- a/applications/MedApplication/tests/test_import_med_modeler.py +++ b/applications/MedApplication/tests/test_import_med_modeler.py @@ -1,16 +1,17 @@ # Importing the Kratos Library -import KratosMultiphysics +import KratosMultiphysics as KM import KratosMultiphysics.KratosUnittest as KratosUnittest +import KratosMultiphysics.MedApplication as KratosMed from KratosMultiphysics.MedApplication.modelers.import_med_modeler import ImportMedModeler from pathlib import Path -from testing_utilities import MedModelPartIOTestCase, GetMedPath +from testing_utilities import MedModelPartIOTestCase, GetMedPath, get_num_geometries_by_type class TestImportMedModeler(MedModelPartIOTestCase): def test_import_med_modeler(self): # Set up the import model part modeler - model = KratosMultiphysics.Model() - settings = KratosMultiphysics.Parameters( + model = KM.Model() + settings = KM.Parameters( """{ "echo_level" : 0, "input_filename" : "", @@ -30,154 +31,31 @@ def test_import_med_modeler(self): self._basic_checks(model_part) - # Check results + # Check read ModelPart + self.assertEqual(model_part.NumberOfNodes(), 216) + self.assertEqual(model_part.NumberOfGeometries(), 371) - return + # check how many geoms of each type + exp_geoms = {KM.Hexahedra3D8: 125, KM.Quadrilateral3D4: 150, KM.Line3D2: 60, KM.Geometry: 36} + self.assertEqual(sum(exp_geoms.values()), model_part.NumberOfGeometries()) + self.assertDictEqual(exp_geoms, get_num_geometries_by_type(model_part)) - self.assertEqual(model_part.NumberOfSubModelParts(), 2) + self.assertAlmostEqual(KratosMed.MedTestingUtilities.ComputeLength(model_part), 3200) + self.assertAlmostEqual(KratosMed.MedTestingUtilities.ComputeArea(model_part), 340000) + self.assertAlmostEqual(KratosMed.MedTestingUtilities.ComputeVolume(model_part), 10000000) + self.assertAlmostEqual(KratosMed.MedTestingUtilities.ComputeDomainSize(model_part), 10343200) - self.assertEqual(model_part.NumberOfTables(), 0) - self.assertEqual(model_part.NumberOfProperties(), 0) - self.assertEqual(model_part.NumberOfNodes(), 6) - self.assertEqual(model_part.NumberOfGeometries(), 9) - self.assertEqual(model_part.NumberOfElements(), 0) - self.assertEqual(model_part.NumberOfConditions(), 5) + for node in model_part.Nodes: + self.assertTrue(0.0 <= node.X <= 500.0) + self.assertTrue(0.0 <= node.X0 <= 500.0) - self.assertEqual(model_part[KratosMultiphysics.AMBIENT_TEMPERATURE], 250.0) - self.assertEqual(model_part[KratosMultiphysics.DISPLACEMENT_X], 2.1) - self.assertEqual(model_part[KratosMultiphysics.DISPLACEMENT_Y], 3.2) - self.assertEqual(model_part[KratosMultiphysics.DISPLACEMENT_Z], 4.3) - self.assertEqual(model_part[KratosMultiphysics.VELOCITY_X], 3.8) - self.assertEqual(model_part[KratosMultiphysics.VELOCITY_Y], 4.9) - self.assertEqual(model_part[KratosMultiphysics.VELOCITY_Z], 0.0) + self.assertTrue(0.0 <= node.Y <= 100.0) + self.assertTrue(0.0 <= node.Y0 <= 100.0) - self.assertTrue(model_part.GetNode(1).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) - self.assertTrue(model_part.GetNode(2).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) - self.assertFalse(model_part.GetNode(3).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) - self.assertFalse(model_part.GetNode(972).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) - self.assertTrue(model_part.GetNode(973).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) - self.assertTrue(model_part.GetNode(974).IsFixed(KratosMultiphysics.DISPLACEMENT_X)) - - self.assertTrue(model_part.GetNode(1).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) - self.assertTrue(model_part.GetNode(2).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) - self.assertFalse(model_part.GetNode(3).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) - self.assertFalse(model_part.GetNode(972).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) - self.assertTrue(model_part.GetNode(973).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) - self.assertTrue(model_part.GetNode(974).IsFixed(KratosMultiphysics.DISPLACEMENT_Y)) - - self.assertTrue(model_part.GetNode(1).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) - self.assertTrue(model_part.GetNode(2).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) - self.assertFalse(model_part.GetNode(3).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) - self.assertFalse(model_part.GetNode(972).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) - self.assertTrue(model_part.GetNode(973).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) - self.assertTrue(model_part.GetNode(974).IsFixed(KratosMultiphysics.DISPLACEMENT_Z)) - - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.1) - self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.2) - self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) - self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) - self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) - self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X), 0.0) - - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) - self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) - self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) - self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.0) - self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.000973) - self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Y), 0.000974) - - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) - self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) - self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) - self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) - self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) - self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_Z), 0.0) - - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) - self.assertEqual(model_part.GetNode(2).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) - self.assertEqual(model_part.GetNode(3).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.0) - self.assertEqual(model_part.GetNode(972).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.0) - self.assertEqual(model_part.GetNode(973).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) - self.assertEqual(model_part.GetNode(974).GetSolutionStepValue(KratosMultiphysics.VISCOSITY), 0.01) - - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VELOCITY_X), 1.1) - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VELOCITY_Y), 2.2) - self.assertEqual(model_part.GetNode(1).GetSolutionStepValue(KratosMultiphysics.VELOCITY_Z), 3.3) - - self.assertTrue(model_part.HasSubModelPart("Inlets")) - - inlets_model_part = model_part.GetSubModelPart("Inlets") - - self.assertEqual(inlets_model_part.NumberOfTables(), 1) - self.assertEqual(inlets_model_part.NumberOfProperties(), 0) - self.assertEqual(inlets_model_part.NumberOfNodes(), 3) - self.assertEqual(inlets_model_part.NumberOfGeometries(), 0) - self.assertEqual(inlets_model_part.NumberOfElements(), 1) - self.assertEqual(inlets_model_part.NumberOfConditions(), 3) - self.assertEqual(inlets_model_part.NumberOfSubModelParts(), 2) - self.assertTrue(inlets_model_part.HasSubModelPart("Inlet1")) - self.assertTrue(inlets_model_part.HasSubModelPart("Inlet2")) - - inlet1_model_part = inlets_model_part.GetSubModelPart("Inlet1") - - self.assertEqual(inlet1_model_part.NumberOfTables(), 0) - self.assertEqual(inlet1_model_part.NumberOfProperties(), 0) - self.assertEqual(inlet1_model_part.NumberOfNodes(), 2) - self.assertEqual(inlet1_model_part.NumberOfGeometries(), 0) - self.assertEqual(inlet1_model_part.NumberOfElements(), 0) - self.assertEqual(inlet1_model_part.NumberOfConditions(), 2) - self.assertEqual(inlet1_model_part.NumberOfSubModelParts(), 0) - - inlet2_model_part = inlets_model_part.GetSubModelPart("Inlet2") - - self.assertEqual(inlet2_model_part.NumberOfTables(), 0) - self.assertEqual(inlet2_model_part.NumberOfProperties(), 0) - self.assertEqual(inlet2_model_part.NumberOfNodes(), 0) - self.assertEqual(inlet2_model_part.NumberOfGeometries(), 0) - self.assertEqual(inlet2_model_part.NumberOfElements(), 0) - self.assertEqual(inlet2_model_part.NumberOfConditions(), 2) - self.assertEqual(inlet2_model_part.NumberOfSubModelParts(), 0) - - self.assertTrue(model_part.HasSubModelPart("Outlet")) - - outlet_model_part = model_part.GetSubModelPart("Outlet") - - self.assertEqual(outlet_model_part.NumberOfTables(), 0) - self.assertEqual(outlet_model_part.NumberOfProperties(), 1) - self.assertEqual(outlet_model_part.NumberOfNodes(), 0) - self.assertEqual(outlet_model_part.NumberOfGeometries(), 0) - self.assertEqual(outlet_model_part.NumberOfElements(), 0) - self.assertEqual(outlet_model_part.NumberOfConditions(), 1) - self.assertEqual(outlet_model_part.NumberOfSubModelParts(), 0) - - properties_1 = model_part.GetProperties()[1] - # Bools - self.assertTrue(properties_1[KratosMultiphysics.IS_RESTARTED]) - self.assertFalse(properties_1[KratosMultiphysics.COMPUTE_DYNAMIC_TANGENT]) - self.assertFalse(properties_1[KratosMultiphysics.COMPUTE_LUMPED_MASS_MATRIX]) - # Double - self.assertEqual(properties_1[KratosMultiphysics.DENSITY], 3.4e-5) - # Array3 - self.assertEqual(properties_1[KratosMultiphysics.VOLUME_ACCELERATION][0], 0.00) - self.assertEqual(properties_1[KratosMultiphysics.VOLUME_ACCELERATION][1], 0.00) - self.assertEqual(properties_1[KratosMultiphysics.VOLUME_ACCELERATION][2], 9.8) - # Matrix3x3 - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][0, 0], 0) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][0, 1], 0.27) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][0, 2], 0.27) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][1, 0], 0.087) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][1, 1], 0) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][1, 2], 0.27) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][2, 0], 0.075) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][2, 1], 0.23) - self.assertEqual(properties_1[KratosMultiphysics.LOCAL_INERTIA_TENSOR][2, 2], 0) - - # SubModelPartData - self.assertTrue(inlets_model_part[KratosMultiphysics.IS_RESTARTED]) - self.assertTrue(inlets_model_part[KratosMultiphysics.COMPUTE_LUMPED_MASS_MATRIX]) - self.assertFalse(inlets_model_part[KratosMultiphysics.COMPUTE_DYNAMIC_TANGENT]) + self.assertTrue(0.0 <= node.Z <= 200.0) + self.assertTrue(0.0 <= node.Z0 <= 200.0) if __name__ == "__main__": - KratosMultiphysics.Logger.GetDefaultOutput().SetSeverity(KratosMultiphysics.Logger.Severity.WARNING) + KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING) KratosUnittest.main() From b6ba8ffa6fc165b331608a17452b596e0dca7970 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 20 Oct 2023 21:14:39 +0200 Subject: [PATCH 4/4] formatting --- applications/MedApplication/tests/run_cpp_unit_tests.py | 5 +++-- applications/MedApplication/tests/test_med_model_part_io.py | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/applications/MedApplication/tests/run_cpp_unit_tests.py b/applications/MedApplication/tests/run_cpp_unit_tests.py index f0d8e31cfa96..b04313406f21 100644 --- a/applications/MedApplication/tests/run_cpp_unit_tests.py +++ b/applications/MedApplication/tests/run_cpp_unit_tests.py @@ -1,9 +1,10 @@ import KratosMultiphysics as KM from KratosMultiphysics.MedApplication import * import sys + if len(sys.argv) < 2: - KM.Tester.SetVerbosity(KM.Tester.Verbosity.PROGRESS) # TESTS_OUTPUTS + KM.Tester.SetVerbosity(KM.Tester.Verbosity.PROGRESS) # TESTS_OUTPUTS KM.Tester.RunTestSuite("KratosMedFastSuite") -else : +else: KM.Tester.SetVerbosity(KM.Tester.Verbosity.TESTS_OUTPUTS) KM.Tester.RunTestCases(sys.argv[1]) diff --git a/applications/MedApplication/tests/test_med_model_part_io.py b/applications/MedApplication/tests/test_med_model_part_io.py index 2a5215dd6f84..9867a208e451 100644 --- a/applications/MedApplication/tests/test_med_model_part_io.py +++ b/applications/MedApplication/tests/test_med_model_part_io.py @@ -39,9 +39,7 @@ def _execute_tests(self, med_path, check_fct, print_vtk=False): med_io_read_2.ReadModelPart(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 + 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):