Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / finiteVolume / fvMesh / extendedStencil / faceToCell / extendedFaceToCellStencilTemplates.C
blob68f843736955589de1a24c7a761f7a752c1b50df
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "extendedFaceToCellStencil.H"
28 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
30 template<class Type>
31 void Foam::extendedFaceToCellStencil::collectData
33     const mapDistribute& map,
34     const labelListList& stencil,
35     const GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
36     List<List<Type> >& stencilFld
39     // 1. Construct face data in compact addressing
40     List<Type> compactFld(map.constructSize(), pTraits<Type>::zero);
42     // Insert my internal values
43     forAll(fld, cellI)
44     {
45         compactFld[cellI] = fld[cellI];
46     }
47     // Insert my boundary values
48     label nCompact = fld.size();
49     forAll(fld.boundaryField(), patchI)
50     {
51         const fvsPatchField<Type>& pfld = fld.boundaryField()[patchI];
53         forAll(pfld, i)
54         {
55             compactFld[nCompact++] = pfld[i];
56         }
57     }
59     // Do all swapping
60     map.distribute(compactFld);
62     // 2. Pull to stencil
63     stencilFld.setSize(stencil.size());
65     forAll(stencil, faceI)
66     {
67         const labelList& compactCells = stencil[faceI];
69         stencilFld[faceI].setSize(compactCells.size());
71         forAll(compactCells, i)
72         {
73             stencilFld[faceI][i] = compactFld[compactCells[i]];
74         }
75     }
79 template<class Type>
80 Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
81 Foam::extendedFaceToCellStencil::weightedSum
83     const mapDistribute& map,
84     const labelListList& stencil,
85     const GeometricField<Type, fvsPatchField, surfaceMesh>& fld,
86     const List<List<scalar> >& stencilWeights
89     const fvMesh& mesh = fld.mesh();
91     // Collect internal and boundary values
92     List<List<Type> > stencilFld;
93     collectData(map, stencil, fld, stencilFld);
95     tmp<GeometricField<Type, fvPatchField, volMesh> > tsfCorr
96     (
97         new GeometricField<Type, fvPatchField, volMesh>
98         (
99             IOobject
100             (
101                 fld.name(),
102                 mesh.time().timeName(),
103                 mesh
104             ),
105             mesh,
106             dimensioned<Type>
107             (
108                 fld.name(),
109                 fld.dimensions(),
110                 pTraits<Type>::zero
111             )
112         )
113     );
114     GeometricField<Type, fvPatchField, volMesh>& sf = tsfCorr();
116     // cells
117     forAll(sf, cellI)
118     {
119         const List<Type>& stField = stencilFld[cellI];
120         const List<scalar>& stWeight = stencilWeights[cellI];
122         forAll(stField, i)
123         {
124             sf[cellI] += stField[i]*stWeight[i];
125         }
126     }
128     // Boundaries values?
130     return tsfCorr;
134 // ************************************************************************* //