def activate_spalart_allmaras(self): # Spalart-Allmaras initialization for node in self.wall_nodes: node.SetValue(IS_VISITED, 1.0) node.SetSolutionStepValue(DISTANCE, 0, 0.0) if (self.domain_size == 2): self.redistance_utils = ParallelDistanceCalculator2D() else: self.redistance_utils = ParallelDistanceCalculator3D() max_levels = 100 max_distance = 1000 self.redistance_utils.CalculateDistancesLagrangianSurface( self.model_part, DISTANCE, NODAL_AREA, max_levels, max_distance) # Spalart-Allmaras uses the componentwise builder and solver, which # requires a neighbour search number_of_avg_elems = 10 number_of_avg_nodes = 10 self.neighbour_search = FindNodalNeighboursProcess( self.model_part, number_of_avg_elems, number_of_avg_nodes) self.neighbour_search.Execute() non_linear_tol = 0.001 max_it = 50 #10 reform_dofset = self.ReformDofSetAtEachStep time_order = 2 if self.spalart_allmaras_linear_solver is None: #pPrecond = DiagonalPreconditioner() #self.spalart_allmaras_linear_solver = BICGSTABSolver( #1e-9, 300, pPrecond) import KratosMultiphysics.ExternalSolversApplication as kes smoother_type = kes.AMGCLSmoother.ILU0 solver_type = kes.AMGCLIterativeSolverType.GMRES gmres_size = 200 max_iter = 200 tol = 1e-9 verbosity = 1 linear_solver = kes.AMGCLSolver(smoother_type, solver_type, tol, max_iter, verbosity, gmres_size) #self.spalart_allmaras_linear_solver = ScalingSolver(linear_solver, True) #self.spalart_allmaras_linear_solver = kes.SuperLUSolver() self.spalart_allmaras_linear_solver = kes.PastixSolver(0, False) self.turbulence_model = SpalartAllmarasTurbulenceModel( self.model_part, self.spalart_allmaras_linear_solver, self.domain_size, non_linear_tol, max_it, reform_dofset, time_order) if self.use_des: self.turbulence_model.ActivateDES(self.Cdes)
def Solve(self): if self.divergence_clearance_steps > 0: print("Calculating divergence-free initial condition") # initialize with a Stokes solution step try: import KratosMultiphysics.ExternalSolversApplication as kes smoother_type = kes.AMGCLSmoother.DAMPED_JACOBI solver_type = kes.AMGCLIterativeSolverType.CG gmres_size = 50 max_iter = 200 tol = 1e-7 verbosity = 0 stokes_linear_solver = kes.AMGCLSolver( smoother_type, solver_type, tol, max_iter, verbosity, gmres_size) except: pPrecond = DiagonalPreconditioner() stokes_linear_solver = BICGSTABSolver(1e-9, 5000, pPrecond) stokes_process = StokesInitializationProcess( self.model_part, stokes_linear_solver, self.domain_size, PATCH_INDEX) # copy periodic conditions to Stokes problem stokes_process.SetConditions(self.model_part.Conditions) # execute Stokes process stokes_process.Execute() stokes_process = None for node in self.model_part.Nodes: node.SetSolutionStepValue(PRESSURE, 0, 0.0) node.SetSolutionStepValue(ACCELERATION_X, 0, 0.0) node.SetSolutionStepValue(ACCELERATION_Y, 0, 0.0) node.SetSolutionStepValue(ACCELERATION_Z, 0, 0.0) # vel = node.GetSolutionStepValue(VELOCITY) # for i in range(0,2): # node.SetSolutionStepValue(VELOCITY,i,vel) self.divergence_clearance_steps = 0 print("Finished divergence clearance") if self.ReformDofSetAtEachStep: if self.use_slip_conditions: self.normal_util.CalculateOnSimplex( self.model_part, self.domain_size, IS_STRUCTURE) if self.use_spalart_allmaras: self.neighbour_search.Execute() (self.solver).Solve()
def DivergenceClearance(self): if self.settings["divergence_clearance_steps"].GetInt() > 0: print("Calculating divergence-free initial condition") ## Initialize with a Stokes solution step try: import KratosMultiphysics.ExternalSolversApplication as KratosExternalSolvers smoother_type = KratosExternalSolvers.AMGCLSmoother.DAMPED_JACOBI solver_type = KratosExternalSolvers.AMGCLIterativeSolverType.CG gmres_size = 50 max_iter = 200 tol = 1e-7 verbosity = 0 stokes_linear_solver = KratosExternalSolvers.AMGCLSolver( smoother_type, solver_type, tol, max_iter, verbosity, gmres_size) except: pPrecond = DiagonalPreconditioner() stokes_linear_solver = BICGSTABSolver(1e-9, 5000, pPrecond) stokes_process = KratosCFD.StokesInitializationProcess( self.main_model_part, stokes_linear_solver, self.computing_model_part.ProcessInfo[ KratosMultiphysics.DOMAIN_SIZE], KratosCFD.PATCH_INDEX) ## Copy periodic conditions to Stokes problem stokes_process.SetConditions(self.main_model_part.Conditions) ## Execute Stokes process stokes_process.Execute() stokes_process = None for node in self.main_model_part.Nodes: node.SetSolutionStepValue(KratosMultiphysics.PRESSURE, 0, 0.0) node.SetSolutionStepValue(KratosMultiphysics.ACCELERATION_X, 0, 0.0) node.SetSolutionStepValue(KratosMultiphysics.ACCELERATION_Y, 0, 0.0) node.SetSolutionStepValue(KratosMultiphysics.ACCELERATION_Z, 0, 0.0) ## vel = node.GetSolutionStepValue(VELOCITY) ## for i in range(0,2): ## node.SetSolutionStepValue(VELOCITY,i,vel) self.settings["divergence_clearance_steps"].SetInt(0) print("Finished divergence clearance.")
def __init__(self, model_part, domain_size, fluid_linear_solver_settings, redistance_settings, ConvectionType): Timer.Start("DPG_Monolithic_constructor") if (ConvectionType == "Classic"): self.use_distance_convection_process = False else: self.use_distance_convection_process = True # DISTANCE CONVECTION SELECTION if (self.use_distance_convection_process == False): import levelset_solver levelset_solver.AddVariables(model_part, distance_settings) levelset_solver.AddDofs(model_part, distance_settings) else: pass #model_part.AddNodalSolutionStepVariable(DISTANCE) #self.compute_flow_length_object=ComputeFlowLength1(model_part) #def __init__(self, model_part, domain_size,linear_solver_iterations=300, linear_solver_tolerance=1e-5,dynamic_tau_levelset=0.01): self.fluid_linear_solver_settings = fluid_linear_solver_settings self.redistance_settings = redistance_settings self.redistance_type = redistance_settings.redistance_type self.model_part = model_part self.domain_size = domain_size self.alpha = -0.0 self.move_mesh_strategy = 0 # self.time_scheme = ResidualBasedPredictorCorrectorVelocityBossakSchemeDPGEnriched( # self.alpha, self.move_mesh_strategy, self.domain_size) self.time_scheme = ResidualBasedPredictorCorrectorBDFSchemeTurbulent( self.domain_size) self.time_scheme.Check(self.model_part) # self.time_scheme = ResidualBasedPredictorCorrectorVelocityBossakScheme( self.alpha,self.move_mesh_strategy ) # definition of the solvers # self.linear_solver = SkylineLUFactorizationSolver() # self.linear_solver =SuperLUSolver() # self.linear_solver = MKLPardisoSolver() # pPrecond = DiagonalPreconditioner() # pPrecond = ILU0Preconditioner() # self.linear_solver = BICGSTABSolver(1e-6, 5000,pPrecond) # gmres_size = 30 # ilu_level_of_fill = 2 # tol = 1e-5 # verbosity = 0 # self.linear_solver = PastixSolver(tol,gmres_size,ilu_level_of_fill,verbosity,False) # self.linear_solver = PastixSolver(verbosity,False) # new solvers self.gmres_size = fluid_linear_solver_settings.gmres_size self.iterations = fluid_linear_solver_settings.linear_solver_iterations #400 # Ojo, antes 200 self.tol = fluid_linear_solver_settings.linear_solver_tolerance #1e-5 #Before 1e-5 self.verbosity = fluid_linear_solver_settings.verbosity if (fluid_linear_solver_settings.linear_solver_type == "BICGSTAB2"): #self.linear_solver = ExternalSolver.ScalingSolver(AMGCLSolver( self.linear_solver = ScalingSolver( ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver.AMGCLIterativeSolverType. BICGSTAB2, #AMGCLIterativeSolverType.GMRES, #BICGSTAB_WITH_GMRES_FALLBACK, fluid_linear_solver_settings.linear_solver_tolerance, fluid_linear_solver_settings.linear_solver_iterations, fluid_linear_solver_settings.verbosity, fluid_linear_solver_settings.gmres_size), True) else: self.linear_solver = ScalingSolver( ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver.AMGCLIterativeSolverType. BICGSTAB_WITH_GMRES_FALLBACK, #AMGCLIterativeSolverType.GMRES, #BICGSTAB_WITH_GMRES_FALLBACK, fluid_linear_solver_settings.linear_solver_tolerance, fluid_linear_solver_settings.linear_solver_iterations, fluid_linear_solver_settings.verbosity, fluid_linear_solver_settings.gmres_size), True) # definition of the convergence criteria self.rel_vel_tol = 1e-5 self.abs_vel_tol = 1e-7 self.rel_pres_tol = 1e-5 self.abs_pres_tol = 1e-7 self.dynamic_tau_levelset = fluid_linear_solver_settings.dynamic_tau_levelset self.dynamic_tau_fluid = fluid_linear_solver_settings.dynamic_tau_fluid #0.01 self.oss_switch = 0 # non newtonian setting self.regularization_coef = 1000 self.max_iter = 30 # default settings self.echo_level = 0 self.CalculateReactionFlag = True self.ReformDofSetAtEachStep = True self.CalculateNormDxFlag = True self.MoveMeshFlag = False self.volume_correction = True self.vol_cr_step = 5 # Data for constructing the mass loss self.AcumulatedMassLossInWalls = 0.0 self.AcumulatedMassLossInWetWalls = 0.0 self.AcumulatedConvectedMass = 0.0 self.AcumulatedLossInRedistance = 0.0 # print "Construction monolithic solver finished" # Creat Lavel_set solver # construct the model part if (self.use_distance_convection_process == False): if (domain_size == 2): raise "error, still not implemented in 2D" conv_elem = "SUPGConv2D" conv_cond = "Condition2D" else: conv_elem = "SUPGConv3D" #"SUPGConvLevelSet"#"SUPGConv3D" conv_cond = "Condition3D" self.level_set_model_part = ModelPart("level_set_model_part") self.conv_generator = ConnectivityPreserveModeler() (self.conv_generator).GenerateModelPart(self.model_part, self.level_set_model_part, conv_elem, conv_cond) # constructing the convection solver for the distance self.level_set_solver = levelset_solver.Solver( self.level_set_model_part, domain_size, distance_settings) self.level_set_solver.max_iter = 8 else: #### The Distance Convection will be used max_cfl = 5.0 ## For using linear solver GMRES #AMGCLIterativeSolverType.GMRES, #BICGSTAB_WITH_GMRES_FALLBACK, #linear_solver = ScalingSolver(AMGCLSolver( AMGCLSmoother.ILU0, AMGCLIterativeSolverType.GMRES, 1e-9, 50, fluid_linear_solver_settings.verbosity, 50),True) self.convection_tolerance = 1e-9 self.convection_max_number_iterations = 100 self.convection_gmres_size = 25 linear_solver = ScalingSolver( ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver. AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK, self.convection_tolerance, self.convection_max_number_iterations, fluid_linear_solver_settings.verbosity, self.convection_gmres_size), True) self.levelset_convection_process = LevelSetConvectionProcess3D( DISTANCE, self.model_part, linear_solver, max_cfl) # # properties of the two fluids self.rho1 = 2400.0 # applied on the negative part of the domain 1000.0 self.conductivity1 = 1.0 self.rho2 = 1.0 # applied to the positive part of the domain#1.0 self.conductivity2 = 1.0 self.mu = 3.0e-3 self.divergence_clearance_performed = False ########################################## ##### Compute Max Edge Size ######## ########################################## if (self.domain_size == 2): self.max_edge_size = ParallelDistanceCalculator2D( ).FindMaximumEdgeSize(self.model_part) else: self.max_edge_size = ParallelDistanceCalculator3D( ).FindMaximumEdgeSize(self.model_part) self.average_edge_size = BiphasicFillingUtilities().ComputePartAvgh( self.model_part) # self.max_distance = self.max_edge_size * self.redistance_settings.max_distance_factor #Ojo antes 5.0 ########################################## ##### Initialize Counters ######## ########################################## self.internal_step_counter = 1 self.redistance_frequency = self.redistance_settings.redistance_frequency ########################################## ##### OLD REDISTANCE ######## ########################################## # Distance utilities if (self.redistance_type == "Old"): print("performing Old Redistance") if (self.domain_size == 2): self.distance_calculator = ParallelDistanceCalculator2D() else: self.distance_calculator = ParallelDistanceCalculator3D() self.max_edge_size = self.distance_calculator.FindMaximumEdgeSize( self.model_part) self.max_distance = self.max_edge_size * self.redistance_settings.max_distance_factor #Ojo antes 5.0 self.max_levels = self.redistance_settings.max_levels #Ojo antes 25 self.max_ns_iterations = self.redistance_settings.max_ns_iterations #Ojo antes 8 else: print("performing New Redistance") for cond in self.model_part.Conditions: for node in cond.GetNodes(): node.Set(BOUNDARY, True) distance_calculator_aux = ParallelDistanceCalculator3D() self.max_edge_size = distance_calculator_aux.FindMaximumEdgeSize( self.model_part) distance_linear_solver = linear_solver_factory.ConstructSolver( self.redistance_settings) self.distance_calculator = VariationalDistanceCalculationProcess3D( self.model_part, distance_linear_solver, self.redistance_settings.redistance_iterations) self.max_distance = self.max_edge_size * self.redistance_settings.max_distance_factor # Slip condition self.use_slip_conditions = False # volume correction self.volume_correction_switch = True self.negative_volume_correction = False self.volume_corrector_type = "Old" # element size self.maxmin = [] ParticleLevelSetUtils3D().FindMaxMinEdgeSize(self.model_part, self.maxmin) # Variables needed for computing the Efficiency of the Injection self.OldNetInletVolume = 0.0 self.OldWetVolume = 0.0 self.distance_utilities = DistanceUtilities() self.volume_corrector = CorrectVolume(self.model_part, self.average_edge_size, self.max_edge_size) Timer.Stop("DPG_Monolithic_constructor")
def Initialize(self): Timer.Start("DPG_Monolithic_initialize") # creating the solution strategy self.conv_criteria = VelPrCriteria(self.rel_vel_tol, self.abs_vel_tol, self.rel_pres_tol, self.abs_pres_tol) builder_and_solver = ResidualBasedBlockBuilderAndSolver( self.linear_solver) # self.solver = ResidualBasedNewtonRaphsonStrategy(self.model_part,self.time_scheme,self.linear_solver,self.conv_criteria,builder_and_solver,self.max_iter,self.CalculateReactionFlag, self.ReformDofSetAtEachStep,self.MoveMeshFlag) self.solver = ResidualBasedNewtonRaphsonStrategy( self.model_part, self.time_scheme, self.linear_solver, self.conv_criteria, builder_and_solver, self.max_iter, self.CalculateReactionFlag, self.ReformDofSetAtEachStep, self.MoveMeshFlag) (self.solver).SetEchoLevel(self.echo_level) self.model_part.ProcessInfo.SetValue(DYNAMIC_TAU, self.dynamic_tau_fluid) self.model_part.ProcessInfo.SetValue(OSS_SWITCH, self.oss_switch) #Calculate Distances self.DoRedistance() # LEvel_set solver initialization if (self.use_distance_convection_process == False): self.level_set_solver.dynamic_tau = self.dynamic_tau_levelset self.level_set_solver.linear_solver = ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver.AMGCLIterativeSolverType.GMRES, 1e-6, #self.tol, 200, self.verbosity, self.gmres_size) self.level_set_solver.Initialize() # End of Levelset SOlver Definition self.ApplyFluidProperties() self.next_redistance = self.redistance_frequency # # FOR SLIP # # Manullay assign! for cond in self.model_part.Conditions: cond.SetValue(IS_STRUCTURE, 1.0) # if we use slip conditions, calculate normals on the boundary if (self.use_slip_conditions): (FindConditionsNeighboursProcess(self.model_part, 3, 20)).ClearNeighbours() (FindConditionsNeighboursProcess(self.model_part, 3, 20)).Execute() self.normal_util = NormalCalculationUtils() ## If needed we swap normals - Mesher is Getting Normals Inside self.normal_util.CalculateOnSimplex( self.model_part, self.domain_size, IS_STRUCTURE, 0, 35.0) # ,0.0),180) #35.0) # ,0.0,35.0 #self.normal_util.CalculateOnSimplex(self.model_part,self.domain_size) # ,0.0),180) #35.0) # ,0.0,35.0 # saving inlet nodes self.inlet_nodes = [] # Memory profiler for cond in self.model_part.Conditions: if (cond.GetValue(IS_INLET) > 0): for node in cond.GetNodes(): self.inlet_nodes.append(node) #import velocity_convection_utility #self.velocity_prediction = velocity_convection_utility.VelocityConvectionUtility(self.model_part) Timer.Stop("DPG_Monolithic_initialize")
def __init__(self, model_part, domain_size, my_settings, SolverSettings): Timer.Start("ConvDiffPhaseChange_Constructor") self.model_part = model_part self.settings = my_settings self.domain_size = domain_size self.max_distance = 1e6 self.echo_level = 0 self.CalculateReactionFlag = False self.ReformDofSetAtEachStep = False self.CalculateNormDxFlag = True self.MoveMeshFlag = False #functions to skip one of the stages self.skip_stage0 = SolverSettings.SkipStage0 self.skip_stage1 = SolverSettings.SkipStage1 self.use_linesearch_in_step1 = SolverSettings.UseLineSearch ##utility to effective store a copy of the variables self.variable_utils = VariableUtils() self.activation_utils = ActivationUtilities() ##strategy to be used in step0 - pure convection step - a non-symmetric linear solver is required gmres_size = SolverSettings.LinearSolverGmresSize tol = SolverSettings.LinearSolverTolerance #BEFORE 1e-4 verbosity = SolverSettings.Verbosity niter = SolverSettings.LinearSolverIteration if (SolverSettings.NonSymmetricLinearSolver == "BICGSTAB_WITH_GMRES_FALLBACK"): self.non_symmetric_linear_solver = ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver. AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK, tol, niter, verbosity, gmres_size ) #AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK, tol, 200, verbosity, gmres_size)# else: self.non_symmetric_linear_solver = ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver.AMGCLIterativeSolverType.GMRES, tol, niter, verbosity, gmres_size ) #self.non_symmetric_linear_solver = AMGCLSolver(AMGCLSmoother.ILU0, AMGCLIterativeSolverType.GMRES, tol, 400, verbosity, gmres_size) #AMGCLIterativeSolverType.BICGSTAB_WITH_GMRES_FALLBACK, tol, 200, verbosity, gmres_size)# self.stage0_time_scheme = ResidualBasedIncrementalUpdateStaticScheme() self.stage0_conv_criteria = IncrementalDisplacementCriteria( SolverSettings.Stage0ConvCriteria1, SolverSettings.Stage0ConvCriteria2) self.stage0_max_iterations = SolverSettings.Stage0MaxIterations ##strategy to be used in step1 - diffusion + phase change - a symmetric linear solver is sufficient #tol = 1e-6 #verbosity = 0 self.symmetric_linear_solver = ExternalSolver.AMGCLSolver( ExternalSolver.AMGCLSmoother.ILU0, ExternalSolver.AMGCLIterativeSolverType.CG, tol, niter, verbosity, gmres_size) self.stage1_time_scheme = ResidualBasedIncrementalUpdateStaticVariablePropertyScheme( ) self.stage1_conv_criteria = IncrementalDisplacementCriteria( SolverSettings.Stage1ConvCriteria1, SolverSettings. Stage1ConvCriteria2) #IncrementalDisplacementCriteria(1e-4, 1e-6) self.stage1_max_iterations = SolverSettings.Stage1MaxIterations ##strategy to be used in step3 - diffusion + phase change - a symmetric linear solver is sufficient #self.stage2_time_scheme = ResidualBasedIncrementalUpdateStaticScheme() #self.stage2_conv_criteria = IncrementalDisplacementCriteria(1e-4,1e-6) #IncrementalDisplacementCriteria(1e-4, 1e-6) #self.stage2_max_iterations = 1 self.MaxLineSearchIterations = SolverSettings.MaxLineSearchIterations Timer.Stop("ConvDiffPhaseChange_Constructor")