BlockMatrixAgglomeration
[foam-extend-3.0.git] / src / foam / matrices / blockLduMatrix / BlockLduPrecons / BlockAmgPrecon / BlockAmgPrecon.C
blobbcf144072ae4b91758a4bf1a1e8a50f92457a660
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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/>.
24 Class
25     BlockAmgPrecon
27 Description
28     AMG preconditioner for BlockLduMatrix
30 Author
31     Klas Jareteg, 2013-04-15
33 \*---------------------------------------------------------------------------*/
35 #include "BlockAmgPrecon.H"
36 #include "fineBlockAmgLevel.H"
37 #include "addToRunTimeSelectionTable.H"
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 template<class Type>
46 Foam::BlockAmgPrecon<Type>::BlockAmgPrecon
48     const BlockLduMatrix<Type>& matrix,
49     const dictionary& dict
52     BlockLduPrecon<Type>
53     (
54         matrix
55     ),
56     cycle_(BlockAmgCycle<Type>::cycleNames_.read(dict.lookup("cycle"))),
57     nPreSweeps_(readLabel(dict.lookup("nPreSweeps"))),
58     nPostSweeps_(readLabel(dict.lookup("nPostSweeps"))),
59     nMaxLevels_(readLabel(dict.lookup("nMaxLevels"))),
60     scale_(dict.lookup("scale")),
61     amgPtr_
62     (
63         new BlockAmgCycle<Type>
64         (
65             autoPtr<BlockAmgLevel<Type> >
66             (
67                 new fineBlockAmgLevel<Type>
68                 (
69                     matrix,
70                     dict,
71                     dict.lookup("coarseningType"),
72                     readLabel(dict.lookup("groupSize")),
73                     readLabel(dict.lookup("minCoarseEqns")),
74                     dict.lookup("smoother")
75                 )
76             )
77         )
78     ),
79     xBuffer_(matrix.lduAddr().size())
81     // Make coarse levels
82     amgPtr_->makeCoarseLevels(nMaxLevels_);
86 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
88 template<class Type>
89 Foam::BlockAmgPrecon<Type>::~BlockAmgPrecon()
93 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
95 template<class Type>
96 Foam::label Foam::BlockAmgPrecon<Type>::nLevels() const
98     return amgPtr_->nLevels();
102 template<class Type>
103 const Foam::Field<Type>& Foam::BlockAmgPrecon<Type>::residual
105     const Field<Type>& x,
106     const Field<Type>& b
107 ) const
109     // Calculate residual
110     amgPtr_->residual(x, b, xBuffer_);
112     return xBuffer_;
116 template<class Type>
117 void Foam::BlockAmgPrecon<Type>::cycle
119     Field<Type>& x,
120     const Field<Type>& b
121 ) const
123     amgPtr_->fixedCycle
124     (
125         x,
126         b,
127         xBuffer_,
128         cycle_,
129         nPreSweeps_,
130         nPostSweeps_,
131         scale_
132     );
135 template<class Type>
136 void Foam::BlockAmgPrecon<Type>::precondition
138     Field<Type>& x,
139     const Field<Type>& b
140 ) const
142     // Execute preconditioning
143     residual(x, b);
144     cycle(x, b);
148 // ************************************************************************* //