symGaussSeidelSmoother.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2018 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 "symGaussSeidelSmoother.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(symGaussSeidelSmoother, 0);
33 
34  lduMatrix::smoother::addsymMatrixConstructorToTable<symGaussSeidelSmoother>
36 
37  lduMatrix::smoother::addasymMatrixConstructorToTable<symGaussSeidelSmoother>
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 (
46  const word& fieldName,
47  const lduMatrix& matrix,
48  const FieldField<Field, scalar>& interfaceBouCoeffs,
49  const FieldField<Field, scalar>& interfaceIntCoeffs,
50  const lduInterfaceFieldPtrsList& interfaces
51 )
52 :
54  (
55  fieldName,
56  matrix,
57  interfaceBouCoeffs,
58  interfaceIntCoeffs,
59  interfaces
60  )
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 (
68  const word& fieldName_,
69  scalarField& psi,
70  const lduMatrix& matrix_,
71  const scalarField& source,
72  const FieldField<Field, scalar>& interfaceBouCoeffs_,
73  const lduInterfaceFieldPtrsList& interfaces_,
74  const direction cmpt,
75  const label nSweeps
76 )
77 {
78  scalar* __restrict__ psiPtr = psi.begin();
79 
80  const label nCells = psi.size();
81 
82  scalarField bPrime(nCells);
83  scalar* __restrict__ bPrimePtr = bPrime.begin();
84 
85  const scalar* const __restrict__ diagPtr = matrix_.diag().begin();
86  const scalar* const __restrict__ upperPtr =
87  matrix_.upper().begin();
88  const scalar* const __restrict__ lowerPtr =
89  matrix_.lower().begin();
90 
91  const label* const __restrict__ uPtr =
92  matrix_.lduAddr().upperAddr().begin();
93 
94  const label* const __restrict__ ownStartPtr =
95  matrix_.lduAddr().ownerStartAddr().begin();
96 
97 
98  // Parallel boundary initialisation. The parallel boundary is treated
99  // as an effective jacobi interface in the boundary.
100  // Note: there is a change of sign in the coupled
101  // interface update. The reason for this is that the
102  // internal coefficients are all located at the l.h.s. of
103  // the matrix whereas the "implicit" coefficients on the
104  // coupled boundaries are all created as if the
105  // coefficient contribution is of a source-kind (i.e. they
106  // have a sign as if they are on the r.h.s. of the matrix.
107  // To compensate for this, it is necessary to turn the
108  // sign of the contribution.
109 
110  FieldField<Field, scalar>& mBouCoeffs =
111  const_cast<FieldField<Field, scalar>&>
112  (
113  interfaceBouCoeffs_
114  );
115 
116  forAll(mBouCoeffs, patchi)
117  {
118  if (interfaces_.set(patchi))
119  {
120  mBouCoeffs[patchi].negate();
121  }
122  }
123 
124 
125  for (label sweep=0; sweep<nSweeps; sweep++)
126  {
127  bPrime = source;
128 
129  matrix_.initMatrixInterfaces
130  (
131  mBouCoeffs,
132  interfaces_,
133  psi,
134  bPrime,
135  cmpt
136  );
137 
138  matrix_.updateMatrixInterfaces
139  (
140  mBouCoeffs,
141  interfaces_,
142  psi,
143  bPrime,
144  cmpt
145  );
146 
147  scalar psii;
148  label fStart;
149  label fEnd = ownStartPtr[0];
150 
151  for (label celli=0; celli<nCells; celli++)
152  {
153  // Start and end of this row
154  fStart = fEnd;
155  fEnd = ownStartPtr[celli + 1];
156 
157  // Get the accumulated neighbour side
158  psii = bPrimePtr[celli];
159 
160  // Accumulate the owner product side
161  for (label facei=fStart; facei<fEnd; facei++)
162  {
163  psii -= upperPtr[facei]*psiPtr[uPtr[facei]];
164  }
165 
166  // Finish current psi
167  psii /= diagPtr[celli];
168 
169  // Distribute the neighbour side using current psi
170  for (label facei=fStart; facei<fEnd; facei++)
171  {
172  bPrimePtr[uPtr[facei]] -= lowerPtr[facei]*psii;
173  }
174 
175  psiPtr[celli] = psii;
176  }
177 
178  fStart = ownStartPtr[nCells];
179 
180  for (label celli=nCells-1; celli>=0; celli--)
181  {
182  // Start and end of this row
183  fEnd = fStart;
184  fStart = ownStartPtr[celli];
185 
186  // Get the accumulated neighbour side
187  psii = bPrimePtr[celli];
188 
189  // Accumulate the owner product side
190  for (label facei=fStart; facei<fEnd; facei++)
191  {
192  psii -= upperPtr[facei]*psiPtr[uPtr[facei]];
193  }
194 
195  // Finish psi for this cell
196  psii /= diagPtr[celli];
197 
198  // Distribute the neighbour side using psi for this cell
199  for (label facei=fStart; facei<fEnd; facei++)
200  {
201  bPrimePtr[uPtr[facei]] -= lowerPtr[facei]*psii;
202  }
203 
204  psiPtr[celli] = psii;
205  }
206  }
207 
208  // Restore interfaceBouCoeffs_
209  forAll(mBouCoeffs, patchi)
210  {
211  if (interfaces_.set(patchi))
212  {
213  mBouCoeffs[patchi].negate();
214  }
215  }
216 }
217 
218 
220 (
221  scalarField& psi,
222  const scalarField& source,
223  const direction cmpt,
224  const label nSweeps
225 ) const
226 {
227  smooth
228  (
229  fieldName_,
230  psi,
231  matrix_,
232  source,
233  interfaceBouCoeffs_,
234  interfaces_,
235  cmpt,
236  nSweeps
237  );
238 }
239 
240 
241 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
uint8_t direction
Definition: direction.H:45
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void initMatrixInterfaces(const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const scalarField &psiif, scalarField &result, const direction cmpt) const
Initialise the update of interfaced interfaces.
static void smooth(const word &fieldName, scalarField &psi, const lduMatrix &matrix, const scalarField &source, const FieldField< Field, scalar > &interfaceBouCoeffs, const lduInterfaceFieldPtrsList &interfaces, const direction cmpt, const label nSweeps)
Smooth for the given number of sweeps.
lduMatrix::smoother::addasymMatrixConstructorToTable< symGaussSeidelSmoother > addsymGaussSeidelSmootherAsymMatrixConstructorToTable_
scalarField & upper()
Definition: lduMatrix.C:197
Generic field type.
Definition: FieldField.H:51
void smooth(volScalarField &field, const scalar coeff)
Definition: fvcSmooth.C:35
void sweep(volScalarField &field, const volScalarField &alpha, const label nLayers, const scalar alphaDiff=0.2)
Definition: fvcSmooth.C:240
Abstract base-class for lduMatrix smoothers.
Definition: lduMatrix.H:270
void negate()
Negate this field.
Definition: FieldField.C:218
A class for handling words, derived from string.
Definition: word.H:59
virtual const labelUList & upperAddr() const =0
Return upper addressing.
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
void updateMatrixInterfaces(const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const scalarField &psiif, scalarField &result, const direction cmpt) const
Update interfaced interfaces for matrix operations.
lduMatrix::smoother::addsymMatrixConstructorToTable< symGaussSeidelSmoother > addsymGaussSeidelSmootherSymMatrixConstructorToTable_
bool set(const label) const
Is element set.
Definition: UPtrListI.H:78
defineTypeNameAndDebug(combustionModel, 0)
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:79
label patchi
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:550
scalarField & lower()
Definition: lduMatrix.C:168
scalarField & diag()
Definition: lduMatrix.C:186
symGaussSeidelSmoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct from components.
const labelUList & ownerStartAddr() const
Return owner start addressing.
Namespace for OpenFOAM.