Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SimplexBndNormal.cpp
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_SimplexBndNormal_cpp_
9#define model_SimplexBndNormal_cpp_
10
11#include <SimplexBndNormal.h>
12
13namespace model
14{
15
16
17
18
19 /**********************************************************************/
21 const Simplex<dim,dim>& simplex,
22 const double& dmax)
23 {
24
25 //std::cout<<simplex.xID<<std::endl;
26 VectorDim temp(VectorDim::Zero());
27 bool found=false;
28
29 // 1) check if P is close to a boundary vertex
30 for(int f=0;f<Simplex<dim,dim>::nFaces;++f) // loop over faces of current Simplex in the path
31 {
32 for(int e=0;e<3;++e)
33 {
34 for(int v=0;v<2;++v)
35 {
36 if((simplex.child(f).child(e).child(v).P0-P).norm()<dmax && simplex.child(f).child(e).child(v).isBoundarySimplex())
37 {
38 temp=simplex.child(f).child(e).child(v).outNormal();
39 found=true;
40 }
41 if(found)
42 {
43 break;
44 }
45 }
46 if(found)
47 {
48 break;
49 }
50 }
51 if(found)
52 {
53 break;
54 }
55 }
56
57 if(!found)
58 {// No boundary vertex was found. Check if P is close to a boundary edge
59 for(int f=0;f<Simplex<dim,dim>::nFaces;++f) // loop over faces of current Simplex in the path
60 {
61 for(int e=0;e<3;++e)
62 {
63 const VectorDim& x1=simplex.child(f).child(e).child(0).P0;
64 const VectorDim& x2=simplex.child(f).child(e).child(1).P0;
65 const double d=(P-x1).cross(P-x2).norm()/(x2-x1).norm(); // distance to edge
66 if(d<dmax && simplex.child(f).child(e).isBoundarySimplex()) // point close to edge, and edge is on boundary
67 {
68 temp=simplex.child(f).child(e).outNormal();
69 found=true;
70 }
71 if(found)
72 {
73 break;
74 }
75 }
76 if(found)
77 {
78 break;
79 }
80 }
81 }
82
83 // 3) check if P is close to a boundary face
84 if(!found) // no boundary face was found
85 {
86 const Eigen::Matrix<double,dim+1,1> bary(simplex.pos2bary(P));
87
88 for(int f=0;f<Simplex<dim,dim>::nFaces;++f) // loop over faces of current Simplex in the path
89 {// volume of tetrahedron V=1/3*A*h. Volume = V0*bary. So h=3*V0*bary/A
90 const double h=3.0*simplex.vol0*bary(f)/simplex.child(f).vol0; // distance from f-th face
91// std::cout<<"h="<<h<<" "<<simplex.child(f).isBoundarySimplex()<<std::endl;
92
93 if(simplex.child(f).isBoundarySimplex() && std::fabs(h)<dmax)
94 {
95// temp=simplex.nda.col(f).normalized();
96 temp=simplex.child(f).outNormal();
97 found=true;
98 }
99 if(found)
100 {
101 break;
102 }
103 }
104 }
105
106 return temp;
107 }
108
109} // close namespace
110#endif
111
static VectorDim get_boundaryNormal(const VectorDim &P, const Simplex< dim, dim > &simplex, const double &dmax)
Eigen::Matrix< double, dim, 1 > VectorDim
function int_R syms a b c u real f
Definition int_R.m:4
REAL * h
int e
vertex temp
REAL v[4]