def test_model_part_sub_model_parts(self): model_part = KratosMultiphysics.ModelPart("Main") model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DISTANCE) KratosMultiphysics.ModelPartIO( GetFilePath("coarse_sphere")).ReadModelPart(model_part) model_part.SetBufferSize(2) for node in model_part.Nodes: node.SetSolutionStepValue( KratosMultiphysics.DISTANCE, 0, self._ExpectedDistance(node.X, node.Y, node.Z)) import new_linear_solver_factory linear_solver = new_linear_solver_factory.ConstructSolver( KratosMultiphysics.Parameters( """ { "solver_type" : "SkylineLUFactorizationSolver" } """)) model_part.CloneTimeStep(1.0) max_iterations = 2 KratosMultiphysics.VariationalDistanceCalculationProcess3D( model_part, linear_solver, max_iterations).Execute() max_distance = -1.0 min_distance = +1.0 for node in model_part.Nodes: d = node.GetSolutionStepValue(KratosMultiphysics.DISTANCE) max_distance = max(max_distance, d) min_distance = min(min_distance, d) self.assertAlmostEqual(max_distance, 0.46121597491907795) self.assertAlmostEqual(min_distance, -0.5072739105922954)
def init_solver(self): # Löser konfigurieren self.model_part.SetBufferSize(1) # Verfahren time_scheme = ResidualBasedIncrementalUpdateStaticScheme() linear_solver = new_linear_solver_factory.ConstructSolver( Parameters(r'{"solver_type": "eigen_sparse_lu"}')) # Abbruchkriterium relative_tolerance = 1e-09 absolute_tolerance = 1e-09 # conv_criteria = ResidualCriteria(relative_tolerance, absolute_tolerance) conv_criteria = DisplacementCriteria(relative_tolerance, absolute_tolerance) conv_criteria.SetEchoLevel(1) # Löser maximum_iterations = 600 #!! Wenn der Löser nur eine Iteration durchführt erhälst du eine lineare Lösung > Iterationszahl erhöhen! compute_reactions = True reform_dofs_at_each_iteration = True move_mesh_flag = True self.solver = ResidualBasedNewtonRaphsonStrategy( self.model_part, time_scheme, linear_solver, conv_criteria, maximum_iterations, compute_reactions, reform_dofs_at_each_iteration, move_mesh_flag) self.solver.SetEchoLevel(1)
def ConstructSolver(settings): import KratosMultiphysics if (type(settings) != KratosMultiphysics.Parameters): raise Exception( "Input is expected to be provided as a Kratos Parameters object") import new_linear_solver_factory linear_solver = new_linear_solver_factory.ConstructSolver( settings["linear_solver_settings"]) solver_type = settings["solver_type"].GetString() if (solver_type == "power_iteration_eigenvalue_solver"): eigen_solver = KratosMultiphysics.PowerIterationEigenvalueSolver( settings, linear_solver) elif (solver_type == "power_iteration_highest_eigenvalue_solver"): eigen_solver = KratosMultiphysics.PowerIterationHighestEigenvalueSolver( settings, linear_solver) elif (solver_type == "rayleigh_quotient_iteration_eigenvalue_solver"): eigen_solver = KratosMultiphysics.RayleighQuotientIterationEigenvalueSolver( settings, linear_solver) elif (solver_type == "FEAST"): import KratosMultiphysics.ExternalSolversApplication eigen_solver = KratosMultiphysics.ExternalSolversApplication.FEASTSolver( settings, linear_solver) else: raise Exception("Solver type not found. Asking for :" + solver_type) return eigen_solver
def _auxiliary_test_function(self, settings, matrix_name="A.mm"): space = KratosMultiphysics.UblasSparseSpace() #read the matrices A = KratosMultiphysics.CompressedMatrix() KratosMultiphysics.ReadMatrixMarketMatrix(GetFilePath(matrix_name), A) Aoriginal = KratosMultiphysics.CompressedMatrix(A) #create a copy of A n = A.Size1() b = KratosMultiphysics.Vector(n) space.SetToZeroVector(b) for i in range(len(b)): b[i] = i / len(b) x = KratosMultiphysics.Vector(n) #KratosMultiphysics.ReadMatrixMarketVector("b.mm",b) boriginal = KratosMultiphysics.Vector(b) #create a copy of b space.SetToZeroVector(x) #space.SetToZeroVector(boriginal) #space.UnaliasedAdd(boriginal, 1.0, b) #boriginal=1*bs #construct the solver import new_linear_solver_factory linear_solver = new_linear_solver_factory.ConstructSolver(settings) #solve linear_solver.Solve(A, x, b) #test the results tmp = KratosMultiphysics.Vector(n) tmp *= 0.0 space.Mult(Aoriginal, x, tmp) check = KratosMultiphysics.Vector(n) check = boriginal - tmp achieved_norm = space.TwoNorm(check) tolerance = 1e-9 if (settings.Has("tolerance")): tolerance = settings["tolerance"].GetDouble() target_norm = tolerance * space.TwoNorm(boriginal) if (not (achieved_norm <= target_norm)): KratosMultiphysics.Logger.PrintInfo( "Test linear solvers: ", "Echo of settings for failing test:\n", settings.PrettyPrintJsonString()) KratosMultiphysics.Logger.PrintInfo("Test linear solvers: ", "Achieved_norm", achieved_norm, "\n", "Target_norm", target_norm) self.assertTrue(achieved_norm <= target_norm)
def __init__(self, model_part, custom_settings): # default settings for laplacian mesh solver default_settings = Parameters(""" { "solver_type" : "mesh_solver_laplacian", "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "unknown_name" }, "ale_linear_solver_settings" : { "solver_type" : "AMGCL", "smoother_type":"ilu0", "krylov_type": "gmres", "coarsening_type": "aggregation", "max_iteration": 200, "provide_coordinates": false, "gmres_krylov_space_dimension": 100, "verbosity" : 0, "tolerance": 1e-7, "scaling": false, "block_size": 1, "use_block_matrices_if_possible" : true, "coarse_enough" : 5000 }, "volume_model_part_name" : "volume_model_part", "time_order" : 2, "mesh_reform_dofs_each_step" : false, "mesh_compute_reactions" : false }""") self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) # assign parameters self.model_part = model_part self.time_order = custom_settings["time_order"].GetInt() self.mesh_reform_dofs_each_step = custom_settings[ "mesh_reform_dofs_each_step"].GetBool() # neighbour search number_of_avg_elems = 10 number_of_avg_nodes = 10 self.neighbour_search = FindNodalNeighboursProcess( model_part, number_of_avg_elems, number_of_avg_nodes) # definition of the solvers import new_linear_solver_factory self.linear_solver = new_linear_solver_factory.ConstructSolver( self.settings["ale_linear_solver_settings"]) print("Construction of MeshSolverLaplacian finished")
def test_levelset_convection(self): current_model = KratosMultiphysics.Model() model_part = current_model.CreateModelPart("Main") model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DISTANCE) model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VELOCITY) KratosMultiphysics.ModelPartIO( GetFilePath("levelset_convection_process_mesh")).ReadModelPart( model_part) model_part.SetBufferSize(2) for node in model_part.Nodes: node.SetSolutionStepValue(KratosMultiphysics.DISTANCE, 0, BaseDistance(node.X, node.Y, node.Z)) node.SetSolutionStepValue( KratosMultiphysics.VELOCITY, 0, ConvectionVelocity(node.X, node.Y, node.Z)) for node in model_part.Nodes: if node.X < 0.001: node.Fix(KratosMultiphysics.DISTANCE) import new_linear_solver_factory linear_solver = new_linear_solver_factory.ConstructSolver( KratosMultiphysics.Parameters( """{"solver_type" : "SkylineLUFactorizationSolver"}""")) model_part.CloneTimeStep(40.0) KratosMultiphysics.LevelSetConvectionProcess2D( KratosMultiphysics.DISTANCE, model_part, linear_solver).Execute() max_distance = -1.0 min_distance = +1.0 for node in model_part.Nodes: d = node.GetSolutionStepValue(KratosMultiphysics.DISTANCE) max_distance = max(max_distance, d) min_distance = min(min_distance, d) self.assertAlmostEqual(max_distance, 0.7904255118014996) self.assertAlmostEqual(min_distance, -0.11710292469993094)
# model_part.GetNode(1).Fix(DISPLACEMENT_Z) # model_part.GetNode(1).Fix(DISPLACEMENT_ROTATION) # # # model_part.GetNode(2).Fix(DISPLACEMENT_X) # model_part.GetNode(2).Fix(DISPLACEMENT_Y) # model_part.GetNode(2).Fix(DISPLACEMENT_Z) # # model_part.GetNode(1).Fix(DISPLACEMENT_ROTATION) # Löser konfigurieren model_part.SetBufferSize(1) # Verfahren time_scheme = ResidualBasedIncrementalUpdateStaticScheme() linear_solver = new_linear_solver_factory.ConstructSolver( Parameters( # r'{"solver_type": "SkylineLUFactorizationSolver"}')) r'{"solver_type": "eigen_sparse_lu"}')) # Abbruchkriterium relative_tolerance = 1e-4 absolute_tolerance = 1e-4 conv_criteria = ResidualCriteria(relative_tolerance, absolute_tolerance) conv_criteria.SetEchoLevel(1) # Löser maximum_iterations = 200 #!! Wenn der Löser nur eine Iteration durchführt erhälst du eine lineare Lösung > Iterationszahl erhöhen! compute_reactions = True reform_dofs_at_each_iteration = True move_mesh_flag = True solver = ResidualBasedNewtonRaphsonStrategy(
def solve_cantilever(create_geometry): model = Model() model_part = model.CreateModelPart('Model') model_part.AddNodalSolutionStepVariable(DISPLACEMENT) model_part.AddNodalSolutionStepVariable(REACTION) model_part.AddNodalSolutionStepVariable(POINT_LOAD) # create property for shell elements shell_properties = model_part.GetProperties()[1] shell_properties.SetValue(THICKNESS, 0.1) shell_properties.SetValue(YOUNG_MODULUS, 210000000) shell_properties.SetValue(POISSON_RATIO, 0) shell_properties.SetValue(DENSITY, 78.5) shell_properties.SetValue(CONSTITUTIVE_LAW, LinearElasticPlaneStress2DLaw()) # create a node based geometry surface = create_geometry(model_part) # create elements for each integration point spans_u = surface.SpansU() spans_v = surface.SpansV() integration_points = list() for span_u in spans_u: for span_v in spans_v: integration_points += IntegrationPoints.Points2D( DegreeU=surface.DegreeU + 1, DegreeV=surface.DegreeV + 1, DomainU=span_u, DomainV=span_v, ) shapes = SurfaceShapeEvaluator( DegreeU=surface.DegreeU, DegreeV=surface.DegreeV, Order=2, ) for i, (u, v, weight) in enumerate(integration_points): shapes.Compute(surface.KnotsU(), surface.KnotsV(), u, v) node_indices = list() for index_u, index_v in shapes.NonzeroPoleIndices: node_id = surface.Node(index_u, index_v).Id node_indices.append(node_id) element = model_part.CreateNewElement('ShellKLDiscreteElement', i + 1, node_indices, shell_properties) n_0 = Vector(shapes.NumberOfNonzeroPoles) n_1 = Matrix(shapes.NumberOfNonzeroPoles, 2) n_2 = Matrix(shapes.NumberOfNonzeroPoles, 3) for j, (poleU, poleV) in enumerate(shapes.NonzeroPoleIndices): indexU = poleU - shapes.FirstNonzeroPoleU indexV = poleV - shapes.FirstNonzeroPoleV n_0[j] = shapes(0, indexU, indexV) n_1[j, 0] = shapes(1, indexU, indexV) n_1[j, 1] = shapes(2, indexU, indexV) n_2[j, 0] = shapes(3, indexU, indexV) n_2[j, 1] = shapes(5, indexU, indexV) n_2[j, 2] = shapes(4, indexU, indexV) element.SetValue(INTEGRATION_WEIGHT, weight) element.SetValue(SHAPE_FUNCTION_VALUES, n_0) element.SetValue(SHAPE_FUNCTION_LOCAL_DERIVATIVES, n_1) element.SetValue(SHAPE_FUNCTION_LOCAL_SECOND_DERIVATIVES, n_2) # add dofs VariableUtils().AddDof(DISPLACEMENT_X, REACTION_X, model_part) VariableUtils().AddDof(DISPLACEMENT_Y, REACTION_Y, model_part) VariableUtils().AddDof(DISPLACEMENT_Z, REACTION_Z, model_part) # apply dirichlet conditions surface.Node(0, 0).Fix(DISPLACEMENT_X) surface.Node(0, 0).Fix(DISPLACEMENT_Y) surface.Node(0, 0).Fix(DISPLACEMENT_Z) surface.Node(0, 1).Fix(DISPLACEMENT_X) surface.Node(0, 1).Fix(DISPLACEMENT_Y) surface.Node(0, 1).Fix(DISPLACEMENT_Z) surface.Node(0, 2).Fix(DISPLACEMENT_X) surface.Node(0, 2).Fix(DISPLACEMENT_Y) surface.Node(0, 2).Fix(DISPLACEMENT_Z) surface.Node(1, 0).Fix(DISPLACEMENT_Z) surface.Node(1, 1).Fix(DISPLACEMENT_Z) surface.Node(1, 2).Fix(DISPLACEMENT_Z) # apply neumann conditions prop = model_part.GetProperties()[2] node_n0 = surface.Node(surface.NumberOfPolesU - 1, 0) node_nm = surface.Node(surface.NumberOfPolesU - 1, surface.NumberOfPolesV - 1) model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [node_n0.Id], prop) node_n0.SetSolutionStepValue(POINT_LOAD_Z, -50) model_part.CreateNewCondition('PointLoadCondition3D1N', 2, [node_nm.Id], prop) node_nm.SetSolutionStepValue(POINT_LOAD_Z, -50) # setup solver model_part.SetBufferSize(1) time_scheme = ResidualBasedIncrementalUpdateStaticScheme() linear_solver = new_linear_solver_factory.ConstructSolver( Parameters(r'{"solver_type": "SkylineLUFactorizationSolver"}')) relative_tolerance = 1e-8 absolute_tolerance = 1e-7 conv_criteria = ResidualCriteria(relative_tolerance, absolute_tolerance) conv_criteria.SetEchoLevel(0) maximum_iterations = 100 compute_reactions = False reform_dofs_at_each_iteration = False move_mesh_flag = True solver = ResidualBasedNewtonRaphsonStrategy( model_part, time_scheme, linear_solver, conv_criteria, maximum_iterations, compute_reactions, reform_dofs_at_each_iteration, move_mesh_flag) solver.SetEchoLevel(0) model_part.CloneTimeStep(1) solver.Solve() return surface
def solve(create_geometry): model_part = ModelPart('Model') model_part.AddNodalSolutionStepVariable(DISPLACEMENT) model_part.AddNodalSolutionStepVariable(REACTION) model_part.AddNodalSolutionStepVariable(POINT_LOAD) # create property for truss elements truss_properties = model_part.GetProperties()[1] truss_properties.SetValue(CROSS_AREA , 0.01 ) truss_properties.SetValue(PRESTRESS_CAUCHY, 0 ) truss_properties.SetValue(YOUNG_MODULUS , 210000) truss_properties.SetValue(POISSON_RATIO , 0 ) truss_properties.SetValue(DENSITY , 7856 ) # create a node based geometry node_1, node_2, curve = create_geometry(model_part) # create elements for each integration point integration_points = [integration_point for span in curve.Spans() for integration_point in IntegrationPoints.Points1D(curve.Degree + 1, span)] shapes = CurveShapeEvaluator(Degree=curve.Degree, Order=1) for i, (t, weight) in enumerate(integration_points): shapes.Compute(curve.Knots(), t) node_indices = [curve.Node(j).Id for j in range(shapes.FirstNonzeroPole, shapes.LastNonzeroPole + 1)] element = model_part.CreateNewElement('IgaTrussElement', i + 1, node_indices, truss_properties) n_0 = Vector(shapes.NumberOfNonzeroPoles) for i in range(shapes.NumberOfNonzeroPoles): n_0[i] = shapes(0, i) n_1 = Matrix(shapes.NumberOfNonzeroPoles, 1) for i in range(shapes.NumberOfNonzeroPoles): n_1[i, 0] = shapes(1, i) element.SetValue(INTEGRATION_WEIGHT, weight) element.SetValue(SHAPE_FUNCTION_VALUES, n_0) element.SetValue(SHAPE_FUNCTION_LOCAL_DERIVATIVES, n_1) # add dofs VariableUtils().AddDof(DISPLACEMENT_X, REACTION_X, model_part) VariableUtils().AddDof(DISPLACEMENT_Y, REACTION_Y, model_part) VariableUtils().AddDof(DISPLACEMENT_Z, REACTION_Z, model_part) # apply dirichlet conditions node_1.Fix(DISPLACEMENT_X) node_1.Fix(DISPLACEMENT_Y) node_1.Fix(DISPLACEMENT_Z) node_2.Fix(DISPLACEMENT_Y) node_2.Fix(DISPLACEMENT_Z) # apply neumann conditions prop = model_part.GetProperties()[2] model_part.CreateNewCondition('PointLoadCondition3D1N', 2, [node_2.Id], prop) node_2.SetSolutionStepValue(POINT_LOAD_X, 1000) # setup solver model_part.SetBufferSize(1) time_scheme = ResidualBasedIncrementalUpdateStaticScheme() linear_solver = new_linear_solver_factory.ConstructSolver(Parameters( r'{"solver_type": "SkylineLUFactorizationSolver"}')) relative_tolerance = 1e-7 absolute_tolerance = 1e-7 conv_criteria = ResidualCriteria(relative_tolerance, absolute_tolerance) conv_criteria.SetEchoLevel(0) maximum_iterations = 100 compute_reactions = False reform_dofs_at_each_iteration = True move_mesh_flag = True solver = ResidualBasedNewtonRaphsonStrategy( model_part, time_scheme, linear_solver, conv_criteria, maximum_iterations, compute_reactions, reform_dofs_at_each_iteration, move_mesh_flag ) solver.SetEchoLevel(0) model_part.CloneTimeStep(1) solver.Solve() return node_1, node_2, curve
# randbedingungen: knotenlasten load_properties = model_part.GetProperties()[2] # typ id knoten eigenschaften model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [node_2.Id], load_properties) # löser konfigurieren # anzahl der schritte die gespeichert werden sollen model_part.SetBufferSize(1) # verfahren time_scheme = ResidualBasedIncrementalUpdateStaticScheme() linear_solver = new_linear_solver_factory.ConstructSolver( Parameters(r'{"solver_type": "SkylineLUFactorizationSolver"}')) # abbruchkriterium relative_tolerance = 1e-7 absolute_tolerance = 1e-7 conv_criteria = ResidualCriteria(relative_tolerance, absolute_tolerance) conv_criteria.SetEchoLevel(0) # löser maximum_iterations = 1000 compute_reactions = True reform_dofs_at_each_iteration = True move_mesh_flag = True solver = ResidualBasedNewtonRaphsonStrategy( model_part, time_scheme, linear_solver, conv_criteria, maximum_iterations,
def ConstructSolver(configuration): params = 0 ############################################################## ###THIS IS A VERY DIRTY HACK TO ALLOW PARAMETERS TO BE PASSED TO THE LINEAR SOLVER FACTORY ###TODO: clean this up!! if (type(configuration) == Parameters): import new_linear_solver_factory return new_linear_solver_factory.ConstructSolver(configuration) #solver_type = configuration["solver_type"].GetString() #import json #tmp = json.loads(configuration.PrettyPrintJsonString()) #params = configuration #class aux(object): #pass #configuration = aux() #configuration.__dict__.update(tmp) ############################################################## solver_type = configuration.solver_type scaling = False if hasattr(configuration, 'scaling'): scaling = configuration.scaling linear_solver = None # if (solver_type == "Conjugate gradient" or solver_type == "Conjugate_gradient" or solver_type == "CGSolver"): precond = ConstructPreconditioner(configuration) max_it = configuration.max_iteration tol = configuration.tolerance if (precond is None): linear_solver = CGSolver(tol, max_it) else: linear_solver = CGSolver(tol, max_it, precond) # elif (solver_type == "BiConjugate gradient stabilized" or solver_type == "BiConjugate_gradient_stabilized" or solver_type == "BICGSTABSolver"): precond = ConstructPreconditioner(configuration) max_it = configuration.max_iteration tol = configuration.tolerance if (precond is None): linear_solver = BICGSTABSolver(tol, max_it) else: linear_solver = BICGSTABSolver(tol, max_it, precond) # elif (solver_type == "GMRES" or solver_type == "GMRESSolver"): import KratosMultiphysics.ExternalSolversApplication precond = ConstructPreconditioner(configuration) max_it = configuration.max_iteration tol = configuration.tolerance if (precond is None): linear_solver = KratosMultiphysics.ExternalSolversApplication.GMRESSolver( tol, max_it) else: linear_solver = KratosMultiphysics.ExternalSolversApplication.GMRESSolver( tol, max_it, precond) # elif (solver_type == "Deflated Conjugate gradient" or solver_type == "Deflated_Conjugate_gradient" or solver_type == "DeflatedCGSolver"): max_it = configuration.max_iteration tol = configuration.tolerance assume_constant_structure = False if hasattr(configuration, 'assume_constant_structure'): assume_constant_structure = configuration.assume_constant_structure max_reduced_size = 1000 if hasattr(configuration, 'assume_constant_structure'): max_reduced_size = configuration.max_reduced_size linear_solver = DeflatedCGSolver(tol, max_it, assume_constant_structure, max_reduced_size) # elif (solver_type == "GMRES-UP Block" or solver_type == "GMRES-UP_Block"): velocity_linear_solver = ConstructSolver( configuration.velocity_block_configuration) pressure_linear_solver = ConstructSolver( configuration.pressure_block_configuration) m = configuration.gmres_krylov_space_dimension max_it = configuration.max_iteration tol = configuration.tolerance linear_solver = MixedUPLinearSolver(velocity_linear_solver, pressure_linear_solver, tol, max_it, m) # elif (solver_type == "Skyline LU factorization" or solver_type == "Skyline_LU_factorization" or solver_type == "SkylineLUFactorizationSolver"): linear_solver = SkylineLUFactorizationSolver() # elif (solver_type == "Super LU" or solver_type == "Super_LU" or solver_type == "SuperLUSolver"): import KratosMultiphysics.ExternalSolversApplication linear_solver = KratosMultiphysics.ExternalSolversApplication.SuperLUSolver( ) # elif (solver_type == "SuperLUIterativeSolver"): import KratosMultiphysics.ExternalSolversApplication tol = configuration.tolerance max_it = configuration.max_iteration if (hasattr(configuration, "gmres_krylov_space_dimension")): restart = configuration.gmres_krylov_space_dimension else: print( "WARNING: restart not specitifed, setting it to the number of iterations" ) restart = max_it if (hasattr(configuration, "DropTol")): DropTol = configuration.DropTol else: print("WARNING: DropTol not specified, setting it to 1e-4") DropTol = 1e-4 if (hasattr(configuration, "FillTol")): FillTol = configuration.FillTol else: print("WARNING: FillTol not specified, setting it to 1e-2") FillTol = 1e-2 if (hasattr(configuration, "ilu_level_of_fill")): ilu_level_of_fill = configuration.ilu_level_of_fill else: print("WARNING: level of fill not specified, setting it to 10") ilu_level_of_fill = 10 linear_solver = KratosMultiphysics.ExternalSolversApplication.SuperLUIterativeSolver( tol, max_it, restart, DropTol, FillTol, ilu_level_of_fill) # elif (solver_type == "PastixDirect" or solver_type == "PastixSolver"): import KratosMultiphysics.ExternalSolversApplication is_symmetric = False if hasattr(configuration, 'is_symmetric'): configuration.is_symmetric verbosity = 0 if hasattr(configuration, 'verbosity'): verbosity = configuration.verbosity linear_solver = KratosMultiphysics.ExternalSolversApplication.PastixSolver( verbosity, is_symmetric) # elif (solver_type == "PastixIterative"): import KratosMultiphysics.ExternalSolversApplication tol = configuration.tolerance max_it = configuration.max_iteration restart = configuration.gmres_krylov_space_dimension ilu_level_of_fill = configuration.ilu_level_of_fill is_symmetric = configuration.is_symmetric verbosity = 0 if hasattr(configuration, 'verbosity'): verbosity = configuration.verbosity linear_solver = KratosMultiphysics.ExternalSolversApplication.PastixSolver( tol, restart, ilu_level_of_fill, verbosity, is_symmetric) # elif (solver_type == "AMGCL"): if (params == 0): #old style construction if hasattr(configuration, 'preconditioner_type'): if (configuration.preconditioner_type != "None"): print( "WARNING: preconditioner specified in preconditioner_type will not be used as it is not compatible with the AMGCL solver" ) max_it = configuration.max_iteration tol = configuration.tolerance verbosity = 0 if hasattr(configuration, 'verbosity'): verbosity = configuration.verbosity if hasattr(configuration, 'smoother_type'): smoother_type = configuration.smoother_type # options are DAMPED_JACOBI, ILU0, SPAI if (smoother_type == "ILU0"): amgcl_smoother = AMGCLSmoother.ILU0 elif (smoother_type == "DAMPED_JACOBI"): amgcl_smoother = AMGCLSmoother.DAMPED_JACOBI elif (smoother_type == "SPAI0"): amgcl_smoother = AMGCLSmoother.SPAI0 elif (smoother_type == "GAUSS_SEIDEL"): amgcl_smoother = AMGCLSmoother.GAUSS_SEIDEL else: print( "ERROR: smoother_type shall be one of \"ILU0\", \"DAMPED_JACOBI\", \"SPAI0\", got \"{0}\".\n\"ILU0\" will be used." .format(smoother_type)) amgcl_smoother = AMGCLSmoother.ILU0 else: print( "WARNING: smoother_type not prescribed for AMGCL solver, setting it to ILU0" ) amgcl_smoother = AMGCLSmoother.ILU0 if hasattr(configuration, 'krylov_type'): krylov_type = configuration.krylov_type if (krylov_type == "GMRES"): amgcl_krylov_type = AMGCLIterativeSolverType.GMRES if (krylov_type == "LGMRES"): amgcl_krylov_type = AMGCLIterativeSolverType.LGMRES elif (krylov_type == "BICGSTAB"): amgcl_krylov_type = AMGCLIterativeSolverType.BICGSTAB elif (krylov_type == "CG"): amgcl_krylov_type = AMGCLIterativeSolverType.CG elif (krylov_type == "BICGSTAB2"): amgcl_krylov_type = AMGCLIterativeSolverType.BICGSTAB2 elif (krylov_type == "BICGSTAB_WITH_GMRES_FALLBACK"): amgcl_krylov_type = AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK else: print( "ERROR: krylov_type shall be one of \"GMRES\", \"LGMRES\",\"BICGSTAB\", \"CG\", \"BICGSTAB2\", \"BICGSTAB_WITH_GMRES_FALLBACK\", got \"{0}\".\n\"GMRES\" will be used" .format(krylov_type)) amgcl_krylov_type = AMGCLIterativeSolverType.GMRES else: print( "WARNING: krylov_type not prescribed for AMGCL solver, setting it to GMRES" ) amgcl_krylov_type = AMGCLIterativeSolverType.GMRES if hasattr(configuration, 'coarsening_type'): coarsening_type = configuration.coarsening_type if (coarsening_type == "RUGE_STUBEN"): amgcl_coarsening_type = AMGCLCoarseningType.RUGE_STUBEN elif (coarsening_type == "AGGREGATION"): amgcl_coarsening_type = AMGCLCoarseningType.AGGREGATION elif (coarsening_type == "SA"): amgcl_coarsening_type = AMGCLCoarseningType.SA elif (coarsening_type == "SA_EMIN"): amgcl_coarsening_type = AMGCLCoarseningType.SA_EMIN else: print( "ERROR: coarsening_type shall be one of \"RUGE_STUBEN\", \"AGGREGATION\", \"SA\", \"SA_EMIN\", got \"{0}\".\n\"AGGREGATION\" will be used" .format(krylov_type)) amgcl_coarsening_type = AMGCLCoarseningType.AGGREGATION else: amgcl_coarsening_type = AMGCLCoarseningType.AGGREGATION if hasattr(configuration, 'gmres_krylov_space_dimension'): m = configuration.gmres_krylov_space_dimension else: m = max_it if hasattr(configuration, 'provide_coordinates'): provide_coordinates = configuration.provide_coordinates else: provide_coordinates = False linear_solver = AMGCLSolver(amgcl_smoother, amgcl_krylov_type, amgcl_coarsening_type, tol, max_it, verbosity, m, provide_coordinates) else: ##construction by parameters linear_solver = AMGCLSolver(params) elif (solver_type == "AMGCL_NS_Solver"): if (params == 0): #old style construction params = Parameters(""" { "solver_type" : "AMGCL_NS_Solver", "krylov_type" : "gmres", "velocity_block_preconditioner" : { "krylov_type" : "gmres", "tolerance" : 1e-3, "preconditioner_type" : "ilu0" }, "pressure_block_preconditioner" : { "krylov_type" : "bicgstab", "tolerance" : 1e-2, "preconditioner_type" : "spai0" }, "tolerance" : 1e-6, "gmres_krylov_space_dimension": 50, "coarsening_type": "aggregation", "max_iteration": 50, "verbosity" : 1, "scaling": , "coarse_enough" : 5000 } """) scaling = params["scaling"].GetBool() linear_solver = AMGCL_NS_Solver(params) # elif (solver_type == "Parallel MKL Pardiso" or solver_type == "Parallel_MKL_Pardiso"): import MKLSolversApplication linear_solver = MKLSolversApplication.ParallelMKLPardisoSolver() else: print( "*****************************************************************" ) print("Inexisting solver type. Possibilities are:") print("Conjugate gradient") print("BiConjugate gradient stabilized") print("GMRES") print("Deflated Conjugate gradient") print("AMGCL") print("GMRES-UP Block") print("Skyline LU factorization") print("Super LU (requires ExternalSolversApplication)") print("SuperLUIterativeSolver (requires ExternalSolversApplication)") print( "PastixDirect (requires ExternalSolversApplication + shall be habilitated at compilation time)" ) print( "PastixIterative (requires ExternalSolversApplication + shall be habilitated at compilation time)" ) print("Parallel MKL Pardiso (requires MKLSolversApplication)") print( "*****************************************************************" ) raise RuntimeError(" Wrong Solver Definition ") # else: # except LogicError: if (scaling == False): return linear_solver else: return ScalingSolver(linear_solver, True)
# model_part.GetNode(2).Fix(DISPLACEMENT_X) # model_part.GetNode(2).Fix(DISPLACEMENT_X) model_part.GetNode(2).Fix(DISPLACEMENT_Y) model_part.GetNode(2).Fix(DISPLACEMENT_Z) model_part.GetNode(3).Fix(DISPLACEMENT_Y) model_part.GetNode(4).Fix(DISPLACEMENT_Y) # Löser konfigurieren model_part.SetBufferSize(1) # Verfahren time_scheme = ResidualBasedIncrementalUpdateStaticScheme() linear_solver = new_linear_solver_factory.ConstructSolver( Parameters(r'{"solver_type": "eigen_sparse_lu"}')) # r'{"solver_type": "SkylineLUFactorizationSolver"}')) # Abbruchkriterium relative_tolerance = 1e-7 absolute_tolerance = 1e-7 conv_criteria = ResidualCriteria(relative_tolerance, absolute_tolerance) conv_criteria.SetEchoLevel(1) # Löser maximum_iterations = 200 compute_reactions = True reform_dofs_at_each_iteration = True move_mesh_flag = True solver = ResidualBasedNewtonRaphsonStrategy(