TDILUPreconditioner.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) 2011-2015 OpenFOAM Foundation
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 
26 #include "TDILUPreconditioner.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type, class DType, class LUType>
32 (
33  const typename LduMatrix<Type, DType, LUType>::solver& sol,
34  const dictionary&
35 )
36 :
38  rD_(sol.matrix().diag())
39 {
40  calcInvD(rD_, sol.matrix());
41 }
42 
43 
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
45 
46 template<class Type, class DType, class LUType>
48 (
49  Field<DType>& rD,
50  const LduMatrix<Type, DType, LUType>& matrix
51 )
52 {
53  DType* __restrict__ rDPtr = rD.begin();
54 
55  const label* const __restrict__ uPtr = matrix.lduAddr().upperAddr().begin();
56  const label* const __restrict__ lPtr = matrix.lduAddr().lowerAddr().begin();
57 
58  const LUType* const __restrict__ upperPtr = matrix.upper().begin();
59  const LUType* const __restrict__ lowerPtr = matrix.lower().begin();
60 
61  label nFaces = matrix.upper().size();
62  for (label face=0; face<nFaces; face++)
63  {
64  rDPtr[uPtr[face]] -=
65  dot(dot(upperPtr[face], lowerPtr[face]), inv(rDPtr[lPtr[face]]));
66  }
67 
68 
69  // Calculate the reciprocal of the preconditioned diagonal
70  label nCells = rD.size();
71 
72  for (label cell=0; cell<nCells; cell++)
73  {
74  rDPtr[cell] = inv(rDPtr[cell]);
75  }
76 }
77 
78 
79 template<class Type, class DType, class LUType>
81 (
82  Field<Type>& wA,
83  const Field<Type>& rA
84 ) const
85 {
86  Type* __restrict__ wAPtr = wA.begin();
87  const Type* __restrict__ rAPtr = rA.begin();
88  const DType* __restrict__ rDPtr = rD_.begin();
89 
90  const label* const __restrict__ uPtr =
91  this->solver_.matrix().lduAddr().upperAddr().begin();
92  const label* const __restrict__ lPtr =
93  this->solver_.matrix().lduAddr().lowerAddr().begin();
94  const label* const __restrict__ losortPtr =
95  this->solver_.matrix().lduAddr().losortAddr().begin();
96 
97  const LUType* const __restrict__ upperPtr =
98  this->solver_.matrix().upper().begin();
99  const LUType* const __restrict__ lowerPtr =
100  this->solver_.matrix().lower().begin();
101 
102  label nCells = wA.size();
103  label nFaces = this->solver_.matrix().upper().size();
104  label nFacesM1 = nFaces - 1;
105 
106  for (label cell=0; cell<nCells; cell++)
107  {
108  wAPtr[cell] = dot(rDPtr[cell], rAPtr[cell]);
109  }
110 
111 
112  label sface;
113 
114  for (label face=0; face<nFaces; face++)
115  {
116  sface = losortPtr[face];
117  wAPtr[uPtr[sface]] -=
118  dot(rDPtr[uPtr[sface]], dot(lowerPtr[sface], wAPtr[lPtr[sface]]));
119  }
120 
121  for (label face=nFacesM1; face>=0; face--)
122  {
123  wAPtr[lPtr[face]] -=
124  dot(rDPtr[lPtr[face]], dot(upperPtr[face], wAPtr[uPtr[face]]));
125  }
126 }
127 
128 
129 template<class Type, class DType, class LUType>
131 (
132  Field<Type>& wT,
133  const Field<Type>& rT
134 ) const
135 {
136  Type* __restrict__ wTPtr = wT.begin();
137  const Type* __restrict__ rTPtr = rT.begin();
138  const DType* __restrict__ rDPtr = rD_.begin();
139 
140  const label* const __restrict__ uPtr =
141  this->solver_.matrix().lduAddr().upperAddr().begin();
142  const label* const __restrict__ lPtr =
143  this->solver_.matrix().lduAddr().lowerAddr().begin();
144  const label* const __restrict__ losortPtr =
145  this->solver_.matrix().lduAddr().losortAddr().begin();
146 
147  const LUType* const __restrict__ upperPtr =
148  this->solver_.matrix().upper().begin();
149  const LUType* const __restrict__ lowerPtr =
150  this->solver_.matrix().lower().begin();
151 
152  label nCells = wT.size();
153  label nFaces = this->solver_.matrix().upper().size();
154  label nFacesM1 = nFaces - 1;
155 
156  for (label cell=0; cell<nCells; cell++)
157  {
158  wTPtr[cell] = dot(rDPtr[cell], rTPtr[cell]);
159  }
160 
161  for (label face=0; face<nFaces; face++)
162  {
163  wTPtr[uPtr[face]] -=
164  dot(rDPtr[uPtr[face]], dot(upperPtr[face], wTPtr[lPtr[face]]));
165  }
166 
167 
168  label sface;
169 
170  for (label face=nFacesM1; face>=0; face--)
171  {
172  sface = losortPtr[face];
173  wTPtr[lPtr[sface]] -=
174  dot(rDPtr[lPtr[sface]], dot(lowerPtr[sface], wTPtr[uPtr[sface]]));
175  }
176 }
177 
178 
179 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual void precondition(Field< Type > &wA, const Field< Type > &rA) const
Return wA the preconditioned form of residual rA.
Field< LUType > & lower()
Definition: LduMatrix.C:225
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Abstract base-class for LduMatrix preconditioners.
Definition: LduMatrix.H:358
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
Field< LUType > & upper()
Definition: LduMatrix.C:202
const LduMatrix< Type, DType, LUType > & matrix() const
Definition: LduMatrix.H:232
Abstract base-class for LduMatrix solvers.
Definition: LduMatrix.H:112
TDILUPreconditioner(const typename LduMatrix< Type, DType, LUType >::solver &sol, const dictionary &preconditionerDict)
Construct from matrix components and preconditioner data dictionary.
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
LduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: LduMatrix.H:69
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: LduMatrix.H:495
static void calcInvD(Field< DType > &rD, const LduMatrix< Type, DType, LUType > &matrix)
Calculate the reciprocal of the preconditioned diagonal.
virtual void preconditionT(Field< Type > &wT, const Field< Type > &rT) const
Return wT the transpose-matrix preconditioned form of.