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

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-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 void Foam::extendedCellToFaceStencil::collectData
00032 (
00033     const mapDistribute& map,
00034     const labelListList& stencil,
00035     const GeometricField<Type, fvPatchField, volMesh>& fld,
00036     List<List<Type> >& stencilFld
00037 )
00038 {
00039     // 1. Construct cell 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 fvPatchField<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::fvsPatchField, Foam::surfaceMesh> >
00081 Foam::extendedCellToFaceStencil::weightedSum
00082 (
00083     const mapDistribute& map,
00084     const labelListList& stencil,
00085     const GeometricField<Type, fvPatchField, volMesh>& 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, fvsPatchField, surfaceMesh> > tsfCorr
00096     (
00097         new GeometricField<Type, fvsPatchField, surfaceMesh>
00098         (
00099             IOobject
00100             (
00101                 fld.name(),
00102                 mesh.time().timeName(),
00103                 mesh,
00104                 IOobject::NO_READ,
00105                 IOobject::NO_WRITE,
00106                 false
00107             ),
00108             mesh,
00109             dimensioned<Type>
00110             (
00111                 fld.name(),
00112                 fld.dimensions(),
00113                 pTraits<Type>::zero
00114             )
00115         )
00116     );
00117     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsfCorr();
00118 
00119     // Internal faces
00120     for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
00121     {
00122         const List<Type>& stField = stencilFld[faceI];
00123         const List<scalar>& stWeight = stencilWeights[faceI];
00124 
00125         forAll(stField, i)
00126         {
00127             sf[faceI] += stField[i]*stWeight[i];
00128         }
00129     }
00130 
00131     // Boundaries. Either constrained or calculated so assign value
00132     // directly (instead of nicely using operator==)
00133     typename GeometricField<Type, fvsPatchField, surfaceMesh>::
00134         GeometricBoundaryField& bSfCorr = sf.boundaryField();
00135 
00136     forAll(bSfCorr, patchi)
00137     {
00138         fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
00139 
00140         if (pSfCorr.coupled())
00141         {
00142             label faceI = pSfCorr.patch().patch().start();
00143 
00144             forAll(pSfCorr, i)
00145             {
00146                 const List<Type>& stField = stencilFld[faceI];
00147                 const List<scalar>& stWeight = stencilWeights[faceI];
00148 
00149                 forAll(stField, j)
00150                 {
00151                     pSfCorr[i] += stField[j]*stWeight[j];
00152                 }
00153 
00154                 faceI++;
00155             }
00156         }
00157     }
00158 
00159     return tsfCorr;
00160 }
00161 
00162 
00163 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines