FreeFOAM The Cross-Platform CFD Toolkit
GAMGPreconditioner.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 
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  // Initialise the above data structures
103  initVcycle(coarseCorrFields, coarseSources, smoothers);
104 
105  for (label cycle=0; cycle<nVcycles_; cycle++)
106  {
107  Vcycle
108  (
109  smoothers,
110  wA,
111  rA,
112  AwA,
113  finestCorrection,
114  finestResidual,
115  coarseCorrFields,
116  coarseSources,
117  cmpt
118  );
119 
120  if (cycle < nVcycles_-1)
121  {
122  // Calculate finest level residual field
123  matrix_.Amul(AwA, wA, interfaceBouCoeffs_, interfaces_, cmpt);
124  finestResidual = rA;
125  finestResidual -= AwA;
126  }
127  }
128 }
129 
130 
131 // ************************ vim: set sw=4 sts=4 et: ************************ //