1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
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
39 label triI = triFaces.size();
43 // adjust the addressable size (and allocate space if needed)
44 triFaces.setSize(triI + nTriangles());
46 return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
51 Type Foam::face::average
53 const pointField& meshPoints,
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
72 label nPoints = size();
74 point centrePoint = point::zero;
75 Type cf = pTraits<Type>::zero;
77 for (register label pI=0; pI<nPoints; pI++)
79 centrePoint += meshPoints[operator[](pI)];
80 cf += f[operator[](pI)];
83 centrePoint /= nPoints;
87 Type sumAf = pTraits<Type>::zero;
89 for (register label pI=0; pI<nPoints; pI++)
91 // Calculate 3*triangle centre field value
95 + f[operator[]((pI + 1) % nPoints)]
99 // Calculate 2*triangle area
100 scalar ta = Foam::mag
102 (meshPoints[operator[](pI)] - centrePoint)
103 ^ (meshPoints[operator[]((pI + 1) % nPoints)] - centrePoint)
112 return sumAf/(3*sumA);
120 // ************************************************************************* //