source: issm/trunk/src/c/Bamgx/objects/MatVVP2x2.cpp@ 2981

Last change on this file since 2981 was 2981, checked in by Mathieu Morlighem, 15 years ago

Moved MetricAnIso to Metric (no more MetricIso)

File size: 1.5 KB
RevLine 
[2838]1#include <cstdio>
2#include <cstring>
3#include <cmath>
4#include <ctime>
5
[2865]6#include "../Mesh2.h"
[2838]7#include "../QuadTree.h"
8#include "../SetOfE4.h"
9
10#include "../../shared/shared.h"
11#include "../../include/macros.h"
12#include "../../toolkits/toolkits.h"
13
[2850]14#undef __FUNCT__
15#define __FUNCT__ "MatVVP2x2"
16
[2838]17namespace bamg {
18
[2841]19 /*Constructor*/
[2981]20 /*FUNCTION MatVVP2x2::MatVVP2x2(const Metric M){{{1*/
21 MatVVP2x2::MatVVP2x2(const Metric M){
[2838]22 double a11=M.a11,a21=M.a21,a22=M.a22;
23 const double eps = 1.e-5;
24 double c11 = a11*a11, c22 = a22*a22, c21= a21*a21;
25 double b=-a11-a22,c=-c21+a11*a22;
[2917]26 double delta = b*b - 4 * c ;
[2838]27 double n2=(c11+c22+c21);
[2917]28
29 //if norm(M)<10^30 -> M=zeros(2,2)
30 if ( n2 < 1e-30) lambda1=lambda2=0,v.x=1,v.y=0;
31
[2928]32 //if matrix is already diagonal and has a 0 eigen value
[2917]33 else if (delta < eps*n2){
[2838]34 lambda1=lambda2=-b/2, v.x=1,v.y=0;
[2917]35 }
36
37 //general case: construction of 2 eigen vectors
38 else {
39 delta = sqrt(delta);
40 lambda1 = (-b-delta)/2.0,lambda2 = (-b+delta)/2.0;
[2838]41 double v0 = a11-lambda1, v1 = a21,v2 = a22 - lambda1;
42 double s0 = v0*v0 + v1*v1, s1 = v1*v1 +v2*v2;
43 if(s1 < s0)
44 s0=sqrt(s0),v.x=v1/s0,v.y=-v0/s0;
45 else
46 s1=sqrt(s1),v.x=v2/s1,v.y=-v1/s1;
[2917]47 };
[2838]48 }
49 /*}}}1*/
[2841]50
[2899]51 /*Methods*/
52 /*FUNCTION MatVVP2x2::Echo {{{1*/
53
54 void MatVVP2x2::Echo(void){
55
56 printf("MatVVP2x2:\n");
57 printf(" lambda1: %g\n",lambda1);
58 printf(" lambda2: %g\n",lambda2);
59 printf(" v.x: %g\n",v.x);
60 printf(" v.y: %g\n",v.y);
61
62 return;
63 }
64 /*}}}*/
65
[2838]66}
Note: See TracBrowser for help on using the repository browser.