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

DICPreconditioner.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 "DICPreconditioner.H"
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineTypeNameAndDebug(DICPreconditioner, 0);
00034 
00035     lduMatrix::preconditioner::
00036         addsymMatrixConstructorToTable<DICPreconditioner>
00037         addDICPreconditionerSymMatrixConstructorToTable_;
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 Foam::DICPreconditioner::DICPreconditioner
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::DICPreconditioner::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     const scalar* const __restrict__ upperPtr = matrix.upper().begin();
00069 
00070     // Calculate the DIC diagonal
00071     register const label nFaces = matrix.upper().size();
00072     for (register label face=0; face<nFaces; face++)
00073     {
00074         rDPtr[uPtr[face]] -= upperPtr[face]*upperPtr[face]/rDPtr[lPtr[face]];
00075     }
00076 
00077 
00078     // Calculate the reciprocal of the preconditioned diagonal
00079     register const label nCells = rD.size();
00080 
00081     for (register label cell=0; cell<nCells; cell++)
00082     {
00083         rDPtr[cell] = 1.0/rDPtr[cell];
00084     }
00085 }
00086 
00087 
00088 void Foam::DICPreconditioner::precondition
00089 (
00090     scalarField& wA,
00091     const scalarField& rA,
00092     const direction
00093 ) const
00094 {
00095     scalar* __restrict__ wAPtr = wA.begin();
00096     const scalar* __restrict__ rAPtr = rA.begin();
00097     const scalar* __restrict__ rDPtr = rD_.begin();
00098 
00099     const label* const __restrict__ uPtr =
00100         solver_.matrix().lduAddr().upperAddr().begin();
00101     const label* const __restrict__ lPtr =
00102         solver_.matrix().lduAddr().lowerAddr().begin();
00103     const scalar* const __restrict__ upperPtr = solver_.matrix().upper().begin();
00104 
00105     register label nCells = wA.size();
00106     register label nFaces = solver_.matrix().upper().size();
00107     register label nFacesM1 = nFaces - 1;
00108 
00109     for (register label cell=0; cell<nCells; cell++)
00110     {
00111         wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
00112     }
00113 
00114     for (register label face=0; face<nFaces; face++)
00115     {
00116         wAPtr[uPtr[face]] -= rDPtr[uPtr[face]]*upperPtr[face]*wAPtr[lPtr[face]];
00117     }
00118 
00119     for (register label face=nFacesM1; face>=0; face--)
00120     {
00121         wAPtr[lPtr[face]] -= rDPtr[lPtr[face]]*upperPtr[face]*wAPtr[uPtr[face]];
00122     }
00123 }
00124 
00125 
00126 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd