valib
Vortex Analysis LIBrary
Loading...
Searching...
No Matches
rortex.h
Go to the documentation of this file.
1
5#ifndef VA_RORTEX_H
6#define VA_RORTEX_H
7
8#include "common_defs.h"
9#include "linalg3.h"
10
11/***************************************************************************/
53VA_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 if (debug) {
86 printf(" %s:\n", "A");
87 int i, j;
88 for (i = 0; i < 3; i++) {
89 printf(" [ ");
90 for (j = 0; j < 3; j++) {
91 printf(" %13.6f ", A[j*3+i]);
92 }
93 printf(" ]\n");
94 }
95 printf("a, b, c, d: %lf, %lf, %lf, %lf\n", a, b, c, d);
96 }
97
98 // find the three complex roots
99 int info;
100 VA_COMPLEX x1, x2, x3;
101 valib_solve_cubic_equation(a, b, c, d, &x1, &x2, &x3, &info);
102
103 VA_REAL lambda_r, lambda_ci;
104
105 if (info == -1) {
106 // only real eigenvalues exist, Rortex is zero
107 rortex[0] = 0.;
108 rortex[1] = 0.;
109 rortex[2] = 0.;
110
111 return;
112 }
113 else if (info == 0) {
114 // search for eigenvalues was successful
115 lambda_r = creal(x1);
116 lambda_ci = cimag(x2);
117 }
118 else {
119 // there was another error in the search for eigenvalues
120 printf("The solve of the cubic equation has failed with info: %d \n", info);
121 rortex[0] = 0.;
122 rortex[1] = 0.;
123 rortex[2] = 0.;
124 return;
125 }
126
127 // now find the corresponding eigenvector as the solution of
128 // (A - lambda_r*I)x = 0
129
130 // form matrix B = A - lambda_r*I
131 VA_REAL B[9];
132 for (int i = 0; i < 9; i++)
133 B[i] = A[i];
134 for (int i = 0; i < 3; i++)
135 B[i+i*3] -= lambda_r;
136
137 valib_find_nullspace3(B, rortex, &info);
138 if (info < 0) {
139 printf("Something is wrong, find_nullspace returned with info %d.\n", info);
140 rortex[0] = 0.;
141 rortex[1] = 0.;
142 rortex[2] = 0.;
143 return;
144 }
145
146 // print the eigenvector
147 if (debug) {
148 printf("the real eigenvector is: [ %lf, %lf, %lf ]\n",
149 rortex[0], rortex[1], rortex[2]);
150 }
151
152 // ensure condition (14) by reverting the eigenvector if needed
153 VA_REAL vr = valib_scalar_prod3(vorticity, rortex);
154 if (vr < 0) {
155 for (int i = 0; i < 3; i++)
156 rortex[i] = -rortex[i];
157 }
158
159 vr = valib_scalar_prod3(vorticity, rortex);
160 if (vr < 0) {
161 printf("Something is wrong, the scalar product of vorticity and rortex should be positive, %lf.\n", vr);
162 rortex[0] = 0.;
163 rortex[1] = 0.;
164 rortex[2] = 0.;
165 return;
166 }
167
168 // compute the magnitude of Rortex by equation (13)
169 VA_REAL diff = vr*vr - 4.*lambda_ci*lambda_ci;
170 VA_REAL R;
171 if (diff >= 0.)
172 R = vr - sqrt(diff);
173 else
174 R = 0.;
175
176 // scale the rortex
177 for (int i = 0; i < 3; i++)
178 rortex[i] *= R;
179}
180
181#endif // VA_RORTEX_H
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
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_scalar_prod3(VA_REAL *v1, VA_REAL *v2)
Definition linalg3.h:293
VA_DEVICE_FUN void valib_second_invariant3(VA_REAL *A, VA_REAL *second_invariant)
Definition linalg3.h:379
VA_DEVICE_FUN void valib_find_nullspace3(VA_REAL *A, VA_REAL *x, int *info)
Definition linalg3.h:683
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