GaussSeidelSmoother.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 "GaussSeidelSmoother.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(GaussSeidelSmoother, 0);
33 
34  lduMatrix::smoother::addsymMatrixConstructorToTable<GaussSeidelSmoother>
36 
37  lduMatrix::smoother::addasymMatrixConstructorToTable<GaussSeidelSmoother>
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 psi for this cell
167  psii /= diagPtr[celli];
168 
169  // Distribute the neighbour side using psi for this cell
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 
179  // Restore interfaceBouCoeffs_
180  forAll(mBouCoeffs, patchi)
181  {
182  if (interfaces_.set(patchi))
183  {
184  mBouCoeffs[patchi].negate();
185  }
186  }
187 }
188 
189 
191 (
192  scalarField& psi,
193  const scalarField& source,
194  const direction cmpt,
195  const label nSweeps
196 ) const
197 {
198  smooth
199  (
200  fieldName_,
201  psi,
202  matrix_,
203  source,
204  interfaceBouCoeffs_,
205  interfaces_,
206  cmpt,
207  nSweeps
208  );
209 }
210 
211 
212 // ************************************************************************* //
virtual const labelUList & upperAddr() const =0
Return upper addressing.
unsigned char direction
Definition: direction.H:43
Generic field type.
Definition: FieldField.H:51
const labelUList & ownerStartAddr() const
Return owner start addressing.
scalarField & lower()
Definition: lduMatrix.C:165
lduMatrix::smoother::addsymMatrixConstructorToTable< GaussSeidelSmoother > addGaussSeidelSmootherSymMatrixConstructorToTable_
A class for handling words, derived from string.
Definition: word.H:59
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
void sweep(volScalarField &field, const volScalarField &alpha, const label nLayers, const scalar alphaDiff=0.2)
Definition: fvcSmooth.C:222
Namespace for OpenFOAM.
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:550
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.
Abstract base-class for lduMatrix smoothers.
Definition: lduMatrix.H:265
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 is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:77
#define forAll(list, i)
Definition: UList.H:421
label patchi
GaussSeidelSmoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct from components.
scalarField & diag()
Definition: lduMatrix.C:183
bool set(const label) const
Is element set.
Definition: UPtrListI.H:80
void negate()
Negate this field.
Definition: FieldField.C:224
lduMatrix::smoother::addasymMatrixConstructorToTable< GaussSeidelSmoother > addGaussSeidelSmootherAsymMatrixConstructorToTable_
scalarField & upper()
Definition: lduMatrix.C:194
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.
void smooth(volScalarField &field, const scalar coeff)
Definition: fvcSmooth.C:35
defineTypeNameAndDebug(combustionModel, 0)