Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
meshes
meshShapes
face
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) 1991-2010 OpenCFD Ltd.
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 <
OpenFOAM/DynamicList.H
>
28
29
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30
31
template
<
unsigned
SizeInc,
unsigned
SizeMult,
unsigned
SizeDiv>
32
Foam::label
Foam::face::triangles
33
(
34
const
pointField
&
points
,
35
DynamicList<face, SizeInc, SizeMult, SizeDiv>
& triFaces
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>
50
Type
Foam::face::average
51
(
52
const
pointField
& meshPoints,
53
const
Field<Type>
&
f
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
f[operator[](0)]
66
+ f[operator[](1)]
67
+ f[operator[](2)]
68
);
69
}
70
71
label
nPoints
= size();
72
73
point
centrePoint = point::zero;
74
Type cf =
pTraits<Type>::zero
;
75
76
for
(
register
label pI=0; pI<
nPoints
; pI++)
77
{
78
centrePoint += meshPoints[operator[](pI)];
79
cf += f[operator[](pI)];
80
}
81
82
centrePoint /=
nPoints
;
83
cf /=
nPoints
;
84
85
scalar sumA = 0;
86
Type sumAf =
pTraits<Type>::zero
;
87
88
for
(
register
label pI=0; pI<
nPoints
; pI++)
89
{
90
// Calculate 3*triangle centre field value
91
Type ttcf =
92
(
93
f[operator[](pI)]
94
+ f[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
// ************************ vim: set sw=4 sts=4 et: ************************ //