void CIntegration::Adjoint_Setup(CGeometry ***geometry, CSolver ****solver_container, CConfig **config, unsigned short RunTime_EqSystem, unsigned long Iteration, unsigned short iZone) { unsigned short iMGLevel; if ( ( ((RunTime_EqSystem == RUNTIME_ADJFLOW_SYS) || (RunTime_EqSystem == RUNTIME_LINFLOW_SYS)) && (Iteration == 0) ) ){ for (iMGLevel = 0; iMGLevel <= config[iZone]->GetMGLevels(); iMGLevel++) { /*--- Set the time step in all the MG levels ---*/ solver_container[iZone][iMGLevel][FLOW_SOL]->SetTime_Step(geometry[iZone][iMGLevel], solver_container[iZone][iMGLevel], config[iZone], iMGLevel, Iteration); /*--- Set the force coefficients ---*/ solver_container[iZone][iMGLevel][FLOW_SOL]->SetTotal_CDrag(solver_container[iZone][MESH_0][FLOW_SOL]->GetTotal_CDrag()); solver_container[iZone][iMGLevel][FLOW_SOL]->SetTotal_CLift(solver_container[iZone][MESH_0][FLOW_SOL]->GetTotal_CLift()); solver_container[iZone][iMGLevel][FLOW_SOL]->SetTotal_CT(solver_container[iZone][MESH_0][FLOW_SOL]->GetTotal_CT()); solver_container[iZone][iMGLevel][FLOW_SOL]->SetTotal_CQ(solver_container[iZone][MESH_0][FLOW_SOL]->GetTotal_CQ()); /*--- Restrict solution and gradients to the coarse levels ---*/ if (iMGLevel != config[iZone]->GetMGLevels()) { SetRestricted_Solution(RUNTIME_FLOW_SYS, solver_container[iZone][iMGLevel], solver_container[iZone][iMGLevel+1], geometry[iZone][iMGLevel], geometry[iZone][iMGLevel+1], config[iZone]); SetRestricted_Gradient(RUNTIME_FLOW_SYS, solver_container[iZone][iMGLevel], solver_container[iZone][iMGLevel+1], geometry[iZone][iMGLevel], geometry[iZone][iMGLevel+1], config[iZone]); } } } else if ((RunTime_EqSystem == RUNTIME_ADJTNE2_SYS) && (Iteration == 0)) { for (iMGLevel = 0; iMGLevel <= config[iZone]->GetMGLevels(); iMGLevel++) { /*--- Set the time step in all the MG levels ---*/ solver_container[iZone][iMGLevel][TNE2_SOL]->SetTime_Step(geometry[iZone][iMGLevel], solver_container[iZone][iMGLevel], config[iZone], iMGLevel, Iteration); /*--- Set the force coefficients ---*/ solver_container[iZone][iMGLevel][TNE2_SOL]->SetTotal_CDrag(solver_container[iZone][MESH_0][TNE2_SOL]->GetTotal_CDrag()); solver_container[iZone][iMGLevel][TNE2_SOL]->SetTotal_CLift(solver_container[iZone][MESH_0][TNE2_SOL]->GetTotal_CLift()); solver_container[iZone][iMGLevel][TNE2_SOL]->SetTotal_CT(solver_container[iZone][MESH_0][TNE2_SOL]->GetTotal_CT()); solver_container[iZone][iMGLevel][TNE2_SOL]->SetTotal_CQ(solver_container[iZone][MESH_0][TNE2_SOL]->GetTotal_CQ()); /*--- Restrict solution and gradients to the coarse levels ---*/ if (iMGLevel != config[iZone]->GetMGLevels()) { SetRestricted_Solution(RUNTIME_TNE2_SYS, solver_container[iZone][iMGLevel], solver_container[iZone][iMGLevel+1], geometry[iZone][iMGLevel], geometry[iZone][iMGLevel+1], config[iZone]); SetRestricted_Gradient(RUNTIME_TNE2_SYS, solver_container[iZone][iMGLevel], solver_container[iZone][iMGLevel+1], geometry[iZone][iMGLevel], geometry[iZone][iMGLevel+1], config[iZone]); } } } }
void CSingleGridIntegration::SingleGrid_Iteration(CGeometry ***geometry, CSolver ****solver_container, CNumerics *****numerics_container, CConfig **config, unsigned short RunTime_EqSystem, unsigned long Iteration, unsigned short iZone) { unsigned short iMesh; double monitor = 0.0; unsigned short SolContainer_Position = config[iZone]->GetContainerPosition(RunTime_EqSystem); /*--- Preprocessing ---*/ solver_container[iZone][MESH_0][SolContainer_Position]->Preprocessing(geometry[iZone][MESH_0], solver_container[iZone][MESH_0], config[iZone], MESH_0, 0, RunTime_EqSystem, false); /*--- Set the old solution ---*/ solver_container[iZone][MESH_0][SolContainer_Position]->Set_OldSolution(geometry[iZone][MESH_0]); /*--- Time step evaluation ---*/ solver_container[iZone][MESH_0][SolContainer_Position]->SetTime_Step(geometry[iZone][MESH_0], solver_container[iZone][MESH_0], config[iZone], MESH_0, 0); /*--- Space integration ---*/ Space_Integration(geometry[iZone][MESH_0], solver_container[iZone][MESH_0], numerics_container[iZone][MESH_0][SolContainer_Position], config[iZone], MESH_0, NO_RK_ITER, RunTime_EqSystem); /*--- Time integration ---*/ Time_Integration(geometry[iZone][MESH_0], solver_container[iZone][MESH_0], config[iZone], NO_RK_ITER, RunTime_EqSystem, Iteration); /*--- Postprocessing ---*/ solver_container[iZone][MESH_0][SolContainer_Position]->Postprocessing(geometry[iZone][MESH_0], solver_container[iZone][MESH_0], config[iZone], MESH_0); /*--- Compute adimensional parameters and the convergence monitor ---*/ switch (RunTime_EqSystem) { case RUNTIME_WAVE_SYS: monitor = log10(solver_container[iZone][MESH_0][WAVE_SOL]->GetRes_RMS(0)); break; case RUNTIME_FEA_SYS: monitor = log10(solver_container[iZone][MESH_0][FEA_SOL]->GetRes_RMS(0)); break; case RUNTIME_HEAT_SYS: monitor = log10(solver_container[iZone][MESH_0][HEAT_SOL]->GetRes_RMS(0)); break; case RUNTIME_POISSON_SYS: monitor = log10(solver_container[iZone][MESH_0][POISSON_SOL]->GetRes_RMS(0)); break; } /*--- Convergence strategy ---*/ Convergence_Monitoring(geometry[iZone][MESH_0], config[iZone], Iteration, monitor); /*--- Copy the solution to the coarse levels, and run the post-processing ---*/ for (iMesh = 0; iMesh < config[iZone]->GetMGLevels(); iMesh++) { SetRestricted_Solution(RunTime_EqSystem, solver_container[iZone][iMesh], solver_container[iZone][iMesh+1], geometry[iZone][iMesh], geometry[iZone][iMesh+1], config[iZone]); solver_container[iZone][iMesh+1][SolContainer_Position]->Postprocessing(geometry[iZone][iMesh+1], solver_container[iZone][iMesh+1], config[iZone], iMesh+1); } }
void CMultiGridIntegration::MultiGrid_Cycle(CGeometry ***geometry, CSolver ****solver_container, CNumerics *****numerics_container, CConfig **config, unsigned short iMesh, unsigned short mu, unsigned short RunTime_EqSystem, unsigned long Iteration, unsigned short iZone) { unsigned short iPreSmooth, iPostSmooth, iRKStep, iRKLimit = 1; bool startup_multigrid = (config[iZone]->GetRestart_Flow() && (RunTime_EqSystem == RUNTIME_FLOW_SYS) && (Iteration == 0)); unsigned short SolContainer_Position = config[iZone]->GetContainerPosition(RunTime_EqSystem); /*--- Do a presmoothing on the grid iMesh to be restricted to the grid iMesh+1 ---*/ for (iPreSmooth = 0; iPreSmooth < config[iZone]->GetMG_PreSmooth(iMesh); iPreSmooth++) { switch (config[iZone]->GetKind_TimeIntScheme()) { case RUNGE_KUTTA_EXPLICIT: iRKLimit = config[iZone]->GetnRKStep(); break; case EULER_EXPLICIT: case EULER_IMPLICIT: iRKLimit = 1; break; } /*--- Time and space integration ---*/ for (iRKStep = 0; iRKStep < iRKLimit; iRKStep++) { /*--- Send-Receive boundary conditions, and preprocessing ---*/ solver_container[iZone][iMesh][SolContainer_Position]->Preprocessing(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh, iRKStep, RunTime_EqSystem, false); if (iRKStep == 0) { /*--- Set the old solution ---*/ solver_container[iZone][iMesh][SolContainer_Position]->Set_OldSolution(geometry[iZone][iMesh]); /*--- Compute time step, max eigenvalue, and integration scheme (steady and unsteady problems) ---*/ solver_container[iZone][iMesh][SolContainer_Position]->SetTime_Step(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh, Iteration); /*--- Restrict the solution and gradient for the adjoint problem ---*/ Adjoint_Setup(geometry, solver_container, config, RunTime_EqSystem, Iteration, iZone); } /*--- Space integration ---*/ Space_Integration(geometry[iZone][iMesh], solver_container[iZone][iMesh], numerics_container[iZone][iMesh][SolContainer_Position], config[iZone], iMesh, iRKStep, RunTime_EqSystem); /*--- Time integration, update solution using the old solution plus the solution increment ---*/ Time_Integration(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iRKStep, RunTime_EqSystem, Iteration); /*--- Send-Receive boundary conditions, and postprocessing ---*/ solver_container[iZone][iMesh][SolContainer_Position]->Postprocessing(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh); } } /*--- Compute Forcing Term $P_(k+1) = I^(k+1)_k(P_k+F_k(u_k))-F_(k+1)(I^(k+1)_k u_k)$ and update solution for multigrid ---*/ if ( (iMesh < config[iZone]->GetMGLevels() && ((Iteration >= config[iZone]->GetnStartUpIter()) || startup_multigrid)) ) { /*--- Compute $r_k = P_k + F_k(u_k)$ ---*/ solver_container[iZone][iMesh][SolContainer_Position]->Preprocessing(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh, NO_RK_ITER, RunTime_EqSystem, false); Space_Integration(geometry[iZone][iMesh], solver_container[iZone][iMesh], numerics_container[iZone][iMesh][SolContainer_Position], config[iZone], iMesh, NO_RK_ITER, RunTime_EqSystem); SetResidual_Term(geometry[iZone][iMesh], solver_container[iZone][iMesh][SolContainer_Position]); /*--- Compute $r_(k+1) = F_(k+1)(I^(k+1)_k u_k)$ ---*/ SetRestricted_Solution(RunTime_EqSystem, solver_container[iZone][iMesh][SolContainer_Position], solver_container[iZone][iMesh+1][SolContainer_Position], geometry[iZone][iMesh], geometry[iZone][iMesh+1], config[iZone]); solver_container[iZone][iMesh+1][SolContainer_Position]->Preprocessing(geometry[iZone][iMesh+1], solver_container[iZone][iMesh+1], config[iZone], iMesh+1, NO_RK_ITER, RunTime_EqSystem, false); Space_Integration(geometry[iZone][iMesh+1], solver_container[iZone][iMesh+1], numerics_container[iZone][iMesh+1][SolContainer_Position], config[iZone], iMesh+1, NO_RK_ITER, RunTime_EqSystem); /*--- Compute $P_(k+1) = I^(k+1)_k(r_k) - r_(k+1) ---*/ SetForcing_Term(solver_container[iZone][iMesh][SolContainer_Position], solver_container[iZone][iMesh+1][SolContainer_Position], geometry[iZone][iMesh], geometry[iZone][iMesh+1], config[iZone]); /*--- Recursive call to MultiGrid_Cycle ---*/ for (unsigned short imu = 0; imu <= mu; imu++) { if (iMesh == config[iZone]->GetMGLevels()-2) MultiGrid_Cycle(geometry, solver_container, numerics_container, config, iMesh+1, 0, RunTime_EqSystem, Iteration, iZone); else MultiGrid_Cycle(geometry, solver_container, numerics_container, config, iMesh+1, mu, RunTime_EqSystem, Iteration, iZone); } /*--- Compute prolongated solution, and smooth the correction $u^(new)_k = u_k + Smooth(I^k_(k+1)(u_(k+1)-I^(k+1)_k u_k))$ ---*/ GetProlongated_Correction(RunTime_EqSystem, solver_container[iZone][iMesh][SolContainer_Position], solver_container[iZone][iMesh+1][SolContainer_Position], geometry[iZone][iMesh],geometry[iZone][iMesh+1], config[iZone]); SmoothProlongated_Correction(RunTime_EqSystem, solver_container[iZone][iMesh][SolContainer_Position], geometry[iZone][iMesh], config[iZone]->GetMG_CorrecSmooth(iMesh), 1.25, config[iZone]); SetProlongated_Correction(solver_container[iZone][iMesh][SolContainer_Position], geometry[iZone][iMesh], config[iZone]); /*--- Solution postsmoothing in the prolongated grid ---*/ for (iPostSmooth = 0; iPostSmooth < config[iZone]->GetMG_PostSmooth(iMesh); iPostSmooth++) { switch (config[iZone]->GetKind_TimeIntScheme()) { case RUNGE_KUTTA_EXPLICIT: iRKLimit = config[iZone]->GetnRKStep(); break; case EULER_EXPLICIT: case EULER_IMPLICIT: iRKLimit = 1; break; } for (iRKStep = 0; iRKStep < iRKLimit; iRKStep++) { solver_container[iZone][iMesh][SolContainer_Position]->Preprocessing(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh, iRKStep, RunTime_EqSystem, false); if (iRKStep == 0) { solver_container[iZone][iMesh][SolContainer_Position]->Set_OldSolution(geometry[iZone][iMesh]); solver_container[iZone][iMesh][SolContainer_Position]->SetTime_Step(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh, Iteration); } Space_Integration(geometry[iZone][iMesh], solver_container[iZone][iMesh], numerics_container[iZone][iMesh][SolContainer_Position], config[iZone], iMesh, iRKStep, RunTime_EqSystem); Time_Integration(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iRKStep, RunTime_EqSystem, Iteration); solver_container[iZone][iMesh][SolContainer_Position]->Postprocessing(geometry[iZone][iMesh], solver_container[iZone][iMesh], config[iZone], iMesh); } } } }
void CMultiGridIntegration::MultiGrid_Iteration(CGeometry ***geometry, CSolver ****solver_container, CNumerics *****numerics_container, CConfig **config, unsigned short RunTime_EqSystem, unsigned long Iteration, unsigned short iZone) { unsigned short FinestMesh, iMGLevel; double monitor = 1.0; const bool restart = (config[iZone]->GetRestart() || config[iZone]->GetRestart_Flow()); const bool startup_multigrid = ((config[iZone]->GetRestart_Flow()) && (RunTime_EqSystem == RUNTIME_FLOW_SYS) && (Iteration == 0)); const bool direct = ((config[iZone]->GetKind_Solver() == EULER) || (config[iZone]->GetKind_Solver() == NAVIER_STOKES) || (config[iZone]->GetKind_Solver() == RANS) || (config[iZone]->GetKind_Solver() == TNE2_EULER) || (config[iZone]->GetKind_Solver() == TNE2_NAVIER_STOKES) || (config[iZone]->GetKind_Solver() == FLUID_STRUCTURE_EULER) || (config[iZone]->GetKind_Solver() == FLUID_STRUCTURE_NAVIER_STOKES) || (config[iZone]->GetKind_Solver() == FLUID_STRUCTURE_RANS)); const unsigned short SolContainer_Position = config[iZone]->GetContainerPosition(RunTime_EqSystem); /*--- If low fidelity simulation ---*/ if (config[iZone]->GetLowFidelitySim()) config[iZone]->SetFinestMesh(MESH_1); /*--- If restart, update multigrid levels at the first multigrid iteration ---*/ if ((restart && (Iteration == config[iZone]->GetnStartUpIter())) || startup_multigrid) { for (iMGLevel = 0; iMGLevel < config[iZone]->GetMGLevels(); iMGLevel++) { SetRestricted_Solution(RunTime_EqSystem, solver_container[iZone][iMGLevel][SolContainer_Position], solver_container[iZone][iMGLevel+1][SolContainer_Position], geometry[iZone][iMGLevel], geometry[iZone][iMGLevel+1], config[iZone]); } } /*--- Full multigrid strategy and start up with fine grid only works with the direct problem ---*/ if (!config[iZone]->GetRestart() && config[iZone]->GetFullMG() && direct && ( GetConvergence_FullMG() && (config[iZone]->GetFinestMesh() != MESH_0 ))) { SetProlongated_Solution(RunTime_EqSystem, solver_container[iZone][config[iZone]->GetFinestMesh()-1][SolContainer_Position], solver_container[iZone][config[iZone]->GetFinestMesh()][SolContainer_Position], geometry[iZone][config[iZone]->GetFinestMesh()-1], geometry[iZone][config[iZone]->GetFinestMesh()], config[iZone]); config[iZone]->SubtractFinestMesh(); } /*--- Set the current finest grid (full multigrid strategy) ---*/ FinestMesh = config[iZone]->GetFinestMesh(); /*--- Perform the Full Approximation Scheme multigrid ---*/ MultiGrid_Cycle(geometry, solver_container, numerics_container, config, FinestMesh, config[iZone]->GetMGCycle(), RunTime_EqSystem, Iteration, iZone); /*--- Computes primitive variables and gradients in the finest mesh (useful for the next solver (turbulence) and output ---*/ solver_container[iZone][MESH_0][SolContainer_Position]->Preprocessing(geometry[iZone][MESH_0], solver_container[iZone][MESH_0], config[iZone], MESH_0, NO_RK_ITER, RunTime_EqSystem, true); /*--- Compute non-dimensional parameters and the convergence monitor ---*/ NonDimensional_Parameters(geometry[iZone], solver_container[iZone], numerics_container[iZone], config[iZone], FinestMesh, RunTime_EqSystem, Iteration, &monitor); /*--- Convergence strategy ---*/ Convergence_Monitoring(geometry[iZone][FinestMesh], config[iZone], Iteration, monitor); }