findCellPointFaceTet.H
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 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
26Description
27 find the tetrahedron in which the position is.
28 while searching for the tet, store the tet
29 closest to the position.
30 This way, if position is not inside any tet,
31 choose the closest one.
32
33\*---------------------------------------------------------------------------*/
34
35// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36
37namespace Foam
38{
39
40// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41
42template<class Type>
43bool interpolationCellPointFace<Type>::findTet
44(
45 const vector& position,
46 const label nFace,
47 vector tetPoints[],
48 label tetLabelCandidate[],
49 label tetPointLabels[],
50 scalar phi[],
51 scalar phiCandidate[],
52 label& closestFace,
53 scalar& minDistance
54) const
55{
56 bool foundTet = false;
57
58 const labelList& thisFacePoints = this->pMeshFaces_[nFace];
59 tetPoints[2] = this->pMeshFaceCentres_[nFace];
60
61 label pointi = 0;
62
63 while (pointi < thisFacePoints.size() && !foundTet)
64 {
65 label nextPointLabel = (pointi + 1) % thisFacePoints.size();
66
67 tetPointLabels[0] = thisFacePoints[pointi];
68 tetPointLabels[1] = thisFacePoints[nextPointLabel];
69
70 tetPoints[0] = this->pMeshPoints_[tetPointLabels[0]];
71 tetPoints[1] = this->pMeshPoints_[tetPointLabels[1]];
72
73 bool inside = true;
74 scalar dist = 0.0;
75
76 for (label n=0; n<4; n++)
77 {
78 label p1 = (n + 1) % 4;
79 label p2 = (n + 2) % 4;
80 label p3 = (n + 3) % 4;
81
82 vector referencePoint, faceNormal;
83 referencePoint = tetPoints[p1];
84
85 faceNormal =
87 (
88 (tetPoints[p3] - tetPoints[p1])
89 ^ (tetPoints[p2] - tetPoints[p1])
90 );
91
92 // correct normal to point into the tet
93 vector v0 = tetPoints[n] - referencePoint;
94 scalar correct = v0 & faceNormal;
95 if (correct < 0)
96 {
97 faceNormal = -faceNormal;
98 }
99
100 vector v1 = position - referencePoint + SMALL*faceNormal;
101 scalar rightSide = v1 & faceNormal;
102
103 // since normal is inwards, inside the tet
104 // is defined as all dot-products being positive
105 inside = inside && (rightSide >= 0);
106
107 scalar phiLength = (position - referencePoint) & faceNormal;
108
109 scalar maxLength =
110 max(VSMALL, (tetPoints[n] - referencePoint) & faceNormal);
111
112 phi[n] = phiLength/maxLength;
113
114 dist += phi[n];
115 }
116
117 if (!inside)
118 {
119 if (mag(dist - 1.0) < minDistance)
120 {
121 minDistance = mag(dist - 1.0);
122 closestFace = nFace;
123
124 for (label i=0; i<4; i++)
125 {
126 phiCandidate[i] = phi[i];
127 }
128
129 tetLabelCandidate[0] = tetPointLabels[0];
130 tetLabelCandidate[1] = tetPointLabels[1];
131 }
132 }
133
134 foundTet = inside;
135
136 pointi++;
137 }
138
139 if (foundTet)
140 {
141 closestFace = nFace;
142 }
143
144 return foundTet;
145}
146
147
148// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149
150} // End namespace Foam
151
152// ************************************************************************* //
label n
surfaceScalarField & phi
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
thermo correct()
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
List< label > labelList
A List of labels.
Definition: List.H:66
quaternion normalised(const quaternion &q)
Return the normalised (unit) quaternion of the given quaternion.
Definition: quaternionI.H:680
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)