valib
Vortex Analysis LIBrary
rortex.h
1 
5 #ifndef VA_RORTEX_H
6 #define VA_RORTEX_H
7 
8 #include "common_defs.h"
9 #include "linalg3.h"
10 
11 /***************************************************************************/
53 VA_DEVICE_FUN void valib_rortex(VA_REAL *A, VA_REAL *rortex)
54 {
55  int debug = 0;
56 
57  // get vector of vorticity
58  VA_REAL vorticity[3];
59  vorticity[0] = A[2+1*3] - A[1+2*3];
60  vorticity[1] = A[0+2*3] - A[2+0*3];
61  vorticity[2] = A[1+0*3] - A[0+1*3];
62 
63 
64  if (debug) {
65  printf("the vorticity vector is: [ %lf, %lf, %lf ]\n",
66  vorticity[0], vorticity[1], vorticity[2]);
67  }
68 
69  // cast the eigenvalue problem to finding roots of the cubic characteristic
70  // equation
71  // ax^3 + bx^2 + cx + d = 0
72  // x^3 - trace(A) x^2 + II_A x - det(A) = 0
73  VA_REAL a, b, c, d;
74 
75  a = 1.;
76 
77  valib_trace3(A, &b);
78  b = -b;
79 
81 
82  valib_determinant3(A, &d);
83  d = -d;
84 
85  // find the three complex roots
86  int info;
87  VA_REAL complex x1, x2, x3;
88  valib_solve_cubic_equation(a, b, c, d, &x1, &x2, &x3, &info);
89 
90  VA_REAL lambda_r, lambda_ci;
91 
92  if (info == -1) {
93  // only real eigenvalues exist, Rortex is zero
94  rortex[0] = 0.;
95  rortex[1] = 0.;
96  rortex[2] = 0.;
97 
98  return;
99  }
100  else if (info == 0) {
101  // search for eigenvalues was successful
102  lambda_r = creal(x1);
103  lambda_ci = cimag(x2);
104  }
105  else {
106  // there was another error in the search for eigenvalues
107  printf("The solve of the cubic equation has failed with info: %d \n", info);
108  rortex[0] = 0.;
109  rortex[1] = 0.;
110  rortex[2] = 0.;
111  return;
112  }
113 
114  // now find the corresponding eigenvector as the solution of
115  // (A - lambda_r*I)x = 0
116 
117  // form matrix B = A - lambda_r*I
118  VA_REAL B[9];
119  for (int i = 0; i < 9; i++)
120  B[i] = A[i];
121  for (int i = 0; i < 3; i++)
122  B[i+i*3] -= lambda_r;
123 
124  valib_find_nullspace3(B, rortex, &info);
125  if (info < 0) {
126  printf("Something is wrong, find_nullspace returned with info %d.\n", info);
127  rortex[0] = 0.;
128  rortex[1] = 0.;
129  rortex[2] = 0.;
130  return;
131  }
132 
133  // print the eigenvector
134  if (debug) {
135  printf("the real eigenvector is: [ %lf, %lf, %lf ]\n",
136  rortex[0], rortex[1], rortex[2]);
137  }
138 
139  // ensure condition (14) by reverting the eigenvector if needed
140  VA_REAL vr = valib_scalar_prod3(vorticity, rortex);
141  if (vr < 0) {
142  for (int i = 0; i < 3; i++)
143  rortex[i] = -rortex[i];
144  }
145 
146  vr = valib_scalar_prod3(vorticity, rortex);
147  if (vr < 0) {
148  printf("Something is wrong, the scalar product of vorticity and rortex should be positive, %lf.\n", vr);
149  rortex[0] = 0.;
150  rortex[1] = 0.;
151  rortex[2] = 0.;
152  return;
153  }
154 
155  // compute the magnitude of Rortex by equation (13)
156  VA_REAL R = vr - sqrt(vr*vr - 4.*lambda_ci*lambda_ci);
157  // scale the rortex
158  for (int i = 0; i < 3; i++)
159  rortex[i] *= R;
160 }
161 
162 #endif // VA_RORTEX_H
valib_scalar_prod3
VA_DEVICE_FUN VA_REAL valib_scalar_prod3(VA_REAL *v1, VA_REAL *v2)
Definition: linalg3.h:196
valib_determinant3
VA_DEVICE_FUN void valib_determinant3(VA_REAL *A, VA_REAL *det)
Definition: linalg3.h:293
valib_trace3
VA_DEVICE_FUN void valib_trace3(VA_REAL *A, VA_REAL *tr3)
Definition: linalg3.h:273
valib_find_nullspace3
VA_DEVICE_FUN void valib_find_nullspace3(VA_REAL *A, VA_REAL *x, int *info)
Definition: linalg3.h:569
valib_solve_cubic_equation
VA_DEVICE_FUN void valib_solve_cubic_equation(VA_REAL a, VA_REAL b, VA_REAL c, VA_REAL d, VA_REAL complex *x1, VA_REAL complex *x2, VA_REAL complex *x3, int *info)
Definition: linalg3.h:74
valib_rortex
VA_DEVICE_FUN void valib_rortex(VA_REAL *A, VA_REAL *rortex)
The Rortex vector (a.k.a. the Vortex vector or the Liutex vector) .
Definition: rortex.h:53
valib_second_invariant3
VA_DEVICE_FUN void valib_second_invariant3(VA_REAL *A, VA_REAL *second_invariant)
Definition: linalg3.h:282