faceTemplates.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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "face.H"
27 #include "DynamicList.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
33 (
34  const pointField& points,
36 ) const
37 {
38  label triI = triFaces.size();
39  label quadI = 0;
40  faceList quadFaces;
41 
42  // adjust the addressable size (and allocate space if needed)
43  triFaces.setSize(triI + nTriangles());
44 
45  return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
46 }
47 
48 
49 template<class Type>
51 (
52  const pointField& meshPoints,
53  const Field<Type>& fld
54 ) const
55 {
56  // Calculate the average by breaking the face into triangles and
57  // area-weighted averaging their averages
58 
59  // If the face is a triangle, do a direct calculation
60  if (size() == 3)
61  {
62  return
63  (1.0/3.0)
64  *(
65  fld[operator[](0)]
66  + fld[operator[](1)]
67  + fld[operator[](2)]
68  );
69  }
70 
71  label nPoints = size();
72 
73  point centrePoint = Zero;
74  Type cf = Zero;
75 
76  for (label pI=0; pI<nPoints; pI++)
77  {
78  centrePoint += meshPoints[operator[](pI)];
79  cf += fld[operator[](pI)];
80  }
81 
82  centrePoint /= nPoints;
83  cf /= nPoints;
84 
85  scalar sumA = 0;
86  Type sumAf = Zero;
87 
88  for (label pI=0; pI<nPoints; pI++)
89  {
90  // Calculate 3*triangle centre field value
91  Type ttcf =
92  (
93  fld[operator[](pI)]
94  + fld[operator[]((pI + 1) % nPoints)]
95  + cf
96  );
97 
98  // Calculate 2*triangle area
99  scalar ta = Foam::mag
100  (
101  (meshPoints[operator[](pI)] - centrePoint)
102  ^ (meshPoints[operator[]((pI + 1) % nPoints)] - centrePoint)
103  );
104 
105  sumA += ta;
106  sumAf += ta*ttcf;
107  }
108 
109  if (sumA > VSMALL)
110  {
111  return sumAf/(3*sumA);
112  }
113  else
114  {
115  return cf;
116  }
117 }
118 
119 
120 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
label triangles(const pointField &points, label &triI, faceList &triFaces) const
Split into triangles using existing points.
Definition: face.C:829
void setSize(const label)
Alter the addressed list size.
Definition: DynamicListI.H:163
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
label nPoints
static const zero Zero
Definition: zero.H:91
Type average(const pointField &, const Field< Type > &) const
Calculate average value at centroid of face.
Definition: faceTemplates.C:51
dimensioned< scalar > mag(const dimensioned< Type > &)