FDICSmoother.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 "FDICSmoother.H"
30 #include "DICPreconditioner.H"
31 #include "PrecisionAdaptor.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(FDICSmoother, 0);
38 
39  lduMatrix::smoother::addsymMatrixConstructorToTable<FDICSmoother>
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 (
48  const word& fieldName,
49  const lduMatrix& matrix,
50  const FieldField<Field, scalar>& interfaceBouCoeffs,
51  const FieldField<Field, scalar>& interfaceIntCoeffs,
52  const lduInterfaceFieldPtrsList& interfaces
53 )
54 :
56  (
57  fieldName,
58  matrix,
59  interfaceBouCoeffs,
60  interfaceIntCoeffs,
61  interfaces
62  ),
63  rD_(matrix_.diag().size()),
64  rDuUpper_(matrix_.upper().size()),
65  rDlUpper_(matrix_.upper().size())
66 {
67  solveScalar* __restrict__ rDPtr = rD_.begin();
68  solveScalar* __restrict__ rDuUpperPtr = rDuUpper_.begin();
69  solveScalar* __restrict__ rDlUpperPtr = rDlUpper_.begin();
70 
71  const label* const __restrict__ uPtr =
72  matrix_.lduAddr().upperAddr().begin();
73  const label* const __restrict__ lPtr =
74  matrix_.lduAddr().lowerAddr().begin();
75  const scalar* const __restrict__ upperPtr =
76  matrix_.upper().begin();
77 
78  const label nFaces = matrix_.upper().size();
79 
80  const scalarField& diag = matrix_.diag();
81  std::copy(diag.begin(), diag.end(), rD_.begin());
82 
83  DICPreconditioner::calcReciprocalD(rD_, matrix_);
84 
85  for (label face=0; face<nFaces; face++)
86  {
87  rDuUpperPtr[face] = rDPtr[uPtr[face]]*upperPtr[face];
88  rDlUpperPtr[face] = rDPtr[lPtr[face]]*upperPtr[face];
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 
96 (
98  const scalarField& source,
99  const direction cmpt,
100  const label nSweeps
101 ) const
102 {
103  const solveScalar* const __restrict__ rDuUpperPtr = rDuUpper_.begin();
104  const solveScalar* const __restrict__ rDlUpperPtr = rDlUpper_.begin();
105 
106  const label* const __restrict__ uPtr =
107  matrix_.lduAddr().upperAddr().begin();
108  const label* const __restrict__ lPtr =
109  matrix_.lduAddr().lowerAddr().begin();
110 
111  // Temporary storage for the residual
112  solveScalarField rA(rD_.size());
113  solveScalar* __restrict__ rAPtr = rA.begin();
114 
115  for (label sweep=0; sweep<nSweeps; sweep++)
116  {
117  matrix_.residual
118  (
119  rA,
120  psi,
121  source,
122  interfaceBouCoeffs_,
123  interfaces_,
124  cmpt
125  );
126 
127  forAll(rA, i)
128  {
129  rA[i] *= rD_[i];
130  }
131 
132  const label nFaces = matrix_.upper().size();
133  for (label face=0; face<nFaces; face++)
134  {
135  rAPtr[uPtr[face]] -= rDuUpperPtr[face]*rAPtr[lPtr[face]];
136  }
137 
138  const label nFacesM1 = nFaces - 1;
139  for (label face=nFacesM1; face>=0; face--)
140  {
141  rAPtr[lPtr[face]] -= rDlUpperPtr[face]*rAPtr[uPtr[face]];
142  }
143 
144  psi += rA;
145  }
146 }
147 
148 
150 (
152  const solveScalarField& source,
153  const direction cmpt,
154  const label nSweeps
155 ) const
156 {
157  smooth
158  (
159  psi,
161  cmpt,
162  nSweeps
163  );
164 }
165 
166 
167 // ************************************************************************* //
Foam::FDICSmoother::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: FDICSmoother.C:96
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::lduMatrix
lduMatrix is a general matrix class in which the coefficients are stored as three arrays,...
Definition: lduMatrix.H:83
PrecisionAdaptor.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::addFDICSmootherSymMatrixConstructorToTable_
lduMatrix::smoother::addsymMatrixConstructorToTable< FDICSmoother > addFDICSmootherSymMatrixConstructorToTable_
Definition: FDICSmoother.C:40
DICPreconditioner.H
Foam::Field< scalar >
Foam::UPtrList< const lduInterfaceField >
Foam::lduMatrix::smoother
Abstract base-class for lduMatrix smoothers.
Definition: lduMatrix.H:287
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::FDICSmoother::scalarSmooth
virtual void scalarSmooth(solveScalarField &psi, const solveScalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
Definition: FDICSmoother.C:150
Foam::FDICSmoother::FDICSmoother
FDICSmoother(const word &fieldName, const lduMatrix &matrix, const FieldField< Field, scalar > &interfaceBouCoeffs, const FieldField< Field, scalar > &interfaceIntCoeffs, const lduInterfaceFieldPtrsList &interfaces)
Construct from matrix components.
Definition: FDICSmoother.C:47
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::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
FDICSmoother.H
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