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

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

Added ariginal file location

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