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

FDICPreconditioner.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 "FDICPreconditioner.H"
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineTypeNameAndDebug(FDICPreconditioner, 0);
00034 
00035     lduMatrix::preconditioner::
00036         addsymMatrixConstructorToTable<FDICPreconditioner>
00037         addFDICPreconditionerSymMatrixConstructorToTable_;
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 Foam::FDICPreconditioner::FDICPreconditioner
00044 (
00045     const lduMatrix::solver& sol,
00046     const dictionary&
00047 )
00048 :
00049     lduMatrix::preconditioner(sol),
00050     rD_(sol.matrix().diag()),
00051     rDuUpper_(sol.matrix().upper().size()),
00052     rDlUpper_(sol.matrix().upper().size())
00053 {
00054     scalar* __restrict__ rDPtr = rD_.begin();
00055     scalar* __restrict__ rDuUpperPtr = rDuUpper_.begin();
00056     scalar* __restrict__ rDlUpperPtr = rDlUpper_.begin();
00057 
00058     const label* const __restrict__ uPtr =
00059         solver_.matrix().lduAddr().upperAddr().begin();
00060     const label* const __restrict__ lPtr =
00061         solver_.matrix().lduAddr().lowerAddr().begin();
00062     const scalar* const __restrict__ upperPtr = solver_.matrix().upper().begin();
00063 
00064     register label nCells = rD_.size();
00065     register label nFaces = solver_.matrix().upper().size();
00066 
00067     for (register label face=0; face<nFaces; face++)
00068     {
00069         rDPtr[uPtr[face]] -= sqr(upperPtr[face])/rDPtr[lPtr[face]];
00070     }
00071 
00072     // Generate reciprocal FDIC
00073     for (register label cell=0; cell<nCells; cell++)
00074     {
00075         rDPtr[cell] = 1.0/rDPtr[cell];
00076     }
00077 
00078     for (register label face=0; face<nFaces; face++)
00079     {
00080         rDuUpperPtr[face] = rDPtr[uPtr[face]]*upperPtr[face];
00081         rDlUpperPtr[face] = rDPtr[lPtr[face]]*upperPtr[face];
00082     }
00083 }
00084 
00085 
00086 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00087 
00088 void Foam::FDICPreconditioner::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 
00104     const scalar* const __restrict__ rDuUpperPtr = rDuUpper_.begin();
00105     const scalar* const __restrict__ rDlUpperPtr = rDlUpper_.begin();
00106 
00107     register label nCells = wA.size();
00108     register label nFaces = solver_.matrix().upper().size();
00109     register label nFacesM1 = nFaces - 1;
00110 
00111     for (register label cell=0; cell<nCells; cell++)
00112     {
00113         wAPtr[cell] = rDPtr[cell]*rAPtr[cell];
00114     }
00115 
00116     for (register label face=0; face<nFaces; face++)
00117     {
00118         wAPtr[uPtr[face]] -= rDuUpperPtr[face]*wAPtr[lPtr[face]];
00119     }
00120 
00121     for (register label face=nFacesM1; face>=0; face--)
00122     {
00123         wAPtr[lPtr[face]] -= rDlUpperPtr[face]*wAPtr[uPtr[face]];
00124     }
00125 }
00126 
00127 
00128 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd