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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "face.H"
29 #include "DynamicList.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<int SizeMin>
34 Foam::label Foam::face::triangles
35 (
36  const UList<point>& points,
38 ) const
39 {
40  label triI = triFaces.size();
41  label quadI = 0;
42  faceList quadFaces;
43 
44  // adjust the addressable size (and allocate space if needed)
45  triFaces.setSize(triI + nTriangles());
46 
47  return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
48 }
49 
50 
51 template<class Type>
53 (
54  const UList<point>& meshPoints,
55  const Field<Type>& fld
56 ) const
57 {
58  // Calculate the average by breaking the face into triangles and
59  // area-weighted averaging their averages
60 
61  // If the face is a triangle, do a direct calculation
62  if (size() == 3)
63  {
64  return
65  (1.0/3.0)
66  *(
67  fld[operator[](0)]
68  + fld[operator[](1)]
69  + fld[operator[](2)]
70  );
71  }
72 
73  label nPoints = size();
74 
75  point centrePoint = Zero;
76  Type cf = Zero;
77 
78  for (label pI=0; pI<nPoints; pI++)
79  {
80  centrePoint += meshPoints[operator[](pI)];
81  cf += fld[operator[](pI)];
82  }
83 
84  centrePoint /= nPoints;
85  cf /= nPoints;
86 
87  scalar sumA = 0;
88  Type sumAf = Zero;
89 
90  for (label pI=0; pI<nPoints; pI++)
91  {
92  // Calculate 3*triangle centre field value
93  Type ttcf =
94  (
95  fld[operator[](pI)]
96  + fld[operator[]((pI + 1) % nPoints)]
97  + cf
98  );
99 
100  // Calculate 2*triangle area
101  scalar ta = Foam::mag
102  (
103  (meshPoints[operator[](pI)] - centrePoint)
104  ^ (meshPoints[operator[]((pI + 1) % nPoints)] - centrePoint)
105  );
106 
107  sumA += ta;
108  sumAf += ta*ttcf;
109  }
110 
111  if (sumA > VSMALL)
112  {
113  return sumAf/(3*sumA);
114  }
115  else
116  {
117  return cf;
118  }
119 }
120 
121 
122 // ************************************************************************* //
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
face.H
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::face::average
Type average(const UList< point > &meshPoints, const Field< Type > &fld) const
Calculate average value at centroid of face.
Definition: faceTemplates.C:53
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::DynamicList::setSize
void setSize(const label n)
Same as resize()
Definition: DynamicList.H:224
Foam::face::triangles
label triangles(const UList< point > &points, label &triI, faceList &triFaces) const
Split into triangles using existing points.
Definition: face.C:836
Foam::Vector< scalar >
Foam::List< face >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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
split
static bool split(const std::string &line, std::string &key, std::string &val)
Definition: cpuInfo.C:39
DynamicList.H