source: issm/trunk/src/c/objects/Bamg/GeomEdge.cpp@ 12706

Last change on this file since 12706 was 12706, checked in by Mathieu Morlighem, 13 years ago

merged trunk-jpl and trunk for revision 12703

File size: 4.3 KB
RevLine 
[3913]1#include <cstdio>
2#include <string.h>
3#include <cmath>
4
5#include "../../include/include.h"
6#include "../../shared/Exceptions/exceptions.h"
7
[5573]8#include "GeomEdge.h"
[3913]9#include "Geometry.h"
10
11using namespace std;
12
13namespace bamg {
14
15 /*Constructor/Destructor*/
16
17 /*Methods*/
[12706]18 /*FUNCTION GeomEdge::Cracked{{{*/
[5573]19 int GeomEdge::Cracked() const {
[5151]20 return type &1;
21 }/*}}}*/
[12706]22 /*FUNCTION GeomEdge::F{{{*/
[5573]23 R2 GeomEdge::F(double theta) const{
[5151]24 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/F)*/
25 // parametrization of the curve edge
26
27 R2 A=v[0]->r,B=v[1]->r;
28 double ca,cb,cta,ctb;
[5447]29
30 //Check that theta is in [0 1]
[6412]31 _assert_(theta>-1e-12 && theta<1+1e-12);
[5447]32
[5489]33 if (TgA()){
34 if (TgB()){ //Hermite interpolation
35 cb = theta*theta*(3-2*theta);
36 ca = 1-cb;
37 cta = (1-theta)*(1-theta)*theta;
38 ctb = (theta-1)*theta*theta ;
[5151]39 }
[5489]40 else {
41 double t = theta;
42 cb = t*t;
43 ca = 1-cb;
44 cta= t-cb;
45 ctb=0;
46 }
47 }
48 else{
49 if (TgB()){
50 double t = 1-theta;
51 ca = t*t;
52 cb = 1-ca;
53 ctb= -t+ca;
54 cta=0;
55 }
56 else { // lagrange P1
57 ca =(1-theta);
58 cb = theta;
59 cta=ctb=0;
60 }
61 }
62 return A*ca + B*cb + tg[0]*cta + tg[1]*ctb;
[5151]63 }
[12706]64 /*}}}*/
65 /*FUNCTION GeomEdge::Mark{{{*/
[5573]66 int GeomEdge::Mark() const {
[5151]67 return type &16;
68 }/*}}}*/
[12706]69 /*FUNCTION GeomEdge::R1tg{{{*/
[5573]70 double GeomEdge::R1tg(double theta,R2 & t) const{
[3913]71 /*Original code from Frederic Hecht <hecht@ann.jussieu.fr> (BAMG v1.01, MeshGeom.cpp/R1tg)*/
72 // 1/R of radius of cuvature
73
74 R2 A=v[0]->r,B=v[1]->r;
75 double dca,dcb,dcta,dctb;
76 double ddca,ddcb,ddcta,ddctb;
77 double tt = theta*theta;
78
79 //check theta
[6412]80 _assert_(theta>=0 && theta<=1);
[3913]81
82 if (TgA()){
83 if (TgB()){
84 // Tangent A and B provided:
85 // interpolation d'hermite
86 dcb = 6*theta*(1-theta);
87 ddcb = 6*(1-2*theta);
88 dca = -dcb;
89 ddca = -ddcb;
90 dcta = (3*theta - 4)*theta + 1;
91 ddcta=6*theta-4;
92 dctb = 3*tt - 2*theta;
93 ddctb = 6*theta-2;
94 }
95 else {
96 //Tangent A provided but tangent B not provided
97 // 1-t*t, t-t*t, t*t
98 double t = theta;
99 dcb = 2*t;
100 ddcb = 2;
101 dca = -dcb;
102 ddca = -2;
103 dcta = 1-dcb;
104 ddcta = -ddcb;
105 dctb=0;
106 ddctb=0;
107 }
108 }
109 else{
110 if (TgB()){
111 //Tangent B provided but tangent A not provided
112 double t = 1-theta;
113 dca = -2*t;
114 ddca = 2;
115 dcb = -dca;
116 ddcb = -2;
117 dctb = 1+dca;
118 ddctb= ddca;
119 dcta =0;
120 ddcta =0;
121 }
122 else {
123 //Neither thangent A nor tangent B provided
124 // lagrange P1
125 t=B-A;
126 return 0;
127 }
128 }
129 R2 d = A*dca + B*dcb + tg[0]* dcta + tg[1] * dctb;
130 R2 dd = A*ddca + B*ddcb + tg[0]* ddcta + tg[1] * ddctb;
131 double d2=(d,d);
132 double sd2 = sqrt(d2);
133 t=d;
134 if(d2>1.0e-20){
135 t/=sd2;
136 return Abs(Det(d,dd))/(d2*sd2);
137 }
138 else return 0;
139 }
[12706]140 /*}}}*/
141 /*FUNCTION GeomEdge::Required{{{*/
[5573]142 int GeomEdge::Required() {
[5151]143 return type &64;
144 }/*}}}*/
[12706]145 /*FUNCTION GeomEdge::Set {{{*/
[5573]146 void GeomEdge::Set(const GeomEdge & rec,const Geometry & Gh ,Geometry & GhNew){
[3913]147 *this = rec;
[5149]148 v[0] = GhNew.vertices + Gh.GetId(v[0]);
149 v[1] = GhNew.vertices + Gh.GetId(v[1]);
150 if (Adj[0]) Adj[0] = GhNew.edges + Gh.GetId(Adj[0]);
151 if (Adj[1]) Adj[1] = GhNew.edges + Gh.GetId(Adj[1]);
[3913]152 }
153 /*}}}*/
[12706]154 /*FUNCTION GeomEdge::SetCracked{{{*/
[5573]155 void GeomEdge::SetCracked() {
[5397]156 type |= 1;/*=>1st digit to 1*/
[5151]157 }/*}}}*/
[12706]158 /*FUNCTION GeomEdge::SetTgA{{{*/
[5573]159 void GeomEdge::SetTgA() {
[5397]160 type |=4; /*=>2d digit to 1*/
[5151]161 }/*}}}*/
[12706]162 /*FUNCTION GeomEdge::SetTgB{{{*/
[5573]163 void GeomEdge::SetTgB() {
[5397]164 type |=8; /*=> 3d digit to 1*/
[5151]165 }/*}}}*/
[12706]166 /*FUNCTION GeomEdge::SetMark{{{*/
[5573]167 void GeomEdge::SetMark() {
[5397]168 type |=16;/*=> 4th digiy to 1*/
[5151]169 }/*}}}*/
[12706]170 /*FUNCTION GeomEdge::SetUnMark{{{*/
[5573]171 void GeomEdge::SetUnMark() {
[5397]172 type &= 1007 /* 1023-16 = 000111110111 => 4th digit to 0*/;
[5151]173 }/*}}}*/
[12706]174 /*FUNCTION GeomEdge::SetRequired{{{*/
[5573]175 void GeomEdge::SetRequired() {
[5447]176 type |= 64;/*=>6th digit to 1*/
[5151]177 }/*}}}*/
[12706]178 /*FUNCTION GeomEdge::Tg{{{*/
[5573]179 int GeomEdge::Tg(int i) const {
[5151]180 return i==0 ? TgA() : TgB();
181 }/*}}}*/
[12706]182 /*FUNCTION GeomEdge::TgA{{{*/
[5573]183 int GeomEdge::TgA() const {
[5151]184 return type &4;
185 }/*}}}*/
[12706]186 /*FUNCTION GeomEdge::TgB{{{*/
[5573]187 int GeomEdge::TgB() const {
[5151]188 return type &8;
189 }/*}}}*/
[3913]190}
Note: See TracBrowser for help on using the repository browser.