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

lduMatrixATmul.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     Multiply a given vector (second argument) by the matrix or its transpose
00027     and return the result in the first argument.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "lduMatrix.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 void Foam::lduMatrix::Amul
00036 (
00037     scalarField& Apsi,
00038     const tmp<scalarField>& tpsi,
00039     const FieldField<Field, scalar>& interfaceBouCoeffs,
00040     const lduInterfaceFieldPtrsList& interfaces,
00041     const direction cmpt
00042 ) const
00043 {
00044     scalar* __restrict__ ApsiPtr = Apsi.begin();
00045 
00046     const scalarField& psi = tpsi();
00047     const scalar* const __restrict__ psiPtr = psi.begin();
00048 
00049     const scalar* const __restrict__ diagPtr = diag().begin();
00050 
00051     const label* const __restrict__ uPtr = lduAddr().upperAddr().begin();
00052     const label* const __restrict__ lPtr = lduAddr().lowerAddr().begin();
00053 
00054     const scalar* const __restrict__ upperPtr = upper().begin();
00055     const scalar* const __restrict__ lowerPtr = lower().begin();
00056 
00057     // Initialise the update of interfaced interfaces
00058     initMatrixInterfaces
00059     (
00060         interfaceBouCoeffs,
00061         interfaces,
00062         psi,
00063         Apsi,
00064         cmpt
00065     );
00066 
00067     register const label nCells = diag().size();
00068     for (register label cell=0; cell<nCells; cell++)
00069     {
00070         ApsiPtr[cell] = diagPtr[cell]*psiPtr[cell];
00071     }
00072 
00073 
00074     register const label nFaces = upper().size();
00075 
00076     for (register label face=0; face<nFaces; face++)
00077     {
00078         ApsiPtr[uPtr[face]] += lowerPtr[face]*psiPtr[lPtr[face]];
00079         ApsiPtr[lPtr[face]] += upperPtr[face]*psiPtr[uPtr[face]];
00080     }
00081 
00082     // Update interface interfaces
00083     updateMatrixInterfaces
00084     (
00085         interfaceBouCoeffs,
00086         interfaces,
00087         psi,
00088         Apsi,
00089         cmpt
00090     );
00091 
00092     tpsi.clear();
00093 }
00094 
00095 
00096 void Foam::lduMatrix::Tmul
00097 (
00098     scalarField& Tpsi,
00099     const tmp<scalarField>& tpsi,
00100     const FieldField<Field, scalar>& interfaceIntCoeffs,
00101     const lduInterfaceFieldPtrsList& interfaces,
00102     const direction cmpt
00103 ) const
00104 {
00105     scalar* __restrict__ TpsiPtr = Tpsi.begin();
00106 
00107     const scalarField& psi = tpsi();
00108     const scalar* const __restrict__ psiPtr = psi.begin();
00109 
00110     const scalar* const __restrict__ diagPtr = diag().begin();
00111 
00112     const label* const __restrict__ uPtr = lduAddr().upperAddr().begin();
00113     const label* const __restrict__ lPtr = lduAddr().lowerAddr().begin();
00114 
00115     const scalar* const __restrict__ lowerPtr = lower().begin();
00116     const scalar* const __restrict__ upperPtr = upper().begin();
00117 
00118     // Initialise the update of interfaced interfaces
00119     initMatrixInterfaces
00120     (
00121         interfaceIntCoeffs,
00122         interfaces,
00123         psi,
00124         Tpsi,
00125         cmpt
00126     );
00127 
00128     register const label nCells = diag().size();
00129     for (register label cell=0; cell<nCells; cell++)
00130     {
00131         TpsiPtr[cell] = diagPtr[cell]*psiPtr[cell];
00132     }
00133 
00134     register const label nFaces = upper().size();
00135     for (register label face=0; face<nFaces; face++)
00136     {
00137         TpsiPtr[uPtr[face]] += upperPtr[face]*psiPtr[lPtr[face]];
00138         TpsiPtr[lPtr[face]] += lowerPtr[face]*psiPtr[uPtr[face]];
00139     }
00140 
00141     // Update interface interfaces
00142     updateMatrixInterfaces
00143     (
00144         interfaceIntCoeffs,
00145         interfaces,
00146         psi,
00147         Tpsi,
00148         cmpt
00149     );
00150 
00151     tpsi.clear();
00152 }
00153 
00154 
00155 void Foam::lduMatrix::sumA
00156 (
00157     scalarField& sumA,
00158     const FieldField<Field, scalar>& interfaceBouCoeffs,
00159     const lduInterfaceFieldPtrsList& interfaces
00160 ) const
00161 {
00162     scalar* __restrict__ sumAPtr = sumA.begin();
00163 
00164     const scalar* __restrict__ diagPtr = diag().begin();
00165 
00166     const label* __restrict__ uPtr = lduAddr().upperAddr().begin();
00167     const label* __restrict__ lPtr = lduAddr().lowerAddr().begin();
00168 
00169     const scalar* __restrict__ lowerPtr = lower().begin();
00170     const scalar* __restrict__ upperPtr = upper().begin();
00171 
00172     register const label nCells = diag().size();
00173     register const label nFaces = upper().size();
00174 
00175     for (register label cell=0; cell<nCells; cell++)
00176     {
00177         sumAPtr[cell] = diagPtr[cell];
00178     }
00179 
00180     for (register label face=0; face<nFaces; face++)
00181     {
00182         sumAPtr[uPtr[face]] += lowerPtr[face];
00183         sumAPtr[lPtr[face]] += upperPtr[face];
00184     }
00185 
00186     // Add the interface internal coefficients to diagonal
00187     // and the interface boundary coefficients to the sum-off-diagonal
00188     forAll(interfaces, patchI)
00189     {
00190         if (interfaces.set(patchI))
00191         {
00192             const unallocLabelList& pa = lduAddr().patchAddr(patchI);
00193             const scalarField& pCoeffs = interfaceBouCoeffs[patchI];
00194 
00195             forAll(pa, face)
00196             {
00197                 sumAPtr[pa[face]] -= pCoeffs[face];
00198             }
00199         }
00200     }
00201 }
00202 
00203 
00204 void Foam::lduMatrix::residual
00205 (
00206     scalarField& rA,
00207     const scalarField& psi,
00208     const scalarField& source,
00209     const FieldField<Field, scalar>& interfaceBouCoeffs,
00210     const lduInterfaceFieldPtrsList& interfaces,
00211     const direction cmpt
00212 ) const
00213 {
00214     scalar* __restrict__ rAPtr = rA.begin();
00215 
00216     const scalar* const __restrict__ psiPtr = psi.begin();
00217     const scalar* const __restrict__ diagPtr = diag().begin();
00218     const scalar* const __restrict__ sourcePtr = source.begin();
00219 
00220     const label* const __restrict__ uPtr = lduAddr().upperAddr().begin();
00221     const label* const __restrict__ lPtr = lduAddr().lowerAddr().begin();
00222 
00223     const scalar* const __restrict__ upperPtr = upper().begin();
00224     const scalar* const __restrict__ lowerPtr = lower().begin();
00225 
00226     // Parallel boundary initialisation.
00227     // Note: there is a change of sign in the coupled
00228     // interface update.  The reason for this is that the
00229     // internal coefficients are all located at the l.h.s. of
00230     // the matrix whereas the "implicit" coefficients on the
00231     // coupled boundaries are all created as if the
00232     // coefficient contribution is of a source-kind (i.e. they
00233     // have a sign as if they are on the r.h.s. of the matrix.
00234     // To compensate for this, it is necessary to turn the
00235     // sign of the contribution.
00236 
00237     FieldField<Field, scalar> mBouCoeffs(interfaceBouCoeffs.size());
00238 
00239     forAll(mBouCoeffs, patchi)
00240     {
00241         if (interfaces.set(patchi))
00242         {
00243             mBouCoeffs.set(patchi, -interfaceBouCoeffs[patchi]);
00244         }
00245     }
00246 
00247     // Initialise the update of interfaced interfaces
00248     initMatrixInterfaces
00249     (
00250         mBouCoeffs,
00251         interfaces,
00252         psi,
00253         rA,
00254         cmpt
00255     );
00256 
00257     register const label nCells = diag().size();
00258     for (register label cell=0; cell<nCells; cell++)
00259     {
00260         rAPtr[cell] = sourcePtr[cell] - diagPtr[cell]*psiPtr[cell];
00261     }
00262 
00263 
00264     register const label nFaces = upper().size();
00265 
00266     for (register label face=0; face<nFaces; face++)
00267     {
00268         rAPtr[uPtr[face]] -= lowerPtr[face]*psiPtr[lPtr[face]];
00269         rAPtr[lPtr[face]] -= upperPtr[face]*psiPtr[uPtr[face]];
00270     }
00271 
00272     // Update interface interfaces
00273     updateMatrixInterfaces
00274     (
00275         mBouCoeffs,
00276         interfaces,
00277         psi,
00278         rA,
00279         cmpt
00280     );
00281 }
00282 
00283 
00284 Foam::tmp<Foam::scalarField> Foam::lduMatrix::residual
00285 (
00286     const scalarField& psi,
00287     const scalarField& source,
00288     const FieldField<Field, scalar>& interfaceBouCoeffs,
00289     const lduInterfaceFieldPtrsList& interfaces,
00290     const direction cmpt
00291 ) const
00292 {
00293     tmp<scalarField> trA(new scalarField(psi.size()));
00294     residual(trA(), psi, source, interfaceBouCoeffs, interfaces, cmpt);
00295     return trA;
00296 }
00297 
00298 
00299 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd