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

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-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 "extendedFaceToCellStencil.H"
00027 
00028 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00029 
00030 template<class Type>
00031 void Foam::extendedFaceToCellStencil::collectData
00032 (
00033     const mapDistribute& map,
00034     const labelListList& stencil,
00035     const GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
00036     List<List<Type> >& stencilFld
00037 )
00038 {
00039     // 1. Construct face data in compact addressing
00040     List<Type> compactFld(map.constructSize(), pTraits<Type>::zero);
00041 
00042     // Insert my internal values
00043     forAll(fld, cellI)
00044     {
00045         compactFld[cellI] = fld[cellI];
00046     }
00047     // Insert my boundary values
00048     label nCompact = fld.size();
00049     forAll(fld.boundaryField(), patchI)
00050     {
00051         const fvsPatchField<Type>& pfld = fld.boundaryField()[patchI];
00052 
00053         forAll(pfld, i)
00054         {
00055             compactFld[nCompact++] = pfld[i];
00056         }
00057     }
00058 
00059     // Do all swapping
00060     map.distribute(compactFld);
00061 
00062     // 2. Pull to stencil
00063     stencilFld.setSize(stencil.size());
00064 
00065     forAll(stencil, faceI)
00066     {
00067         const labelList& compactCells = stencil[faceI];
00068 
00069         stencilFld[faceI].setSize(compactCells.size());
00070 
00071         forAll(compactCells, i)
00072         {
00073             stencilFld[faceI][i] = compactFld[compactCells[i]];
00074         }
00075     }
00076 }
00077 
00078 
00079 template<class Type>
00080 Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
00081 Foam::extendedFaceToCellStencil::weightedSum
00082 (
00083     const mapDistribute& map,
00084     const labelListList& stencil,
00085     const GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
00086     const List<List<scalar> >& stencilWeights
00087 )
00088 {
00089     const fvMesh& mesh = fld.mesh();
00090 
00091     // Collect internal and boundary values
00092     List<List<Type> > stencilFld;
00093     collectData(map, stencil, fld, stencilFld);
00094 
00095     tmp<GeometricField<Type, fvPatchField, volMesh> > tsfCorr
00096     (
00097         new GeometricField<Type, fvPatchField, volMesh>
00098         (
00099             IOobject
00100             (
00101                 fld.name(),
00102                 mesh.time().timeName(),
00103                 mesh
00104             ),
00105             mesh,
00106             dimensioned<Type>
00107             (
00108                 fld.name(),
00109                 fld.dimensions(),
00110                 pTraits<Type>::zero
00111             )
00112         )
00113     );
00114     GeometricField<Type, fvPatchField, volMesh>& sf = tsfCorr();
00115 
00116     // cells
00117     forAll(sf, cellI)
00118     {
00119         const List<Type>& stField = stencilFld[cellI];
00120         const List<scalar>& stWeight = stencilWeights[cellI];
00121 
00122         forAll(stField, i)
00123         {
00124             sf[cellI] += stField[i]*stWeight[i];
00125         }
00126     }
00127 
00128     // Boundaries values?
00129 
00130     return tsfCorr;
00131 }
00132 
00133 
00134 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines