Loading...
Searching...
No Matches
symGaussSeidelSmoother.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) 2012-2015 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 * * * * * * * * * * * * * //
33
34namespace Foam
37
38 lduMatrix::smoother::addsymMatrixConstructorToTable<symGaussSeidelSmoother>
40
41 lduMatrix::smoother::addasymMatrixConstructorToTable<symGaussSeidelSmoother>
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,
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
124 (
125 false,
126 interfaceBouCoeffs_,
127 interfaces_,
128 psi,
129 bPrime,
130 cmpt
131 );
132
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 current psi
164 psii /= diagPtr[celli];
165
166 // Distribute the neighbour side using current psi
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 fStart = ownStartPtr[nCells];
176
177 for (label celli=nCells-1; celli>=0; celli--)
178 {
179 // Start and end of this row
180 fEnd = fStart;
181 fStart = ownStartPtr[celli];
182
183 // Get the accumulated neighbour side
184 psii = bPrimePtr[celli];
185
186 // Accumulate the owner product side
187 for (label facei=fStart; facei<fEnd; facei++)
188 {
189 psii -= upperPtr[facei]*psiPtr[uPtr[facei]];
190 }
191
192 // Note: do not need to distribute the neighbour side
193 // since these will not be revisited
194
195 // Finish psi for this cell
196 psii /= diagPtr[celli];
198 psiPtr[celli] = psii;
199 }
200 }
201}
202
203
205(
207 const solveScalarField& source,
208 const direction cmpt,
209 const label nSweeps
210) const
211{
212 smooth
213 (
214 fieldName_,
215 psi,
216 matrix_,
217 source,
218 interfaceBouCoeffs_,
220 cmpt,
221 nSweeps
222 );
223}
224
225
227(
229 const scalarField& source,
230 const direction cmpt,
231 const label nSweeps
232) const
233{
234 scalarSmooth
235 (
236 psi,
238 cmpt,
239 nSweeps
240 );
241}
242
243
244// ************************************************************************* //
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).
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const labelUList & ownerStartAddr() const
Return owner start addressing.
virtual const labelUList & upperAddr() const =0
Return upper addressing.
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
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 & upper() const
Definition lduMatrix.C:235
const scalarField & lower() const
Definition lduMatrix.C:306
const solveScalarField & work() const
Work array.
Definition lduMatrix.C:443
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.
A lduMatrix::smoother for symmetric Gauss-Seidel.
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.
symGaussSeidelSmoother(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.
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
void smooth(volScalarField &field, const scalar coeff)
Definition fvcSmooth.C:37
Namespace for OpenFOAM.
lduMatrix::smoother::addasymMatrixConstructorToTable< symGaussSeidelSmoother > addsymGaussSeidelSmootherAsymMatrixConstructorToTable_
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Field< solveScalar > solveScalarField
uint8_t direction
Definition direction.H:49
lduMatrix::smoother::addsymMatrixConstructorToTable< symGaussSeidelSmoother > addsymGaussSeidelSmootherSymMatrixConstructorToTable_
UPtrList< const lduInterfaceField > lduInterfaceFieldPtrsList
List of coupled interface fields to be used in coupling.