Loading...
Searching...
No Matches
cellModel.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017,2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "cellModel.H"
30#include "pyramid.H"
31
32// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// Average of points
38// Note: use double precision to avoid overflows when summing
40(
41 const UList<point>& points,
43)
44{
45 doubleVector avg(Zero);
46
47 if (const auto n = pointLabels.size(); n)
48 {
49 for (const auto pointi : pointLabels)
50 {
51 avg += points[pointi];
52 }
53 avg /= n;
54 }
55
56 return avg;
58
59} // End namespace Foam
60
61
62// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63
65(
66 const labelUList& pointLabels,
67 const UList<point>& points
68) const
69{
70 // Note: use double precision to avoid overflows when summing
71
72 // Estimated centre by averaging the cell points
73 const point centrePoint(pointsAverage(points, pointLabels));
74
75
76 // Calculate the centre by breaking the cell into pyramids and
77 // volume-weighted averaging their centres
78
79 doubleScalar sumV(0);
80 doubleVector sumVc(Zero);
81
82 forAll(faces_, facei)
83 {
84 const Foam::face f(pointLabels, faces_[facei]);
85
86 const scalar pyrVol = pyramidPointFaceRef(f, centrePoint).mag(points);
87
88 if (pyrVol > SMALL)
89 {
91 << "zero or negative pyramid volume: " << -pyrVol
92 << " for face " << facei
93 << endl;
94 }
95
96 sumV -= pyrVol;
97 sumVc -= pyrVol * pyramidPointFaceRef(f, centrePoint).centre(points);
98 }
99
100 return sumVc/(sumV + VSMALL);
101}
102
103
104Foam::scalar Foam::cellModel::mag
105(
106 const labelUList& pointLabels,
107 const UList<point>& points
108) const
109{
110 // Note: use double precision to avoid overflows when summing
111
112 // Estimated centre by averaging the cell points
113 const point centrePoint(pointsAverage(points, pointLabels));
114
115
116 // Calculate the magnitude by summing the -mags of the pyramids
117 // The sign change is because the faces point outwards
118 // and a pyramid is constructed from an inward pointing face
119 // and the base centre-apex vector
120
121 scalar sumV(0);
122
123 forAll(faces_, facei)
124 {
125 const Foam::face f(pointLabels, faces_[facei]);
126
127 const scalar pyrVol = pyramidPointFaceRef(f, centrePoint).mag(points);
128
129 if (pyrVol > SMALL)
130 {
132 << "zero or negative pyramid volume: " << -pyrVol
133 << " for face " << facei
134 << endl;
135 }
136
137 sumV -= pyrVol;
138 }
139
140 return sumV;
141}
142
143
144// ************************************************************************* //
label n
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
vector centre(const labelUList &pointLabels, const UList< point > &points) const
Centroid of the cell.
Definition cellModel.C:58
scalar mag(const labelUList &pointLabels, const UList< point > &points) const
Cell volume.
Definition cellModel.C:98
A Vector of values with double precision.
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
scalar mag(const UList< point > &points) const
Return scalar magnitude - returns volume of pyramid.
Definition pyramidI.H:69
Point centre(const UList< point > &points) const
Return centre (centroid).
Definition pyramidI.H:48
const pointField & points
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
static Foam::doubleVector pointsAverage(const UList< point > &points, const labelUList &pointLabels)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
double doubleScalar
A typedef for double.
Definition scalarFwd.H:48
Vector< double > doubleVector
Definition vector.H:54
pyramid< point, const point &, const face & > pyramidPointFaceRef
A pyramid using referred point and face.
Definition pyramid.H:70
vector point
Point is a vector.
Definition point.H:37
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
Vector< scalar > vector
Definition vector.H:57
UList< label > labelUList
A UList of labels.
Definition UList.H:75
labelList f(nPoints)
labelList pointLabels(nPoints, -1)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299