Esempio n. 1
0
    def test_overdefined_materials(self):
        import read_materials_process
        current_model = KratosMultiphysics.Model()
        test_settings = KratosMultiphysics.Parameters(
            """ { "Parameters": { "materials_filename": ""}} """)

        test_settings["Parameters"]["materials_filename"].SetString(
            GetFilePath(
                os.path.join("auxiliar_files_for_python_unnitest",
                             "materials_files", "wrong_materials_input",
                             "wrong_materials_1.json")))
        expected_error_msg = "Error: Materials for ModelPart \"Main\" are specified multiple times!"

        with self.assertRaisesRegex(RuntimeError, expected_error_msg):
            KratosMultiphysics.ReadMaterialsUtility(test_settings,
                                                    current_model)
        with self.assertRaisesRegex(Exception, expected_error_msg):
            read_materials_process.Factory(test_settings, current_model)

        test_settings["Parameters"]["materials_filename"].SetString(
            GetFilePath(
                os.path.join("auxiliar_files_for_python_unnitest",
                             "materials_files", "wrong_materials_input",
                             "wrong_materials_2.json")))
        expected_error_msg = "Error: Materials for ModelPart \"Main.sub\" are specified multiple times!"

        with self.assertRaisesRegex(RuntimeError, expected_error_msg):
            KratosMultiphysics.ReadMaterialsUtility(test_settings,
                                                    current_model)
        with self.assertRaisesRegex(Exception, expected_error_msg):
            read_materials_process.Factory(test_settings, current_model)

        test_settings["Parameters"]["materials_filename"].SetString(
            GetFilePath(
                os.path.join("auxiliar_files_for_python_unnitest",
                             "materials_files", "wrong_materials_input",
                             "wrong_materials_3.json")))
        expected_error_msg = "Error: Materials for ModelPart \"Main.sub\" are specified multiple times!\n"
        expected_error_msg += "Overdefined due to also specifying the materials for Parent-ModelPart \"Main\"!"

        with self.assertRaisesRegex(RuntimeError, expected_error_msg):
            KratosMultiphysics.ReadMaterialsUtility(test_settings,
                                                    current_model)
        with self.assertRaisesRegex(Exception, expected_error_msg):
            read_materials_process.Factory(test_settings, current_model)

        test_settings["Parameters"]["materials_filename"].SetString(
            GetFilePath(
                os.path.join("auxiliar_files_for_python_unnitest",
                             "materials_files", "wrong_materials_input",
                             "wrong_materials_4.json")))
        expected_error_msg = "Error: Materials for ModelPart \"Main.sub1.subsub\" are specified multiple times!\n"
        expected_error_msg += "Overdefined due to also specifying the materials for Parent-ModelPart \"Main.sub1\"!"

        with self.assertRaisesRegex(RuntimeError, expected_error_msg):
            KratosMultiphysics.ReadMaterialsUtility(test_settings,
                                                    current_model)
        with self.assertRaisesRegex(Exception, expected_error_msg):
            read_materials_process.Factory(test_settings, current_model)
Esempio n. 2
0
    def test_input_python(self):

        if (missing_external_dependencies is True):
            self.skipTest("{} is not available".format(missing_application))
        self._prepare_test()
        import read_materials_process
        read_materials_process.Factory(self.test_settings,self.current_model)
        self._check_results()
Esempio n. 3
0
    def __init__(self, ProjectParameters):
        self.model_part = ModelPart(
            ProjectParameters["problem_data"]["model_part_name"].GetString())
        self.model_part.ProcessInfo.SetValue(
            DOMAIN_SIZE,
            ProjectParameters["problem_data"]["domain_size"].GetInt())

        ###TODO replace this "model" for real one once available in kratos core
        self.Model = {
            ProjectParameters["problem_data"]["model_part_name"].GetString():
            self.model_part
        }

        #construct the IGASolver (main setting methods are located in the solver_module)
        solver_module = __import__(
            ProjectParameters["solver_settings"]["solver_type"].GetString())
        self.IGASolver = solver_module.CreateSolver(
            self.model_part, ProjectParameters["solver_settings"])

        import read_materials_process
        read_materials_process.Factory(ProjectParameters, self.Model)

        self.IGASolver.AddVariables()
        self.IGASolver.ImportModelPart(ProjectParameters)
        self.IGASolver.AddDofs()

        for i in range(ProjectParameters["solver_settings"]
                       ["processes_sub_model_part_list"].size()):
            part_name = ProjectParameters["solver_settings"][
                "processes_sub_model_part_list"][i].GetString()
            self.Model.update(
                {part_name: self.model_part.GetSubModelPart(part_name)})

        import process_factory
        self.list_of_processes = process_factory.KratosProcessFactory(
            self.Model).ConstructListOfProcesses(
                ProjectParameters["constraints_process_list"])
        self.list_of_processes += process_factory.KratosProcessFactory(
            self.Model).ConstructListOfProcesses(
                ProjectParameters["loads_process_list"])
        if (ProjectParameters.Has("list_other_processes") == True):
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    ProjectParameters["list_other_processes"])
        if (ProjectParameters.Has("json_check_process") == True):
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    ProjectParameters["json_check_process"])
        if (ProjectParameters.Has("json_output_process") == True):
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    ProjectParameters["json_output_process"])

        for process in self.list_of_processes:
            process.ExecuteInitialize()

        self.IGASolver.Initialize()
Esempio n. 4
0
 def import_constitutive_laws(self):
     materials_filename = self.settings["material_import_settings"]["materials_filename"].GetString()
     if (materials_filename != ""):
         # Add constitutive laws and material properties from json file to model parts.
         material_settings = KratosMultiphysics.Parameters("""{"Parameters": {"materials_filename": ""}} """)
         material_settings["Parameters"]["materials_filename"].SetString(materials_filename)
         import read_materials_process # TODO update this, it is deprecated!!!
         read_materials_process.Factory(material_settings,self.model)
         #KratosMultiphysics.ReadMaterialsUtility(material_settings, self.model)
         materials_imported = True
     else:
         materials_imported = False
     return materials_imported
Esempio n. 5
0
 def test_input_python(self):
     self._prepare_test()
     import read_materials_process
     read_materials_process.Factory(self.test_settings, self.current_model)
     self._check_results()
Esempio n. 6
0
    def test_input(self):
        try:
            import KratosMultiphysics.FluidDynamicsApplication as KratosFluid
        except:
            self.skipTest(
                "KratosMultiphysics.FluidDynamicsApplication is not available")

        try:
            import KratosMultiphysics.StructuralMechanicsApplication
        except:
            self.skipTest(
                "KratosMultiphysics.StructuralMechanicsApplication is not available"
            )

        model_part = KratosMultiphysics.ModelPart("Main")
        model_part.AddNodalSolutionStepVariable(
            KratosMultiphysics.DISPLACEMENT)
        model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VISCOSITY)
        model_part_io = KratosMultiphysics.ModelPartIO(
            GetFilePath("test_model_part_io_read")
        )  #reusing the file that is already in the directory
        model_part_io.ReadModelPart(model_part)

        #define a Model TODO: replace to use the real Model once available
        Model = {
            "Main":
            model_part,
            "Inlets":
            model_part.GetSubModelPart("Inlets"),
            "Inlet1":
            model_part.GetSubModelPart("Inlets").GetSubModelPart("Inlet1"),
            "Inlet2":
            model_part.GetSubModelPart("Inlets").GetSubModelPart("Inlet2"),
            "Outlet":
            model_part.GetSubModelPart("Outlet")
        }

        test_settings = KratosMultiphysics.Parameters("""
            {
                    "Parameters": {
                            "materials_filename": "materials.json"
                    }
            }
            """)

        #assign the real path
        test_settings["Parameters"]["materials_filename"].SetString(
            GetFilePath("materials.json"))

        import read_materials_process
        read_materials_process.Factory(test_settings, Model)

        #test if the element properties are assigned correctly to the elements and conditions
        for elem in Model["Inlets"].Elements:
            self.assertTrue(elem.Properties.Id == 1)
        for cond in Model["Inlets"].Conditions:
            self.assertTrue(cond.Properties.Id == 1)
        for elem in Model["Outlet"].Elements:
            self.assertTrue(elem.Properties.Id == 2)
        for cond in Model["Outlet"].Conditions:
            self.assertTrue(cond.Properties.Id == 2)

        #test that the properties are read correctly
        self.assertTrue(model_part.Properties[1].GetValue(
            KratosMultiphysics.YOUNG_MODULUS) == 200.0)
        self.assertTrue(model_part.Properties[1].GetValue(
            KratosMultiphysics.POISSON_RATIO) == 0.3)
        self.assertTrue(model_part.Properties[1].GetValue(
            KratosMultiphysics.YIELD_STRESS) == 400.0)
        self.assertTrue(model_part.Properties[1].GetValue(
            KratosFluid.SUBSCALE_PRESSURE) == 0.1)
        self.assertTrue(model_part.Properties[1].GetValue(
            KratosFluid.VORTICITY_MAGNITUDE) == -5.888)

        self.assertTrue(model_part.Properties[2].GetValue(
            KratosMultiphysics.YOUNG_MODULUS) == 100.0)
        self.assertTrue(model_part.Properties[2].GetValue(
            KratosMultiphysics.POISSON_RATIO) == 0.1)
        self.assertTrue(model_part.Properties[2].GetValue(
            KratosMultiphysics.YIELD_STRESS) == 800.0)
        self.assertTrue(
            model_part.Properties[2].GetValue(KratosMultiphysics.HTC) == 0.3)
        self.assertTrue(model_part.Properties[2].GetValue(
            KratosMultiphysics.TIME_STEPS) == 159)  # int
        self.assertTrue(model_part.Properties[2].GetValue(
            KratosMultiphysics.UPDATE_SENSITIVITIES) == True)  # bool
        self.assertTrue(model_part.Properties[2].GetValue(
            KratosMultiphysics.IDENTIFIER) == "MyTestString")  # std::string

        mat_vector = model_part.Properties[2].GetValue(
            KratosMultiphysics.CAUCHY_STRESS_VECTOR)
        self.assertAlmostEqual(mat_vector[0], 1.5)
        self.assertAlmostEqual(mat_vector[1], 0.3)
        self.assertAlmostEqual(mat_vector[2], -2.58)

        mat_matrix = model_part.Properties[2].GetValue(
            KratosMultiphysics.LOCAL_INERTIA_TENSOR)
        self.assertAlmostEqual(mat_matrix[0, 0], 1.27)
        self.assertAlmostEqual(mat_matrix[0, 1], -22.5)
        self.assertAlmostEqual(mat_matrix[1, 0], 2.01)
        self.assertAlmostEqual(mat_matrix[1, 1], 0.257)

        table = model_part.Properties[2].GetTable(
            KratosMultiphysics.TEMPERATURE, KratosMultiphysics.YOUNG_MODULUS)
        self.assertAlmostEqual(table.GetValue(1.5), 11.0)
        self.assertAlmostEqual(table.GetNearestValue(1.1), 10.0)
        self.assertAlmostEqual(table.GetDerivative(1.2), 2.0)
Esempio n. 7
0
    def test_input(self):
        try:
            import KratosMultiphysics.SolidMechanicsApplication
        except:
            self.skipTest(
                "KratosMultiphysics.SolidMechanicsApplication is not available"
            )

        model_part = ModelPart("Main")
        model_part.AddNodalSolutionStepVariable(DISPLACEMENT)
        model_part.AddNodalSolutionStepVariable(VISCOSITY)
        model_part_io = ModelPartIO(
            GetFilePath("test_model_part_io_read"
                        ))  #reusing the file that is already in the directory
        model_part_io.ReadModelPart(model_part)

        #define a Model TODO: replace to use the real Model once available
        Model = {
            "Main":
            model_part,
            "Inlets":
            model_part.GetSubModelPart("Inlets"),
            "Inlet1":
            model_part.GetSubModelPart("Inlets").GetSubModelPart("Inlet1"),
            "Inlet2":
            model_part.GetSubModelPart("Inlets").GetSubModelPart("Inlet2"),
            "Outlet":
            model_part.GetSubModelPart("Outlet")
        }

        test_settings = Parameters("""
            {
                    "Parameters": {
                            "materials_filename": "materials.json"
                    }
            }
            """)

        ##assign the real path
        test_settings["Parameters"]["materials_filename"].SetString(
            GetFilePath("materials.json"))

        import read_materials_process
        read_materials_process.Factory(test_settings, Model)

        #test if the element properties are assigned correctly to the elements and conditions
        for elem in Model["Inlets"].Elements:
            self.assertTrue(elem.Properties.Id == 1)
        for cond in Model["Inlets"].Conditions:
            self.assertTrue(cond.Properties.Id == 1)
        for elem in Model["Outlet"].Elements:
            self.assertTrue(elem.Properties.Id == 2)
        for cond in Model["Outlet"].Conditions:
            self.assertTrue(cond.Properties.Id == 2)

        #test that the properties are read correctly
        self.assertTrue(
            model_part.Properties[1].GetValue(YOUNG_MODULUS) == 200.0)
        self.assertTrue(
            model_part.Properties[1].GetValue(POISSON_RATIO) == 0.3)
        self.assertTrue(
            model_part.Properties[1].GetValue(YIELD_STRESS) == 400.0)

        self.assertTrue(
            model_part.Properties[2].GetValue(YOUNG_MODULUS) == 100.0)
        self.assertTrue(
            model_part.Properties[2].GetValue(POISSON_RATIO) == 0.1)
        self.assertTrue(
            model_part.Properties[2].GetValue(YIELD_STRESS) == 800.0)
        self.assertTrue(model_part.Properties[2].GetValue(HTC) == 0.3)