17 DALinearEqn::DALinearEqn(
81 word jacMatReOrdering =
91 label useNonZeroInitGuess =
98 PC MLRMasterPC, MLRGlobalPC;
104 PetscInt MLRnlocal, MLRfirst;
111 KSPSetOperators(ksp, jacMat, jacPCMat);
137 KSPSetFromOptions(ksp);
141 KSPType kspObjectType = KSPGMRES;
143 KSPSetType(ksp, kspObjectType);
145 PetscInt restartGMRES = gmresRestart;
148 if (useNonZeroInitGuess)
150 KSPSetInitialGuessNonzero(ksp, PETSC_TRUE);
154 KSPSetInitialGuessNonzero(ksp, PETSC_FALSE);
157 KSPGMRESSetRestart(ksp, restartGMRES);
159 KSPGMRESSetCGSRefinementType(ksp, KSP_GMRES_CGS_REFINE_IFNEEDED);
165 KSPGMRESSetOrthogonalization(ksp, KSPGMRESModifiedGramSchmidtOrthogonalization);
169 KSPSetPCSide(ksp, PC_RIGHT);
172 PetscInt globalPreConIts = globalPCIters;
177 if (globalPreConIts > 1)
180 KSPGetPC(ksp, &MLRMasterPC);
184 PCSetType(MLRMasterPC, PCKSP);
187 PCKSPGetKSP(MLRMasterPC, &MLRMasterPCKSP);
191 KSPSetType(MLRMasterPCKSP, KSPRICHARDSON);
194 KSPSetNormType(MLRMasterPCKSP, KSP_NORM_NONE);
198 KSPSetTolerances(MLRMasterPCKSP, PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT, globalPreConIts);
202 KSPGetPC(MLRMasterPCKSP, &MLRGlobalPC);
207 KSPGetPC(ksp, &MLRGlobalPC);
211 PCSetType(MLRGlobalPC, PCASM);
214 MLRoverlap = asmOverlap;
215 PCASMSetOverlap(MLRGlobalPC, MLRoverlap);
227 PCASMGetSubKSP(MLRGlobalPC, &MLRnlocal, &MLRfirst, &MLRsubksp);
231 PetscInt localPreConIts = localPCIters;
232 word matOrdering = jacMatReOrdering;
233 PetscInt localFillLevel = pcFillLevel;
234 for (PetscInt i = 0; i < MLRnlocal; i++)
239 if (localPreConIts > 1)
243 KSPSetType(MLRsubksp[i], KSPRICHARDSON);
246 KSPSetTolerances(MLRsubksp[i], PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT, localPreConIts);
249 KSPSetNormType(MLRsubksp[i], KSP_NORM_NONE);
253 KSPSetType(MLRsubksp[i], KSPPREONLY);
257 KSPGetPC(MLRsubksp[i], &MLRsubpc);
260 PCType localPCType = PCILU;
261 PCSetType(MLRsubpc, localPCType);
264 PCFactorSetPivotInBlocks(MLRsubpc, PETSC_TRUE);
265 PCFactorSetShiftType(MLRsubpc, MAT_SHIFT_NONZERO);
266 PCFactorSetShiftAmount(MLRsubpc, PETSC_DECIDE);
274 MatOrderingType localMatrixOrdering;
275 if (matOrdering ==
"natural")
277 localMatrixOrdering = MATORDERINGNATURAL;
279 else if (matOrdering ==
"nd")
281 localMatrixOrdering = MATORDERINGND;
283 else if (matOrdering ==
"rcm")
285 localMatrixOrdering = MATORDERINGRCM;
287 else if (matOrdering ==
"1wd")
289 localMatrixOrdering = MATORDERING1WD;
291 else if (matOrdering ==
"qmd")
293 localMatrixOrdering = MATORDERINGQMD;
297 Info <<
"matOrdering not known. Using default: nested dissection" << endl;
298 localMatrixOrdering = MATORDERINGND;
300 PCFactorSetMatOrderingType(MLRsubpc, localMatrixOrdering);
303 PCFactorSetLevels(MLRsubpc, localFillLevel);
307 KSPSetNormType(ksp, KSP_NORM_UNPRECONDITIONED);
314 PetscInt maxIts = gmresMaxIters;
315 PetscScalar rtol, atol;
318 KSPSetTolerances(ksp, rtol, atol, PETSC_DEFAULT, maxIts);
322 Info <<
"Solver Type: " << kspObjectType << endl;
323 Info <<
"GMRES Restart: " << restartGMRES << endl;
324 Info <<
"ASM Overlap: " << MLRoverlap << endl;
325 Info <<
"Global PC Iters: " << globalPreConIts << endl;
326 Info <<
"Local PC Iters: " << localPreConIts << endl;
327 Info <<
"Mat ReOrdering: " << matOrdering << endl;
328 Info <<
"ILU PC Fill Level: " << localFillLevel << endl;
329 Info <<
"GMRES Max Iterations: " << maxIts << endl;
330 Info <<
"GMRES Relative Tolerance: " << rtol << endl;
331 Info <<
"GMRES Absolute Tolerance: " << atol << endl;
355 Info <<
"Solving Linear Equation... " << this->
getRunTime() <<
" s" << endl;
363 PetscScalar rGMRESHist[gmresMaxIters + 1];
364 label nGMRESIters = gmresMaxIters + 1;
365 KSPSetResidualHistory(ksp, rGMRESHist, nGMRESIters, PETSC_TRUE);
368 KSPSolve(ksp, rhsVec, solVec);
372 KSPGetIterationNumber(ksp, &its);
373 PetscScalar initResNorm = rGMRESHist[0];
374 PetscScalar finalResNorm = rGMRESHist[its];
377 "Main iteration %D KSP Residual norm %14.12e %d s \n",
381 PetscPrintf(PETSC_COMM_WORLD,
"Total iterations %D\n", its);
383 VecAssemblyBegin(solVec);
384 VecAssemblyEnd(solVec);
386 Info <<
"Solving Linear Equation... Completed! "
394 if (relResRatio > resDiff && absResRatio > resDiff)
396 Info <<
"Residual tolerance not satisfied, solution failed!" << endl;
401 Info <<
"Residual tolerance satisfied, solution finished!" << endl;
429 if (n % printFrequency == 0)
433 "Main iteration %D KSP Residual norm %14.12e %d s\n",
447 return mesh_.time().elapsedClockTime();