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

GaussSeidelSmoother.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 "GaussSeidelSmoother.H"
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     defineTypeNameAndDebug(GaussSeidelSmoother, 0);
00034 
00035     lduMatrix::smoother::addsymMatrixConstructorToTable<GaussSeidelSmoother>
00036         addGaussSeidelSmootherSymMatrixConstructorToTable_;
00037 
00038     lduMatrix::smoother::addasymMatrixConstructorToTable<GaussSeidelSmoother>
00039         addGaussSeidelSmootherAsymMatrixConstructorToTable_;
00040 }
00041 
00042 
00043 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00044 
00045 Foam::GaussSeidelSmoother::GaussSeidelSmoother
00046 (
00047     const word& fieldName,
00048     const lduMatrix& matrix,
00049     const FieldField<Field, scalar>& interfaceBouCoeffs,
00050     const FieldField<Field, scalar>& interfaceIntCoeffs,
00051     const lduInterfaceFieldPtrsList& interfaces
00052 )
00053 :
00054     lduMatrix::smoother
00055     (
00056         fieldName,
00057         matrix,
00058         interfaceBouCoeffs,
00059         interfaceIntCoeffs,
00060         interfaces
00061     )
00062 {}
00063 
00064 
00065 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00066 
00067 void Foam::GaussSeidelSmoother::smooth
00068 (
00069     const word& fieldName_,
00070     scalarField& psi,
00071     const lduMatrix& matrix_,
00072     const scalarField& source,
00073     const FieldField<Field, scalar>& interfaceBouCoeffs_,
00074     const lduInterfaceFieldPtrsList& interfaces_,
00075     const direction cmpt,
00076     const label nSweeps
00077 )
00078 {
00079     register scalar* __restrict__ psiPtr = psi.begin();
00080 
00081     register const label nCells = psi.size();
00082 
00083     scalarField bPrime(nCells);
00084     register scalar* __restrict__ bPrimePtr = bPrime.begin();
00085 
00086     register const scalar* const __restrict__ diagPtr = matrix_.diag().begin();
00087     register const scalar* const __restrict__ upperPtr =
00088         matrix_.upper().begin();
00089     register const scalar* const __restrict__ lowerPtr =
00090         matrix_.lower().begin();
00091 
00092     register const label* const __restrict__ uPtr =
00093         matrix_.lduAddr().upperAddr().begin();
00094 
00095     register const label* const __restrict__ ownStartPtr =
00096         matrix_.lduAddr().ownerStartAddr().begin();
00097 
00098 
00099     // Parallel boundary initialisation.  The parallel boundary is treated
00100     // as an effective jacobi interface in the boundary.
00101     // Note: there is a change of sign in the coupled
00102     // interface update.  The reason for this is that the
00103     // internal coefficients are all located at the l.h.s. of
00104     // the matrix whereas the "implicit" coefficients on the
00105     // coupled boundaries are all created as if the
00106     // coefficient contribution is of a source-kind (i.e. they
00107     // have a sign as if they are on the r.h.s. of the matrix.
00108     // To compensate for this, it is necessary to turn the
00109     // sign of the contribution.
00110 
00111     FieldField<Field, scalar> mBouCoeffs(interfaceBouCoeffs_.size());
00112 
00113     forAll(mBouCoeffs, patchi)
00114     {
00115         if (interfaces_.set(patchi))
00116         {
00117             mBouCoeffs.set(patchi, -interfaceBouCoeffs_[patchi]);
00118         }
00119     }
00120 
00121     for (label sweep=0; sweep<nSweeps; sweep++)
00122     {
00123         bPrime = source;
00124 
00125         matrix_.initMatrixInterfaces
00126         (
00127             mBouCoeffs,
00128             interfaces_,
00129             psi,
00130             bPrime,
00131             cmpt
00132         );
00133 
00134         matrix_.updateMatrixInterfaces
00135         (
00136             mBouCoeffs,
00137             interfaces_,
00138             psi,
00139             bPrime,
00140             cmpt
00141         );
00142 
00143         register scalar curPsi;
00144         register label fStart;
00145         register label fEnd = ownStartPtr[0];
00146 
00147         for (register label cellI=0; cellI<nCells; cellI++)
00148         {
00149             // Start and end of this row
00150             fStart = fEnd;
00151             fEnd = ownStartPtr[cellI + 1];
00152 
00153             // Get the accumulated neighbour side
00154             curPsi = bPrimePtr[cellI];
00155 
00156             // Accumulate the owner product side
00157             for (register label curFace=fStart; curFace<fEnd; curFace++)
00158             {
00159                 curPsi -= upperPtr[curFace]*psiPtr[uPtr[curFace]];
00160             }
00161 
00162             // Finish current psi
00163             curPsi /= diagPtr[cellI];
00164 
00165             // Distribute the neighbour side using current psi
00166             for (register label curFace=fStart; curFace<fEnd; curFace++)
00167             {
00168                 bPrimePtr[uPtr[curFace]] -= lowerPtr[curFace]*curPsi;
00169             }
00170 
00171             psiPtr[cellI] = curPsi;
00172         }
00173     }
00174 }
00175 
00176 
00177 void Foam::GaussSeidelSmoother::smooth
00178 (
00179     scalarField& psi,
00180     const scalarField& source,
00181     const direction cmpt,
00182     const label nSweeps
00183 ) const
00184 {
00185     smooth
00186     (
00187         fieldName_,
00188         psi,
00189         matrix_,
00190         source,
00191         interfaceBouCoeffs_,
00192         interfaces_,
00193         cmpt,
00194         nSweeps
00195     );
00196 }
00197 
00198 
00199 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd