def test_GetSolver_zero_levels(self):
        # CoSim contains only one SolverWrapper (not really CoSimulation...)
        params = KM.Parameters("""{
            "problem_data" : {
                "problem_name" : "my_dummy_solver",
                "start_time" : 0.0,
                "end_time" : 3.0,
                "echo_level" : 0,
                "print_colors" : true,
                "parallel_type" : "OpenMP"
            },
            "solver_settings" : {
                "type"        : "helpers.dummy_solver_wrapper",
                "solver_wrapper_settings": {
                    "time_step" : 1.0,
                    "domain_size" : 1,
                    "main_model_part_name" : "dummy"
                }
            }
        }""")

        co_sim_analysis = CoSimulationAnalysis(params)

        top_level_solver_wrapper = co_sim_analysis._GetSolver()

        self.assertIsInstance(top_level_solver_wrapper, CoSimulationSolverWrapper)
        self.assertEqual(top_level_solver_wrapper.name, "my_dummy_solver")
Exemplo n.º 2
0
    def test_ping_pong(self):
        self._createTest("ping_pong_test", "cosim_ping_pong_parameters")
        CoSimulationAnalysis(self.cosim_parameters).Run()

        #TODO: temporary figure out how to properly do it.
        os.remove('ping.log')
        os.remove('pong.log')
        os.remove('EMPIRE_datafield_pong_recv_data.dat')
        os.remove('EMPIRE_datafield_ping_recv_data.dat')
Exemplo n.º 3
0
    def test_ping_pong(self):
        self._createTest("ping_pong_test", "cosim_ping_pong_parameters")
        CoSimulationAnalysis(self.cosim_parameters).Run()

        DeleteFileIfExisting('ping.log')
        DeleteFileIfExisting('pong.log')
        DeleteFileIfExisting('EMPIRE_datafield_pong_send_data.dat')
        DeleteFileIfExisting('EMPIRE_datafield_ping_send_data.dat')
        DeleteFileIfExisting('EMPIRE_datafield_pong_recv_data.dat')
        DeleteFileIfExisting('EMPIRE_datafield_ping_recv_data.dat')
Exemplo n.º 4
0
    def _runTestWithExternal(self, subprocess_args_list):
        self.addCleanup(self.__TerminateSubProcessIfRunning)

        self.p = subprocess.Popen(subprocess_args_list)

        CoSimulationAnalysis(self.cosim_parameters).Run()

        self.p.communicate()

        self.assertEqual(self.p.returncode, 0)
Exemplo n.º 5
0
    def _runTest(self):
        p = subprocess.Popen(
            ["python3", os.path.join(self.problem_dir_name,"dummy_flower_solver.py"), self.ext_parameter_file_name],
            cwd=os.path.dirname(os.path.abspath(__file__)))

        CoSimulationAnalysis(self.cosim_parameters).Run()

        p.communicate()

        kratos_utils.DeleteTimeFiles(self.problem_dir_name)
Exemplo n.º 6
0
    def _createTest(self, problem_dir_name, parameter_file_name):
        self.problem_dir_name = problem_dir_name

        full_parameter_file_name = os.path.join(problem_dir_name, parameter_file_name + '_parameters.json')

        with open(full_parameter_file_name, 'r') as parameter_file:
            self.cable_net_parameters = KM.Parameters(parameter_file.read())

        # To avoid many prints
        echo_level = self.cable_net_parameters["problem_data"]["echo_level"].GetInt()
        if (echo_level == 0):
            KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.WARNING)
        else:
            KM.Logger.GetDefaultOutput().SetSeverity(KM.Logger.Severity.INFO)

        self.test = CoSimulationAnalysis(self.cable_net_parameters)
Exemplo n.º 7
0
 def _runTest(self):
     CoSimulationAnalysis(self.cosim_parameters).Run()
    def test_GetSolver_one_level(self):
        params = KM.Parameters("""{
            "problem_data" : {
                "problem_name" : "coupling_solver_top_level",
                "start_time" : 0.0,
                "end_time" : 3.0,
                "echo_level" : 0,
                "print_colors" : true,
                "parallel_type" : "OpenMP"
            },
            "solver_settings" : {
                "type"        : "coupled_solvers.gauss_seidel_weak",
                "coupling_sequence" : [{
                    "name": "structure",
                    "output_data_list": [],
                    "input_data_list": []
                },{
                    "name": "aux_structure",
                    "output_data_list": [],
                    "input_data_list": []
                },{
                    "name": "fluid",
                    "output_data_list": [],
                    "input_data_list": []
                }],
                "solvers" : {
                    "fluid": {
                        "type"        : "helpers.dummy_solver_wrapper",
                        "solver_wrapper_settings": {
                            "time_step" : 1.0,
                            "domain_size" : 1,
                            "main_model_part_name" : "dummy"
                        }
                    },
                    "structure": {
                        "type"        : "helpers.dummy_solver_wrapper",
                        "solver_wrapper_settings": {
                            "time_step" : 1.0,
                            "domain_size" : 1,
                            "main_model_part_name" : "dummy"
                        }
                    },
                    "aux_structure": {
                        "type"        : "helpers.dummy_solver_wrapper",
                        "solver_wrapper_settings": {
                            "time_step" : 1.0,
                            "domain_size" : 1,
                            "main_model_part_name" : "dummy"
                        }
                    }
                }
            }
        }""")

        co_sim_analysis = CoSimulationAnalysis(params)

        top_level_solver_wrapper  = co_sim_analysis._GetSolver()
        fluid_solver_wrapper      = co_sim_analysis._GetSolver("fluid")
        structural_solver_wrapper = co_sim_analysis._GetSolver("structure")
        aux_structural_solver_wrapper = co_sim_analysis._GetSolver("aux_structure")

        self.assertIsInstance(top_level_solver_wrapper, CoSimulationCoupledSolver)
        self.assertIsInstance(fluid_solver_wrapper, CoSimulationSolverWrapper)
        self.assertIsInstance(structural_solver_wrapper, CoSimulationSolverWrapper)
        self.assertIsInstance(aux_structural_solver_wrapper, CoSimulationSolverWrapper)

        self.assertEqual(top_level_solver_wrapper.name, "coupling_solver_top_level")
        self.assertEqual(fluid_solver_wrapper.name, "fluid")
        self.assertEqual(structural_solver_wrapper.name, "structure")
        self.assertEqual(aux_structural_solver_wrapper.name, "aux_structure")
Exemplo n.º 9
0
    def test_pass_model_two_levels(self):
        params = KM.Parameters("""{
            "problem_data" : {
                "problem_name" : "my_dummy_solver",
                "start_time" : 0.0,
                "end_time" : 3.0,
                "echo_level" : 0,
                "print_colors" : true,
                "parallel_type" : "OpenMP"
            },
            "solver_settings" : {
                "type"        : "coupled_solvers.gauss_seidel_weak",
                "solver_wrapper_settings": {
                    "time_step" : 1.0,
                    "domain_size" : 1,
                    "main_model_part_name" : "dummy"
                },
                "coupling_sequence" : [{
                    "name": "fsi",
                    "output_data_list": [],
                    "input_data_list": []
                },{
                    "name": "controller",
                    "output_data_list": [],
                    "input_data_list": []
                }],
                "solvers" : {
                    "fsi": {
                        "type"        : "coupled_solvers.gauss_seidel_weak",
                        "coupling_sequence" : [{
                            "name": "structure",
                            "output_data_list": [],
                            "input_data_list": []
                        },{
                            "name": "fluid",
                            "output_data_list": [],
                            "input_data_list": []
                        }],
                        "solvers" : {
                            "fluid": {
                                "type"        : "helpers.dummy_solver_wrapper",
                                "solver_wrapper_settings": {
                                    "time_step" : 1.0,
                                    "domain_size" : 1,
                                    "main_model_part_name" : "fl_model_part"
                                }
                            },
                            "structure": {
                                "type"        : "helpers.dummy_solver_wrapper",
                                "solver_wrapper_settings": {
                                    "time_step" : 1.0,
                                    "domain_size" : 1,
                                    "main_model_part_name" : "strct_model_part"
                                }
                            }
                        }
                    },
                    "controller": {
                        "type"        : "helpers.dummy_solver_wrapper",
                        "solver_wrapper_settings": {
                            "time_step" : 1.0,
                            "domain_size" : 1,
                            "main_model_part_name" : "interface"
                        }
                    }
                }
            }
        }""")

        structure_model = KM.Model()
        controller_model = KM.Model()

        models = {
            "controller": controller_model,
            "fsi": {
                "structure": structure_model
            }
        }

        co_sim_analysis = CoSimulationAnalysis(params, models)

        top_level_solver_wrapper = co_sim_analysis._GetSolver()
        fluid_solver_wrapper = co_sim_analysis._GetSolver("fsi.fluid")
        structural_solver_wrapper = co_sim_analysis._GetSolver("fsi.structure")
        controller_solver_wrapper = co_sim_analysis._GetSolver("controller")

        self.assertIs(structure_model, structural_solver_wrapper.model)
        self.assertIs(structure_model,
                      top_level_solver_wrapper.model["fsi.structure"])

        self.assertIs(controller_model, controller_solver_wrapper.model)
        self.assertIs(controller_model,
                      top_level_solver_wrapper.model["controller"])

        self.assertIsNot(structure_model, fluid_solver_wrapper.model)
        self.assertIsNot(controller_model, fluid_solver_wrapper.model)

        self.assertIs(fluid_solver_wrapper.model,
                      top_level_solver_wrapper.model["fsi.fluid"])
Exemplo n.º 10
0
    def test_pass_model_one_level(self):
        params = KM.Parameters("""{
            "problem_data" : {
                "problem_name" : "my_dummy_solver",
                "start_time" : 0.0,
                "end_time" : 3.0,
                "echo_level" : 0,
                "print_colors" : true,
                "parallel_type" : "OpenMP"
            },
            "solver_settings" : {
                "type"        : "coupled_solvers.gauss_seidel_weak",
                "coupling_sequence" : [{
                    "name": "structure",
                    "output_data_list": [],
                    "input_data_list": []
                },{
                    "name": "fluid",
                    "output_data_list": [],
                    "input_data_list": []
                }],
                "solvers" : {
                    "fluid": {
                        "type"        : "helpers.dummy_solver_wrapper",
                        "solver_wrapper_settings": {
                            "time_step" : 1.0,
                            "domain_size" : 1,
                            "main_model_part_name" : "fl_model_part"
                        }
                    },
                    "structure": {
                        "type"        : "helpers.dummy_solver_wrapper",
                        "solver_wrapper_settings": {
                            "time_step" : 1.0,
                            "domain_size" : 1,
                            "main_model_part_name" : "strct_model_part"
                        }
                    }
                }
            }
        }""")

        structure_model = KM.Model()

        with self.assertRaisesRegex(
                Exception,
                'A coupled solver can either be passed a dict of Models\nor None, got object of type'
        ):
            co_sim_analysis = CoSimulationAnalysis(params, structure_model)

        with self.assertRaisesRegex(
                Exception,
                'A solver wrapper can either be passed a Model\nor None, got object of type'
        ):  # this throws in the SolverWrapper
            co_sim_analysis = CoSimulationAnalysis(
                params, {"structure": "structure_model"})

        with self.assertRaisesRegex(
                Exception,
                'A Model was given for solver "wrong_name" but this solver does not exist!'
        ):
            co_sim_analysis = CoSimulationAnalysis(
                params, {"wrong_name": structure_model})

        co_sim_analysis = CoSimulationAnalysis(
            params, {"structure": structure_model
                     })  # name has to match the one in json!

        top_level_solver_wrapper = co_sim_analysis._GetSolver()
        fluid_solver_wrapper = co_sim_analysis._GetSolver("fluid")
        structural_solver_wrapper = co_sim_analysis._GetSolver("structure")

        self.assertIs(structure_model,
                      top_level_solver_wrapper.model["structure"])
        self.assertIsNot(structure_model,
                         top_level_solver_wrapper.model["fluid"])
        self.assertIs(structure_model, structural_solver_wrapper.model)
        self.assertIsNot(structure_model, fluid_solver_wrapper.model)
Exemplo n.º 11
0
import KratosMultiphysics as KM
from KratosMultiphysics.CoSimulationApplication.co_simulation_analysis import CoSimulationAnalysis
"""
For user-scripting it is intended that a new class is derived
from CoSimulationAnalysis to do modifications
Check also "kratos/python_scripts/analysis-stage.py" for available methods that can be overridden
"""

parameter_file_name = "ProjectParametersCoSim.json"
with open(parameter_file_name, 'r') as parameter_file:
    parameters = KM.Parameters(parameter_file.read())

simulation = CoSimulationAnalysis(parameters)
simulation.Run()
Exemplo n.º 12
0
 def _runTest(self):
     CoSimulationAnalysis(self.cosim_parameters).Run()
     kratos_utils.DeleteTimeFiles(self.problem_dir_name)