1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 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
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 \*---------------------------------------------------------------------------*/
27 #include "FDICPreconditioner.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(FDICPreconditioner, 0);
35 lduMatrix::preconditioner::
36 addsymMatrixConstructorToTable<FDICPreconditioner>
37 addFDICPreconditionerSymMatrixConstructorToTable_;
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 Foam::FDICPreconditioner::FDICPreconditioner
45 const lduMatrix::solver& sol,
49 lduMatrix::preconditioner(sol),
50 rD_(sol.matrix().diag()),
51 rDuUpper_(sol.matrix().upper().size()),
52 rDlUpper_(sol.matrix().upper().size())
54 scalar* __restrict__ rDPtr = rD_.begin();
55 scalar* __restrict__ rDuUpperPtr = rDuUpper_.begin();
56 scalar* __restrict__ rDlUpperPtr = rDlUpper_.begin();
58 const label* const __restrict__ uPtr =
59 solver_.matrix().lduAddr().upperAddr().begin();
60 const label* const __restrict__ lPtr =
61 solver_.matrix().lduAddr().lowerAddr().begin();
62 const scalar* const __restrict__ upperPtr = solver_.matrix().upper().begin();
64 register label nCells = rD_.size();
65 register label nFaces = solver_.matrix().upper().size();
67 for (register label face=0; face<nFaces; face++)
69 rDPtr[uPtr[face]] -= sqr(upperPtr[face])/rDPtr[lPtr[face]];
72 // Generate reciprocal FDIC
73 for (register label cell=0; cell<nCells; cell++)
75 rDPtr[cell] = 1.0/rDPtr[cell];
78 for (register label face=0; face<nFaces; face++)
80 rDuUpperPtr[face] = rDPtr[uPtr[face]]*upperPtr[face];
81 rDlUpperPtr[face] = rDPtr[lPtr[face]]*upperPtr[face];
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
88 void Foam::FDICPreconditioner::precondition
91 const scalarField& rA,
95 scalar* __restrict__ wAPtr = wA.begin();
96 const scalar* __restrict__ rAPtr = rA.begin();
97 const scalar* __restrict__ rDPtr = rD_.begin();
99 const label* const __restrict__ uPtr =
100 solver_.matrix().lduAddr().upperAddr().begin();
101 const label* const __restrict__ lPtr =
102 solver_.matrix().lduAddr().lowerAddr().begin();
104 const scalar* const __restrict__ rDuUpperPtr = rDuUpper_.begin();
105 const scalar* const __restrict__ rDlUpperPtr = rDlUpper_.begin();
107 register label nCells = wA.size();
108 register label nFaces = solver_.matrix().upper().size();
109 register label nFacesM1 = nFaces - 1;
111 for (register label cell=0; cell<nCells; cell++)
113 wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
116 for (register label face=0; face<nFaces; face++)
118 wAPtr[uPtr[face]] -= rDuUpperPtr[face]*wAPtr[lPtr[face]];
121 for (register label face=nFacesM1; face>=0; face--)
123 wAPtr[lPtr[face]] -= rDlUpperPtr[face]*wAPtr[uPtr[face]];
128 // ************************************************************************* //