コード例 #1
0
    def __init__(self, model_part, project_parameters, do_pre_recovery=False):
        L2_projection_recoverer.L2ProjectionMaterialAccelerationRecoverer.__init__(
            self, project_parameters, model_part)
        Pouliot2012GradientRecoverer.__init__(self, project_parameters,
                                              model_part)
        self.do_pre_recovery = do_pre_recovery

        scheme = Kratos.ResidualBasedIncrementalUpdateStaticScheme()
        amgcl_smoother = Kratos.AMGCLSmoother.SPAI0
        amgcl_krylov_type = Kratos.AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK
        tolerance = 1e-12
        max_iterations = 200
        verbosity = 2  # 0->shows no information, 1->some information, 2->all the information
        gmres_size = 400

        if self.use_lumped_mass_matrix:
            linear_solver = Kratos.CGSolver()
        else:
            linear_solver = Kratos.AMGCLSolver(amgcl_smoother,
                                               amgcl_krylov_type, tolerance,
                                               max_iterations, verbosity,
                                               gmres_size)

        self.recovery_strategy = Kratos.ResidualBasedDerivativeRecoveryStrategy(
            self.recovery_model_part, scheme, linear_solver, False, True,
            False, False)
        self.recovery_strategy.SetEchoLevel(0)
コード例 #2
0
    def CreateCPluPlusStrategies(self, echo_level=1):
        # from KratosMultiphysics.ExternalSolversApplication import SuperLUIterativeSolver
        # from KratosMultiphysics.ExternalSolversApplication import SuperLUSolver
        # linear_solver = SuperLUIterativeSolver()
        scheme = Kratos.ResidualBasedIncrementalUpdateStaticScheme()
        amgcl_smoother = Kratos.AMGCLSmoother.SPAI0
        amgcl_krylov_type = Kratos.AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK
        tolerance = 1e-8
        max_iterations = 400
        verbosity = 2  #0->shows no information, 1->some information, 2->all the information
        gmres_size = 400

        # if self.use_lumped_mass_matrix:
        #     linear_solver = CGSolver()
        # else:
        linear_solver = Kratos.AMGCLSolver(amgcl_smoother, amgcl_krylov_type,
                                           tolerance, max_iterations,
                                           verbosity, gmres_size)
        # linear_solver = SuperLUIterativeSolver()
        # linear_solver = CGSolver()
        # linear_solver = SkylineLUFactorizationSolver()
        # linear_solver = SuperLUSolver()
        # linear_solver = ITSOL_ARMS_Solver()
        # linear_solver = MKLPardisoSolver()
        # linear_solver = AMGCLSolver(amgcl_smoother, amgcl_krylov_type, tolerance, max_iterations, verbosity,gmres_size)
        self.recovery_strategy = Kratos.ResidualBasedDerivativeRecoveryStrategy(
            self.recovery_model_part, scheme, linear_solver, False, False,
            False, False)

        self.recovery_strategy.SetEchoLevel(echo_level)
コード例 #3
0
    def _setup_solver(self, solving_with="Block", linear_solver="AMGCL"):

        #define a minimal newton raphson solver
        if linear_solver == "AMGCL":
            self.linear_solver = KM.AMGCLSolver()
        else:
            self.linear_solver = KM.SkylineLUFactorizationSolver()
        if solving_with == "Block":
            self.builder_and_solver = KM.ResidualBasedBlockBuilderAndSolver(
                self.linear_solver)
        else:  # Block default
            self.builder_and_solver = KM.ResidualBasedBlockBuilderAndSolver(
                self.linear_solver)
        self.scheme = KM.ResidualBasedBossakDisplacementScheme(-0.01)
        self.convergence_criterion = KM.ResidualCriteria(1e-6, 1e-9)
        self.convergence_criterion.SetEchoLevel(0)

        max_iters = 10
        compute_reactions = True
        reform_step_dofs = True
        move_mesh_flag = False
        self.strategy = KM.ResidualBasedNewtonRaphsonStrategy(
            self.mp, self.scheme, self.linear_solver,
            self.convergence_criterion, self.builder_and_solver, max_iters,
            compute_reactions, reform_step_dofs, move_mesh_flag)
        self.strategy.SetEchoLevel(0)
        self.strategy.Initialize()

        self.strategy.Check()
コード例 #4
0
 def SetStrategy(self):
     scheme = KratosMultiphysics.ResidualBasedIncrementalUpdateStaticScheme(
     )
     linear_solver = KratosMultiphysics.AMGCLSolver()
     self.l2_projector_strategy = KratosMultiphysics.ResidualBasedLinearStrategy(
         self.error_model_part, scheme, linear_solver, False, False, False,
         False)
コード例 #5
0
 def _create_linear_solver(self):
     linear_solver = super(ContactImplicitMechanicalSolver,
                           self)._create_linear_solver()
     if (self.contact_settings["rescale_linear_solver"].GetBool() is True):
         linear_solver = KM.ScalingSolver(linear_solver, False)
     mortar_type = self.contact_settings["mortar_type"].GetString()
     if (mortar_type == "ALMContactFrictional"
             or mortar_type == "ALMContactFrictionlessComponents"):
         if (self.contact_settings["use_mixed_ulm_solver"].GetBool() == True
             ):
             self.print_on_rank_zero(
                 "::[Contact Mechanical Implicit Dynamic Solver]:: ",
                 "Using MixedULMLinearSolver, definition of ALM parameters recommended"
             )
             name_mixed_solver = self.contact_settings[
                 "mixed_ulm_solver_parameters"]["solver_type"].GetString()
             if (name_mixed_solver == "mixed_ulm_linear_solver"):
                 linear_solver_name = self.settings[
                     "linear_solver_settings"]["solver_type"].GetString()
                 if (linear_solver_name == "AMGCL"
                         or linear_solver_name == "AMGCLSolver"):
                     amgcl_param = KM.Parameters("""
                     {
                         "solver_type"                    : "AMGCL",
                         "smoother_type"                  : "ilu0",
                         "krylov_type"                    : "lgmres",
                         "coarsening_type"                : "aggregation",
                         "max_iteration"                  : 100,
                         "provide_coordinates"            : false,
                         "gmres_krylov_space_dimension"   : 100,
                         "verbosity"                      : 1,
                         "tolerance"                      : 1e-6,
                         "scaling"                        : false,
                         "block_size"                     : 3,
                         "use_block_matrices_if_possible" : true,
                         "coarse_enough"                  : 500
                     }
                     """)
                     amgcl_param["block_size"].SetInt(
                         self.main_model_part.ProcessInfo[KM.DOMAIN_SIZE])
                     self.linear_solver_settings.RecursivelyValidateAndAssignDefaults(
                         amgcl_param)
                     linear_solver = KM.AMGCLSolver(
                         self.linear_solver_settings)
                 mixed_ulm_solver = CSMA.MixedULMLinearSolver(
                     linear_solver,
                     self.contact_settings["mixed_ulm_solver_parameters"])
                 return mixed_ulm_solver
             else:
                 self.print_on_rank_zero(
                     "::[Contact Mechanical Implicit Dynamic Solver]:: ",
                     "Mixed solver not available: " + name_mixed_solver +
                     ". Using not mixed linear solver")
                 return linear_solver
         else:
             return linear_solver
     else:
         return linear_solver
コード例 #6
0
    def __init__(self, model_part, custom_settings):

        self.main_model_part = model_part

        ##settings string in json format
        default_settings = KratosMultiphysics.Parameters("""
        {
            "solver_type"                   : "dam_P_solver",
            "model_import_settings"         : {
                "input_type"       : "mdpa",
                "input_filename"   : "unknown_name",
                "input_file_label" : 0
            },
            "echo_level"                    : 1,
            "buffer_size"                   : 2,
            "processes_sub_model_part_list" : [""],
            "acoustic_solver_settings"      : {
                "strategy_type"               : "Newton-Raphson",
                "scheme_type"                 : "Newmark",
                "convergence_criterion"       : "Residual_criterion",
                "residual_relative_tolerance" : 0.0001,
                "residual_absolute_tolerance" : 1e-9,
                "max_iteration"               : 10,
                "move_mesh_flag"              : false,
                "echo_level"                  : 0,
                "linear_solver_settings"      : {
                    "solver_type"   : "amgcl",
                    "max_iteration" : 200,
                    "tolerance"     : 1e-7,
                    "verbosity"     : 0,
                    "GMRES_size"    : 50
                    }
            }
         }""")

        ##overwrite the default settings with user-provided parameters
        self.settings = custom_settings
        self.settings.ValidateAndAssignDefaults(default_settings)

        ## Definition of the linear solver
        amgcl_smoother = KratosMultiphysics.AMGCLSmoother.ILU0
        amgcl_krylov_type = KratosMultiphysics.AMGCLIterativeSolverType.BICGSTAB
        tolerance = self.settings["acoustic_solver_settings"][
            "linear_solver_settings"]["tolerance"].GetDouble()
        max_iterations = self.settings["acoustic_solver_settings"][
            "linear_solver_settings"]["max_iteration"].GetInt()
        verbosity = self.settings["acoustic_solver_settings"][
            "linear_solver_settings"]["verbosity"].GetInt()
        gmres_size = self.settings["acoustic_solver_settings"][
            "linear_solver_settings"]["GMRES_size"].GetInt()

        self.linear_solver = KratosMultiphysics.AMGCLSolver(
            amgcl_smoother, amgcl_krylov_type, tolerance, max_iterations,
            verbosity, gmres_size)
コード例 #7
0
def  AuxiliarCreateLinearSolver(main_model_part, settings, contact_settings, linear_solver_settings, linear_solver):
    if contact_settings["rescale_linear_solver"].GetBool():
        linear_solver = KM.ScalingSolver(linear_solver, False)
    mortar_type = contact_settings["mortar_type"].GetString()
    if "ALMContactFrictional" in mortar_type or mortar_type == "ALMContactFrictionlessComponents":
        if contact_settings["use_mixed_ulm_solver"].GetBool():
            KM.Logger.PrintInfo("::[Contact Mechanical Solver]:: ", "Using MixedULMLinearSolver, definition of ALM parameters recommended")
            name_mixed_solver = contact_settings["mixed_ulm_solver_parameters"]["solver_type"].GetString()
            if name_mixed_solver == "mixed_ulm_linear_solver":
                if settings.Has("linear_solver_settings"):
                    if settings["linear_solver_settings"].Has("solver_type"):
                        linear_solver_name = settings["linear_solver_settings"]["solver_type"].GetString()
                        if linear_solver_name == "amgcl" or linear_solver_name == "AMGCL" or linear_solver_name == "AMGCLSolver":
                            amgcl_param = KM.Parameters("""
                            {
                                "solver_type"                    : "amgcl",
                                "smoother_type"                  : "ilu0",
                                "krylov_type"                    : "lgmres",
                                "coarsening_type"                : "aggregation",
                                "max_iteration"                  : 100,
                                "provide_coordinates"            : false,
                                "gmres_krylov_space_dimension"   : 100,
                                "verbosity"                      : 1,
                                "tolerance"                      : 1e-6,
                                "scaling"                        : false,
                                "block_size"                     : 3,
                                "use_block_matrices_if_possible" : true,
                                "coarse_enough"                  : 500
                            }
                            """)
                            amgcl_param["block_size"].SetInt(main_model_part.ProcessInfo[KM.DOMAIN_SIZE])
                            linear_solver_settings.RecursivelyValidateAndAssignDefaults(amgcl_param)
                            linear_solver = KM.AMGCLSolver(linear_solver_settings)
                        mixed_ulm_solver = CSMA.MixedULMLinearSolver(linear_solver, contact_settings["mixed_ulm_solver_parameters"])
                        return mixed_ulm_solver
                    else:
                        return linear_solver
                else:
                    return linear_solver
            else:
                KM.Logger.PrintInfo("::[Contact Mechanical Solver]:: ", "Mixed solver not available: " + name_mixed_solver + ". Using not mixed linear solver")
                return linear_solver
        else:
            return linear_solver
    else:
        return linear_solver
コード例 #8
0
    def _setup_solver(self, solving_with="Block", linear_solver="AMGCL"):

        #define a minimal newton raphson solver
        if linear_solver == "AMGCL":
            self.linear_solver = KM.AMGCLSolver()
        else:
            self.linear_solver = KM.SkylineLUFactorizationSolver()
        if solving_with == "Block":
            self.builder_and_solver = KM.ResidualBasedBlockBuilderAndSolver(
                self.linear_solver)
        elif solving_with == "LM":
            params = KM.Parameters("""{
                "diagonal_values_for_dirichlet_dofs"                 : "use_max_diagonal",
                "silent_warnings"                                    : false,
                "consider_lagrange_multiplier_constraint_resolution" : "single"
            }""")
            self.builder_and_solver = KM.ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier(
                self.linear_solver, params)
        elif solving_with == "DoubleLM":
            params = KM.Parameters("""{
                "diagonal_values_for_dirichlet_dofs"                 : "use_max_diagonal",
                "silent_warnings"                                    : false,
                "consider_lagrange_multiplier_constraint_resolution" : "double"
            }""")
            self.builder_and_solver = KM.ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier(
                self.linear_solver, params)
        else:  # Block default
            self.builder_and_solver = KM.ResidualBasedBlockBuilderAndSolver(
                self.linear_solver)
        self.scheme = KM.ResidualBasedBossakDisplacementScheme(-0.01)
        self.convergence_criterion = KM.ResidualCriteria(1e-6, 1e-9)
        self.convergence_criterion.SetEchoLevel(0)

        max_iters = 10
        compute_reactions = True
        reform_step_dofs = True
        move_mesh_flag = False
        self.strategy = KM.ResidualBasedNewtonRaphsonStrategy(
            self.mp, self.scheme, self.convergence_criterion,
            self.builder_and_solver, max_iters, compute_reactions,
            reform_step_dofs, move_mesh_flag)
        self.strategy.SetEchoLevel(0)
        self.strategy.Initialize()

        self.strategy.Check()
