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")
    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")
Example #3
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"])
Example #4
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)