1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cellModel.H"
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 Foam::vector Foam::cellModel::centre
33 const labelList& pointLabels,
34 const pointField& points
37 // Estimate centre of cell
38 vector cEst = vector::zero;
40 // Sum the points idicated by the label list
41 forAll(pointLabels, i)
43 cEst += points[pointLabels[i]];
46 // Average by dividing by the number summed over.
47 cEst /= scalar(pointLabels.size());
50 // Calculate the centre by breaking the cell into pyramids and
51 // volume-weighted averaging their centres
53 vector sumVc = vector::zero;
55 const faceList cellFaces = faces(pointLabels);
59 const face& curFace = cellFaces[i];
62 pyramid<point, const point&, const face&>
70 WarningIn("cellModel::centre(const labelList&, const pointField&)")
71 << "zero or negative pyramid volume: " << -pyrVol
78 *pyramid<point, const point&, const face&>(curFace, cEst)
84 return sumVc/(sumV + VSMALL);
88 Foam::scalar Foam::cellModel::mag
90 const labelList& pointLabels,
91 const pointField& points
94 // Estimate centre of cell
95 vector cEst = vector::zero;
97 // Sum the points idicated by the label list
98 forAll(pointLabels, i)
100 cEst += points[pointLabels[i]];
103 // Average by dividing by the number summed over.
104 cEst /= scalar(pointLabels.size());
107 // Calculate the magnitude by summing the -mags of the pyramids
108 // The sign change is because the faces point outwards
109 // and a pyramid is constructed from an inward pointing face
110 // and the base centre-apex vector
113 const faceList cellFaces = faces(pointLabels);
117 const face& curFace =cellFaces[i];
120 pyramid<point, const point&, const face&>
128 WarningIn("cellModel::mag(const labelList&, const pointField&)")
129 << "zero or negative pyramid volume: " << -pyrVol
140 // ************************************************************************* //