BoundaryElementEdgeDist.cc 1.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "BoundaryElementEdgeDist.h"

int 
BoundaryElementEdgeDist::calcDistOnBoundaryElement(
			 ElInfo *elInfo,
			 FixVec<double, VERTEX> &dVec)
{
  WorldVector<double> vert1, vert2;
  int vert1Ind, vert2Ind;
  double length;
  double val;
  
  
  // Get intersection information.
  int  elStatus = elLS->createElementLevelSet(elInfo);
  if (elStatus != ElementLevelSet::LEVEL_SET_BOUNDARY)
    return elStatus;
  
  VectorOfFixVecs<DimVec<double> > *elIntersecPoints = 
    elLS->getElIntersecPoints();
  int numIntersecPoints = elLS->getNumElIntersecPoints();
  
  // For all vertices: calculate distance to intersection points.
  for (int i = 0; i < numIntersecPoints; ++i) {
    vert1Ind = -1; 
    vert2Ind = -1;
    length = 0;
    
    // Get vertices on edge with intersection point.
    for (int j=0; j<=dim; ++j) {
      if ((*elIntersecPoints)[i][j] > 1.e-15) {
	if (vert1Ind == -1) vert1Ind = j;
	else {
	  vert2Ind = j;
	  break;
	}
      }
    }
    
    // Get length of edge with intersection point.
    vert1 = elInfo->getCoord(vert1Ind);
    vert2 = elInfo->getCoord(vert2Ind);
    for (int j=0; j<dim; ++j) {
      length += (vert1[j] - vert2[j])*(vert1[j]-vert2[j]);
    }
    length = sqrt(length);
    
    // Get distance of vert1 and vert2 to intersection point.
    val = (*elIntersecPoints)[i][vert2Ind] * length;
    dVec[vert1Ind] = val;
    dVec[vert2Ind] = length - val;
  }
  
  return elStatus;
}