113 (scratch1.
size() ? scratch1 : Apsi),
114 (scratch2.
size() ? scratch2 : finestCorrection),
123 finestResidual = source;
124 finestResidual -= Apsi;
150 void Foam::GAMGSolver::Vcycle
169 const label coarsestLevel = matrixLevels_.size() - 1;
172 agglomeration_.restrictField(coarseSources[0], finestResidual, 0,
true);
174 if (debug >= 2 && nPreSweeps_)
176 Pout<<
"Pre-smoothing scaling factors: ";
181 for (
label leveli = 0; leveli < coarsestLevel; leveli++)
183 if (coarseSources.
set(leveli + 1))
189 coarseCorrFields[leveli] = 0.0;
191 smoothers[leveli + 1].smooth
193 coarseCorrFields[leveli],
194 coarseSources[leveli],
198 nPreSweeps_ + preSweepsLevelMultiplier_*leveli,
206 coarseCorrFields[leveli].size()
211 if (scaleCorrection_ && leveli < coarsestLevel - 1)
215 coarseCorrFields[leveli],
220 matrixLevels_[leveli],
221 interfaceLevelsBouCoeffs_[leveli],
222 interfaceLevels_[leveli],
223 coarseSources[leveli],
229 matrixLevels_[leveli].Amul
235 coarseCorrFields[leveli],
236 interfaceLevelsBouCoeffs_[leveli],
237 interfaceLevels_[leveli],
241 coarseSources[leveli] -= ACf;
245 agglomeration_.restrictField
247 coarseSources[leveli + 1],
248 coarseSources[leveli],
255 if (debug >= 2 && nPreSweeps_)
262 if (coarseCorrFields.
set(coarsestLevel))
266 coarseCorrFields[coarsestLevel],
267 coarseSources[coarsestLevel]
273 Pout<<
"Post-smoothing scaling factors: ";
281 for (
label leveli = coarsestLevel - 1; leveli >= 0; leveli--)
283 if (coarseCorrFields.
set(leveli))
291 coarseCorrFields[leveli].size()
298 preSmoothedCoarseCorrField = coarseCorrFields[leveli];
301 agglomeration_.prolongField
303 coarseCorrFields[leveli],
305 coarseCorrFields.
set(leveli + 1)
306 ? coarseCorrFields[leveli + 1]
318 coarseCorrFields[leveli].size()
323 if (interpolateCorrection_)
325 if (coarseCorrFields.
set(leveli+1))
329 coarseCorrFields[leveli],
331 matrixLevels_[leveli],
332 interfaceLevelsBouCoeffs_[leveli],
333 interfaceLevels_[leveli],
334 agglomeration_.restrictAddressing(leveli + 1),
335 coarseCorrFields[leveli + 1],
343 coarseCorrFields[leveli],
345 matrixLevels_[leveli],
346 interfaceLevelsBouCoeffs_[leveli],
347 interfaceLevels_[leveli],
358 && (interpolateCorrection_ || leveli < coarsestLevel - 1)
363 coarseCorrFields[leveli],
365 matrixLevels_[leveli],
366 interfaceLevelsBouCoeffs_[leveli],
367 interfaceLevels_[leveli],
368 coarseSources[leveli],
377 coarseCorrFields[leveli] += preSmoothedCoarseCorrField;
380 smoothers[leveli + 1].smooth
382 coarseCorrFields[leveli],
383 coarseSources[leveli],
387 nPostSweeps_ + postSweepsLevelMultiplier_*leveli,
395 agglomeration_.prolongField
403 if (interpolateCorrection_)
412 agglomeration_.restrictAddressing(0),
418 if (scaleCorrection_)
435 psi[i] += finestCorrection[i];
448 void Foam::GAMGSolver::initVcycle
450 PtrList<scalarField>& coarseCorrFields,
451 PtrList<scalarField>& coarseSources,
452 PtrList<lduMatrix::smoother>& smoothers,
457 label maxSize = matrix_.diag().size();
459 coarseCorrFields.setSize(matrixLevels_.size());
460 coarseSources.setSize(matrixLevels_.size());
461 smoothers.setSize(matrixLevels_.size() + 1);
478 forAll(matrixLevels_, leveli)
480 if (agglomeration_.nCells(leveli) >= 0)
482 label nCoarseCells = agglomeration_.nCells(leveli);
484 coarseSources.set(leveli,
new scalarField(nCoarseCells));
487 if (matrixLevels_.set(leveli))
489 const lduMatrix& mat = matrixLevels_[leveli];
491 label nCoarseCells = mat.diag().size();
493 maxSize =
max(maxSize, nCoarseCells);
495 coarseCorrFields.set(leveli,
new scalarField(nCoarseCells));
503 matrixLevels_[leveli],
504 interfaceLevelsBouCoeffs_[leveli],
505 interfaceLevelsIntCoeffs_[leveli],
506 interfaceLevels_[leveli],
513 if (maxSize > matrix_.diag().size())
516 scratch1.setSize(maxSize);
517 scratch2.setSize(maxSize);
528 dictionary
dict(IStringStream(
"solver PCG; preconditioner DIC;")());
542 dictionary
dict(IStringStream(
"solver PBiCGStab; preconditioner DILU;")());
550 void Foam::GAMGSolver::solveCoarsestLevel
556 const label coarsestLevel = matrixLevels_.size() - 1;
558 label coarseComm = matrixLevels_[coarsestLevel].mesh().comm();
560 if (directSolveCoarsest_)
562 coarsestLUMatrixPtr_->solve(coarsestCorrField, coarsestSource);
665 coarsestCorrField = 0;
668 if (matrixLevels_[coarsestLevel].asymmetric())
670 coarseSolverPerf = PBiCGStab
673 matrixLevels_[coarsestLevel],
674 interfaceLevelsBouCoeffs_[coarsestLevel],
675 interfaceLevelsIntCoeffs_[coarsestLevel],
676 interfaceLevels_[coarsestLevel],
677 PBiCGStabSolverDict(tolerance_, relTol_)
686 coarseSolverPerf = PCG
689 matrixLevels_[coarsestLevel],
690 interfaceLevelsBouCoeffs_[coarsestLevel],
691 interfaceLevelsIntCoeffs_[coarsestLevel],
692 interfaceLevels_[coarsestLevel],
693 PCGsolverDict(tolerance_, relTol_)
703 coarseSolverPerf.print(
Info(coarseComm));
#define forAll(list, i)
Loop across all elements in list.
SubField< scalar > subField
Declare type of subField.
virtual solverPerformance solve(scalarField &psi, const scalarField &source, const direction cmpt=0) const
Solve.
void size(const label)
Override size to be inconsistent with allocated storage.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
bool set(const label) const
Is element set.
A list of keyword definitions, which are a keyword followed by any number of values (e....
bool add(entry *, bool mergeEntry=false)
Add a new entry.
static autoPtr< smoother > New(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls)
Return a new smoother.
const lduMatrix & matrix_
label maxIter_
Maximum number of iterations in the solver.
scalar tolerance_
Final convergence tolerance.
scalar normFactor(const scalarField &psi, const scalarField &source, const scalarField &Apsi, scalarField &tmpField) const
Return the matrix norm used to normalise the residual for the.
lduInterfaceFieldPtrsList interfaces_
const FieldField< Field, scalar > & interfaceBouCoeffs_
label minIter_
Minimum number of iterations in the solver.
scalar relTol_
Convergence tolerance relative to the initial.
const lduMatrix & matrix() const
void Amul(scalarField &, const tmp< scalarField > &, const FieldField< Field, scalar > &, const lduInterfaceFieldPtrsList &, const direction cmpt) const
Matrix multiplication with updated interfaces.
const volScalarField & psi
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
scalar gSumMag(const FieldField< Field, Type > &f)
Ostream & endl(Ostream &os)
Add newline and flush stream.
SolverPerformance< scalar > solverPerformance
SolverPerformance instantiated for a scalar.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Pout(cout, "Pout")