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

extendedUpwindCellToFaceStencilTemplates.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 "extendedCellToFaceStencil.H"
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 template<class Type>
00032 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
00033 Foam::extendedUpwindCellToFaceStencil::weightedSum
00034 (
00035     const surfaceScalarField& phi,
00036     const GeometricField<Type, fvPatchField, volMesh>& fld,
00037     const List<List<scalar> >& ownWeights,
00038     const List<List<scalar> >& neiWeights
00039 ) const
00040 {
00041     const fvMesh& mesh = fld.mesh();
00042 
00043     // Collect internal and boundary values
00044     List<List<Type> > ownFld;
00045     collectData(ownMap(), ownStencil(), fld, ownFld);
00046     List<List<Type> > neiFld;
00047     collectData(neiMap(), neiStencil(), fld, neiFld);
00048 
00049     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
00050     (
00051         new GeometricField<Type, fvsPatchField, surfaceMesh>
00052         (
00053             IOobject
00054             (
00055                 fld.name(),
00056                 mesh.time().timeName(),
00057                 mesh,
00058                 IOobject::NO_READ,
00059                 IOobject::NO_WRITE,
00060                 false
00061             ),
00062             mesh,
00063             dimensioned<Type>
00064             (
00065                 fld.name(),
00066                 fld.dimensions(),
00067                 pTraits<Type>::zero
00068             )
00069         )
00070     );
00071     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsfCorr();
00072 
00073     // Internal faces
00074     for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00075     {
00076         if (phi[faceI] > 0)
00077         {
00078             // Flux out of owner. Use upwind (= owner side) stencil.
00079             const List<Type>& stField = ownFld[faceI];
00080             const List<scalar>& stWeight = ownWeights[faceI];
00081 
00082             forAll(stField, i)
00083             {
00084                 sf[faceI] += stField[i]*stWeight[i];
00085             }
00086         }
00087         else
00088         {
00089             const List<Type>& stField = neiFld[faceI];
00090             const List<scalar>& stWeight = neiWeights[faceI];
00091 
00092             forAll(stField, i)
00093             {
00094                 sf[faceI] += stField[i]*stWeight[i];
00095             }
00096         }
00097     }
00098 
00099     // Boundaries. Either constrained or calculated so assign value
00100     // directly (instead of nicely using operator==)
00101     typename GeometricField<Type, fvsPatchField, surfaceMesh>::
00102         GeometricBoundaryField& bSfCorr = sf.boundaryField();
00103 
00104     forAll(bSfCorr, patchi)
00105     {
00106         fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
00107 
00108         if (pSfCorr.coupled())
00109         {
00110             label faceI = pSfCorr.patch().patch().start();
00111 
00112             forAll(pSfCorr, i)
00113             {
00114                 if (phi.boundaryField()[patchi][i] > 0)
00115                 {
00116                     // Flux out of owner. Use upwind (= owner side) stencil.
00117                     const List<Type>& stField = ownFld[faceI];
00118                     const List<scalar>& stWeight = ownWeights[faceI];
00119 
00120                     forAll(stField, j)
00121                     {
00122                         pSfCorr[i] += stField[j]*stWeight[j];
00123                     }
00124                 }
00125                 else
00126                 {
00127                     const List<Type>& stField = neiFld[faceI];
00128                     const List<scalar>& stWeight = neiWeights[faceI];
00129 
00130                     forAll(stField, j)
00131                     {
00132                         pSfCorr[i] += stField[j]*stWeight[j];
00133                     }
00134                 }
00135                 faceI++;
00136             }
00137         }
00138     }
00139 
00140     return tsfCorr;
00141 }
00142 
00143 
00144 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd