diagonalPreconditioner.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "diagonalPreconditioner.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
35 
36  lduMatrix::preconditioner::
37  addsymMatrixConstructorToTable<diagonalPreconditioner>
39 
40  lduMatrix::preconditioner::
41  addasymMatrixConstructorToTable<diagonalPreconditioner>
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 Foam::diagonalPreconditioner::diagonalPreconditioner
49 (
50  const lduMatrix::solver& sol,
51  const dictionary&
52 )
53 :
54  lduMatrix::preconditioner(sol),
55  rD(sol.matrix().diag().size())
56 {
57  solveScalar* __restrict__ rDPtr = rD.begin();
58  const scalar* __restrict__ DPtr = solver_.matrix().diag().begin();
59 
60  const label nCells = rD.size();
61 
62  // Generate reciprocal diagonal
63  for (label cell=0; cell<nCells; cell++)
64  {
65  rDPtr[cell] = 1.0/DPtr[cell];
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
73 (
74  solveScalarField& wA,
75  const solveScalarField& rA,
76  const direction
77 ) const
78 {
79  solveScalar* __restrict__ wAPtr = wA.begin();
80  const solveScalar* __restrict__ rAPtr = rA.begin();
81  const solveScalar* __restrict__ rDPtr = rD.begin();
82 
83  const label nCells = wA.size();
84 
85  for (label cell=0; cell<nCells; cell++)
86  {
87  wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
88  }
89 }
90 
91 
92 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
virtual void precondition(solveScalarField &wA, const solveScalarField &rA, const direction cmpt=0) const
Return wA the preconditioned form of residual rA.
uint8_t direction
Definition: direction.H:46
Field< solveScalar > solveScalarField
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const solver & solver_
Reference to the base-solver this preconditioner is used with.
Definition: lduMatrix.H:558
const lduMatrix & matrix() const noexcept
Definition: lduMatrix.H:306
lduMatrix::preconditioner::addasymMatrixConstructorToTable< diagonalPreconditioner > adddiagonalPreconditionerAsymMatrixConstructorToTable_
void diag(pointPatchField< vector > &, const pointPatchField< tensor > &)
Abstract base-class for lduMatrix solvers.
Definition: lduMatrix.H:129
Diagonal preconditioner for both symmetric and asymmetric matrices.
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:391
defineTypeNameAndDebug(combustionModel, 0)
lduMatrix::preconditioner::addsymMatrixConstructorToTable< diagonalPreconditioner > adddiagonalPreconditionerSymMatrixConstructorToTable_
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:53
scalarField & diag()
Definition: lduMatrix.C:197
Namespace for OpenFOAM.