Split real and imag part in jacobian
This commit is contained in:
@ -21,7 +21,8 @@ limitations under the License.
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MATSIZE (K1*(2*K2+1)+K2)
|
||||
#define MATSIZE (2*(K1*(2*K2+1)+K2))
|
||||
#define USIZE (K1*(2*K2+1)+K2)
|
||||
|
||||
// compute Lyapunov exponents
|
||||
int lyapunov(
|
||||
@ -50,8 +51,8 @@ int lyapunov(
|
||||
){
|
||||
double* lyapunov;
|
||||
double* lyapunov_avg;
|
||||
_Complex double* Du_prod;
|
||||
_Complex double* Du;
|
||||
double* Du_prod;
|
||||
double* Du;
|
||||
_Complex double* u;
|
||||
_Complex double* prevu;
|
||||
_Complex double* tmp1;
|
||||
@ -63,7 +64,7 @@ int lyapunov(
|
||||
_Complex double* tmp7;
|
||||
_Complex double* tmp8;
|
||||
_Complex double* tmp9;
|
||||
_Complex double* tmp10;
|
||||
double* tmp10;
|
||||
double time;
|
||||
fft_vect fft1;
|
||||
fft_vect fft2;
|
||||
@ -82,9 +83,6 @@ int lyapunov(
|
||||
double step=delta;
|
||||
double next_step=step;
|
||||
|
||||
const _Complex double one=1;
|
||||
const _Complex double zero=0;
|
||||
|
||||
int i;
|
||||
// init average
|
||||
for (i=0; i<MATSIZE; i++){
|
||||
@ -109,9 +107,9 @@ int lyapunov(
|
||||
|
||||
// multiply Jacobian
|
||||
// switch to column major order, so transpose Du
|
||||
cblas_zgemm(CblasColMajor, CblasNoTrans, CblasTrans, MATSIZE, MATSIZE, MATSIZE, &one, Du_prod, MATSIZE, Du, MATSIZE, &zero, tmp10, MATSIZE);
|
||||
cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, MATSIZE, MATSIZE, MATSIZE, 1., Du_prod, MATSIZE, Du, MATSIZE, 0., tmp10, MATSIZE);
|
||||
// copy back to Du_prod
|
||||
_Complex double* move=tmp10;
|
||||
double* move=tmp10;
|
||||
tmp10=Du_prod;
|
||||
Du_prod=move;
|
||||
|
||||
@ -124,10 +122,10 @@ int lyapunov(
|
||||
|
||||
// QR decomposition
|
||||
// do not touch tmp1, it might be used in the next step
|
||||
LAPACKE_zgerqf(LAPACK_COL_MAJOR, MATSIZE, MATSIZE, Du_prod, MATSIZE, tmp2);
|
||||
LAPACKE_dgerqf(LAPACK_COL_MAJOR, MATSIZE, MATSIZE, Du_prod, MATSIZE, tmp10);
|
||||
// extract eigenvalues (diagonal elements of Du_prod)
|
||||
for(i=0; i<MATSIZE; i++){
|
||||
lyapunov[i]=log(cabs(Du_prod[i*MATSIZE+i]))/(time-prevtime);
|
||||
lyapunov[i]=log(fabs(Du_prod[i*MATSIZE+i]))/(time-prevtime);
|
||||
}
|
||||
|
||||
// sort lyapunov exponents
|
||||
@ -153,7 +151,7 @@ int lyapunov(
|
||||
}
|
||||
|
||||
// set Du_prod to Q:
|
||||
LAPACKE_zungrq(LAPACK_COL_MAJOR, MATSIZE, MATSIZE, MATSIZE, Du_prod, MATSIZE, tmp2);
|
||||
LAPACKE_dorgrq(LAPACK_COL_MAJOR, MATSIZE, MATSIZE, MATSIZE, Du_prod, MATSIZE, tmp10);
|
||||
|
||||
// reset prevtime
|
||||
prevtime=time;
|
||||
@ -177,7 +175,7 @@ int compare_double(const void* x, const void* y) {
|
||||
|
||||
// Jacobian of u_n -> u_{n+1}
|
||||
int ns_D_step(
|
||||
_Complex double* out,
|
||||
double* out,
|
||||
_Complex double* un,
|
||||
_Complex double* un_next,
|
||||
int K1,
|
||||
@ -218,7 +216,7 @@ int ns_D_step(
|
||||
for(ly=(lx>0 ? -K2 : 1);ly<=K2;ly++){
|
||||
// derivative in the real direction
|
||||
// finite difference vector
|
||||
for (i=0;i<MATSIZE;i++){
|
||||
for (i=0;i<USIZE;i++){
|
||||
if(i==klookup_sym(lx,ly,K2)){
|
||||
tmp1[i]=un[i]+epsilon;
|
||||
}else{
|
||||
@ -230,15 +228,16 @@ int ns_D_step(
|
||||
step=delta;
|
||||
next_step=delta;
|
||||
ns_step(algorithm, tmp1, K1, K2, N1, N2, nu, &step, &next_step, adaptive_tolerance, adaptive_factor, max_delta, adaptive_norm, L, g, time, time, fft1, fft2, ifft, &tmp2, &tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, irreversible, keep_en_cst, target_en);
|
||||
// compute derivative
|
||||
for (i=0;i<MATSIZE;i++){
|
||||
// derivative
|
||||
for (i=0;i<USIZE;i++){
|
||||
// use row major order
|
||||
out[klookup_sym(lx,ly,K2)*MATSIZE+i]=(tmp1[i]-un_next[i])/epsilon;
|
||||
out[2*klookup_sym(lx,ly,K2)*USIZE+2*i]=(__real__ (tmp1[i]-un_next[i]))/epsilon;
|
||||
out[(2*klookup_sym(lx,ly,K2)+1)*USIZE+2*i]=(__imag__ (tmp1[i]-un_next[i]))/epsilon;
|
||||
}
|
||||
|
||||
// derivative in the imaginary direction
|
||||
// finite difference vector
|
||||
for (i=0;i<MATSIZE;i++){
|
||||
for (i=0;i<USIZE;i++){
|
||||
if(i==klookup_sym(lx,ly,K2)){
|
||||
tmp1[i]=un[i]+epsilon*I;
|
||||
}else{
|
||||
@ -251,9 +250,10 @@ int ns_D_step(
|
||||
next_step=delta;
|
||||
ns_step(algorithm, tmp1, K1, K2, N1, N2, nu, &step, &next_step, adaptive_tolerance, adaptive_factor, max_delta, adaptive_norm, L, g, time, time, fft1, fft2, ifft, &tmp2, &tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, irreversible, keep_en_cst, target_en);
|
||||
// compute derivative
|
||||
for (i=0;i<MATSIZE;i++){
|
||||
for (i=0;i<USIZE;i++){
|
||||
// use row major order
|
||||
out[klookup_sym(lx,ly,K2)*MATSIZE+i]=-(tmp1[i]-un_next[i])/epsilon*I;
|
||||
out[2*klookup_sym(lx,ly,K2)*USIZE+2*i+1]=(__real__ (tmp1[i]-un_next[i]))/epsilon;
|
||||
out[(2*klookup_sym(lx,ly,K2)+1)*USIZE+2*i+1]=(__imag__ (tmp1[i]-un_next[i]))/epsilon;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -265,8 +265,8 @@ int ns_D_step(
|
||||
int lyapunov_init_tmps(
|
||||
double ** lyapunov,
|
||||
double ** lyapunov_avg,
|
||||
_Complex double ** Du_prod,
|
||||
_Complex double ** Du,
|
||||
double ** Du_prod,
|
||||
double ** Du,
|
||||
_Complex double ** u,
|
||||
_Complex double ** prevu,
|
||||
_Complex double ** tmp1,
|
||||
@ -278,7 +278,7 @@ int lyapunov_init_tmps(
|
||||
_Complex double ** tmp7,
|
||||
_Complex double ** tmp8,
|
||||
_Complex double ** tmp9,
|
||||
_Complex double ** tmp10,
|
||||
double ** tmp10,
|
||||
fft_vect* fft1,
|
||||
fft_vect* fft2,
|
||||
fft_vect* ifft,
|
||||
@ -293,12 +293,12 @@ int lyapunov_init_tmps(
|
||||
|
||||
*lyapunov=calloc(sizeof(double),MATSIZE);
|
||||
*lyapunov_avg=calloc(sizeof(double),MATSIZE);
|
||||
*Du_prod=calloc(sizeof(_Complex double),MATSIZE*MATSIZE);
|
||||
*Du=calloc(sizeof(_Complex double),MATSIZE*MATSIZE);
|
||||
*prevu=calloc(sizeof(_Complex double),MATSIZE);
|
||||
*tmp1=calloc(sizeof(_Complex double),MATSIZE);
|
||||
*tmp2=calloc(sizeof(_Complex double),MATSIZE);
|
||||
*tmp10=calloc(sizeof(_Complex double),MATSIZE*MATSIZE);
|
||||
*Du_prod=calloc(sizeof(double),MATSIZE*MATSIZE);
|
||||
*Du=calloc(sizeof(double),MATSIZE*MATSIZE);
|
||||
*prevu=calloc(sizeof(_Complex double),USIZE);
|
||||
*tmp1=calloc(sizeof(_Complex double),USIZE);
|
||||
*tmp2=calloc(sizeof(_Complex double),USIZE);
|
||||
*tmp10=calloc(sizeof(double),MATSIZE*MATSIZE);
|
||||
|
||||
return(0);
|
||||
}
|
||||
@ -307,8 +307,8 @@ int lyapunov_init_tmps(
|
||||
int lyapunov_free_tmps(
|
||||
double* lyapunov,
|
||||
double* lyapunov_avg,
|
||||
_Complex double* Du_prod,
|
||||
_Complex double* Du,
|
||||
double* Du_prod,
|
||||
double* Du,
|
||||
_Complex double* u,
|
||||
_Complex double* prevu,
|
||||
_Complex double* tmp1,
|
||||
@ -320,7 +320,7 @@ int lyapunov_free_tmps(
|
||||
_Complex double* tmp7,
|
||||
_Complex double* tmp8,
|
||||
_Complex double* tmp9,
|
||||
_Complex double* tmp10,
|
||||
double* tmp10,
|
||||
fft_vect fft1,
|
||||
fft_vect fft2,
|
||||
fft_vect ifft,
|
||||
|
@ -26,12 +26,12 @@ int lyapunov( int K1, int K2, int N1, int N2, double final_time, double lyapunov
|
||||
int compare_double(const void* x, const void* y);
|
||||
|
||||
// Jacobian of step
|
||||
int ns_D_step( _Complex double* out, _Complex double* un, _Complex double* un_next, int K1, int K2, int N1, int N2, double nu, double epsilon, double delta, unsigned int algorithm, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, double L, _Complex double* g, double time, fft_vect fft1, fft_vect fft2, fft_vect ifft, _Complex double* tmp1, _Complex double* tmp2, _Complex double* tmp3, _Complex double* tmp4, _Complex double* tmp5, _Complex double* tmp6, _Complex double* tmp7, _Complex double* tmp8, bool irreversible, bool keep_en_cst, double target_en);
|
||||
int ns_D_step( double* out, _Complex double* un, _Complex double* un_next, int K1, int K2, int N1, int N2, double nu, double epsilon, double delta, unsigned int algorithm, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, double L, _Complex double* g, double time, fft_vect fft1, fft_vect fft2, fft_vect ifft, _Complex double* tmp1, _Complex double* tmp2, _Complex double* tmp3, _Complex double* tmp4, _Complex double* tmp5, _Complex double* tmp6, _Complex double* tmp7, _Complex double* tmp8, bool irreversible, bool keep_en_cst, double target_en);
|
||||
|
||||
// init vectors
|
||||
int lyapunov_init_tmps(double** lyapunov, double** lyapunov_avg, _Complex double ** Du_prod, _Complex double ** Du, _Complex double ** u, _Complex double ** prevu, _Complex double ** tmp1, _Complex double ** tmp2, _Complex double ** tmp3, _Complex double ** tmp4, _Complex double ** tmp5, _Complex double ** tmp6, _Complex double ** tmp7, _Complex double ** tmp8, _Complex double ** tmp9, _Complex double** tmp10, fft_vect* fft1, fft_vect* fft2, fft_vect* ifft, int K1, int K2, int N1, int N2, unsigned int nthreads, unsigned int algorithm);
|
||||
int lyapunov_init_tmps(double** lyapunov, double** lyapunov_avg, double ** Du_prod, double ** Du, _Complex double ** u, _Complex double ** prevu, _Complex double ** tmp1, _Complex double ** tmp2, _Complex double ** tmp3, _Complex double ** tmp4, _Complex double ** tmp5, _Complex double ** tmp6, _Complex double ** tmp7, _Complex double ** tmp8, _Complex double ** tmp9, double** tmp10, fft_vect* fft1, fft_vect* fft2, fft_vect* ifft, int K1, int K2, int N1, int N2, unsigned int nthreads, unsigned int algorithm);
|
||||
// release vectors
|
||||
int lyapunov_free_tmps(double* lyapunov, double* lyapunov_avg, _Complex double* Du_prod, _Complex double* Du, _Complex double* u, _Complex double* prevu, _Complex double* tmp1, _Complex double* tmp2, _Complex double* tmp3, _Complex double* tmp4, _Complex double* tmp5, _Complex double* tmp6, _Complex double* tmp7, _Complex double* tmp8, _Complex double* tmp9, _Complex double* tmp10, fft_vect fft1, fft_vect fft2, fft_vect ifft, unsigned int algorithm);
|
||||
int lyapunov_free_tmps(double* lyapunov, double* lyapunov_avg, double* Du_prod, double* Du, _Complex double* u, _Complex double* prevu, _Complex double* tmp1, _Complex double* tmp2, _Complex double* tmp3, _Complex double* tmp4, _Complex double* tmp5, _Complex double* tmp6, _Complex double* tmp7, _Complex double* tmp8, _Complex double* tmp9, double* tmp10, fft_vect fft1, fft_vect fft2, fft_vect ifft, unsigned int algorithm);
|
||||
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user