FreeFOAM The Cross-Platform CFD Toolkit
DICPreconditioner.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(DICPreconditioner, 0);
33 
34  lduMatrix::preconditioner::
35  addsymMatrixConstructorToTable<DICPreconditioner>
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
44  const lduMatrix::solver& sol,
45  const dictionary&
46 )
47 :
49  rD_(sol.matrix().diag())
50 {
51  calcReciprocalD(rD_, sol.matrix());
52 }
53 
54 
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 
58 (
59  scalarField& rD,
60  const lduMatrix& matrix
61 )
62 {
63  scalar* __restrict__ rDPtr = rD.begin();
64 
65  const label* const __restrict__ uPtr = matrix.lduAddr().upperAddr().begin();
66  const label* const __restrict__ lPtr = matrix.lduAddr().lowerAddr().begin();
67  const scalar* const __restrict__ upperPtr = matrix.upper().begin();
68 
69  // Calculate the DIC diagonal
70  register const label nFaces = matrix.upper().size();
71  for (register label face=0; face<nFaces; face++)
72  {
73  rDPtr[uPtr[face]] -= upperPtr[face]*upperPtr[face]/rDPtr[lPtr[face]];
74  }
75 
76 
77  // Calculate the reciprocal of the preconditioned diagonal
78  register const label nCells = rD.size();
79 
80  for (register label cell=0; cell<nCells; cell++)
81  {
82  rDPtr[cell] = 1.0/rDPtr[cell];
83  }
84 }
85 
86 
88 (
89  scalarField& wA,
90  const scalarField& rA,
91  const direction
92 ) const
93 {
94  scalar* __restrict__ wAPtr = wA.begin();
95  const scalar* __restrict__ rAPtr = rA.begin();
96  const scalar* __restrict__ rDPtr = rD_.begin();
97 
98  const label* const __restrict__ uPtr =
99  solver_.matrix().lduAddr().upperAddr().begin();
100  const label* const __restrict__ lPtr =
101  solver_.matrix().lduAddr().lowerAddr().begin();
102  const scalar* const __restrict__ upperPtr = solver_.matrix().upper().begin();
103 
104  register label nCells = wA.size();
105  register label nFaces = solver_.matrix().upper().size();
106  register label nFacesM1 = nFaces - 1;
107 
108  for (register label cell=0; cell<nCells; cell++)
109  {
110  wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
111  }
112 
113  for (register label face=0; face<nFaces; face++)
114  {
115  wAPtr[uPtr[face]] -= rDPtr[uPtr[face]]*upperPtr[face]*wAPtr[lPtr[face]];
116  }
117 
118  for (register label face=nFacesM1; face>=0; face--)
119  {
120  wAPtr[lPtr[face]] -= rDPtr[lPtr[face]]*upperPtr[face]*wAPtr[uPtr[face]];
121  }
122 }
123 
124 
125 // ************************ vim: set sw=4 sts=4 et: ************************ //