DICSmoother.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 -------------------------------------------------------------------------------
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 "DICSmoother.H"
30 #include "DICPreconditioner.H"
31 #include "PrecisionAdaptor.H"
32 #include <algorithm>
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(DICSmoother, 0);
39 
40  lduMatrix::smoother::addsymMatrixConstructorToTable<DICSmoother>
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 :
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 
69  DICPreconditioner::calcReciprocalD(rD_, matrix_);
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  const scalar* const __restrict__ upperPtr = matrix_.upper().begin();
85  const label* const __restrict__ uPtr =
86  matrix_.lduAddr().upperAddr().begin();
87  const label* const __restrict__ lPtr =
88  matrix_.lduAddr().lowerAddr().begin();
89 
90  // Temporary storage for the residual
91  solveScalarField rA(rD_.size());
92  solveScalar* __restrict__ rAPtr = rA.begin();
93 
94  for (label sweep=0; sweep<nSweeps; sweep++)
95  {
96  matrix_.residual
97  (
98  rA,
99  psi,
100  source,
101  interfaceBouCoeffs_,
102  interfaces_,
103  cmpt
104  );
105 
106  forAll(rA, i)
107  {
108  rA[i] *= rD_[i];
109  }
110 
111  const label nFaces = matrix_.upper().size();
112  for (label facei=0; facei<nFaces; facei++)
113  {
114  const label u = uPtr[facei];
115  rAPtr[u] -= rDPtr[u]*upperPtr[facei]*rAPtr[lPtr[facei]];
116  }
117 
118  const label nFacesM1 = nFaces - 1;
119  for (label facei=nFacesM1; facei>=0; facei--)
120  {
121  const label l = lPtr[facei];
122  rAPtr[l] -= rDPtr[l]*upperPtr[facei]*rAPtr[uPtr[facei]];
123  }
124 
125  psi += rA;
126  }
127 }
128 
129 
131 (
133  const solveScalarField& source,
134  const direction cmpt,
135  const label nSweeps
136 ) const
137 {
138  smooth
139  (
140  psi,
142  cmpt,
143  nSweeps
144  );
145 }
146 
147 
148 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::FieldField
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:53
Foam::diag
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
Definition: pointPatchFieldFunctions.H:287
Foam::DICSmoother::scalarSmooth
void scalarSmooth(solveScalarField &psi, const solveScalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
Definition: DICSmoother.C:131
Foam::lduMatrix
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:83
PrecisionAdaptor.H
DICSmoother.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
DICPreconditioner.H
Foam::Field< scalar >
Foam::UPtrList< const lduInterfaceField >
Foam::addDICSmootherSymMatrixConstructorToTable_
lduMatrix::smoother::addsymMatrixConstructorToTable< DICSmoother > addDICSmootherSymMatrixConstructorToTable_
Definition: DICSmoother.C:41
Foam::lduMatrix::smoother
Abstract base-class for lduMatrix smoothers.
Definition: lduMatrix.H:287
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ConstPrecisionAdaptor
A const Field/List wrapper with possible data conversion.
Definition: PrecisionAdaptor.H:57
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::DICSmoother::smooth
void smooth(solveScalarField &psi, const scalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
Definition: DICSmoother.C:76
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
Foam::DICSmoother::DICSmoother
DICSmoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct from matrix components.
Definition: DICSmoother.C:48
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::fvc::sweep
void sweep(volScalarField &field, const volScalarField &alpha, const label nLayers, const scalar alphaDiff=0.2)
Definition: fvcSmooth.C:231
Foam::fvc::smooth
void smooth(volScalarField &field, const scalar coeff)
Definition: fvcSmooth.C:44