コード例 #9
0
    def CreateCPluPlusStrategies(self, echo_level=1):
        from KratosMultiphysics.ExternalSolversApplication import SuperLUIterativeSolver
        # linear_solver = SuperLUIterativeSolver()
        # from KratosMultiphysics.ExternalSolversApplication import SuperLUSolver
        scheme = Kratos.ResidualBasedIncrementalUpdateStaticScheme()
        amgcl_smoother = Kratos.AMGCLSmoother.ILU0
        amgcl_krylov_type = Kratos.AMGCLIterativeSolverType.BICGSTAB
        tolerance = 1e-8
        max_iterations = 1000
        verbosity = 0  #0->shows no information, 1->some information, 2->all the information
        gmres_size = 50

        if self.use_lumped_mass_matrix:
            linear_solver = SuperLUIterativeSolver()
        else:
            linear_solver = Kratos.AMGCLSolver(amgcl_smoother,
                                               amgcl_krylov_type, tolerance,
                                               max_iterations, verbosity,
                                               gmres_size)

        self.recovery_strategy = Kratos.ResidualBasedDerivativeRecoveryStrategy(
            self.recovery_model_part, scheme, linear_solver, False, True,
            False, False)
        self.recovery_strategy.SetEchoLevel(echo_level)
コード例 #10
0
def ConstructSolver(configuration):
    import KratosMultiphysics

    if (type(configuration) != KratosMultiphysics.Parameters):
        raise Exception(
            "input is expected to be provided as a Kratos Parameters object")

    solver_type = configuration["solver_type"].GetString()

    if configuration.Has("scaling"):
        scaling = configuration["scaling"].GetBool()
    else:
        scaling = False

    if (solver_type == "CGSolver"):
        linear_solver = KratosMultiphysics.CGSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "BICGSTABSolver"):
        linear_solver = KratosMultiphysics.BICGSTABSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "TFQMRSolver"):
        linear_solver = KratosMultiphysics.TFQMRSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "DeflatedCGSolver"):
        linear_solver = KratosMultiphysics.DeflatedCGSolver(configuration)
    elif (solver_type == "MixedUPLinearSolver"):
        linear_solver = KratosMultiphysics.MixedUPLinearSolver(configuration)
    elif (solver_type == "SkylineLUFactorizationSolver"):
        linear_solver = KratosMultiphysics.SkylineLUFactorizationSolver(
            configuration)
    elif (solver_type == "complex_skyline_lu_solver"):
        linear_solver = KratosMultiphysics.ComplexSkylineLUSolver(
            configuration)

    ################################## following solvers need importing the ExternalSolversApplication
    elif (solver_type == "GMRESSolver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.GMRESSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "SuperLUSolver" or solver_type == "Super LU"
          or solver_type == "Super_LU"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.SuperLUSolver(
            configuration)
    elif (solver_type == "SuperLUIterativeSolver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.SuperLUIterativeSolver(
            configuration)
    elif (solver_type == "PastixSolver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.PastixSolver(
            configuration)
    elif (solver_type == "AMGCL"):
        linear_solver = KratosMultiphysics.AMGCLSolver(configuration)
    elif (solver_type == "AMGCL_NS_Solver"):
        linear_solver = KratosMultiphysics.AMGCL_NS_Solver(configuration)
    elif (solver_type == "complex_pastix_solver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.PastixComplexSolver(
            configuration)

    ################################## following solvers need importing the EigenSolversApplication
    elif (solver_type == "eigen_sparse_lu"):
        import KratosMultiphysics.EigenSolversApplication
        linear_solver = KratosMultiphysics.EigenSolversApplication.SparseLUSolver(
            configuration)
    elif (solver_type == "eigen_pardiso_llt"):  # needs Intel MKL
        import KratosMultiphysics.EigenSolversApplication
        linear_solver = KratosMultiphysics.EigenSolversApplication.PardisoLLTSolver(
            configuration)
    elif (solver_type == "eigen_pardiso_ldlt"):  # needs Intel MKL
        import KratosMultiphysics.EigenSolversApplication
        linear_solver = KratosMultiphysics.EigenSolversApplication.PardisoLDLTSolver(
            configuration)
    elif (solver_type == "eigen_pardiso_lu"):  # needs Intel MKL
        import KratosMultiphysics.EigenSolversApplication
        linear_solver = KratosMultiphysics.EigenSolversApplication.PardisoLUSolver(
            configuration)

    # emulating the solvers of the MKLSolversApplication through the EigenSolversApplication
    elif (solver_type == "ParallelMKLPardisoSolver"):
        KratosMultiphysics.Logger.PrintWarning(
            "LinearSolverFactor", "Solver Parallel_MKL_Pardiso is deprecated,\
        please use it through the EigenSolversApplication (see the Readme in the Application)"
        )
        import KratosMultiphysics.EigenSolversApplication
        linear_solver = KratosMultiphysics.EigenSolversApplication.PardisoLUSolver(
            configuration)

    ###################################### FAILED TO FIND solver_type
    else:
        raise Exception("solver type not found. Asking for :" + solver_type)

    ###### here decide if a prescaling is to be applied
    if (scaling == False):
        return linear_solver
    else:
        return KratosMultiphysics.ScalingSolver(linear_solver, True)
コード例 #11
0
def ConstructSolver(configuration):
    import KratosMultiphysics

    if (type(configuration) != KratosMultiphysics.Parameters):
        raise Exception(
            "input is expected to be provided as a Kratos Parameters object")

    solver_type = configuration["solver_type"].GetString()

    if configuration.Has("scaling"):
        scaling = configuration["scaling"].GetBool()
    else:
        scaling = False

    if (solver_type == "CGSolver"):
        linear_solver = KratosMultiphysics.CGSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "BICGSTABSolver"):
        linear_solver = KratosMultiphysics.BICGSTABSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "TFQMRSolver"):
        linear_solver = KratosMultiphysics.TFQMRSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "DeflatedCGSolver"):
        linear_solver = KratosMultiphysics.DeflatedCGSolver(configuration)
    elif (solver_type == "MixedUPLinearSolver"):
        linear_solver = KratosMultiphysics.MixedUPLinearSolver(configuration)
    elif (solver_type == "SkylineLUFactorizationSolver"):
        linear_solver = KratosMultiphysics.SkylineLUFactorizationSolver(
            configuration)
    elif (solver_type == "complex_skyline_lu_solver"):
        linear_solver = KratosMultiphysics.ComplexSkylineLUSolver(
            configuration)

    ################################## following solvers need importing the ExternalSolversApplication
    elif (solver_type == "GMRESSolver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.GMRESSolver(
            configuration, ConstructPreconditioner(configuration))
    elif (solver_type == "SuperLUSolver" or solver_type == "Super LU"
          or solver_type == "Super_LU"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.SuperLUSolver(
            configuration)
    elif (solver_type == "SuperLUIterativeSolver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.SuperLUIterativeSolver(
            configuration)
    elif (solver_type == "PastixSolver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.PastixSolver(
            configuration)
    elif (solver_type == "AMGCL"):
        linear_solver = KratosMultiphysics.AMGCLSolver(configuration)
    elif (solver_type == "AMGCL_NS_Solver"):
        linear_solver = KratosMultiphysics.AMGCL_NS_Solver(configuration)
    elif (solver_type == "complex_pastix_solver"):
        import KratosMultiphysics.ExternalSolversApplication
        linear_solver = KratosMultiphysics.ExternalSolversApplication.PastixComplexSolver(
            configuration)

    ################################## following solvers need importing the MKLSolversApplication
    elif (solver_type == "ParallelMKLPardisoSolver"):
        import KratosMultiphysics.MKLSolversApplication
        linear_solver = KratosMultiphysics.MKLSolversApplication.ParallelMKLPardisoSolver(
            configuration)

    ###################################### FAILED TO FIND solver_type
    else:
        raise Exception("solver type not found. Asking for :" + solver_type)

    ###### here decide if a prescaling is to be applied
    if (scaling == False):
        return linear_solver
    else:
        return KratosMultiphysics.ScalingSolver(linear_solver, True)