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

extendedCellToFaceStencilTemplates.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 void Foam::extendedCellToFaceStencil::collectData
00033 (
00034     const mapDistribute& map,
00035     const labelListList& stencil,
00036     const GeometricField<Type, fvPatchField, volMesh>& fld,
00037     List<List<Type> >& stencilFld
00038 )
00039 {
00040     // 1. Construct cell data in compact addressing
00041     List<Type> compactFld(map.constructSize(), pTraits<Type>::zero);
00042 
00043     // Insert my internal values
00044     forAll(fld, cellI)
00045     {
00046         compactFld[cellI] = fld[cellI];
00047     }
00048     // Insert my boundary values
00049     label nCompact = fld.size();
00050     forAll(fld.boundaryField(), patchI)
00051     {
00052         const fvPatchField<Type>& pfld = fld.boundaryField()[patchI];
00053 
00054         forAll(pfld, i)
00055         {
00056             compactFld[nCompact++] = pfld[i];
00057         }
00058     }
00059 
00060     // Do all swapping
00061     map.distribute(compactFld);
00062 
00063     // 2. Pull to stencil
00064     stencilFld.setSize(stencil.size());
00065 
00066     forAll(stencil, faceI)
00067     {
00068         const labelList& compactCells = stencil[faceI];
00069 
00070         stencilFld[faceI].setSize(compactCells.size());
00071 
00072         forAll(compactCells, i)
00073         {
00074             stencilFld[faceI][i] = compactFld[compactCells[i]];
00075         }
00076     }
00077 }
00078 
00079 
00080 template<class Type>
00081 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
00082 Foam::extendedCellToFaceStencil::weightedSum
00083 (
00084     const mapDistribute& map,
00085     const labelListList& stencil,
00086     const GeometricField<Type, fvPatchField, volMesh>& fld,
00087     const List<List<scalar> >& stencilWeights
00088 )
00089 {
00090     const fvMesh& mesh = fld.mesh();
00091 
00092     // Collect internal and boundary values
00093     List<List<Type> > stencilFld;
00094     collectData(map, stencil, fld, stencilFld);
00095 
00096     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
00097     (
00098         new GeometricField<Type, fvsPatchField, surfaceMesh>
00099         (
00100             IOobject
00101             (
00102                 fld.name(),
00103                 mesh.time().timeName(),
00104                 mesh,
00105                 IOobject::NO_READ,
00106                 IOobject::NO_WRITE,
00107                 false
00108             ),
00109             mesh,
00110             dimensioned<Type>
00111             (
00112                 fld.name(),
00113                 fld.dimensions(),
00114                 pTraits<Type>::zero
00115             )
00116         )
00117     );
00118     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsfCorr();
00119 
00120     // Internal faces
00121     for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00122     {
00123         const List<Type>& stField = stencilFld[faceI];
00124         const List<scalar>& stWeight = stencilWeights[faceI];
00125 
00126         forAll(stField, i)
00127         {
00128             sf[faceI] += stField[i]*stWeight[i];
00129         }
00130     }
00131 
00132     // Boundaries. Either constrained or calculated so assign value
00133     // directly (instead of nicely using operator==)
00134     typename GeometricField<Type, fvsPatchField, surfaceMesh>::
00135         GeometricBoundaryField& bSfCorr = sf.boundaryField();
00136 
00137     forAll(bSfCorr, patchi)
00138     {
00139         fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
00140 
00141         if (pSfCorr.coupled())
00142         {
00143             label faceI = pSfCorr.patch().patch().start();
00144 
00145             forAll(pSfCorr, i)
00146             {
00147                 const List<Type>& stField = stencilFld[faceI];
00148                 const List<scalar>& stWeight = stencilWeights[faceI];
00149 
00150                 forAll(stField, j)
00151                 {
00152                     pSfCorr[i] += stField[j]*stWeight[j];
00153                 }
00154 
00155                 faceI++;
00156             }
00157         }
00158     }
00159 
00160     return tsfCorr;
00161 }
00162 
00163 
00164 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd