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

lduMatrixOperations.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 Description
00026     lduMatrix member operations.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "lduMatrix.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 void Foam::lduMatrix::sumDiag()
00035 {
00036     const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
00037     const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
00038     scalarField& Diag = diag();
00039 
00040     const unallocLabelList& l = lduAddr().lowerAddr();
00041     const unallocLabelList& u = lduAddr().upperAddr();
00042 
00043     for (register label face=0; face<l.size(); face++)
00044     {
00045         Diag[l[face]] += Lower[face];
00046         Diag[u[face]] += Upper[face];
00047     }
00048 }
00049 
00050 
00051 void Foam::lduMatrix::negSumDiag()
00052 {
00053     const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
00054     const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
00055     scalarField& Diag = diag();
00056 
00057     const unallocLabelList& l = lduAddr().lowerAddr();
00058     const unallocLabelList& u = lduAddr().upperAddr();
00059 
00060     for (register label face=0; face<l.size(); face++)
00061     {
00062         Diag[l[face]] -= Lower[face];
00063         Diag[u[face]] -= Upper[face];
00064     }
00065 }
00066 
00067 
00068 void Foam::lduMatrix::sumMagOffDiag
00069 (
00070     scalarField& sumOff
00071 ) const
00072 {
00073     const scalarField& Lower = const_cast<const lduMatrix&>(*this).lower();
00074     const scalarField& Upper = const_cast<const lduMatrix&>(*this).upper();
00075 
00076     const unallocLabelList& l = lduAddr().lowerAddr();
00077     const unallocLabelList& u = lduAddr().upperAddr();
00078 
00079     for (register label face = 0; face < l.size(); face++)
00080     {
00081         sumOff[u[face]] += mag(Lower[face]);
00082         sumOff[l[face]] += mag(Upper[face]);
00083     }
00084 }
00085 
00086 
00087 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00088 
00089 void Foam::lduMatrix::operator=(const lduMatrix& A)
00090 {
00091     if (this == &A)
00092     {
00093         FatalError
00094             << "lduMatrix::operator=(const lduMatrix&) : "
00095             << "attempted assignment to self"
00096             << abort(FatalError);
00097     }
00098 
00099     if (A.lowerPtr_)
00100     {
00101         lower() = A.lower();
00102     }
00103     else if (lowerPtr_)
00104     {
00105         delete lowerPtr_;
00106         lowerPtr_ = NULL;
00107     }
00108 
00109     if (A.upperPtr_)
00110     {
00111         upper() = A.upper();
00112     }
00113     else if (upperPtr_)
00114     {
00115         delete upperPtr_;
00116         upperPtr_ = NULL;
00117     }
00118 
00119     if (A.diagPtr_)
00120     {
00121         diag() = A.diag();
00122     }
00123 }
00124 
00125 
00126 void Foam::lduMatrix::negate()
00127 {
00128     if (lowerPtr_)
00129     {
00130         lowerPtr_->negate();
00131     }
00132 
00133     if (upperPtr_)
00134     {
00135         upperPtr_->negate();
00136     }
00137 
00138     if (diagPtr_)
00139     {
00140         diagPtr_->negate();
00141     }
00142 }
00143 
00144 
00145 void Foam::lduMatrix::operator+=(const lduMatrix& A)
00146 {
00147     if (A.diagPtr_)
00148     {
00149         diag() += A.diag();
00150     }
00151 
00152     if (symmetric() && A.symmetric())
00153     {
00154         upper() += A.upper();
00155     }
00156     else if (symmetric() && A.asymmetric())
00157     {
00158         if (upperPtr_)
00159         {
00160             lower();
00161         }
00162         else
00163         {
00164             upper();
00165         }
00166 
00167         upper() += A.upper();
00168         lower() += A.lower();
00169     }
00170     else if (asymmetric() && A.symmetric())
00171     {
00172         if (A.upperPtr_)
00173         {
00174             lower() += A.upper();
00175             upper() += A.upper();
00176         }
00177         else
00178         {
00179             lower() += A.lower();
00180             upper() += A.lower();
00181         }
00182 
00183     }
00184     else if (asymmetric() && A.asymmetric())
00185     {
00186         lower() += A.lower();
00187         upper() += A.upper();
00188     }
00189     else if (diagonal())
00190     {
00191         if (A.upperPtr_)
00192         {
00193             upper() = A.upper();
00194         }
00195 
00196         if (A.lowerPtr_)
00197         {
00198             lower() = A.lower();
00199         }
00200     }
00201     else if (A.diagonal())
00202     {
00203     }
00204     else
00205     {
00206         FatalErrorIn("lduMatrix::operator+=(const lduMatrix& A)")
00207             << "Unknown matrix type combination"
00208             << abort(FatalError);
00209     }
00210 }
00211 
00212 
00213 void Foam::lduMatrix::operator-=(const lduMatrix& A)
00214 {
00215     if (A.diagPtr_)
00216     {
00217         diag() -= A.diag();
00218     }
00219 
00220     if (symmetric() && A.symmetric())
00221     {
00222         upper() -= A.upper();
00223     }
00224     else if (symmetric() && A.asymmetric())
00225     {
00226         if (upperPtr_)
00227         {
00228             lower();
00229         }
00230         else
00231         {
00232             upper();
00233         }
00234 
00235         upper() -= A.upper();
00236         lower() -= A.lower();
00237     }
00238     else if (asymmetric() && A.symmetric())
00239     {
00240         if (A.upperPtr_)
00241         {
00242             lower() -= A.upper();
00243             upper() -= A.upper();
00244         }
00245         else
00246         {
00247             lower() -= A.lower();
00248             upper() -= A.lower();
00249         }
00250 
00251     }
00252     else if (asymmetric() && A.asymmetric())
00253     {
00254         lower() -= A.lower();
00255         upper() -= A.upper();
00256     }
00257     else if (diagonal())
00258     {
00259         if (A.upperPtr_)
00260         {
00261             upper() = -A.upper();
00262         }
00263 
00264         if (A.lowerPtr_)
00265         {
00266             lower() = -A.lower();
00267         }
00268     }
00269     else if (A.diagonal())
00270     {
00271     }
00272     else
00273     {
00274         FatalErrorIn("lduMatrix::operator-=(const lduMatrix& A)")
00275             << "Unknown matrix type combination"
00276             << abort(FatalError);
00277     }
00278 }
00279 
00280 
00281 void Foam::lduMatrix::operator*=(const scalarField& sf)
00282 {
00283     if (diagPtr_)
00284     {
00285         *diagPtr_ *= sf;
00286     }
00287 
00288     if (upperPtr_)
00289     {
00290         scalarField& upper = *upperPtr_;
00291 
00292         const unallocLabelList& l = lduAddr().lowerAddr();
00293 
00294         for (register label face=0; face<upper.size(); face++)
00295         {
00296             upper[face] *= sf[l[face]];
00297         }
00298     }
00299 
00300     if (lowerPtr_)
00301     {
00302         scalarField& lower = *lowerPtr_;
00303 
00304         const unallocLabelList& u = lduAddr().upperAddr();
00305 
00306         for (register label face=0; face<lower.size(); face++)
00307         {
00308             lower[face] *= sf[u[face]];
00309         }
00310     }
00311 }
00312 
00313 
00314 void Foam::lduMatrix::operator*=(scalar s)
00315 {
00316     if (diagPtr_)
00317     {
00318         *diagPtr_ *= s;
00319     }
00320 
00321     if (upperPtr_)
00322     {
00323         *upperPtr_ *= s;
00324     }
00325 
00326     if (lowerPtr_)
00327     {
00328         *lowerPtr_ *= s;
00329     }
00330 }
00331 
00332 
00333 Foam::tmp<Foam::scalarField > Foam::lduMatrix::H1() const
00334 {
00335     tmp<scalarField > tH1
00336     (
00337         new scalarField(lduAddr().size(), 0.0)
00338     );
00339 
00340     if (lowerPtr_ || upperPtr_)
00341     {
00342         scalarField& H1_ = tH1();
00343 
00344         scalar* __restrict__ H1Ptr = H1_.begin();
00345 
00346         const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
00347         const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
00348 
00349         const scalar* __restrict__ lowerPtr = lower().begin();
00350         const scalar* __restrict__ upperPtr = upper().begin();
00351 
00352         register const label nFaces = upper().size();
00353 
00354         for (register label face=0; face<nFaces; face++)
00355         {
00356             H1Ptr[uPtr[face]] -= lowerPtr[face];
00357             H1Ptr[lPtr[face]] -= upperPtr[face];
00358         }
00359     }
00360 
00361     return tH1;
00362 }
00363 
00364 
00365 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd