FreeFOAM The Cross-Platform CFD Toolkit
DILUPreconditioner.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(DILUPreconditioner, 0);
33 
34  lduMatrix::preconditioner::
35  addasymMatrixConstructorToTable<DILUPreconditioner>
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 
68  const scalar* const __restrict__ upperPtr = matrix.upper().begin();
69  const scalar* const __restrict__ lowerPtr = matrix.lower().begin();
70 
71  register label nFaces = matrix.upper().size();
72  for (register label face=0; face<nFaces; face++)
73  {
74  rDPtr[uPtr[face]] -= upperPtr[face]*lowerPtr[face]/rDPtr[lPtr[face]];
75  }
76 
77 
78  // Calculate the reciprocal of the preconditioned diagonal
79  register label nCells = rD.size();
80 
81  for (register label cell=0; cell<nCells; cell++)
82  {
83  rDPtr[cell] = 1.0/rDPtr[cell];
84  }
85 }
86 
87 
89 (
90  scalarField& wA,
91  const scalarField& rA,
92  const direction
93 ) const
94 {
95  scalar* __restrict__ wAPtr = wA.begin();
96  const scalar* __restrict__ rAPtr = rA.begin();
97  const scalar* __restrict__ rDPtr = rD_.begin();
98 
99  const label* const __restrict__ uPtr =
100  solver_.matrix().lduAddr().upperAddr().begin();
101  const label* const __restrict__ lPtr =
102  solver_.matrix().lduAddr().lowerAddr().begin();
103  const label* const __restrict__ losortPtr =
104  solver_.matrix().lduAddr().losortAddr().begin();
105 
106  const scalar* const __restrict__ upperPtr =
107  solver_.matrix().upper().begin();
108  const scalar* const __restrict__ lowerPtr =
109  solver_.matrix().lower().begin();
110 
111  register label nCells = wA.size();
112  register label nFaces = solver_.matrix().upper().size();
113  register label nFacesM1 = nFaces - 1;
114 
115  for (register label cell=0; cell<nCells; cell++)
116  {
117  wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
118  }
119 
120 
121  register label sface;
122 
123  for (register label face=0; face<nFaces; face++)
124  {
125  sface = losortPtr[face];
126  wAPtr[uPtr[sface]] -=
127  rDPtr[uPtr[sface]]*lowerPtr[sface]*wAPtr[lPtr[sface]];
128  }
129 
130  for (register label face=nFacesM1; face>=0; face--)
131  {
132  wAPtr[lPtr[face]] -=
133  rDPtr[lPtr[face]]*upperPtr[face]*wAPtr[uPtr[face]];
134  }
135 }
136 
137 
139 (
140  scalarField& wT,
141  const scalarField& rT,
142  const direction
143 ) const
144 {
145  scalar* __restrict__ wTPtr = wT.begin();
146  const scalar* __restrict__ rTPtr = rT.begin();
147  const scalar* __restrict__ rDPtr = rD_.begin();
148 
149  const label* const __restrict__ uPtr =
150  solver_.matrix().lduAddr().upperAddr().begin();
151  const label* const __restrict__ lPtr =
152  solver_.matrix().lduAddr().lowerAddr().begin();
153  const label* const __restrict__ losortPtr =
154  solver_.matrix().lduAddr().losortAddr().begin();
155 
156  const scalar* const __restrict__ upperPtr =
157  solver_.matrix().upper().begin();
158  const scalar* const __restrict__ lowerPtr =
159  solver_.matrix().lower().begin();
160 
161  register label nCells = wT.size();
162  register label nFaces = solver_.matrix().upper().size();
163  register label nFacesM1 = nFaces - 1;
164 
165  for (register label cell=0; cell<nCells; cell++)
166  {
167  wTPtr[cell] = rDPtr[cell]*rTPtr[cell];
168  }
169 
170  for (register label face=0; face<nFaces; face++)
171  {
172  wTPtr[uPtr[face]] -=
173  rDPtr[uPtr[face]]*upperPtr[face]*wTPtr[lPtr[face]];
174  }
175 
176 
177  register label sface;
178 
179  for (register label face=nFacesM1; face>=0; face--)
180  {
181  sface = losortPtr[face];
182  wTPtr[lPtr[sface]] -=
183  rDPtr[lPtr[sface]]*lowerPtr[sface]*wTPtr[uPtr[sface]];
184  }
185 }
186 
187 
188 // ************************ vim: set sw=4 sts=4 et: ************************ //