GAMGPreconditioner.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "GAMGPreconditioner.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(GAMGPreconditioner, 0);
33 
34  lduMatrix::preconditioner::addsymMatrixConstructorToTable
36 
37  lduMatrix::preconditioner::addasymMatrixConstructorToTable
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const lduMatrix::solver& sol,
47  const dictionary& solverControls
48 )
49 :
51  (
52  sol.fieldName(),
53  sol.matrix(),
54  sol.interfaceBouCoeffs(),
55  sol.interfaceIntCoeffs(),
56  sol.interfaces(),
57  solverControls
58  ),
60  nVcycles_(2)
61 {
62  readControls();
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
67 
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
75 {
76  GAMGSolver::readControls();
77  nVcycles_ = controlDict_.lookupOrDefault<label>("nVcycles", 2);
78 }
79 
80 
82 (
83  scalarField& wA,
84  const scalarField& rA,
85  const direction cmpt
86 ) const
87 {
88  wA = 0.0;
89  scalarField AwA(wA.size());
90  scalarField finestCorrection(wA.size());
91  scalarField finestResidual(rA);
92 
93  // Create coarse grid correction fields
94  PtrList<scalarField> coarseCorrFields;
95 
96  // Create coarse grid sources
97  PtrList<scalarField> coarseSources;
98 
99  // Create the smoothers for all levels
101 
102  // Scratch fields if processor-agglomerated coarse level meshes
103  // are bigger than original. Usually not needed
104  scalarField ApsiScratch;
105  scalarField finestCorrectionScratch;
106 
107  // Initialise the above data structures
108  initVcycle
109  (
110  coarseCorrFields,
111  coarseSources,
112  smoothers,
113  ApsiScratch,
114  finestCorrectionScratch
115  );
116 
117  for (label cycle=0; cycle<nVcycles_; cycle++)
118  {
119  Vcycle
120  (
121  smoothers,
122  wA,
123  rA,
124  AwA,
125  finestCorrection,
126  finestResidual,
127 
128  (ApsiScratch.size() ? ApsiScratch : AwA),
129  (
130  finestCorrectionScratch.size()
131  ? finestCorrectionScratch
132  : finestCorrection
133  ),
134 
135  coarseCorrFields,
136  coarseSources,
137  cmpt
138  );
139 
140  if (cycle < nVcycles_-1)
141  {
142  // Calculate finest level residual field
143  matrix_.Amul(AwA, wA, interfaceBouCoeffs_, interfaces_, cmpt);
144  finestResidual = rA;
145  finestResidual -= AwA;
146  }
147  }
148 }
149 
150 
151 // ************************************************************************* //
GAMGPreconditioner(const lduMatrix::solver &, const dictionary &solverControls)
Construct from matrix components and preconditioner solver controls.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Geometric agglomerated algebraic multigrid preconditioner.
uint8_t direction
Definition: direction.H:45
virtual void readControls()
Read the control parameters from the controlDict_.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const lduMatrix & matrix() const
Definition: lduMatrix.H:226
const FieldField< Field, scalar > & interfaceBouCoeffs() const
Definition: lduMatrix.H:231
virtual ~GAMGPreconditioner()
Destructor.
const FieldField< Field, scalar > & interfaceIntCoeffs() const
Definition: lduMatrix.H:236
virtual void precondition(scalarField &wA, const scalarField &rA, const direction cmpt=0) const
Return wA the preconditioned form of residual rA.
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:93
const lduInterfaceFieldPtrsList & interfaces() const
Definition: lduMatrix.H:241
lduMatrix::preconditioner::addasymMatrixConstructorToTable< GAMGPreconditioner > addGAMGPreconditionerAsymMatrixConstructorToTable_
defineTypeNameAndDebug(combustionModel, 0)
Geometric agglomerated algebraic multigrid solver.
Definition: GAMGSolver.H:70
Abstract base-class for lduMatrix preconditioners.
Definition: lduMatrix.H:410
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
lduMatrix::preconditioner::addsymMatrixConstructorToTable< GAMGPreconditioner > addGAMGPreconditionerSymMatrixConstructorToTable_
const word & fieldName() const
Definition: lduMatrix.H:221
Namespace for OpenFOAM.