initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / meshShapes / face / faceTemplates.C
blob7675a91bdf646f494c0ce13d73024d60048e7571
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 "face.H"
28 #include "DynamicList.H"
30 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
32 template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
33 Foam::label Foam::face::triangles
35     const pointField& points,
36     DynamicList<face, SizeInc, SizeMult, SizeDiv>& triFaces
37 ) const
39     label triI = triFaces.size();
40     label quadI = 0;
41     faceList quadFaces;
43     // adjust the addressable size (and allocate space if needed)
44     triFaces.setSize(triI + nTriangles());
46     return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
50 template<class Type>
51 Type Foam::face::average
53     const pointField& meshPoints,
54     const Field<Type>& f
55 ) const
57     // Calculate the average by breaking the face into triangles and
58     // area-weighted averaging their averages
60     // If the face is a triangle, do a direct calculation
61     if (size() == 3)
62     {
63         return
64             (1.0/3.0)
65            *(
66                f[operator[](0)]
67              + f[operator[](1)]
68              + f[operator[](2)]
69             );
70     }
72     label nPoints = size();
74     point centrePoint = point::zero;
75     Type cf = pTraits<Type>::zero;
77     for (register label pI=0; pI<nPoints; pI++)
78     {
79         centrePoint += meshPoints[operator[](pI)];
80         cf += f[operator[](pI)];
81     }
83     centrePoint /= nPoints;
84     cf /= nPoints;
86     scalar sumA = 0;
87     Type sumAf = pTraits<Type>::zero;
89     for (register label pI=0; pI<nPoints; pI++)
90     {
91         // Calculate 3*triangle centre field value
92         Type ttcf  =
93         (
94             f[operator[](pI)]
95           + f[operator[]((pI + 1) % nPoints)]
96           + cf
97         );
99         // Calculate 2*triangle area
100         scalar ta = Foam::mag
101         (
102             (meshPoints[operator[](pI)] - centrePoint)
103           ^ (meshPoints[operator[]((pI + 1) % nPoints)] - centrePoint)
104         );
106         sumA += ta;
107         sumAf += ta*ttcf;
108     }
110     if (sumA > VSMALL)
111     {
112         return sumAf/(3*sumA);
113     }
114     else
115     {
116         return cf;
117     }
120 // ************************************************************************* //