Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / matrices / lduMatrix / smoothers / DIC / DICSmoother.C
bloba196b989f82d86bd47bbb9d2303901fa609b6bd1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
26 #include "DICSmoother.H"
27 #include "DICPreconditioner.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 namespace Foam
33     defineTypeNameAndDebug(DICSmoother, 0);
35     lduSmoother::addsymMatrixConstructorToTable<DICSmoother>
36         addDICSmootherSymMatrixConstructorToTable_;
40 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
42 Foam::DICSmoother::DICSmoother
44     const lduMatrix& matrix,
45     const FieldField<Field, scalar>& coupleBouCoeffs,
46     const FieldField<Field, scalar>& coupleIntCoeffs,
47     const lduInterfaceFieldPtrsList& interfaces
50     lduSmoother
51     (
52         matrix,
53         coupleBouCoeffs,
54         coupleIntCoeffs,
55         interfaces
56     ),
57     rD_(matrix_.diag())
59     DICPreconditioner::calcReciprocalD(rD_, matrix_);
63 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
65 void Foam::DICSmoother::smooth
67     scalarField& x,
68     const scalarField& b,
69     const direction cmpt,
70     const label nSweeps
71 ) const
73     const scalar* const __restrict__ rDPtr = rD_.begin();
74     const scalar* const __restrict__ upperPtr = matrix_.upper().begin();
75     const label* const __restrict__ uPtr =
76         matrix_.lduAddr().upperAddr().begin();
78     const label* const __restrict__ lPtr =
79         matrix_.lduAddr().lowerAddr().begin();
81     // Temporary storage for the residual
82     scalarField rA(rD_.size());
83     scalar* __restrict__ rAPtr = rA.begin();
85     for (label sweep=0; sweep<nSweeps; sweep++)
86     {
87         matrix_.residual
88         (
89             rA,
90             x,
91             b,
92             coupleBouCoeffs_,
93             interfaces_,
94             cmpt
95         );
97         rA *= rD_;
99         register label nFaces = matrix_.upper().size();
100         for (register label face=0; face<nFaces; face++)
101         {
102             register label u = uPtr[face];
103             rAPtr[u] -= rDPtr[u]*upperPtr[face]*rAPtr[lPtr[face]];
104         }
106         register label nFacesM1 = nFaces - 1;
107         for (register label face=nFacesM1; face>=0; face--)
108         {
109             register label l = lPtr[face];
110             rAPtr[l] -= rDPtr[l]*upperPtr[face]*rAPtr[uPtr[face]];
111         }
113         x += rA;
114     }
118 // ************************************************************************* //