1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "GAMGSolver.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(GAMGSolver, 0);
34 lduMatrix::solver::addsymMatrixConstructorToTable<GAMGSolver>
35 addGAMGSolverMatrixConstructorToTable_;
37 lduMatrix::solver::addasymMatrixConstructorToTable<GAMGSolver>
38 addGAMGAsymSolverMatrixConstructorToTable_;
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 Foam::GAMGSolver::GAMGSolver
46 const word& fieldName,
47 const lduMatrix& matrix,
48 const FieldField<Field, scalar>& interfaceBouCoeffs,
49 const FieldField<Field, scalar>& interfaceIntCoeffs,
50 const lduInterfaceFieldPtrsList& interfaces,
51 const dictionary& solverControls
64 // Default values for all controls
65 // which may be overridden by those in controlDict
66 cacheAgglomeration_(false),
70 scaleCorrection_(matrix.symmetric()),
71 directSolveCoarsest_(false),
72 agglomeration_(GAMGAgglomeration::New(matrix_, controlDict_)),
74 matrixLevels_(agglomeration_.size()),
75 interfaceLevels_(agglomeration_.size()),
76 interfaceLevelsBouCoeffs_(agglomeration_.size()),
77 interfaceLevelsIntCoeffs_(agglomeration_.size())
81 forAll(agglomeration_, fineLevelIndex)
83 agglomerateMatrix(fineLevelIndex);
86 if (matrixLevels_.size())
88 const label coarsestLevel = matrixLevels_.size() - 1;
90 if (directSolveCoarsest_)
92 coarsestLUMatrixPtr_.set
96 matrixLevels_[coarsestLevel],
97 interfaceLevelsBouCoeffs_[coarsestLevel],
98 interfaceLevels_[coarsestLevel]
107 "GAMGSolver::GAMGSolver"
109 "const word& fieldName,"
110 "const lduMatrix& matrix,"
111 "const FieldField<Field, scalar>& interfaceBouCoeffs,"
112 "const FieldField<Field, scalar>& interfaceIntCoeffs,"
113 "const lduInterfaceFieldPtrsList& interfaces,"
114 "const dictionary& solverControls"
116 ) << "No coarse levels created, either matrix too small for GAMG"
117 " or nCellsInCoarsestLevel too large.\n"
118 " Either choose another solver of reduce "
119 "nCellsInCoarsestLevel."
125 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
127 Foam::GAMGSolver::~GAMGSolver()
129 // Clear the the lists of pointers to the interfaces
130 forAll(interfaceLevels_, leveli)
132 lduInterfaceFieldPtrsList& curLevel = interfaceLevels_[leveli];
143 if (!cacheAgglomeration_)
145 delete &agglomeration_;
150 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
152 void Foam::GAMGSolver::readControls()
154 lduMatrix::solver::readControls();
156 // we could also consider supplying defaults here too
157 controlDict_.readIfPresent("cacheAgglomeration", cacheAgglomeration_);
158 controlDict_.readIfPresent("nPreSweeps", nPreSweeps_);
159 controlDict_.readIfPresent("nPostSweeps", nPostSweeps_);
160 controlDict_.readIfPresent("nFinestSweeps", nFinestSweeps_);
161 controlDict_.readIfPresent("scaleCorrection", scaleCorrection_);
162 controlDict_.readIfPresent("directSolveCoarsest", directSolveCoarsest_);
166 const Foam::lduMatrix& Foam::GAMGSolver::matrixLevel(const label i) const
174 return matrixLevels_[i - 1];
179 const Foam::lduInterfaceFieldPtrsList& Foam::GAMGSolver::interfaceLevel
190 return interfaceLevels_[i - 1];
195 const Foam::FieldField<Foam::Field, Foam::scalar>&
196 Foam::GAMGSolver::interfaceBouCoeffsLevel
203 return interfaceBouCoeffs_;
207 return interfaceLevelsBouCoeffs_[i - 1];
212 const Foam::FieldField<Foam::Field, Foam::scalar>&
213 Foam::GAMGSolver::interfaceIntCoeffsLevel
220 return interfaceIntCoeffs_;
224 return interfaceLevelsIntCoeffs_[i - 1];
229 // ************************************************************************* //