Loading...
Searching...
No Matches
nonBlockingGaussSeidelSmoother.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-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
30#include "PrecisionAdaptor.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34namespace Foam
35{
38 lduMatrix::smoother::
39 addsymMatrixConstructorToTable<nonBlockingGaussSeidelSmoother>
41
42 lduMatrix::smoother::
43 addasymMatrixConstructorToTable<nonBlockingGaussSeidelSmoother>
45}
46
47
48// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49
51(
52 const word& fieldName,
53 const lduMatrix& matrix,
54 const FieldField<Field, scalar>& interfaceBouCoeffs,
55 const FieldField<Field, scalar>& interfaceIntCoeffs,
56 const lduInterfaceFieldPtrsList& interfaces,
57 const dictionary& solverControls
58)
59:
60 lduMatrix::smoother
61 (
62 fieldName,
63 matrix,
64 interfaceBouCoeffs,
65 interfaceIntCoeffs,
66 interfaces
67 )
68{
69 // Check that all interface addressing is sorted to be after the
70 // non-interface addressing.
71
72 const label nCells = matrix.diag().size();
73
74 blockStart_ = nCells;
75
76 labelList startCelli(interfaceBouCoeffs.size(), -1);
77 forAll(interfaces, patchi)
78 {
79 if (interfaces.set(patchi))
80 {
81 const labelUList& faceCells = matrix_.lduAddr().patchAddr(patchi);
82
83 blockStart_ = min(blockStart_, min(faceCells));
84 }
85 }
86
87 if (debug)
88 {
89 Pout<< "nonBlockingGaussSeidelSmoother :"
90 << " Starting block on cell " << blockStart_
91 << " out of " << nCells << endl;
92 }
93}
94
95
96// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97
99(
100 const word& fieldName_,
102 const lduMatrix& matrix_,
103 const label blockStart,
104 const solveScalarField& source,
105 const FieldField<Field, scalar>& interfaceBouCoeffs_,
106 const lduInterfaceFieldPtrsList& interfaces_,
107 const direction cmpt,
108 const label nSweeps
109)
110{
111 solveScalar* __restrict__ psiPtr = psi.begin();
112
113 const label nCells = psi.size();
114
115 solveScalarField bPrime(nCells);
116 solveScalar* __restrict__ bPrimePtr = bPrime.begin();
117
118 const scalar* const __restrict__ diagPtr = matrix_.diag().begin();
119 const scalar* const __restrict__ upperPtr =
120 matrix_.upper().begin();
121 const scalar* const __restrict__ lowerPtr =
122 matrix_.lower().begin();
123
124 const label* const __restrict__ uPtr =
125 matrix_.lduAddr().upperAddr().begin();
126
127 const label* const __restrict__ ownStartPtr =
128 matrix_.lduAddr().ownerStartAddr().begin();
129
130 // Parallel boundary initialisation. The parallel boundary is treated
131 // as an effective jacobi interface in the boundary.
132 // Note: there is a change of sign in the coupled
133 // interface update. The reason for this is that the
134 // internal coefficients are all located at the l.h.s. of
135 // the matrix whereas the "implicit" coefficients on the
136 // coupled boundaries are all created as if the
137 // coefficient contribution is of a source-kind (i.e. they
138 // have a sign as if they are on the r.h.s. of the matrix.
139 // To compensate for this, it is necessary to turn the
140 // sign of the contribution.
141
142 for (label sweep=0; sweep<nSweeps; sweep++)
143 {
144 bPrime = source;
145
146 const label startRequest = UPstream::nRequests();
147
148 matrix_.initMatrixInterfaces
149 (
150 false,
151 interfaceBouCoeffs_,
152 interfaces_,
153 psi,
154 bPrime,
155 cmpt
156 );
157
158 solveScalar curPsi;
159 label fStart;
160 label fEnd = ownStartPtr[0];
161
162 for (label celli=0; celli<blockStart; celli++)
163 {
164 // Start and end of this row
165 fStart = fEnd;
166 fEnd = ownStartPtr[celli + 1];
167
168 // Get the accumulated neighbour side
169 curPsi = bPrimePtr[celli];
170
171 // Accumulate the owner product side
172 for (label curFace=fStart; curFace<fEnd; curFace++)
173 {
174 curPsi -= upperPtr[curFace]*psiPtr[uPtr[curFace]];
175 }
176
177 // Finish current psi
178 curPsi /= diagPtr[celli];
179
180 // Distribute the neighbour side using current psi
181 for (label curFace=fStart; curFace<fEnd; curFace++)
182 {
183 bPrimePtr[uPtr[curFace]] -= lowerPtr[curFace]*curPsi;
184 }
185
186 psiPtr[celli] = curPsi;
187 }
188
189 matrix_.updateMatrixInterfaces
190 (
191 false,
192 interfaceBouCoeffs_,
193 interfaces_,
194 psi,
195 bPrime,
196 cmpt,
197 startRequest
198 );
199
200 // Update rest of the cells
201 for (label celli=blockStart; celli < nCells; celli++)
202 {
203 // Start and end of this row
204 fStart = fEnd;
205 fEnd = ownStartPtr[celli + 1];
206
207 // Get the accumulated neighbour side
208 curPsi = bPrimePtr[celli];
209
210 // Accumulate the owner product side
211 for (label curFace=fStart; curFace<fEnd; curFace++)
212 {
213 curPsi -= upperPtr[curFace]*psiPtr[uPtr[curFace]];
214 }
215
216 // Finish current psi
217 curPsi /= diagPtr[celli];
218
219 // Distribute the neighbour side using current psi
220 for (label curFace=fStart; curFace<fEnd; curFace++)
221 {
222 bPrimePtr[uPtr[curFace]] -= lowerPtr[curFace]*curPsi;
223 }
225 psiPtr[celli] = curPsi;
226 }
227 }
228}
229
230
232(
234 const solveScalarField& source,
235 const direction cmpt,
236 const label nSweeps
237) const
238{
239 smooth
240 (
241 fieldName_,
242 psi,
243 matrix_,
244 blockStart_,
245 source,
246 interfaceBouCoeffs_,
248 cmpt,
249 nSweeps
250 );
251}
252
253
255(
257 const scalarField& source,
258 const direction cmpt,
259 const label nSweeps
260) const
261{
262 scalarSmooth
263 (
264 psi,
266 cmpt,
267 nSweeps
268 );
269}
270
271
272// ************************************************************************* //
A const Field/List wrapper with possible data conversion.
A field of fields is a PtrList of fields with reference counting.
Definition FieldField.H:77
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition UListI.H:410
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests).
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
Definition UPtrList.H:366
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Smooth ATC in cells next to a set of patches supplied by type.
Definition faceCells.H:55
virtual const labelUList & patchAddr(const label patchNo) const =0
Return patch to internal addressing given patch number.
const FieldField< Field, scalar > & interfaceIntCoeffs() const noexcept
Definition lduMatrix.H:538
const lduMatrix & matrix_
Definition lduMatrix.H:416
const lduInterfaceFieldPtrsList & interfaces_
Definition lduMatrix.H:419
smoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct for given field name, matrix etc.
const lduInterfaceFieldPtrsList & interfaces() const noexcept
Definition lduMatrix.H:543
const FieldField< Field, scalar > & interfaceBouCoeffs_
Definition lduMatrix.H:417
const lduMatrix & matrix() const noexcept
Definition lduMatrix.H:528
const FieldField< Field, scalar > & interfaceBouCoeffs() const noexcept
Definition lduMatrix.H:533
const word & fieldName() const noexcept
Definition lduMatrix.H:523
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition lduMatrix.H:81
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition lduMatrix.H:769
const scalarField & diag() const
Definition lduMatrix.C:195
Variant of gaussSeidelSmoother that expects processor boundary cells to be sorted last and so can blo...
nonBlockingGaussSeidelSmoother(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.
static void smooth(const word &fieldName, solveScalarField &psi, const lduMatrix &matrix, const label blockStart, const solveScalarField &source, const FieldField< Field, scalar > &interfaceBouCoeffs, const lduInterfaceFieldPtrsList &interfaces, const direction cmpt, const label nSweeps)
Smooth for the given number of sweeps.
virtual void scalarSmooth(solveScalarField &psi, const solveScalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
const volScalarField & psi
Namespace for handling debugging switches.
Definition debug.C:45
void smooth(volScalarField &field, const scalar coeff)
Definition fvcSmooth.C:37
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
lduMatrix::smoother::addasymMatrixConstructorToTable< nonBlockingGaussSeidelSmoother > addnonBlockingGaussSeidelSmootherAsymMatrixConstructorToTable_
Field< solveScalar > solveScalarField
uint8_t direction
Definition direction.H:49
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.
lduMatrix::smoother::addsymMatrixConstructorToTable< nonBlockingGaussSeidelSmoother > addnonBlockingGaussSeidelSmootherSymMatrixConstructorToTable_
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299