1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Algebraic multigrid cycle class for BlockLduMatrix
31 Klas Jareteg, 2012-12-12
33 \*---------------------------------------------------------------------------*/
35 #include "BlockAmgCycle.H"
36 #include "demandDrivenData.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 // Construct from AMG level
46 Foam::BlockAmgCycle<Type>::BlockAmgCycle
48 autoPtr<BlockAmgLevel<Type> > levelPtr
52 coarseLevelPtr_(NULL),
56 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 Foam::BlockAmgCycle<Type>::~BlockAmgCycle()
61 deleteDemandDrivenData(coarseLevelPtr_);
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 void Foam::BlockAmgCycle<Type>::makeCoarseLevels(const label nMaxLevels)
73 bool addCoarse = true;
74 BlockAmgCycle<Type>* curCyclePtr = this;
81 autoPtr<BlockAmgLevel<Type> > coarsePtr =
82 curCyclePtr->levelPtr_->makeNextLevel();
84 // Check if a coarse level is valid and allowed
85 if (nLevels_ >= nMaxLevels || !coarsePtr.valid())
90 reduce(addCoarse, andOp<bool>());
94 curCyclePtr->coarseLevelPtr_ =
95 new BlockAmgCycle<Type>(coarsePtr);
97 // Point to the next coarse level
98 curCyclePtr = curCyclePtr->coarseLevelPtr_;
106 if (BlockLduMatrix<Type>::debug >= 2)
108 Info<< "Created " << nLevels_ << " AMG levels" << endl;
115 void Foam::BlockAmgCycle<Type>::fixedCycle
118 const Field<Type>& b,
119 Field<Type>& xBuffer,
120 const blockAmgCycleName::cycleType cycle,
121 const label nPreSweeps,
122 const label nPostSweeps,
129 levelPtr_->smooth(x, b, nPreSweeps);
131 // Get reference to coarse level
132 Field<Type>& xCoarse = coarseLevelPtr_->levelPtr_->x();
133 Field<Type>& bCoarse = coarseLevelPtr_->levelPtr_->b();
136 xCoarse = pTraits<Type>::zero;
138 // Restrict residual: optimisation on number of pre-sweeps
139 levelPtr_->restrictResidual
145 nPreSweeps > 0 || cycle != V_CYCLE
148 coarseLevelPtr_->fixedCycle
159 if (cycle == F_CYCLE)
161 coarseLevelPtr_->fixedCycle
172 else if (cycle == W_CYCLE)
174 coarseLevelPtr_->fixedCycle
188 // Calculate scaling factor using a buffer
189 coarseLevelPtr_->levelPtr_->scaleX(xCoarse, bCoarse, xBuffer);
192 levelPtr_->prolongateCorrection(x, xCoarse);
195 levelPtr_->smooth(x, b, nPostSweeps);
199 // Call direct solver
200 levelPtr_->solve(x, b, 1e-9, 0);
205 // ************************************************************************* //