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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2017-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 "GaussSeidelSmoother.H"
30 #include "PrecisionAdaptor.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
37 
38  lduMatrix::smoother::addsymMatrixConstructorToTable<GaussSeidelSmoother>
40 
41  lduMatrix::smoother::addasymMatrixConstructorToTable<GaussSeidelSmoother>
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 (
50  const word& fieldName,
51  const lduMatrix& matrix,
52  const FieldField<Field, scalar>& interfaceBouCoeffs,
53  const FieldField<Field, scalar>& interfaceIntCoeffs,
54  const lduInterfaceFieldPtrsList& interfaces,
55  const dictionary& solverControls
56 )
57 :
58  lduMatrix::smoother
59  (
60  fieldName,
61  matrix,
62  interfaceBouCoeffs,
63  interfaceIntCoeffs,
64  interfaces
65  )
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
72 (
73  const word& fieldName_,
75  const lduMatrix& matrix_,
76  const solveScalarField& source,
77  const FieldField<Field, scalar>& interfaceBouCoeffs_,
78  const lduInterfaceFieldPtrsList& interfaces_,
79  const direction cmpt,
80  const label nSweeps
81 )
82 {
83  solveScalar* __restrict__ psiPtr = psi.begin();
84 
85  const label nCells = psi.size();
86 
87  //solveScalarField bPrime(nCells);
88  solveScalarField& bPrime = matrix_.work(nCells);
89 
90  solveScalar* __restrict__ bPrimePtr = bPrime.begin();
91 
92  const scalar* const __restrict__ diagPtr = matrix_.diag().begin();
93  const scalar* const __restrict__ upperPtr =
94  matrix_.upper().begin();
95  const scalar* const __restrict__ lowerPtr =
96  matrix_.lower().begin();
97 
98  const label* const __restrict__ uPtr =
99  matrix_.lduAddr().upperAddr().begin();
100 
101  const label* const __restrict__ ownStartPtr =
102  matrix_.lduAddr().ownerStartAddr().begin();
103 
104 
105  // Parallel boundary initialisation. The parallel boundary is treated
106  // as an effective jacobi interface in the boundary.
107  // Note: there is a change of sign in the coupled
108  // interface update. The reason for this is that the
109  // internal coefficients are all located at the l.h.s. of
110  // the matrix whereas the "implicit" coefficients on the
111  // coupled boundaries are all created as if the
112  // coefficient contribution is of a source-kind (i.e. they
113  // have a sign as if they are on the r.h.s. of the matrix.
114  // To compensate for this, it is necessary to turn the
115  // sign of the contribution.
116 
117  for (label sweep=0; sweep<nSweeps; sweep++)
118  {
119  bPrime = source;
120 
121  const label startRequest = UPstream::nRequests();
122 
123  matrix_.initMatrixInterfaces
124  (
125  false,
126  interfaceBouCoeffs_,
127  interfaces_,
128  psi,
129  bPrime,
130  cmpt
131  );
132 
133  matrix_.updateMatrixInterfaces
134  (
135  false,
136  interfaceBouCoeffs_,
137  interfaces_,
138  psi,
139  bPrime,
140  cmpt,
141  startRequest
142  );
143 
144  solveScalar psii;
145  label fStart;
146  label fEnd = ownStartPtr[0];
147 
148  for (label celli=0; celli<nCells; celli++)
149  {
150  // Start and end of this row
151  fStart = fEnd;
152  fEnd = ownStartPtr[celli + 1];
153 
154  // Get the accumulated neighbour side
155  psii = bPrimePtr[celli];
156 
157  // Accumulate the owner product side
158  for (label facei=fStart; facei<fEnd; facei++)
159  {
160  psii -= upperPtr[facei]*psiPtr[uPtr[facei]];
161  }
162 
163  // Finish psi for this cell
164  psii /= diagPtr[celli];
165 
166  // Distribute the neighbour side using psi for this cell
167  for (label facei=fStart; facei<fEnd; facei++)
168  {
169  bPrimePtr[uPtr[facei]] -= lowerPtr[facei]*psii;
170  }
171 
172  psiPtr[celli] = psii;
173  }
174  }
175 }
176 
177 
179 (
181  const scalarField& source,
182  const direction cmpt,
183  const label nSweeps
184 ) const
185 {
186  smooth
187  (
188  fieldName_,
189  psi,
190  matrix_,
191  ConstPrecisionAdaptor<solveScalar, scalar>(source),
192  interfaceBouCoeffs_,
193  interfaces_,
194  cmpt,
195  nSweeps
196  );
197 }
198 
199 
201 (
203  const solveScalarField& source,
204  const direction cmpt,
205  const label nSweeps
206 ) const
207 {
208  smooth
209  (
210  fieldName_,
211  psi,
212  matrix_,
213  source,
214  interfaceBouCoeffs_,
215  interfaces_,
216  cmpt,
217  nSweeps
218  );
219 }
220 
221 
222 // ************************************************************************* //
const scalarField & diag() const
Definition: lduMatrix.C:195
virtual void scalarSmooth(solveScalarField &psi, const solveScalarField &Source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
uint8_t direction
Definition: direction.H:46
Field< solveScalar > solveScalarField
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
const solveScalarField & work() const
Work array.
Definition: lduMatrix.C:443
GaussSeidelSmoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces, const dictionary &solverControls)
Construct from components.
A lduMatrix::smoother for Gauss-Seidel.
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
void smooth(volScalarField &field, const scalar coeff)
Definition: fvcSmooth.C:37
void sweep(volScalarField &field, const volScalarField &alpha, const label nLayers, const scalar alphaDiff=0.2)
Definition: fvcSmooth.C:224
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual const labelUList & upperAddr() const =0
Return upper addressing.
void updateMatrixInterfaces(const bool add, const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const solveScalarField &psiif, solveScalarField &result, const direction cmpt, const label startRequest) const
Update interfaced interfaces for matrix operations.
void initMatrixInterfaces(const bool add, const FieldField< Field, scalar > &interfaceCoeffs, const lduInterfaceFieldPtrsList &interfaces, const solveScalarField &psiif, solveScalarField &result, const direction cmpt) const
Initialise the update of interfaced interfaces for matrix operations.
const scalarField & lower() const
Definition: lduMatrix.C:306
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:385
lduMatrix::smoother::addasymMatrixConstructorToTable< GaussSeidelSmoother > addGaussSeidelSmootherAsymMatrixConstructorToTable_
defineTypeNameAndDebug(combustionModel, 0)
static void smooth(const word &fieldName, solveScalarField &psi, const lduMatrix &matrix, const solveScalarField &source, const FieldField< Field, scalar > &interfaceBouCoeffs, const lduInterfaceFieldPtrsList &interfaces, const direction cmpt, const label nSweeps)
Smooth for the given number of sweeps.
lduMatrix::smoother::addsymMatrixConstructorToTable< GaussSeidelSmoother > addGaussSeidelSmootherSymMatrixConstructorToTable_
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
const volScalarField & psi
const labelUList & ownerStartAddr() const
Return owner start addressing.
Namespace for OpenFOAM.