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 
8 namespace Foam
9 {
10 
11 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
12 
13 template<class Type>
14 bool 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 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::normalised
VectorSpace< Form, Cmpt, Ncmpts > normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:487