OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

DILUPreconditioner.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "DILUPreconditioner.H"
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineTypeNameAndDebug(DILUPreconditioner, 0);
00034 
00035     lduMatrix::preconditioner::
00036         addasymMatrixConstructorToTable<DILUPreconditioner>
00037         addDILUPreconditionerAsymMatrixConstructorToTable_;
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 Foam::DILUPreconditioner::DILUPreconditioner
00044 (
00045     const lduMatrix::solver& sol,
00046     const dictionary&
00047 )
00048 :
00049     lduMatrix::preconditioner(sol),
00050     rD_(sol.matrix().diag())
00051 {
00052     calcReciprocalD(rD_, sol.matrix());
00053 }
00054 
00055 
00056 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00057 
00058 void Foam::DILUPreconditioner::calcReciprocalD
00059 (
00060     scalarField& rD,
00061     const lduMatrix& matrix
00062 )
00063 {
00064     scalar* __restrict__ rDPtr = rD.begin();
00065 
00066     const label* const __restrict__ uPtr = matrix.lduAddr().upperAddr().begin();
00067     const label* const __restrict__ lPtr = matrix.lduAddr().lowerAddr().begin();
00068 
00069     const scalar* const __restrict__ upperPtr = matrix.upper().begin();
00070     const scalar* const __restrict__ lowerPtr = matrix.lower().begin();
00071 
00072     register label nFaces = matrix.upper().size();
00073     for (register label face=0; face<nFaces; face++)
00074     {
00075         rDPtr[uPtr[face]] -= upperPtr[face]*lowerPtr[face]/rDPtr[lPtr[face]];
00076     }
00077 
00078 
00079     // Calculate the reciprocal of the preconditioned diagonal
00080     register label nCells = rD.size();
00081 
00082     for (register label cell=0; cell<nCells; cell++)
00083     {
00084         rDPtr[cell] = 1.0/rDPtr[cell];
00085     }
00086 }
00087 
00088 
00089 void Foam::DILUPreconditioner::precondition
00090 (
00091     scalarField& wA,
00092     const scalarField& rA,
00093     const direction
00094 ) const
00095 {
00096     scalar* __restrict__ wAPtr = wA.begin();
00097     const scalar* __restrict__ rAPtr = rA.begin();
00098     const scalar* __restrict__ rDPtr = rD_.begin();
00099 
00100     const label* const __restrict__ uPtr =
00101         solver_.matrix().lduAddr().upperAddr().begin();
00102     const label* const __restrict__ lPtr =
00103         solver_.matrix().lduAddr().lowerAddr().begin();
00104     const label* const __restrict__ losortPtr =
00105         solver_.matrix().lduAddr().losortAddr().begin();
00106 
00107     const scalar* const __restrict__ upperPtr =
00108         solver_.matrix().upper().begin();
00109     const scalar* const __restrict__ lowerPtr =
00110         solver_.matrix().lower().begin();
00111 
00112     register label nCells = wA.size();
00113     register label nFaces = solver_.matrix().upper().size();
00114     register label nFacesM1 = nFaces - 1;
00115 
00116     for (register label cell=0; cell<nCells; cell++)
00117     {
00118         wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
00119     }
00120 
00121 
00122     register label sface;
00123 
00124     for (register label face=0; face<nFaces; face++)
00125     {
00126         sface = losortPtr[face];
00127         wAPtr[uPtr[sface]] -=
00128             rDPtr[uPtr[sface]]*lowerPtr[sface]*wAPtr[lPtr[sface]];
00129     }
00130 
00131     for (register label face=nFacesM1; face>=0; face--)
00132     {
00133         wAPtr[lPtr[face]] -=
00134             rDPtr[lPtr[face]]*upperPtr[face]*wAPtr[uPtr[face]];
00135     }
00136 }
00137 
00138 
00139 void Foam::DILUPreconditioner::preconditionT
00140 (
00141     scalarField& wT,
00142     const scalarField& rT,
00143     const direction
00144 ) const
00145 {
00146     scalar* __restrict__ wTPtr = wT.begin();
00147     const scalar* __restrict__ rTPtr = rT.begin();
00148     const scalar* __restrict__ rDPtr = rD_.begin();
00149 
00150     const label* const __restrict__ uPtr =
00151         solver_.matrix().lduAddr().upperAddr().begin();
00152     const label* const __restrict__ lPtr =
00153         solver_.matrix().lduAddr().lowerAddr().begin();
00154     const label* const __restrict__ losortPtr =
00155         solver_.matrix().lduAddr().losortAddr().begin();
00156 
00157     const scalar* const __restrict__ upperPtr =
00158         solver_.matrix().upper().begin();
00159     const scalar* const __restrict__ lowerPtr =
00160         solver_.matrix().lower().begin();
00161 
00162     register label nCells = wT.size();
00163     register label nFaces = solver_.matrix().upper().size();
00164     register label nFacesM1 = nFaces - 1;
00165 
00166     for (register label cell=0; cell<nCells; cell++)
00167     {
00168         wTPtr[cell] = rDPtr[cell]*rTPtr[cell];
00169     }
00170 
00171     for (register label face=0; face<nFaces; face++)
00172     {
00173         wTPtr[uPtr[face]] -=
00174             rDPtr[uPtr[face]]*upperPtr[face]*wTPtr[lPtr[face]];
00175     }
00176 
00177 
00178     register label sface;
00179 
00180     for (register label face=nFacesM1; face>=0; face--)
00181     {
00182         sface = losortPtr[face];
00183         wTPtr[lPtr[sface]] -=
00184             rDPtr[lPtr[sface]]*lowerPtr[sface]*wTPtr[uPtr[sface]];
00185     }
00186 }
00187 
00188 
00189 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd