1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 Foam::vector Foam::cellModel::centre
34 const labelList& pointLabels,
35 const pointField& points
38 // Estimate centre of cell
39 vector cEst = vector::zero;
41 // Sum the points idicated by the label list
42 forAll(pointLabels, i)
44 cEst += points[pointLabels[i]];
47 // Average by dividing by the number summed over.
48 cEst /= scalar(pointLabels.size());
51 // Calculate the centre by breaking the cell into pyramids and
52 // volume-weighted averaging their centres
54 vector sumVc = vector::zero;
56 const faceList cellFaces = faces(pointLabels);
60 const face& curFace = cellFaces[i];
63 pyramid<point, const point&, const face&>
71 WarningIn("cellModel::centre(const labelList&, const pointField&)")
72 << "zero or negative pyramid volume: " << -pyrVol
79 *pyramid<point, const point&, const face&>(curFace, cEst)
85 return sumVc/(sumV + VSMALL);
89 Foam::scalar Foam::cellModel::mag
91 const labelList& pointLabels,
92 const pointField& points
95 // Estimate centre of cell
96 vector cEst = vector::zero;
98 // Sum the points idicated by the label list
99 forAll(pointLabels, i)
101 cEst += points[pointLabels[i]];
104 // Average by dividing by the number summed over.
105 cEst /= scalar(pointLabels.size());
108 // Calculate the magnitude by summing the -mags of the pyramids
109 // The sign change is because the faces point outwards
110 // and a pyramid is constructed from an inward pointing face
111 // and the base centre-apex vector
114 const faceList cellFaces = faces(pointLabels);
118 const face& curFace =cellFaces[i];
121 pyramid<point, const point&, const face&>
129 WarningIn("cellModel::mag(const labelList&, const pointField&)")
130 << "zero or negative pyramid volume: " << -pyrVol
141 // ************************************************************************* //