findCellPointFaceTriangle.H
Go to the documentation of this file.
1/*
2 find the triangle in which the position is,
3 when the position is known to be on the face
4*/
5
6// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
7
8namespace Foam
9{
10
11// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
12
13template<class Type>
14bool interpolationCellPointFace<Type>::findTriangle
15(
16 const vector& position,
17 const label nFace,
18 label tetPointLabels[],
19 scalar phi[]
20) const
21{
22 bool foundTriangle = false;
23 vector tetPoints[3];
24 const labelList& facePoints = this->pMeshFaces_[nFace];
25 tetPoints[2] = this->pMeshFaceCentres_[nFace];
26
27 label pointi = 0;
28
29 while (pointi < facePoints.size() && !foundTriangle)
30 {
31 // The triangle is constructed from face center and one
32 // face edge
33 label nextPointLabel = (pointi + 1) % facePoints.size();
34
35 tetPointLabels[0] = facePoints[pointi];
36 tetPointLabels[1] = facePoints[nextPointLabel];
37
38 tetPoints[0] = this->pMeshPoints_[tetPointLabels[0]];
39 tetPoints[1] = this->pMeshPoints_[tetPointLabels[1]];
40
41 vector fc = (tetPoints[0] + tetPoints[1] + tetPoints[2])/3.0;
42
43 vector newPos = position + SMALL*(fc-position);
44
45 // calculate triangle edge vectors and triangle face normal
46 // the 'i':th edge is opposite node i
47 vector edge[3], normal[3];
48 for (label i=0; i<3; i++)
49 {
50 label ip0 = (i+1) % 3;
51 label ipp = (i+2) % 3;
52 edge[i] = tetPoints[ipp]-tetPoints[ip0];
53 }
54
55 vector triangleFaceNormal = edge[1] ^ edge[2];
56
57 // calculate edge normal (pointing inwards)
58 for (label i=0; i<3; i++)
59 {
60 normal[i] = normalised(triangleFaceNormal ^ edge[i]);
61 }
62
63 // check if position is inside triangle
64 bool inside = true;
65 for (label i=0; i<3; i++)
66 {
67 label ip = (i+1) % 3;
68 inside = inside && (((newPos - tetPoints[ip]) & edge[i]) >= 0);
69 }
70
71 if (inside)
72 {
73 foundTriangle = true;
74
75 // calculate phi-values
76 for (label i=0; i<3; i++)
77 {
78 label ip = (i+1) % 3;
79 scalar phiMax = max(VSMALL, normal[i] & edge[ip]);
80 scalar phiLength = (position-tetPoints[ip]) & normal[i];
81 phi[i] = phiLength/phiMax;
82 }
83 }
84
85 pointi++;
86 }
87
88 return foundTriangle;
89}
90
91
92// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93
94} // End namespace Foam
95
96// ************************************************************************* //
surfaceScalarField & phi
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
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