1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 \*---------------------------------------------------------------------------*/
27 #include "cellModel.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 vector cellModel::centre
39 const labelList& pointLabels,
40 const pointField& points
43 // Estimate centre of cell
44 vector cEst = vector::zero;
46 // Sum the points idicated by the label list
47 forAll(pointLabels, i)
49 cEst += points[pointLabels[i]];
52 // Average by dividing by the number summed over.
53 cEst /= scalar(pointLabels.size());
56 // Calculate the centre by breaking the cell into pyramids and
57 // volume-weighted averaging their centres
59 vector sumVc = vector::zero;
61 const faceList cellFaces = faces(pointLabels);
65 const face& curFace = cellFaces[i];
68 pyramid<point, const point&, const face&>
76 WarningIn("cellModel::centre(const labelList&, const pointField&)")
77 << "zero or negative pyramid volume: " << -pyrVol
84 *pyramid<point, const point&, const face&>(curFace, cEst)
90 return sumVc/(sumV + VSMALL);
96 const labelList& pointLabels,
97 const pointField& points
100 // Estimate centre of cell
101 vector cEst = vector::zero;
103 // Sum the points idicated by the label list
104 forAll(pointLabels, i)
106 cEst += points[pointLabels[i]];
109 // Average by dividing by the number summed over.
110 cEst /= scalar(pointLabels.size());
113 // Calculate the magnitude by summing the -mags of the pyramids
114 // The sign change is because the faces point outwards
115 // and a pyramid is constructed from an inward pointing face
116 // and the base centre-apex vector
119 const faceList cellFaces = faces(pointLabels);
123 const face& curFace =cellFaces[i];
126 pyramid<point, const point&, const face&>
134 WarningIn("cellModel::mag(const labelList&, const pointField&)")
135 << "zero or negative pyramid volume: " << -pyrVol
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 } // End namespace Foam
151 // ************************************************************************* //