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 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 (
36  const labelList& pointLabels,
37  const UList<point>& points
38 ) const
39 {
40  // Estimate centre of cell
41  vector cEst = Zero;
42 
43  // Sum the points indicated by the label list
45  {
46  cEst += points[pointLabels[i]];
47  }
48 
49  // Average by dividing by the number summed over.
50  cEst /= scalar(pointLabels.size());
51 
52 
53  // Calculate the centre by breaking the cell into pyramids and
54  // volume-weighted averaging their centres
55  scalar sumV = 0.0;
56  vector sumVc = Zero;
57 
58  const faceList cellFaces = faces(pointLabels);
59 
60  forAll(cellFaces, i)
61  {
62  const face& curFace = cellFaces[i];
63 
64  scalar pyrVol =
66  (
67  curFace,
68  cEst
69  ).mag(points);
70 
71  if (pyrVol > SMALL)
72  {
74  << "zero or negative pyramid volume: " << -pyrVol
75  << " for face " << i
76  << endl;
77  }
78 
79  sumVc -=
80  pyrVol
82  .centre(points);
83 
84  sumV -= pyrVol;
85  }
86 
87  return sumVc/(sumV + VSMALL);
88 }
89 
90 
91 Foam::scalar Foam::cellModel::mag
92 (
93  const labelList& pointLabels,
94  const UList<point>& points
95 ) const
96 {
97  // Estimate centre of cell
98  vector cEst = Zero;
99 
100  // Sum the points indicated by the label list
101  forAll(pointLabels, i)
102  {
103  cEst += points[pointLabels[i]];
104  }
105 
106  // Average by dividing by the number summed over.
107  cEst /= scalar(pointLabels.size());
108 
109 
110  // Calculate the magnitude by summing the -mags of the pyramids
111  // The sign change is because the faces point outwards
112  // and a pyramid is constructed from an inward pointing face
113  // and the base centre-apex vector
114  scalar v = 0;
115 
116  const faceList cellFaces = faces(pointLabels);
117 
118  forAll(cellFaces, i)
119  {
120  const face& curFace =cellFaces[i];
121 
122  scalar pyrVol =
124  (
125  curFace,
126  cEst
127  ).mag(points);
128 
129  if (pyrVol > SMALL)
130  {
132  << "zero or negative pyramid volume: " << -pyrVol
133  << " for face " << i
134  << endl;
135  }
136 
137  v -= pyrVol;
138  }
139 
140  return v;
141 }
142 
143 
144 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::cellModel::centre
vector centre(const labelList &pointLabels, const UList< point > &points) const
Vector centroid.
Definition: cellModel.C:35
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
pyramid.H
cellModel.H
Foam::pyramid::centre
Point centre(const UList< point > &points) const
Return centre (centroid)
Definition: pyramidI.H:69
Foam::pyramid
A geometric pyramid primitive with a base of 'n' sides: i.e. a parametric pyramid....
Definition: pyramid.H:49
Foam::pyramid::mag
scalar mag(const UList< point > &points) const
Return scalar magnitude - returns volume of pyramid.
Definition: pyramidI.H:90
Foam::Vector
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:62
Foam::List< label >
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::cellModel::mag
scalar mag(const labelList &pointLabels, const UList< point > &points) const
Cell volume.
Definition: cellModel.C:92
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
pointLabels
labelList pointLabels(nPoints, -1)