FDICSmoother.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "FDICSmoother.H"
27 #include "FDICPreconditioner.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(FDICSmoother, 0);
34 
35  lduMatrix::smoother::addsymMatrixConstructorToTable<FDICSmoother>
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 (
44  const word& fieldName,
45  const lduMatrix& matrix,
46  const FieldField<Field, scalar>& interfaceBouCoeffs,
47  const FieldField<Field, scalar>& interfaceIntCoeffs,
48  const lduInterfaceFieldPtrsList& interfaces
49 )
50 :
52  (
53  fieldName,
54  matrix,
55  interfaceBouCoeffs,
56  interfaceIntCoeffs,
57  interfaces
58  ),
59  rD_(matrix_.diag()),
60  rDuUpper_(matrix_.upper().size()),
61  rDlUpper_(matrix_.upper().size())
62 {
63  scalar* __restrict__ rDPtr = rD_.begin();
64  scalar* __restrict__ rDuUpperPtr = rDuUpper_.begin();
65  scalar* __restrict__ rDlUpperPtr = rDlUpper_.begin();
66 
67  const label* const __restrict__ uPtr =
68  matrix_.lduAddr().upperAddr().begin();
69  const label* const __restrict__ lPtr =
70  matrix_.lduAddr().lowerAddr().begin();
71  const scalar* const __restrict__ upperPtr =
72  matrix_.upper().begin();
73 
74  label nCells = rD_.size();
75  label nFaces = matrix_.upper().size();
76 
77  for (label face=0; face<nFaces; face++)
78  {
79  rDPtr[uPtr[face]] -= sqr(upperPtr[face])/rDPtr[lPtr[face]];
80  }
81 
82  // Generate reciprocal FDIC
83  for (label cell=0; cell<nCells; cell++)
84  {
85  rDPtr[cell] = 1.0/rDPtr[cell];
86  }
87 
88  for (label face=0; face<nFaces; face++)
89  {
90  rDuUpperPtr[face] = rDPtr[uPtr[face]]*upperPtr[face];
91  rDlUpperPtr[face] = rDPtr[lPtr[face]]*upperPtr[face];
92  }
93 }
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
99 (
100  scalarField& psi,
101  const scalarField& source,
102  const direction cmpt,
103  const label nSweeps
104 ) const
105 {
106  const scalar* const __restrict__ rDuUpperPtr = rDuUpper_.begin();
107  const scalar* const __restrict__ rDlUpperPtr = rDlUpper_.begin();
108 
109  const label* const __restrict__ uPtr =
110  matrix_.lduAddr().upperAddr().begin();
111  const label* const __restrict__ lPtr =
112  matrix_.lduAddr().lowerAddr().begin();
113 
114  // Temporary storage for the residual
115  scalarField rA(rD_.size());
116  scalar* __restrict__ rAPtr = rA.begin();
117 
118  for (label sweep=0; sweep<nSweeps; sweep++)
119  {
120  matrix_.residual
121  (
122  rA,
123  psi,
124  source,
125  interfaceBouCoeffs_,
126  interfaces_,
127  cmpt
128  );
129 
130  rA *= rD_;
131 
132  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  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 
149 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
lduMatrix::smoother::addsymMatrixConstructorToTable< FDICSmoother > addFDICSmootherSymMatrixConstructorToTable_
Definition: FDICSmoother.C:36
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
dimensionedSymmTensor sqr(const dimensionedVector &dv)
uint8_t direction
Definition: direction.H:45
Generic field type.
Definition: FieldField.H:51
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:43
void sweep(volScalarField &field, const volScalarField &alpha, const label nLayers, const scalar alphaDiff=0.2)
Definition: fvcSmooth.C:222
Abstract base-class for lduMatrix smoothers.
Definition: lduMatrix.H:270
A class for handling words, derived from string.
Definition: word.H:59
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
defineTypeNameAndDebug(combustionModel, 0)
lduMatrix is a general matrix class in which the coefficients are stored as three arrays...
Definition: lduMatrix.H:79
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
void smooth(scalarField &psi, const scalarField &source, const direction cmpt, const label nSweeps) const
Smooth the solution for a given number of sweeps.
Definition: FDICSmoother.C:99
Namespace for OpenFOAM.