initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fvMesh / extendedStencil / cellToFace / extendedUpwindCellToFaceStencilTemplates.C
blobee545754fa2fa02c1fdb923a516a1c4aad76668c
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 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
33 Foam::extendedUpwindCellToFaceStencil::weightedSum
35     const surfaceScalarField& phi,
36     const GeometricField<Type, fvPatchField, volMesh>& fld,
37     const List<List<scalar> >& ownWeights,
38     const List<List<scalar> >& neiWeights
39 ) const
41     const fvMesh& mesh = fld.mesh();
43     // Collect internal and boundary values
44     List<List<Type> > ownFld;
45     collectData(ownMap(), ownStencil(), fld, ownFld);
46     List<List<Type> > neiFld;
47     collectData(neiMap(), neiStencil(), fld, neiFld);
49     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsfCorr
50     (
51         new GeometricField<Type, fvsPatchField, surfaceMesh>
52         (
53             IOobject
54             (
55                 fld.name(),
56                 mesh.time().timeName(),
57                 mesh,
58                 IOobject::NO_READ,
59                 IOobject::NO_WRITE,
60                 false
61             ),
62             mesh,
63             dimensioned<Type>
64             (
65                 fld.name(),
66                 fld.dimensions(),
67                 pTraits<Type>::zero
68             )
69         )
70     );
71     GeometricField<Type, fvsPatchField, surfaceMesh>& sf = tsfCorr();
73     // Internal faces
74     for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
75     {
76         if (phi[faceI] > 0)
77         {
78             // Flux out of owner. Use upwind (= owner side) stencil.
79             const List<Type>& stField = ownFld[faceI];
80             const List<scalar>& stWeight = ownWeights[faceI];
82             forAll(stField, i)
83             {
84                 sf[faceI] += stField[i]*stWeight[i];
85             }
86         }
87         else
88         {
89             const List<Type>& stField = neiFld[faceI];
90             const List<scalar>& stWeight = neiWeights[faceI];
92             forAll(stField, i)
93             {
94                 sf[faceI] += stField[i]*stWeight[i];
95             }
96         }
97     }
99     // Boundaries. Either constrained or calculated so assign value
100     // directly (instead of nicely using operator==)
101     typename GeometricField<Type, fvsPatchField, surfaceMesh>::
102         GeometricBoundaryField& bSfCorr = sf.boundaryField();
104     forAll(bSfCorr, patchi)
105     {
106         fvsPatchField<Type>& pSfCorr = bSfCorr[patchi];
108         if (pSfCorr.coupled())
109         {
110             label faceI = pSfCorr.patch().patch().start();
112             forAll(pSfCorr, i)
113             {
114                 if (phi.boundaryField()[patchi][i] > 0)
115                 {
116                     // Flux out of owner. Use upwind (= owner side) stencil.
117                     const List<Type>& stField = ownFld[faceI];
118                     const List<scalar>& stWeight = ownWeights[faceI];
120                     forAll(stField, j)
121                     {
122                         pSfCorr[i] += stField[j]*stWeight[j];
123                     }
124                 }
125                 else
126                 {
127                     const List<Type>& stField = neiFld[faceI];
128                     const List<scalar>& stWeight = neiWeights[faceI];
130                     forAll(stField, j)
131                     {
132                         pSfCorr[i] += stField[j]*stWeight[j];
133                     }
134                 }
135                 faceI++;
136             }
137         }
138     }
140     return tsfCorr;
144 // ************************************************************************* //