예제 #1
0
    def test_aitken_accelerator(self):

        aitken_settings = KratosMultiphysics.Parameters("""{
                                                            "solver_type"        : "Relaxation",
                                                            "acceleration_type"  : "Aitken",
                                                            "w_0"                : 0.825
                                                           }""")

        print("")
        print("Testing accelerator: ",
              aitken_settings["solver_type"].GetString())

        # Construct the accelerator strategy
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(
            aitken_settings)

        x_guess = KratosMultiphysics.Vector(2)
        x_guess[0] = 0.5
        x_guess[1] = 1.0

        tol = 1e-14
        max_it = 20

        self.coupling_utility.Initialize()

        nl_it = 1
        res_norm = 1.0
        convergence = False

        self.coupling_utility.InitializeSolutionStep()

        while (nl_it <= max_it):

            residual = self.ComputeResidual(x_guess)
            res_norm = math.sqrt(residual[0]**2 + residual[1]**2)

            print("Iteration: ", nl_it, " residual norm: ", res_norm)

            if res_norm > tol:
                self.coupling_utility.InitializeNonLinearIteration()
                self.coupling_utility.UpdateSolution(residual, x_guess)
                self.coupling_utility.FinalizeNonLinearIteration()
                nl_it += 1
            else:
                self.coupling_utility.FinalizeSolutionStep()
                convergence = True
                break

        x_final = x_guess

        # Check the obtained solution
        expected_x = KratosMultiphysics.Vector(2)
        expected_x[0] = math.sqrt(2) / 2.0
        expected_x[1] = math.sqrt(2) / 2.0

        if convergence == True:
            for i in range(0, len(expected_x)):
                self.assertAlmostEqual(expected_x[i], x_final[i])
 def _create_convergence_accelerator(self):
     conv_acc_parameters = self.settings["coupling_settings"][
         "convergence_accelerator_settings"]
     convergence_accelerator = convergence_accelerator_factory.CreateConvergenceAccelerator(
         conv_acc_parameters)
     self.print_on_rank_zero(
         "::[ConjugateHeatTransferSolver]::",
         "Convergence accelerator construction finished.")
     return convergence_accelerator
    def test_aitken_accelerator(self,force1,force2,solution):

        aitken_settings = KratosMultiphysics.Parameters("""{
                                                            "solver_type"        : "Relaxation",
                                                            "acceleration_type"  : "Aitken",
                                                            "w_0"                : 0.825
                                                           }""")

        print("")
        print("Testing accelerator: ",aitken_settings["solver_type"].GetString())

        # Construct the accelerator strategy
        coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(aitken_settings)

        top_part = self.model_part.GetSubModelPart("Top")

        coupling_utility.Initialize()

        nl_it = 0
        convergence = False

        coupling_utility.InitializeSolutionStep()

        x_guess = self.InitializeGuess(top_part)
        residual = self.ComputeResidual(top_part,x_guess,force1,force2)
        res_norm = self.ComputeResidualNorm(residual)

        while (nl_it <= self.aitken_iterations):

            if res_norm > self.aitken_tolelance:
                coupling_utility.InitializeNonLinearIteration()
                coupling_utility.UpdateSolution(residual, x_guess)
                coupling_utility.FinalizeNonLinearIteration()
            else:
                coupling_utility.FinalizeSolutionStep()
                convergence = True
                break

            nl_it += 1
            residual = self.ComputeResidual(top_part,x_guess,force1,force2)
            res_norm = self.ComputeResidualNorm(residual)

        # Check the obtained solution
        expected_x = solution(top_part)

        if self.print_gid_output:
            self.PrintGuess(top_part,x_guess)

        for i in range(len(expected_x)):
            self.assertAlmostEqual(expected_x[i],x_guess[i],delta=self.assert_delta)
예제 #4
0
    def __init__(self, ProjectParameters):

        self.ProjectParameters = ProjectParameters

        self.vector_space = KratosMultiphysics.UblasSparseSpace()

        self.structure_main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["structure_solver_settings"]["problem_data"]["model_part_name"].GetString())
        self.structure_main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["structure_solver_settings"]["problem_data"]["domain_size"].GetInt())

        SolidModel = {ProjectParameters["structure_solver_settings"]["problem_data"]["model_part_name"].GetString() : self.structure_main_model_part}

        # Construct the structure solver
        structure_solver_module = __import__(self.ProjectParameters["structure_solver_settings"]["solver_settings"]["solver_type"].GetString())
        self.structure_solver = structure_solver_module.CreateSolver(self.structure_main_model_part,
                                                                     self.ProjectParameters["structure_solver_settings"]["solver_settings"])
        print("* Structure solver constructed.")

        # Construct the coupling partitioned strategy
        import convergence_accelerator_factory
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(self.ProjectParameters["coupling_solver_settings"]["solver_settings"]["coupling_strategy"])
        print("* Coupling strategy constructed.")

        self.structure_solver.AddVariables()

        self.structure_solver.ImportModelPart()

        self.structure_solver.AddDofs()

        # Get the structure process list
        for i in range(self.ProjectParameters["structure_solver_settings"]["solver_settings"]["processes_sub_model_part_list"].size()):
            part_name = self.ProjectParameters["structure_solver_settings"]["solver_settings"]["processes_sub_model_part_list"][i].GetString()
            SolidModel.update({part_name: self.structure_main_model_part.GetSubModelPart(part_name)})

        # Structure processes construction
        import process_factory
        self.list_of_processes = process_factory.KratosProcessFactory(SolidModel).ConstructListOfProcesses( self.ProjectParameters["structure_solver_settings"]["constraints_process_list"] )
        self.list_of_processes += process_factory.KratosProcessFactory(SolidModel).ConstructListOfProcesses( self.ProjectParameters["structure_solver_settings"]["loads_process_list"] )

        # Processes initialization
        for process in self.list_of_processes:
            process.ExecuteInitialize()

        # Structure solver initialization
        self.structure_solver.Initialize()
        self._SetStructureNeumannCondition()

        # Coupling utility initialization
        self.coupling_utility.Initialize()
예제 #5
0
    def __init__(self, structure_main_model_part, fluid_main_model_part, project_parameters):

        print("** Calling the partitioned FSI base solver constructor...")

        # Initial tests
        start_time_structure = project_parameters["structure_solver_settings"]["problem_data"]["start_time"].GetDouble()
        start_time_fluid = project_parameters["fluid_solver_settings"]["problem_data"]["start_time"].GetDouble()
        end_time_structure = project_parameters["structure_solver_settings"]["problem_data"]["end_time"].GetDouble()
        end_time_fluid = project_parameters["fluid_solver_settings"]["problem_data"]["end_time"].GetDouble()

        if start_time_structure != start_time_fluid:
            raise("ERROR: Different initial time among subdomains!")
        if end_time_structure != end_time_fluid:
            raise("ERROR: Different final time among subdomains!")

        #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented
        self.structure_main_model_part = structure_main_model_part
        self.fluid_main_model_part = fluid_main_model_part

        # Settings string in JSON format
        default_settings = KratosMultiphysics.Parameters("""
        {
        "structure_solver_settings":
            {
            "solver_type": "structural_mechanics_implicit_dynamic_solver",
            "model_import_settings": {
                "input_type": "mdpa",
                "input_filename": "unknown_name"
            },
            "material_import_settings" :{
                "materials_filename": "materials.json"
            },
            "echo_level": 0,
            "time_integration_method": "Implicit",
            "analysis_type": "nonlinear",
            "rotation_dofs": false,
            "pressure_dofs": false,
            "stabilization_factor": 1.0,
            "reform_dofs_at_each_step": false,
            "line_search": false,
            "compute_reactions": true,
            "compute_contact_forces": false,
            "block_builder": false,
            "move_mesh_flag": true,
            "solution_type": "Dynamic",
            "scheme_type": "Newmark",
            "convergence_criterion": "Residual_criteria",
            "displacement_relative_tolerance" : 1.0e-3,
            "displacement_absolute_tolerance" : 1.0e-5,
            "residual_relative_tolerance"     : 1.0e-3,
            "residual_absolute_tolerance"     : 1.0e-5,
            "max_iteration": 10,
            "linear_solver_settings":{
                "solver_type"   : "SuperLUSolver",
                "max_iteration" : 200,
                "tolerance"     : 1e-7,
                "scaling"       : false,
                "verbosity"     : 1
            },
            "processes_sub_model_part_list": [""],
            "problem_domain_sub_model_part_list": ["solid_model_part"]
            },
        "fluid_solver_settings":
            {
            "solver_type": "navier_stokes_solver_vmsmonolithic",
            "model_import_settings": {
                "input_type": "mdpa",
                "input_filename": "unknown_name"
            },
            "maximum_iterations": 10,
            "dynamic_tau" : 0.0,
            "oss_switch"  : 0,
            "echo_level"  : 0,
            "consider_periodic_conditions" : false,
            "compute_reactions"            : true,
            "divergence_clearance_steps"   : 0,
            "reform_dofs_at_each_step"     : true,
            "relative_velocity_tolerance"  : 1e-3,
            "absolute_velocity_tolerance"  : 1e-5,
            "relative_pressure_tolerance"  : 1e-3,
            "absolute_pressure_tolerance"  : 1e-5,
            "linear_solver_settings"        : {
                "solver_type"         : "AMGCL",
                "max_iteration"       : 200,
                "tolerance"           : 1e-9,
                "provide_coordinates" : true,
                "smoother_type"       : "ilu0",
                "krylov_type"         : "gmres",
                "coarsening_type"     : "aggregation",
                "scaling"             : true,
                "verbosity"           : 0
            },
            "volume_model_part_name" : "volume_model_part",
            "skin_parts"             : [""],
            "no_skin_parts"          : [""],
            "time_stepping"          : {
                "automatic_time_step" : false,
                "time_step"           : 0.1
            },
            "alpha"                  :-0.3,
            "move_mesh_strategy"     : 0,
            "periodic"               : "periodic",
            "move_mesh_flag"         : false,
            "turbulence_model"       : "None"
            },
        "coupling_solver_settings":
            {
            "coupling_scheme"                : "DirichletNeumann",
            "solver_type"                    : "partitioned_fsi_solver",
            "nl_tol"                         : 1e-5,
            "nl_max_it"                      : 50,
            "solve_mesh_at_each_iteration"   : true,
            "coupling_strategy" : {
                "solver_type"       : "Relaxation",
                "acceleration_type" : "Aitken",
                "w_0"               : 0.825
                },
            "mesh_solver"                    : "mesh_solver_structural_similarity",
            "mesh_reform_dofs_each_step"     : false,
            "structure_interfaces_list"      : [""],
            "fluid_interfaces_list"          : [""]
            },
        "mapper_settings"              : [{
            "mapper_face"                                : "Unique",
            "positive_fluid_interface_submodelpart_name" : "Default_interface_submodelpart_name",
            "structure_interface_submodelpart_name"      : "Default_interface_submodelpart_name"
            }]
        }
        """)

        # Time stepping checks (no sub-stepping between subdomains has been implemented yed)
        time_step_structure = project_parameters["structure_solver_settings"]["problem_data"]["time_step"].GetDouble()
        # If automatic time stepping has been selected in the fluid domain, deactivate it and use the structure time step
        if (project_parameters["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].GetBool()):
            project_parameters["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].SetBool(False)
            time_step_fluid = time_step_structure
            print("WARNING: Automatic fluid time stepping cannot be used. Setting structure time step as fluid time step.")
        else:
            time_step_fluid = project_parameters["fluid_solver_settings"]["solver_settings"]["time_stepping"]["time_step"].GetDouble()
            if time_step_structure != time_step_fluid:
                raise("ERROR: Different time step among subdomains! No sub-stepping implemented yet.")

        self.time_step = time_step_fluid

        # Take the each one of the solvers settings from the ProjectParameters
        self.settings = KratosMultiphysics.Parameters("{}")
        self.settings.AddValue("structure_solver_settings",project_parameters["structure_solver_settings"]["solver_settings"])
        self.settings.AddValue("fluid_solver_settings",project_parameters["fluid_solver_settings"]["solver_settings"])
        self.settings.AddValue("coupling_solver_settings",project_parameters["coupling_solver_settings"]["solver_settings"])
        self.settings.AddValue("mapper_settings",project_parameters["coupling_solver_settings"]["mapper_settings"])

        # Overwrite the default settings with user-provided parameters
        self.settings.RecursivelyValidateAndAssignDefaults(default_settings)

        # Auxiliar variables
        self.max_nl_it = self.settings["coupling_solver_settings"]["nl_max_it"].GetInt()
        self.nl_tol = self.settings["coupling_solver_settings"]["nl_tol"].GetDouble()
        self.solve_mesh_at_each_iteration = self.settings["coupling_solver_settings"]["solve_mesh_at_each_iteration"].GetBool()
        self.coupling_algorithm = self.settings["coupling_solver_settings"]["coupling_scheme"].GetString()
        self.fluid_interface_submodelpart_name = self.settings["coupling_solver_settings"]["fluid_interfaces_list"][0].GetString()
        self.structure_interface_submodelpart_name = self.settings["coupling_solver_settings"]["structure_interfaces_list"][0].GetString()
        coupling_utility_parameters = self.settings["coupling_solver_settings"]["coupling_strategy"]

        # Construct the structure solver
        self.structure_solver = python_solvers_wrapper_structural.CreateSolver(self.structure_main_model_part,
                                                                               project_parameters["structure_solver_settings"])
        print("* Structure solver constructed.")

        # Construct the fluid solver
        self.fluid_solver = python_solvers_wrapper_fluid.CreateSolver(self.fluid_main_model_part,
                                                                      project_parameters["fluid_solver_settings"])
        print("* Fluid solver constructed.")

        # Construct the coupling partitioned strategy
        import convergence_accelerator_factory
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(coupling_utility_parameters)
        print("* Coupling strategy constructed.")

        # Construct the ALE mesh solver
        mesh_solver_settings = KratosMultiphysics.Parameters("{}")
        mesh_solver_settings.AddValue("mesh_reform_dofs_each_step",self.settings["coupling_solver_settings"]["mesh_reform_dofs_each_step"])

        self.mesh_solver_module = __import__(self.settings["coupling_solver_settings"]["mesh_solver"].GetString())
        self.mesh_solver = self.mesh_solver_module.CreateSolver(self.fluid_solver.main_model_part,
                                                                mesh_solver_settings)
        print("* ALE mesh solver constructed.")
        print("** Partitioned FSI base solver constructed.")
    def __init__(self, structure_main_model_part, fluid_main_model_part, project_parameters):

        print("** Calling the partitioned FSI base solver constructor...")

        # Initial tests
        start_time_structure = project_parameters["structure_solver_settings"]["problem_data"]["start_time"].GetDouble()
        start_time_fluid = project_parameters["fluid_solver_settings"]["problem_data"]["start_time"].GetDouble()
        end_time_structure = project_parameters["structure_solver_settings"]["problem_data"]["end_time"].GetDouble()
        end_time_fluid = project_parameters["fluid_solver_settings"]["problem_data"]["end_time"].GetDouble()

        if start_time_structure != start_time_fluid:
            raise("ERROR: Different initial time among subdomains!")
        if end_time_structure != end_time_fluid:
            raise("ERROR: Different final time among subdomains!")

        self.structure_main_model_part = structure_main_model_part
        self.fluid_main_model_part = fluid_main_model_part

        # Time stepping checks (no sub-stepping between subdomains has been implemented yed)
        time_step_structure = project_parameters["structure_solver_settings"]["problem_data"]["time_step"].GetDouble()
        # If automatic time stepping has been selected in the fluid domain, deactivate it and use the structure time step
        if (project_parameters["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].GetBool()):
            project_parameters["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].SetBool(False)
            time_step_fluid = time_step_structure
            print("WARNING: Automatic fluid time stepping cannot be used. Setting structure time step as fluid time step.")
        else:
            time_step_fluid = project_parameters["fluid_solver_settings"]["solver_settings"]["time_stepping"]["time_step"].GetDouble()
            if time_step_structure != time_step_fluid:
                raise("ERROR: Different time step among subdomains! No sub-stepping implemented yet.")

        self.time_step = time_step_fluid

        # Take the each one of the solvers settings from the ProjectParameters
        # Note that the defaults check will be performed inside each field solver
        self.settings = KratosMultiphysics.Parameters("{}")
        self.settings.AddValue("structure_solver_settings",project_parameters["structure_solver_settings"]["solver_settings"])
        self.settings.AddValue("fluid_solver_settings",project_parameters["fluid_solver_settings"]["solver_settings"])
        self.settings.AddValue("coupling_solver_settings",project_parameters["coupling_solver_settings"]["solver_settings"])
        self.settings.AddValue("mapper_settings",project_parameters["coupling_solver_settings"]["mapper_settings"])

        # Auxiliar variables
        self.max_nl_it = self.settings["coupling_solver_settings"]["nl_max_it"].GetInt()
        self.nl_tol = self.settings["coupling_solver_settings"]["nl_tol"].GetDouble()
        self.solve_mesh_at_each_iteration = self.settings["coupling_solver_settings"]["solve_mesh_at_each_iteration"].GetBool()
        self.coupling_algorithm = self.settings["coupling_solver_settings"]["coupling_scheme"].GetString()
        self.fluid_interface_submodelpart_name = self.settings["coupling_solver_settings"]["fluid_interfaces_list"][0].GetString()
        self.structure_interface_submodelpart_name = self.settings["coupling_solver_settings"]["structure_interfaces_list"][0].GetString()
        coupling_utility_parameters = self.settings["coupling_solver_settings"]["coupling_strategy"]

        # Construct the structure solver
        self.structure_solver = python_solvers_wrapper_structural.CreateSolver(self.structure_main_model_part,
                                                                               project_parameters["structure_solver_settings"])
        print("* Structure solver constructed.")

        # Construct the fluid solver
        self.fluid_solver = python_solvers_wrapper_fluid.CreateSolver(self.fluid_main_model_part,
                                                                      project_parameters["fluid_solver_settings"])
        print("* Fluid solver constructed.")

        # Construct the coupling partitioned strategy
        import convergence_accelerator_factory
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(coupling_utility_parameters)
        print("* Coupling strategy constructed.")

        # Construct the ALE mesh solver
        mesh_solver_settings = KratosMultiphysics.Parameters("{}")

        self.mesh_solver_module = __import__(self.settings["coupling_solver_settings"]["mesh_solver"].GetString())
        self.mesh_solver = self.mesh_solver_module.CreateSolver(self.fluid_solver.main_model_part,
                                                                mesh_solver_settings)
        print("* ALE mesh solver constructed.")
        print("** Partitioned FSI base solver constructed.")
예제 #7
0
    def test_accelerator_dx(self):

        settings = KratosMultiphysics.Parameters("""{
                                                     "solver_type" : "MVQN_recursive",
                                                     "w_0"         : 0.825
                                                    }""")
        print("")
        print("Testing Newton-Raphson with accelerator: ",
              settings["solver_type"].GetString(), " version with residual=DX")

        # Construct the coupling partitioned strategy
        import convergence_accelerator_factory
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(
            settings)

        x_guess = KratosMultiphysics.Vector(2)
        x_guess[0] = 0.5
        x_guess[1] = 0.5

        dx = KratosMultiphysics.Vector(2)
        dx[0] = 0.0
        dx[1] = 0.0

        tol = 1e-14
        max_it = 20
        acceleration = True

        if acceleration == True:
            self.coupling_utility.Initialize()

        nl_it = 1
        res_norm = 1.0
        convergence = False

        if acceleration == True:
            self.coupling_utility.InitializeSolutionStep()

        while (nl_it <= max_it):

            residual = self.ComputeResidual(x_guess)
            res_norm = math.sqrt(residual[0]**2 + residual[1]**2)

            print("Iteration: ", nl_it, " residual norm: ", res_norm)

            K = self.Jacobian(x_guess)
            Kinv = self.InvertMatrix(K)
            dx = self.prod(Kinv, residual)

            if res_norm > tol:
                #x_guess = x_guess + dx

                if acceleration == True:
                    residual = dx  #self.ComputeResidual(x_guess)

                    self.coupling_utility.InitializeNonLinearIteration()
                    self.coupling_utility.UpdateSolution(residual, x_guess)
                    self.coupling_utility.FinalizeNonLinearIteration()

                    residual = self.ComputeResidual(x_guess)
                    res_norm = math.sqrt(residual[0]**2 + residual[1]**2)
                    print("Iteration: ", nl_it,
                          " residual norm after acceleration: ", res_norm)

                    if res_norm < tol:
                        if acceleration == True:
                            self.coupling_utility.FinalizeSolutionStep()
                        convergence = True
                        break

                nl_it += 1
            else:
                if acceleration == True:
                    self.coupling_utility.FinalizeSolutionStep()
                convergence = True
                break

        x_final = x_guess

        # Check the obtained solution
        expected_x = KratosMultiphysics.Vector(2)
        expected_x[0] = math.sqrt(2) / 2.0
        expected_x[1] = math.sqrt(2) / 2.0

        if convergence == True:
            for i in range(0, len(expected_x)):
                self.assertAlmostEqual(expected_x[i], x_final[i])
예제 #8
0
    def test_mvqn_recusive_accelerator(self):

        mvqn_recursive_settings = KratosMultiphysics.Parameters("""{
                                                                    "solver_type" : "MVQN_recursive",
                                                                    "w_0"         : 0.825,
                                                                    "buffer_size" : 7
                                                                   }""")

        settings_list = [mvqn_recursive_settings]

        step = 1
        tol = 1e-14
        max_it = 20
        recursive_steps = 10

        x_guess = KratosMultiphysics.Vector(6)
        x_guess[0] = -20.0 * step / recursive_steps
        x_guess[1] = 20.0 * step / recursive_steps
        x_guess[2] = -5.0 * step / recursive_steps
        x_guess[3] = 15.0 * step / recursive_steps
        x_guess[4] = -25.0 * step / recursive_steps
        x_guess[5] = 30.0 * step / recursive_steps

        while (step <= recursive_steps):

            # Iterate throug the settings list
            for i in range(0, len(settings_list)):
                print("")
                print("Testing recursive accelerator: ",
                      settings_list[i]["solver_type"].GetString(), " Step: ",
                      step)

                # Construct the accelerator strategy
                self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(
                    settings_list[i])
                self.coupling_utility.Initialize()

                nl_it = 1
                res_norm = 1.0
                convergence = False

                self.coupling_utility.InitializeSolutionStep()

                while (nl_it <= max_it):

                    residual = self.ComputeMVQNResidual(
                        x_guess, step / recursive_steps)
                    res_norm = math.sqrt(residual[0]**2 + residual[1]**2)

                    print("Iteration: ", nl_it, " residual norm: ", res_norm)

                    if res_norm > tol:
                        self.coupling_utility.InitializeNonLinearIteration()
                        self.coupling_utility.UpdateSolution(residual, x_guess)
                        self.coupling_utility.FinalizeNonLinearIteration()
                        nl_it += 1
                    else:
                        self.coupling_utility.FinalizeSolutionStep()
                        convergence = True
                        break

                x_final = x_guess

                # Check the obtained solution
                expected_RHS = KratosMultiphysics.Vector(6)
                expected_RHS[0] = -3.49458887 * step / recursive_steps
                expected_RHS[1] = 11.98381557 * step / recursive_steps
                expected_RHS[2] = -9.42225393 * step / recursive_steps
                expected_RHS[3] = 3.79688473 * step / recursive_steps
                expected_RHS[4] = 0.72338935 * step / recursive_steps
                expected_RHS[5] = 4.36818068 * step / recursive_steps

                obtained_RHS = self.ComputeMVQNObtainededRHS(x_final)

                if convergence == True:
                    for i in range(0, len(expected_RHS)):
                        self.assertAlmostEqual(expected_RHS[i],
                                               obtained_RHS[i])

                step += 1
예제 #9
0
    def test_mvqn_accelerator(self):

        mvqn_settings = KratosMultiphysics.Parameters("""{
                                                          "solver_type" : "MVQN",
                                                          "w_0"         : 0.825
                                                         }""")

        print("")
        print("Testing accelerator: ",
              mvqn_settings["solver_type"].GetString())

        # Construct the accelerator strategy
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(
            mvqn_settings)

        x_guess = KratosMultiphysics.Vector(6)
        x_guess[0] = -20.0
        x_guess[1] = 20.0
        x_guess[2] = -5.0
        x_guess[3] = 15.0
        x_guess[4] = -25.0
        x_guess[5] = 30.0

        tol = 5e-11
        max_it = 20

        self.coupling_utility.Initialize()

        nl_it = 1
        convergence = False

        self.coupling_utility.InitializeSolutionStep()

        while (nl_it <= max_it):

            residual = self.ComputeMVQNResidual(x_guess)
            res_norm = 0.0
            for i in range(0, len(residual)):
                res_norm += residual[i]**2
            res_norm = math.sqrt(res_norm)

            print("Iteration: ", nl_it, " residual norm: ", res_norm)

            if res_norm > tol:
                self.coupling_utility.InitializeNonLinearIteration()
                self.coupling_utility.UpdateSolution(residual, x_guess)
                self.coupling_utility.FinalizeNonLinearIteration()
                nl_it += 1
            else:
                self.coupling_utility.FinalizeSolutionStep()
                convergence = True
                break

        x_final = x_guess

        # Check the obtained solution
        expected_RHS = KratosMultiphysics.Vector(6)
        expected_RHS[0] = -3.49458887
        expected_RHS[1] = 11.98381557
        expected_RHS[2] = -9.42225393
        expected_RHS[3] = 3.79688473
        expected_RHS[4] = 0.72338935
        expected_RHS[5] = 4.36818068

        obtained_RHS = self.ComputeMVQNObtainededRHS(x_final)

        if convergence == True:
            for i in range(0, len(expected_RHS)):
                self.assertAlmostEqual(expected_RHS[i], obtained_RHS[i])
    def test_mvqn_recusive_accelerator(self):

        mvqn_recursive_settings = KratosMultiphysics.Parameters("""{
                                                                    "solver_type" : "MVQN_recursive",
                                                                    "w_0"         : 0.825,
                                                                    "buffer_size" : 7
                                                                   }""")

        settings_list = [mvqn_recursive_settings]

        step = 1
        recursive_steps = 10

        while (step <= recursive_steps):

            # Iterate throug the settings list
            for i in range(0, len(settings_list)):
                print("")
                print("Testing recursive accelerator: ",
                      settings_list[i]["solver_type"].GetString(), " Step: ",
                      step)

                # Construct the accelerator strategy
                self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(
                    settings_list[i])

                x_guess = KratosMultiphysics.Vector(2)
                x_guess[0] = 0.1 * step
                x_guess[1] = 0.1 * step

                tol = 1e-14
                max_it = 20

                self.coupling_utility.Initialize()

                nl_it = 1
                res_norm = 1.0
                convergence = False

                self.coupling_utility.InitializeSolutionStep()

                while (nl_it <= max_it):

                    residual = self.ComputeResidual(x_guess)
                    res_norm = math.sqrt(residual[0]**2 + residual[1]**2)

                    print("Iteration: ", nl_it, " residual norm: ", res_norm)

                    if res_norm > tol:
                        self.coupling_utility.InitializeNonLinearIteration()
                        self.coupling_utility.UpdateSolution(residual, x_guess)
                        self.coupling_utility.FinalizeNonLinearIteration()
                        nl_it += 1
                    else:
                        self.coupling_utility.FinalizeSolutionStep()
                        convergence = True
                        break

                x_final = x_guess

                # Check the obtained solution
                expected_x = KratosMultiphysics.Vector(2)
                expected_x[0] = math.sqrt(2) / 2.0
                expected_x[1] = math.sqrt(2) / 2.0

                if convergence == True:
                    for i in range(0, len(expected_x)):
                        self.assertAlmostEqual(expected_x[i], x_final[i])

                step += 1
예제 #11
0
    def _CreateMechanicalSolver(self, mechanical_scheme,
                                mechanical_convergence_criterion,
                                builder_and_solver, max_iters,
                                compute_reactions, reform_step_dofs,
                                move_mesh_flag, component_wise, line_search,
                                implex):

        if (component_wise):
            self.mechanical_solver = KratosMultiphysics.SolidMechanicsApplication.ComponentWiseNewtonRaphsonStrategy(
                self.computing_model_part, mechanical_scheme,
                self.linear_solver, mechanical_convergence_criterion,
                builder_and_solver, max_iters, compute_reactions,
                reform_step_dofs, move_mesh_flag)
        else:
            if (line_search):
                if (implex):
                    self.mechanical_solver = KratosMultiphysics.SolidMechanicsApplication.ResidualBasedNewtonRaphsonLineSearchImplexStrategy(
                        self.computing_model_part, mechanical_scheme,
                        self.linear_solver, mechanical_convergence_criterion,
                        builder_and_solver, max_iters, compute_reactions,
                        reform_step_dofs, move_mesh_flag)
                else:
                    self.mechanical_solver = KratosMultiphysics.SolidMechanicsApplication.ResidualBasedNewtonRaphsonLineSearchStrategy(
                        self.computing_model_part, mechanical_scheme,
                        self.linear_solver, mechanical_convergence_criterion,
                        builder_and_solver, max_iters, compute_reactions,
                        reform_step_dofs, move_mesh_flag)

            else:
                if self.settings["analysis_type"].GetString() == "Linear":
                    self.mechanical_solver = KratosMultiphysics.ResidualBasedLinearStrategy(
                        self.computing_model_part, mechanical_scheme,
                        self.linear_solver, builder_and_solver,
                        compute_reactions, reform_step_dofs, False,
                        move_mesh_flag)

                else:
                    if self.settings["accelerate_convergence"].GetBool():
                        params = self.settings["convergence_accelerator"]
                        import convergence_accelerator_factory
                        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(
                            params)
                        self.mechanical_solver = KratosMultiphysics.ContactStructuralMechanicsApplication.ResidualBasedNewtonRaphsonContactAcceleratedStrategy(
                            self.computing_model_part, mechanical_scheme,
                            self.linear_solver,
                            mechanical_convergence_criterion,
                            builder_and_solver, max_iters, compute_reactions,
                            reform_step_dofs, move_mesh_flag,
                            self.coupling_utility)
                    elif self.settings["compute_mortar_contact"].GetInt() > 0:
                        split_factor = self.settings["split_factor"].GetDouble(
                        )
                        max_number_splits = self.settings[
                            "max_number_splits"].GetInt()
                        self.mechanical_solver = KratosMultiphysics.ContactStructuralMechanicsApplication.ResidualBasedNewtonRaphsonContactStrategy(
                            self.computing_model_part, mechanical_scheme,
                            self.linear_solver,
                            mechanical_convergence_criterion,
                            builder_and_solver, max_iters, compute_reactions,
                            reform_step_dofs, move_mesh_flag, split_factor,
                            max_number_splits)
                    else:
                        self.mechanical_solver = KratosMultiphysics.ResidualBasedNewtonRaphsonStrategy(
                            self.computing_model_part, mechanical_scheme,
                            self.linear_solver,
                            mechanical_convergence_criterion,
                            builder_and_solver, max_iters, compute_reactions,
                            reform_step_dofs, move_mesh_flag)
 def _CreateConvergenceAccelerator(self):
     convergence_accelerator = convergence_accelerator_factory.CreateConvergenceAccelerator(self.settings["coupling_settings"]["coupling_strategy_settings"])
     self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Coupling strategy construction finished.")
     return convergence_accelerator
예제 #13
0
    def __init__(self, model, project_parameters):
        super(PartitionedFSIBaseSolver,self).__init__(model, project_parameters)

        # Initial tests
        start_time_structure = self.settings["structure_solver_settings"]["problem_data"]["start_time"].GetDouble()
        start_time_fluid = self.settings["fluid_solver_settings"]["problem_data"]["start_time"].GetDouble()
        end_time_structure = self.settings["structure_solver_settings"]["problem_data"]["end_time"].GetDouble()
        end_time_fluid = self.settings["fluid_solver_settings"]["problem_data"]["end_time"].GetDouble()

        if start_time_structure != start_time_fluid:
            raise Exception('Different initial time among subdomains.')
        if end_time_structure != end_time_fluid:
            raise Exception('Different final time among subdomains.')

        solver_settings = self.settings["fluid_solver_settings"]["solver_settings"]
        problem_data = self.settings["fluid_solver_settings"]["problem_data"]
        if solver_settings.Has("model_part_name"):
            self.fluid_model_part_name = solver_settings["model_part_name"].GetString()
        elif problem_data.Has("model_part_name"):
            self.fluid_model_part_name = problem_data["model_part_name"].GetString()
            # Backwards compatibility: copy the name to the solver section so that the fluid solver can read it
            solver_settings.AddEmptyValue("model_part_name")
            solver_settings["model_part_name"].SetString(self.fluid_model_part_name)

        # Backwards compatibility: copy the domain size to the solver section
        if not solver_settings.Has("domain_size"):
            solver_settings.AddEmptyValue("domain_size")
            solver_settings["domain_size"].SetInt(problem_data["domain_size"].GetInt())

        # Time stepping checks (no sub-stepping between subdomains has been implemented yed)
        time_step_structure = self.settings["structure_solver_settings"]["problem_data"]["time_step"].GetDouble()
        # If automatic time stepping has been selected in the fluid domain, deactivate it and use the structure time step
        if (self.settings["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].GetBool()):
            self.settings["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].SetBool(False)
            time_step_fluid = time_step_structure
            self._PrintWarningOnRankZero("::[PartitionedFSIBaseSolver]::", "Automatic fluid time stepping cannot be used. Setting structure time step as fluid time step.")
        else:
            time_step_fluid = self.settings["fluid_solver_settings"]["solver_settings"]["time_stepping"]["time_step"].GetDouble()
            if time_step_structure != time_step_fluid:
                raise Exception('Different time step among subdomains! No sub-stepping implemented yet.')

        self.time_step = time_step_fluid

        # Auxiliar variables
        coupling_solver_settings = self.settings["coupling_solver_settings"]["solver_settings"]
        self.max_nl_it = coupling_solver_settings["nl_max_it"].GetInt()
        self.nl_tol = coupling_solver_settings["nl_tol"].GetDouble()
        self.solve_mesh_at_each_iteration = coupling_solver_settings["solve_mesh_at_each_iteration"].GetBool()
        self.coupling_algorithm = coupling_solver_settings["coupling_scheme"].GetString()
        self.fluid_interface_submodelpart_name = coupling_solver_settings["fluid_interfaces_list"][0].GetString()
        self.structure_interface_submodelpart_name = coupling_solver_settings["structure_interfaces_list"][0].GetString()
        coupling_utility_parameters = coupling_solver_settings["coupling_strategy"]

        # Construct the structure solver
        structural_solver_settings = self.settings["structure_solver_settings"]["solver_settings"]
        if not structural_solver_settings.Has("time_stepping"):
            self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Using the old way to pass the time_step, this will be removed!")
            time_stepping_params = KratosMultiphysics.Parameters("{}")
            time_stepping_params.AddValue("time_step", self.settings["structure_solver_settings"]["problem_data"]["time_step"])
            structural_solver_settings.AddValue("time_stepping", time_stepping_params)
        if not structural_solver_settings.Has("domain_size"):
            self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Using the old way to pass the domain_size, this will be removed!")
            structural_solver_settings.AddEmptyValue("domain_size")
            structural_solver_settings["domain_size"].SetInt(self.settings["structure_solver_settings"]["problem_data"]["domain_size"].GetInt())
        if not structural_solver_settings.Has("model_part_name"):
            self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Using the old way to pass the model_part_name, this will be removed!")
            structural_solver_settings.AddEmptyValue("model_part_name")
            structural_solver_settings["model_part_name"].SetString(self.settings["structure_solver_settings"]["problem_data"]["model_part_name"].GetString())

        self.structure_solver = python_solvers_wrapper_structural.CreateSolver(self.model,
                                                                               self.settings["structure_solver_settings"])
        self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Structure solver construction finished.")

        # Construct the fluid solver
        self.fluid_solver = python_solvers_wrapper_fluid.CreateSolver(self.model,
                                                                      self.settings["fluid_solver_settings"])
        self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Fluid solver construction finished.")

        # Construct the coupling partitioned strategy
        self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(coupling_utility_parameters)
        self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Coupling strategy construction finished.")

        # Construct the ALE mesh solver
        mesh_solver_settings = KratosMultiphysics.Parameters("{}")
        mesh_solver_settings.AddEmptyValue("problem_data")
        mesh_solver_settings.AddEmptyValue("solver_settings")
        parallel_type = KratosMultiphysics.Parameters('''{"parallel_type" : ""}''')
        parallel_type["parallel_type"].SetString(self.settings["fluid_solver_settings"]["problem_data"]["parallel_type"].GetString())
        mesh_solver_type = KratosMultiphysics.Parameters('''{"solver_type" : ""}''')
        mesh_solver_type["solver_type"].SetString(self.settings["coupling_solver_settings"]["solver_settings"]["mesh_solver"].GetString())
        mesh_solver_settings["problem_data"] = parallel_type
        mesh_solver_settings["solver_settings"] = mesh_solver_type
        #TODO: UPDATE TO MODEL ONCE MESH MOVING APPLICATION SUPPORTS IT
        self.mesh_solver = python_solvers_wrapper_mesh_motion.CreateSolver(self.fluid_solver.main_model_part,
                                                                           mesh_solver_settings)
        self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "ALE mesh solver construction finished.")

        self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Partitioned FSI base solver construction finished.")