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

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

Do not use throw ErrorException -> ISSMERROR macro
Removed all FUNCT definitions (now useless)

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