FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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