FDICPreconditioner.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 "FDICPreconditioner.H"
30 #include <algorithm>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(FDICPreconditioner, 0);
37 
38  lduMatrix::preconditioner::
39  addsymMatrixConstructorToTable<FDICPreconditioner>
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 Foam::FDICPreconditioner::FDICPreconditioner
47 (
48  const lduMatrix::solver& sol,
49  const dictionary&
50 )
51 :
53  rD_(sol.matrix().diag().size()),
54  rDuUpper_(sol.matrix().upper().size()),
55  rDlUpper_(sol.matrix().upper().size())
56 {
57  const scalarField& diag = sol.matrix().diag();
58  std::copy(diag.begin(), diag.end(), rD_.begin());
59 
60  solveScalar* __restrict__ rDPtr = rD_.begin();
61  solveScalar* __restrict__ rDuUpperPtr = rDuUpper_.begin();
62  solveScalar* __restrict__ rDlUpperPtr = rDlUpper_.begin();
63 
64  const label* const __restrict__ uPtr =
65  solver_.matrix().lduAddr().upperAddr().begin();
66  const label* const __restrict__ lPtr =
67  solver_.matrix().lduAddr().lowerAddr().begin();
68  const scalar* const __restrict__ upperPtr =
69  solver_.matrix().upper().begin();
70 
71  const label nCells = rD_.size();
72  const label nFaces = solver_.matrix().upper().size();
73 
74  for (label face=0; face<nFaces; face++)
75  {
76  rDPtr[uPtr[face]] -= sqr(upperPtr[face])/rDPtr[lPtr[face]];
77  }
78 
79  // Generate reciprocal FDIC
80  for (label cell=0; cell<nCells; cell++)
81  {
82  rDPtr[cell] = 1.0/rDPtr[cell];
83  }
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 (
97  solveScalarField& wA,
98  const solveScalarField& rA,
99  const direction
100 ) const
101 {
102  solveScalar* __restrict__ wAPtr = wA.begin();
103  const solveScalar* __restrict__ rAPtr = rA.begin();
104  const solveScalar* __restrict__ rDPtr = rD_.begin();
105 
106  const label* const __restrict__ uPtr =
107  solver_.matrix().lduAddr().upperAddr().begin();
108  const label* const __restrict__ lPtr =
109  solver_.matrix().lduAddr().lowerAddr().begin();
110 
111  const solveScalar* const __restrict__ rDuUpperPtr = rDuUpper_.begin();
112  const solveScalar* const __restrict__ rDlUpperPtr = rDlUpper_.begin();
113 
114  const label nCells = wA.size();
115  const label nFaces = solver_.matrix().upper().size();
116  const label nFacesM1 = nFaces - 1;
117 
118  for (label cell=0; cell<nCells; cell++)
119  {
120  wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
121  }
122 
123  for (label face=0; face<nFaces; face++)
124  {
125  wAPtr[uPtr[face]] -= rDuUpperPtr[face]*wAPtr[lPtr[face]];
126  }
127 
128  for (label face=nFacesM1; face>=0; face--)
129  {
130  wAPtr[lPtr[face]] -= rDlUpperPtr[face]*wAPtr[uPtr[face]];
131  }
132 }
133 
134 
135 // ************************************************************************* //
Foam::addFDICPreconditionerSymMatrixConstructorToTable_
lduMatrix::preconditioner::addsymMatrixConstructorToTable< FDICPreconditioner > addFDICPreconditionerSymMatrixConstructorToTable_
Definition: FDICPreconditioner.C:40
Foam::diag
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
Definition: pointPatchFieldFunctions.H:287
Foam::lduMatrix::upper
scalarField & upper()
Definition: lduMatrix.C:203
FDICPreconditioner.H
Foam::lduMatrix::solver
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:98
Foam::Field< scalar >
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::lduMatrix::diag
scalarField & diag()
Definition: lduMatrix.C:192
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
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
Foam::FDICPreconditioner::precondition
virtual void precondition(solveScalarField &wA, const solveScalarField &rA, const direction cmpt=0) const
Return wA the preconditioned form of residual rA.
Definition: FDICPreconditioner.C:96
Foam::lduMatrix::preconditioner
Abstract base-class for lduMatrix preconditioners.
Definition: lduMatrix.H:433
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cell
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:54
Foam::lduMatrix::solver::matrix
const lduMatrix & matrix() const noexcept
Definition: lduMatrix.H:233