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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "DILUPreconditioner.H"
30 #include <algorithm>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 
38  lduMatrix::preconditioner::
39  addasymMatrixConstructorToTable<DILUPreconditioner>
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 (
48  const lduMatrix::solver& sol,
49  const dictionary&
50 )
51 :
52  lduMatrix::preconditioner(sol),
53  rD_(sol.matrix().diag().size())
54 {
55  const scalarField& diag = sol.matrix().diag();
56  std::copy(diag.begin(), diag.end(), rD_.begin());
57 
58  calcReciprocalD(rD_, sol.matrix());
59 }
60 
61 
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 
65 (
66  solveScalarField& rD,
67  const lduMatrix& matrix
68 )
69 {
70  solveScalar* __restrict__ rDPtr = rD.begin();
71 
72  const label* const __restrict__ uPtr = matrix.lduAddr().upperAddr().begin();
73  const label* const __restrict__ lPtr = matrix.lduAddr().lowerAddr().begin();
74 
75  const scalar* const __restrict__ upperPtr = matrix.upper().begin();
76  const scalar* const __restrict__ lowerPtr = matrix.lower().begin();
77 
78  label nFaces = matrix.upper().size();
79  for (label face=0; face<nFaces; face++)
80  {
81  rDPtr[uPtr[face]] -= upperPtr[face]*lowerPtr[face]/rDPtr[lPtr[face]];
82  }
83 
84 
85  // Calculate the reciprocal of the preconditioned diagonal
86  const label nCells = rD.size();
87 
88  for (label cell=0; cell<nCells; cell++)
89  {
90  rDPtr[cell] = 1.0/rDPtr[cell];
91  }
92 }
93 
94 
96 (
97  solveScalarField& wA,
98  const solveScalarField& rA,
99  const direction
100 ) const
101 {
102  solveScalar* __restrict__ wAPtr = wA.begin();
103  const solveScalar* __restrict__ rAPtr = rA.begin();
104  const solveScalar* __restrict__ rDPtr = rD_.begin();
105 
106  const label* const __restrict__ uPtr =
107  solver_.matrix().lduAddr().upperAddr().begin();
108  const label* const __restrict__ lPtr =
109  solver_.matrix().lduAddr().lowerAddr().begin();
110 
111  const scalar* const __restrict__ upperPtr =
112  solver_.matrix().upper().begin();
113  const scalar* const __restrict__ lowerPtr =
114  solver_.matrix().lower().begin();
115 
116  const label nCells = wA.size();
117  const label nFaces = solver_.matrix().upper().size();
118  const label nFacesM1 = nFaces - 1;
119 
120  for (label cell=0; cell<nCells; cell++)
121  {
122  wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
123  }
124 
125  for (label face=0; face<nFaces; face++)
126  {
127  wAPtr[uPtr[face]] -=
128  rDPtr[uPtr[face]]*lowerPtr[face]*wAPtr[lPtr[face]];
129  }
130 
131  for (label face=nFacesM1; face>=0; face--)
132  {
133  wAPtr[lPtr[face]] -=
134  rDPtr[lPtr[face]]*upperPtr[face]*wAPtr[uPtr[face]];
135  }
136 }
137 
138 
140 (
141  solveScalarField& wT,
142  const solveScalarField& rT,
143  const direction
144 ) const
145 {
146  solveScalar* __restrict__ wTPtr = wT.begin();
147  const solveScalar* __restrict__ rTPtr = rT.begin();
148  const solveScalar* __restrict__ rDPtr = rD_.begin();
149 
150  const label* const __restrict__ uPtr =
151  solver_.matrix().lduAddr().upperAddr().begin();
152  const label* const __restrict__ lPtr =
153  solver_.matrix().lduAddr().lowerAddr().begin();
154  const label* const __restrict__ losortPtr =
155  solver_.matrix().lduAddr().losortAddr().begin();
156 
157  const scalar* const __restrict__ upperPtr =
158  solver_.matrix().upper().begin();
159  const scalar* const __restrict__ lowerPtr =
160  solver_.matrix().lower().begin();
161 
162  const label nCells = wT.size();
163  const label nFaces = solver_.matrix().upper().size();
164  const label nFacesM1 = nFaces - 1;
165 
166  for (label cell=0; cell<nCells; cell++)
167  {
168  wTPtr[cell] = rDPtr[cell]*rTPtr[cell];
169  }
170 
171  for (label face=0; face<nFaces; face++)
172  {
173  wTPtr[uPtr[face]] -=
174  rDPtr[uPtr[face]]*upperPtr[face]*wTPtr[lPtr[face]];
175  }
176 
177 
178  for (label face=nFacesM1; face>=0; face--)
179  {
180  const label sface = losortPtr[face];
181  wTPtr[lPtr[sface]] -=
182  rDPtr[lPtr[sface]]*lowerPtr[sface]*wTPtr[uPtr[sface]];
183  }
184 }
185 
186 
187 // ************************************************************************* //
const scalarField & diag() const
Definition: lduMatrix.C:195
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
uint8_t direction
Definition: direction.H:46
static void calcReciprocalD(solveScalarField &, const lduMatrix &)
Calculate the reciprocal of the preconditioned diagonal.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
lduMatrix::preconditioner::addasymMatrixConstructorToTable< DILUPreconditioner > addDILUPreconditionerAsymMatrixConstructorToTable_
Field< solveScalar > solveScalarField
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const lduMatrix & matrix() const noexcept
Definition: lduMatrix.H:328
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
virtual void precondition(solveScalarField &wA, const solveScalarField &rA, const direction cmpt=0) const
Return wA the preconditioned form of residual rA.
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
DILUPreconditioner(const lduMatrix::solver &, const dictionary &solverControlsUnused)
Construct from matrix components and preconditioner solver controls.
virtual const labelUList & upperAddr() const =0
Return upper addressing.
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:151
virtual void preconditionT(solveScalarField &wT, const solveScalarField &rT, const direction cmpt=0) const
Return wT the transpose-matrix preconditioned form of residual rT.
const scalarField & lower() const
Definition: lduMatrix.C:306
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:385
defineTypeNameAndDebug(combustionModel, 0)
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:80
const scalarField & upper() const
Definition: lduMatrix.C:235
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:769
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:53
Namespace for OpenFOAM.
Simplified diagonal-based incomplete LU preconditioner for asymmetric matrices. The reciprocal of the...