Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / blockMatrix / BlockLduSmoothers / BlockILUSmoother / BlockILUSmoother.H
blob7bda49efbc5e8938028a23c2d76f004db352196e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     BlockILUSmoother
28 Description
29     Gauss-Seidel smoother
31 SourceFiles
32     blockILUSmoothers.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef BlockILUSmoother_H
37 #define BlockILUSmoother_H
39 #include "BlockLduSmoother.H"
40 #include "blockCholeskyPrecons.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 /*---------------------------------------------------------------------------*\
48                    Class BlockILUSmoother Declaration
49 \*---------------------------------------------------------------------------*/
51 template<class Type>
52 class BlockILUSmoother
54     public BlockLduSmoother<Type>
56     // Private Data
58         //- Cholesky preconditioner
59         BlockCholeskyPrecon<Type> precon_;
61         //- Correction array
62         mutable Field<Type> xCorr_;
64         //- Residual array
65         mutable Field<Type> residual_;
68     // Private Member Functions
70         //- Disallow default bitwise copy construct
71         BlockILUSmoother(const BlockILUSmoother&);
73         //- Disallow default bitwise assignment
74         void operator=(const BlockILUSmoother&);
77 public:
79     //- Runtime type information
80     TypeName("ILU");
83     // Constructors
85         //- Construct from components
86         BlockILUSmoother
87         (
88             const BlockLduMatrix<Type>& matrix,
89             const dictionary& dict
90         )
91         :
92             BlockLduSmoother<Type>(matrix),
93             precon_(matrix),
94             xCorr_(matrix.lduAddr().size()),
95             residual_(matrix.lduAddr().size())
96         {}
99     // Destructor
101         virtual ~BlockILUSmoother()
102         {}
105     // Member Functions
107         //- Execute smoothing
108         virtual void smooth
109         (
110             Field<Type>& x,
111             const Field<Type>& b,
112             const label nSweeps
113         ) const
114         {
115             for (label sweep = 0; sweep < nSweeps; sweep++)
116             {
117                 // Calculate residual
118                 this-> matrix_.Amul(residual_, x);
120                 // residual = b - Ax
121                 forAll (b, i)
122                 {
123                     residual_[i] = b[i] - residual_[i];
124                 }
126                 precon_.precondition(xCorr_, residual_);
128                 // Add correction to x
129                 x += xCorr_;
130             }
131         }
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 } // End namespace Foam
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 #endif
143 // ************************************************************************* //