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

extendedFaceToCellStencilTemplates.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 "extendedFaceToCellStencil.H"
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 template<class Type>
00032 void Foam::extendedFaceToCellStencil::collectData
00033 (
00034     const mapDistribute& map,
00035     const labelListList& stencil,
00036     const GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
00037     List<List<Type> >& stencilFld
00038 )
00039 {
00040     // 1. Construct face 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 fvsPatchField<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::fvPatchField, Foam::volMesh> >
00082 Foam::extendedFaceToCellStencil::weightedSum
00083 (
00084     const mapDistribute& map,
00085     const labelListList& stencil,
00086     const GeometricField<Type, fvsPatchField, surfaceMesh>& 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, fvPatchField, volMesh> > tsfCorr
00097     (
00098         new GeometricField<Type, fvPatchField, volMesh>
00099         (
00100             IOobject
00101             (
00102                 fld.name(),
00103                 mesh.time().timeName(),
00104                 mesh
00105             ),
00106             mesh,
00107             dimensioned<Type>
00108             (
00109                 fld.name(),
00110                 fld.dimensions(),
00111                 pTraits<Type>::zero
00112             )
00113         )
00114     );
00115     GeometricField<Type, fvPatchField, volMesh>& sf = tsfCorr();
00116 
00117     // cells
00118     forAll(sf, cellI)
00119     {
00120         const List<Type>& stField = stencilFld[cellI];
00121         const List<scalar>& stWeight = stencilWeights[cellI];
00122 
00123         forAll(stField, i)
00124         {
00125             sf[cellI] += stField[i]*stWeight[i];
00126         }
00127     }
00128 
00129     // Boundaries values?
00130 
00131     return tsfCorr;
00132 }
00133 
00134 
00135 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd