Exemplo n.º 1
0
 def _CreateSolver(self):
     """ Create the Solver (and create and import the ModelPart if it is not alread in the model) """
     ## Solver construction
     return structural_solvers.CreateSolver(self.model, self.project_parameters)
    def RunTestCase(self):
        StructureSolverSettings = Parameters("""
        {
            "problem_data": {
                "parallel_type" : "OpenMP"
            },
            "solver_settings" : {
                "model_part_name"         : "Structure",
                "domain_size"             : 2,
                "solver_type"             : "Dynamic",
                "echo_level"              : 0,
                "analysis_type"           : "linear",
                "time_integration_method" : "implicit",
                "scheme_type"             : "bossak",
                "model_import_settings"              : {
                    "input_type"       : "mdpa",
                    "input_filename"   : "test_FSI_emulator_Structural",
                    "input_file_label" : 0
                },
                "material_import_settings" :{
                    "materials_filename": "materials_2D.json"
                },
                "line_search"                        : false,
                "convergence_criterion"              : "Residual_criterion",
                "displacement_relative_tolerance"    : 1e-8,
                "displacement_absolute_tolerance"    : 1e-10,
                "residual_relative_tolerance"        : 1e-8,
                "residual_absolute_tolerance"        : 1e-10,
                "max_iteration"                      : 20,
                "problem_domain_sub_model_part_list" : ["Parts_Solid"],
                "processes_sub_model_part_list"      : ["DISPLACEMENT_Displacement_BC","PointLoad2D_Point_load","StructureInterface2D_Solid_interface"],
                "rotation_dofs"                      : false,
                "linear_solver_settings"             : {
                    "solver_type" : "SuperLUSolver",
                    "scaling"     : true
                }
            }
        }
        """)

        with WorkFolderScope(self.work_folder):

            self.model = Model()

            # Construct the structure solver
            self.structure_solver = python_solvers_wrapper_structural.CreateSolver(
                self.model, StructureSolverSettings)

            self.structure_solver.AddVariables()

            self.structure_solver.ImportModelPart()

            self.structure_solver.PrepareModelPart()

            self.structure_main_model_part = self.model["Structure"]

            self.structure_solver.AddDofs()

            self.SetStructureBoundaryConditions()

            self.structure_solver.Initialize()

            self.coupling_utility.Initialize()

            residual_size = self.GetInterfaceProblemSize(
            ) * 2  # Interface DOFs number times PROBLEM_SIZE
            self.iteration_value = Vector(
                residual_size
            )  # Interface solution guess (it might be velocity or fluxes depending on the type of coupling)
            for i in range(0, residual_size):
                self.iteration_value[i] = 0.0

            step = 0
            time = 0.0

            while (time <= self.end_time):

                time = time + self.Dt
                step = step + 1

                print("##################################")
                print("########## step = ", step, "#############")
                print("##################################")

                self.structure_solver.main_model_part.ProcessInfo.SetValue(
                    TIME_STEPS, step)

                self.structure_main_model_part.CloneTimeStep(time)

                self.PointLoadUpdate()

                self.structure_solver.InitializeSolutionStep()
                self.structure_solver.Predict()

                self.coupling_utility.InitializeSolutionStep()

                for nl_it in range(1, self.max_nl_it + 1):

                    self.coupling_utility.InitializeNonLinearIteration()

                    # Residual computation
                    disp_residual = self.ComputeDirichletNeumannResidual()
                    nl_res_norm = UblasSparseSpace().TwoNorm(disp_residual)

                    print("nl_it: ", nl_it, " nl_res_norm: ", nl_res_norm)

                    # Check convergence
                    if nl_res_norm < self.nl_tol:
                        break

                    else:
                        # If convergence is not achieved, perform the correction of the prediction
                        self.coupling_utility.UpdateSolution(
                            disp_residual, self.iteration_value)
                        self.coupling_utility.FinalizeNonLinearIteration()

                self.structure_solver.FinalizeSolutionStep()
                self.coupling_utility.FinalizeSolutionStep()

                # Unitcest convergence criterion check
                self.assertLess(nl_res_norm, self.nl_tol)
Exemplo n.º 3
0
    def RunTestCaseIBN(self):
        StructureSolverSettings = Parameters("""
        {
            "problem_data": {
                "parallel_type" : "OpenMP"
            },
            "solver_settings" : {
                "model_part_name"         : "Structure",
                "domain_size"             : 2,
                "solver_type"             : "Dynamic",
                "echo_level"              : 0,
                "analysis_type"           : "linear",
                "time_integration_method" : "implicit",
                "scheme_type"             : "bossak",
                "model_import_settings"              : {
                    "input_type"       : "mdpa",
                    "input_filename"   : "test_FSI_emulator_Structural",
                    "input_file_label" : 0
                },
                "material_import_settings" :{
                    "materials_filename": "materials_2D.json"
                },
                "line_search"                        : false,
                "convergence_criterion"              : "Residual_criterion",
                "displacement_relative_tolerance"    : 1e-8,
                "displacement_absolute_tolerance"    : 1e-10,
                "residual_relative_tolerance"        : 1e-8,
                "residual_absolute_tolerance"        : 1e-10,
                "max_iteration"                      : 20,
                "rotation_dofs"                      : false,
                "linear_solver_settings"             : {
                    "solver_type" : "LinearSolversApplication.sparse_lu",
                    "scaling"     : true
                }
            }
        }
        """)

        with WorkFolderScope(self.work_folder):

            self.model = Model()

            # Construct the structure solver
            self.structure_solver = python_solvers_wrapper_structural.CreateSolver(self.model, StructureSolverSettings)

            self.structure_solver.AddVariables()

            self.structure_solver.ImportModelPart()

            self.structure_solver.PrepareModelPart()

            self.structure_main_model_part = self.model["Structure"]

            self.structure_solver.AddDofs()

            self.SetStructureBoundaryConditions()

            self.structure_solver.Initialize()

            self.coupling_utility.Initialize()

            residual_size = self.GetInterfaceProblemSize()*2 # Interface DOFs number times PROBLEM_SIZE
            self.iteration_value_u = Vector(residual_size) # Interface displacement iteration guess
            self.iteration_value_f = Vector(residual_size) # Interface fluxes iteration guess
            self.corrected_iteration_value_u = Vector(residual_size) # Interface displacement iteration guess
            self.corrected_iteration_value_f = Vector(residual_size) # Interface fluxes iteration guess
            for i in range(0,residual_size):
                self.iteration_value_u[i] = 0.0
                self.iteration_value_f[i] = 0.0
                self.corrected_iteration_value_u[i] = 0.0
                self.corrected_iteration_value_f[i] = 0.0

            step = 0
            time = 0.0

            while(time <= self.end_time):

                time = time + self.Dt
                step = step + 1

                print("##################################")
                print("########## step = ", step, "#############")
                print("##################################")

                self.structure_solver.main_model_part.ProcessInfo.SetValue(TIME_STEPS, step)

                self.structure_main_model_part.CloneTimeStep(time)

                self.PointLoadUpdate()

                self.structure_solver.InitializeSolutionStep()
                self.structure_solver.Predict()

                self.coupling_utility.InitializeSolutionStep()

                # Compute and check first residual
                disp_residual = self.__ComputeInitialResidual()
                nl_res_norm = UblasSparseSpace().TwoNorm(disp_residual)
                if nl_res_norm > self.nl_tol:
                    for nl_it in range(self.max_nl_it):

                        self.coupling_utility.InitializeNonLinearIteration()

                        # Update the structure displacement values
                        self.coupling_utility.UpdateSolutionRight(self.corrected_iteration_value_f, self.iteration_value_u, self.corrected_iteration_value_u)

                        # Solve fluid emulator with the obtained displacements
                        self.__SolveFluidEmulator()

                        # Update the fluid emulator force values
                        self.coupling_utility.UpdateSolutionLeft(self.corrected_iteration_value_u, self.iteration_value_f, self.corrected_iteration_value_f)

                        # Finalize the current non-linear iteration
                        self.coupling_utility.FinalizeNonLinearIteration()

                        # Transfer fluid emulator load to structure
                        self.__TransferFluidEmulatorLoad()

                        # Solve the structure problem
                        self.structure_solver.SolveSolutionStep()

                        # Compute displalcement residual
                        disp_residual = self.__ComputeStructureResidual()

                        # Residual computation
                        nl_res_norm = UblasSparseSpace().TwoNorm(disp_residual)
                        print("nl_it: ",nl_it," nl_res_norm: ",nl_res_norm)

                        # Check convergence
                        if nl_res_norm < self.nl_tol:
                            break

                self.structure_solver.FinalizeSolutionStep()
                self.coupling_utility.FinalizeSolutionStep()

                # Unitcest convergence criterion check
                self.assertLess(nl_res_norm, self.nl_tol)