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 )
56 :
57  lduMatrix::smoother
58  (
59  fieldName,
60  matrix,
61  interfaceBouCoeffs,
62  interfaceIntCoeffs,
63  interfaces
64  )
65 {}
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 (
72  const word& fieldName_,
74  const lduMatrix& matrix_,
75  const solveScalarField& source,
76  const FieldField<Field, scalar>& interfaceBouCoeffs_,
77  const lduInterfaceFieldPtrsList& interfaces_,
78  const direction cmpt,
79  const label nSweeps
80 )
81 {
82  solveScalar* __restrict__ psiPtr = psi.begin();
83 
84  const label nCells = psi.size();
85 
86  //solveScalarField bPrime(nCells);
87  solveScalarField& bPrime = matrix_.work(nCells);
88 
89  solveScalar* __restrict__ bPrimePtr = bPrime.begin();
90 
91  const scalar* const __restrict__ diagPtr = matrix_.diag().begin();
92  const scalar* const __restrict__ upperPtr =
93  matrix_.upper().begin();
94  const scalar* const __restrict__ lowerPtr =
95  matrix_.lower().begin();
96 
97  const label* const __restrict__ uPtr =
98  matrix_.lduAddr().upperAddr().begin();
99 
100  const label* const __restrict__ ownStartPtr =
101  matrix_.lduAddr().ownerStartAddr().begin();
102 
103 
104  // Parallel boundary initialisation. The parallel boundary is treated
105  // as an effective jacobi interface in the boundary.
106  // Note: there is a change of sign in the coupled
107  // interface update. The reason for this is that the
108  // internal coefficients are all located at the l.h.s. of
109  // the matrix whereas the "implicit" coefficients on the
110  // coupled boundaries are all created as if the
111  // coefficient contribution is of a source-kind (i.e. they
112  // have a sign as if they are on the r.h.s. of the matrix.
113  // To compensate for this, it is necessary to turn the
114  // sign of the contribution.
115 
116  for (label sweep=0; sweep<nSweeps; sweep++)
117  {
118  bPrime = source;
119 
120  const label startRequest = UPstream::nRequests();
121 
122  matrix_.initMatrixInterfaces
123  (
124  false,
125  interfaceBouCoeffs_,
126  interfaces_,
127  psi,
128  bPrime,
129  cmpt
130  );
131 
132  matrix_.updateMatrixInterfaces
133  (
134  false,
135  interfaceBouCoeffs_,
136  interfaces_,
137  psi,
138  bPrime,
139  cmpt,
140  startRequest
141  );
142 
143  solveScalar psii;
144  label fStart;
145  label fEnd = ownStartPtr[0];
146 
147  for (label celli=0; celli<nCells; celli++)
148  {
149  // Start and end of this row
150  fStart = fEnd;
151  fEnd = ownStartPtr[celli + 1];
152 
153  // Get the accumulated neighbour side
154  psii = bPrimePtr[celli];
155 
156  // Accumulate the owner product side
157  for (label facei=fStart; facei<fEnd; facei++)
158  {
159  psii -= upperPtr[facei]*psiPtr[uPtr[facei]];
160  }
161 
162  // Finish psi for this cell
163  psii /= diagPtr[celli];
164 
165  // Distribute the neighbour side using psi for this cell
166  for (label facei=fStart; facei<fEnd; facei++)
167  {
168  bPrimePtr[uPtr[facei]] -= lowerPtr[facei]*psii;
169  }
170 
171  psiPtr[celli] = psii;
172  }
173  }
174 }
175 
176 
178 (
180  const scalarField& source,
181  const direction cmpt,
182  const label nSweeps
183 ) const
184 {
185  smooth
186  (
187  fieldName_,
188  psi,
189  matrix_,
190  ConstPrecisionAdaptor<solveScalar, scalar>(source),
191  interfaceBouCoeffs_,
192  interfaces_,
193  cmpt,
194  nSweeps
195  );
196 }
197 
198 
200 (
202  const solveScalarField& source,
203  const direction cmpt,
204  const label nSweeps
205 ) const
206 {
207  smooth
208  (
209  fieldName_,
210  psi,
211  matrix_,
212  source,
213  interfaceBouCoeffs_,
214  interfaces_,
215  cmpt,
216  nSweeps
217  );
218 }
219 
220 
221 // ************************************************************************* //
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:116
uint8_t direction
Definition: direction.H:46
Field< solveScalar > solveScalarField
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
const solveScalarField & work() const
Work array.
Definition: lduMatrix.C:443
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
GaussSeidelSmoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct from components.
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:392
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:765
const volScalarField & psi
const labelUList & ownerStartAddr() const
Return owner start addressing.
Namespace for OpenFOAM.