TGaussSeidelSmoother.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 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
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
33template<class Type, class DType, class LUType>
35(
36 const word& fieldName,
38)
39:
40 LduMatrix<Type, DType, LUType>::smoother
41 (
42 fieldName,
43 matrix
44 ),
45 rD_(matrix.diag().size())
46{
47 const label nCells = matrix.diag().size();
48 const DType* const __restrict__ diagPtr = matrix.diag().begin();
49 DType* __restrict__ rDPtr = rD_.begin();
50
51 for (label celli=0; celli<nCells; celli++)
52 {
53 rDPtr[celli] = inv(diagPtr[celli]);
54 }
55}
56
57
58// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59
60template<class Type, class DType, class LUType>
62(
63 const word& fieldName_,
65 const LduMatrix<Type, DType, LUType>& matrix_,
66 const Field<DType>& rD_,
67 const label nSweeps
68)
69{
70 Type* __restrict__ psiPtr = psi.begin();
71
72 const label nCells = psi.size();
73
74 Field<Type> bPrime(nCells);
75 Type* __restrict__ bPrimePtr = bPrime.begin();
76
77 const DType* const __restrict__ rDPtr = rD_.begin();
78
79 const LUType* const __restrict__ upperPtr =
80 matrix_.upper().begin();
81
82 const LUType* const __restrict__ lowerPtr =
83 matrix_.lower().begin();
84
85 const label* const __restrict__ uPtr =
86 matrix_.lduAddr().upperAddr().begin();
87
88 const label* const __restrict__ ownStartPtr =
89 matrix_.lduAddr().ownerStartAddr().begin();
90
91
92 // Parallel boundary initialisation. The parallel boundary is treated
93 // as an effective jacobi interface in the boundary.
94 // Note: there is a change of sign in the coupled
95 // interface update to add the contibution to the r.h.s.
96
97 for (label sweep=0; sweep<nSweeps; sweep++)
98 {
99 bPrime = matrix_.source();
100
102 (
103 false,
104 matrix_.interfacesUpper(),
105 psi,
106 bPrime
107 );
108
110 (
111 false,
112 matrix_.interfacesUpper(),
113 psi,
114 bPrime
115 );
116
117 Type curPsi;
118 label fStart;
119 label fEnd = ownStartPtr[0];
120
121 for (label celli=0; celli<nCells; celli++)
122 {
123 // Start and end of this row
124 fStart = fEnd;
125 fEnd = ownStartPtr[celli + 1];
126
127 // Get the accumulated neighbour side
128 curPsi = bPrimePtr[celli];
129
130 // Accumulate the owner product side
131 for (label curFace=fStart; curFace<fEnd; curFace++)
132 {
133 curPsi -= dot(upperPtr[curFace], psiPtr[uPtr[curFace]]);
134 }
135
136 // Finish current psi
137 curPsi = dot(rDPtr[celli], curPsi);
138
139 // Distribute the neighbour side using current psi
140 for (label curFace=fStart; curFace<fEnd; curFace++)
141 {
142 bPrimePtr[uPtr[curFace]] -= dot(lowerPtr[curFace], curPsi);
143 }
144
145 psiPtr[celli] = curPsi;
146 }
147 }
148}
149
150
151template<class Type, class DType, class LUType>
153(
155 const label nSweeps
156) const
157{
158 smooth(this->fieldName_, psi, this->matrix_, rD_, nSweeps);
159}
160
161
162// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
const LduMatrix< Type, DType, LUType > & matrix() const noexcept
Definition: LduMatrix.H:346
LduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: LduMatrix.H:88
FieldField< Field, LUType > & interfacesUpper()
Definition: LduMatrix.H:529
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: LduMatrix.H:498
Field< Type > & source()
Definition: LduMatrix.C:250
void updateMatrixInterfaces(const bool add, const FieldField< Field, LUType > &interfaceCoeffs, const Field< Type > &psiif, Field< Type > &result) const
Update interfaced interfaces for matrix operations.
Field< LUType > & upper()
Definition: LduMatrix.C:204
void initMatrixInterfaces(const bool add, const FieldField< Field, LUType > &interfaceCoeffs, const Field< Type > &psiif, Field< Type > &result) const
Initialise the update of interfaced interfaces.
Field< LUType > & lower()
Definition: LduMatrix.C:227
Foam::TGaussSeidelSmoother.
static void smooth(const word &fieldName, Field< Type > &psi, const LduMatrix< Type, DType, LUType > &matrix, const Field< DType > &rD, const label nSweeps)
Smooth for the given number of sweeps.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:329
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
const labelUList & ownerStartAddr() const
Return owner start addressing.
virtual const labelUList & upperAddr() const =0
Return upper addressing.
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & psi
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)