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-------------------------------------------------------------------------------
10License
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
33template<int SizeMin>
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
51template<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// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
virtual void average()
Calculate the average.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void setSize(const label n)
Same as resize()
Definition: DynamicList.H:221
Generic templated field type.
Definition: Field.H:82
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:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
const DynamicList< triPoints > triangles() const
Const access to the triangulation.
label nTriangles() const
Number of triangles after splitting.
Definition: faceI.H:187
const pointField & points
label nPoints
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131