valib
Vortex Analysis LIBrary
Loading...
Searching...
No Matches
compactness.h
Go to the documentation of this file.
1
5#ifndef VA_COMPACTNESS_H
6#define VA_COMPACTNESS_H
7
8#include "common_defs.h"
9#include "linalg3.h"
10
11/***************************************************************************/
38VA_DEVICE_FUN void valib_compactness(VA_REAL *A, VA_REAL *compactness)
39{
40 // cast the eigenvalue problem to finding roots of the cubic characteristic
41 // equation
42 // ax^3 + bx^2 + cx + d = 0
43 // x^3 - trace(A) x^2 + II_A x - det(A) = 0
44 VA_REAL a, b, c, d;
45
46 a = 1.;
47
48 valib_trace3(A, &b);
49 b = -b;
50
52
53 valib_determinant3(A, &d);
54 d = -d;
55
56 // find the three complex roots
57 int info;
58 VA_COMPLEX x1, x2, x3;
59 valib_solve_cubic_equation(a, b, c, d, &x1, &x2, &x3, &info);
60
61 VA_REAL lambda_r, lambda_cr, lambda_ci;
62
63 if (info == -1) {
64 // only real eigenvalues exist, compactness cannot be determined
65 *compactness = -VA_INFINITY;
66 return;
67 }
68 else if (info == 0) {
69 // search for eigenvalues was successful
70 lambda_r = creal(x1);
71 lambda_cr = creal(x2);
72 lambda_ci = fabs(cimag(x2));
73 }
74 else {
75 // there was another error in the search for eigenvalues
76 printf("The solve of the cubic equation has failed with info: %d \n", info);
77 *compactness = -VA_INFINITY;
78 return;
79 }
80
81 // now find the compactness criterion
82 //*compactness = 1. - 1./3. * pow (lambda_cr / lambda_ci - lambda_r / lambda_ci, 2.);
83 *compactness = 1. - 1./3. * valib_square(lambda_cr / lambda_ci - lambda_r / lambda_ci)
84 - valib_sign(1.,2.*lambda_cr+lambda_r)*valib_square(2*lambda_cr+lambda_r) / 6. / valib_square(lambda_ci);
85
86 return;
87}
88
89#endif // VA_COMPACTNESS_H
VA_DEVICE_FUN void valib_compactness(VA_REAL *A, VA_REAL *compactness)
Compactness criterion.
Definition compactness.h:38
VA_DEVICE_FUN void valib_solve_cubic_equation(VA_REAL a, VA_REAL b, VA_REAL c, VA_REAL d, VA_COMPLEX *x1, VA_COMPLEX *x2, VA_COMPLEX *x3, int *info)
Definition linalg3.h:123
VA_DEVICE_FUN VA_REAL valib_square(VA_REAL a)
Definition linalg3.h:98
VA_DEVICE_FUN void valib_second_invariant3(VA_REAL *A, VA_REAL *second_invariant)
Definition linalg3.h:379
VA_DEVICE_FUN VA_REAL valib_sign(VA_REAL a, VA_REAL b)
Definition linalg3.h:20
VA_DEVICE_FUN void valib_trace3(VA_REAL *A, VA_REAL *tr3)
Definition linalg3.h:370
VA_DEVICE_FUN void valib_determinant3(VA_REAL *A, VA_REAL *det)
Definition linalg3.h:390