initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fvMesh / extendedStencil / cellToFace / extendedCellToFaceStencilTemplates.C
blob9ee125de9b52497fdf8068a1ebd0e73fa90c64fc
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "extendedCellToFaceStencil.H"
29 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 template<class Type>
32 void Foam::extendedCellToFaceStencil::collectData
34     const mapDistribute& map,
35     const labelListList& stencil,
36     const GeometricField<Type, fvPatchField, volMesh>& fld,
37     List<List<Type> >& stencilFld
40     // 1. Construct cell data in compact addressing
41     List<Type> compactFld(map.constructSize(), pTraits<Type>::zero);
43     // Insert my internal values
44     forAll(fld, cellI)
45     {
46         compactFld[cellI] = fld[cellI];
47     }
48     // Insert my boundary values
49     label nCompact = fld.size();
50     forAll(fld.boundaryField(), patchI)
51     {
52         const fvPatchField<Type>& pfld = fld.boundaryField()[patchI];
54         forAll(pfld, i)
55         {
56             compactFld[nCompact++] = pfld[i];
57         }
58     }
60     // Do all swapping
61     map.distribute(compactFld);
63     // 2. Pull to stencil
64     stencilFld.setSize(stencil.size());
66     forAll(stencil, faceI)
67     {
68         const labelList& compactCells = stencil[faceI];
70         stencilFld[faceI].setSize(compactCells.size());
72         forAll(compactCells, i)
73         {
74             stencilFld[faceI][i] = compactFld[compactCells[i]];
75         }
76     }
80 template<class Type>
81 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
82 Foam::extendedCellToFaceStencil::weightedSum
84     const mapDistribute& map,
85     const labelListList& stencil,
86     const GeometricField<Type, fvPatchField, volMesh>& fld,
87     const List<List<scalar> >& stencilWeights
90     const fvMesh& mesh = fld.mesh();
92     // Collect internal and boundary values
93     List<List<Type> > stencilFld;
94     collectData(map, stencil, fld, stencilFld);
96     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
97     (
98         new GeometricField<Type, fvsPatchField, surfaceMesh>
99         (
100             IOobject
101             (
102                 fld.name(),
103                 mesh.time().timeName(),
104                 mesh,
105                 IOobject::NO_READ,
106                 IOobject::NO_WRITE,
107                 false
108             ),
109             mesh,
110             dimensioned<Type>
111             (
112                 fld.name(),
113                 fld.dimensions(),
114                 pTraits<Type>::zero
115             )
116         )
117     );
118     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsfCorr();
120     // Internal faces
121     for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
122     {
123         const List<Type>& stField = stencilFld[faceI];
124         const List<scalar>& stWeight = stencilWeights[faceI];
126         forAll(stField, i)
127         {
128             sf[faceI] += stField[i]*stWeight[i];
129         }
130     }
132     // Boundaries. Either constrained or calculated so assign value
133     // directly (instead of nicely using operator==)
134     typename GeometricField<Type, fvsPatchField, surfaceMesh>::
135         GeometricBoundaryField& bSfCorr = sf.boundaryField();
137     forAll(bSfCorr, patchi)
138     {
139         fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
141         if (pSfCorr.coupled())
142         {
143             label faceI = pSfCorr.patch().patch().start();
145             forAll(pSfCorr, i)
146             {
147                 const List<Type>& stField = stencilFld[faceI];
148                 const List<scalar>& stWeight = stencilWeights[faceI];
150                 forAll(stField, j)
151                 {
152                     pSfCorr[i] += stField[j]*stWeight[j];
153                 }
155                 faceI++;
156             }
157         }
158     }
160     return tsfCorr;
164 // ************************************************************************* //