DILUSmoother.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) 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
29#include "DILUSmoother.H"
30#include "DILUPreconditioner.H"
31#include "PrecisionAdaptor.H"
32#include <algorithm>
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
39
40 lduMatrix::smoother::addasymMatrixConstructorToTable<DILUSmoother>
42}
43
44
45// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46
48(
49 const word& fieldName,
50 const lduMatrix& matrix,
51 const FieldField<Field, scalar>& interfaceBouCoeffs,
52 const FieldField<Field, scalar>& interfaceIntCoeffs,
53 const lduInterfaceFieldPtrsList& interfaces
54)
55:
56 lduMatrix::smoother
57 (
58 fieldName,
59 matrix,
60 interfaceBouCoeffs,
61 interfaceIntCoeffs,
62 interfaces
63 ),
64 rD_(matrix_.diag().size())
65{
66 const scalarField& diag = matrix_.diag();
67 std::copy(diag.begin(), diag.end(), rD_.begin());
68
70}
71
72
73// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74
76(
78 const scalarField& source,
79 const direction cmpt,
80 const label nSweeps
81) const
82{
83 const solveScalar* const __restrict__ rDPtr = rD_.begin();
84
85 const label* const __restrict__ uPtr =
86 matrix_.lduAddr().upperAddr().begin();
87 const label* const __restrict__ lPtr =
88 matrix_.lduAddr().lowerAddr().begin();
89
90 const scalar* const __restrict__ upperPtr = matrix_.upper().begin();
91 const scalar* const __restrict__ lowerPtr = matrix_.lower().begin();
92
93 // Temporary storage for the residual
94 solveScalarField rA(rD_.size());
95 solveScalar* __restrict__ rAPtr = rA.begin();
96
97 for (label sweep=0; sweep<nSweeps; sweep++)
98 {
99 matrix_.residual
100 (
101 rA,
102 psi,
103 source,
104 interfaceBouCoeffs_,
105 interfaces_,
106 cmpt
107 );
108
109 forAll(rA, i)
110 {
111 rA[i] *= rD_[i];
112 }
113
114 const label nFaces = matrix_.upper().size();
115 for (label face=0; face<nFaces; face++)
116 {
117 const label u = uPtr[face];
118 rAPtr[u] -= rDPtr[u]*lowerPtr[face]*rAPtr[lPtr[face]];
119 }
120
121 const label nFacesM1 = nFaces - 1;
122 for (label face=nFacesM1; face>=0; face--)
123 {
124 const label l = lPtr[face];
125 rAPtr[l] -= rDPtr[l]*upperPtr[face]*rAPtr[uPtr[face]];
126 }
127
128 psi += rA;
129 }
130}
131
132
134(
136 const solveScalarField& source,
137 const direction cmpt,
138 const label nSweeps
139) const
140{
141 smooth
142 (
143 psi,
145 cmpt,
146 nSweeps
147 );
148}
149
150
151// ************************************************************************* //
A const Field/List wrapper with possible data conversion.
static void calcReciprocalD(solveScalarField &, const lduMatrix &)
Calculate the reciprocal of the preconditioned diagonal.
Simplified diagonal-based incomplete LU smoother for asymmetric matrices.
Definition: DILUSmoother.H:57
void smooth(solveScalarField &psi, const scalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
Definition: DILUSmoother.C:76
void scalarSmooth(solveScalarField &psi, const solveScalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
Definition: DILUSmoother.C:134
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:80
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
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
const lduMatrix & matrix_
Definition: lduMatrix.H:294
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:84
scalarField & diag()
Definition: lduMatrix.C:192
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const volScalarField & psi
const labelList nFaces(UPstream::listGatherValues< label >(aMesh.nFaces()))
Namespace for OpenFOAM.
uint8_t direction
Definition: direction.H:56
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
lduMatrix::smoother::addasymMatrixConstructorToTable< DILUSmoother > addDILUSmootherAsymMatrixConstructorToTable_
Definition: DILUSmoother.C:41
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333