Allow the Lyapunov computation to be interrupted

This commit is contained in:
2025-01-31 21:58:54 -05:00
parent 53a0a0ae4c
commit 06e5b0e0da
5 changed files with 217 additions and 15 deletions

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "constants.cpp"
#include "lyapunov.h"
#include "io.h"
#include <openblas64/cblas.h>
#include <openblas64/lapacke.h>
#include <math.h>
@ -48,7 +49,16 @@ int lyapunov(
unsigned int algorithm,
unsigned int algorithm_lyapunov,
double starting_time,
unsigned int nthreads
unsigned int nthreads,
double* flow0,
double* lyapunov_avg0,
FILE* savefile,
FILE* utfile,
// for interrupt recovery
const char* cmd_string,
const char* params_string,
const char* savefile_string,
const char* utfile_string
){
double* lyapunov;
double* lyapunov_avg;
@ -82,15 +92,13 @@ int lyapunov(
// copy initial condition
copy_u(u, u0, K1, K2);
// initialize flow with identity matrix
// initialize flow and averages
for (i=0;i<MATSIZE;i++){
for (j=0;j<MATSIZE;j++){
if(i!=j){
flow[i*MATSIZE+j]=0.;
} else {
flow[i*MATSIZE+j]=1.;
}
flow[i*MATSIZE+j]=flow0[i*MATSIZE+j];
}
lyapunov_avg[i]=lyapunov_avg0[i];
}
// store step (useful for adaptive step methods)
@ -168,9 +176,27 @@ int lyapunov(
// reset prevtime
prevtime=time;
// catch abort signal
if (g_abort){
// print u to stderr if no savefile
if (savefile==NULL){
savefile=stderr;
}
break;
}
}
}
if(savefile!=NULL){
lyapunov_save_state(flow, u, lyapunov_avg, savefile, K1, K2, cmd_string, params_string, savefile_string, utfile_string, utfile, COMMAND_LYAPUNOV, algorithm, step, time, nthreads);
}
// save final u to utfile in txt format
if(utfile!=NULL){
write_vec(u, K1, K2, utfile);
}
lyapunov_free_tmps(lyapunov, lyapunov_avg, flow, u, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10, tmp11, fftu1, fftu2, fftu3, fftu4, fft1, ifft, algorithm, algorithm_lyapunov);
return(0);
}
@ -749,3 +775,35 @@ int lyapunov_free_tmps(
return(0);
}
// save state of lyapunov computation
int lyapunov_save_state(
double* flow,
_Complex double* u,
double* lyapunov_avg,
FILE* savefile,
int K1,
int K2,
const char* cmd_string,
const char* params_string,
const char* savefile_string,
const char* utfile_string,
FILE* utfile,
unsigned int command,
unsigned int algorithm,
double step,
double time,
unsigned int nthreads
){
// save u and step
save_state(u, savefile, K1, K2, cmd_string, params_string, savefile_string, utfile_string, utfile, command, algorithm, step, time, nthreads);
if(savefile!=stderr && savefile!=stdout){
// save tangent flow
write_mat2_bin(flow,K1,K2,savefile);
// save lyapunov averages
write_vec2_bin(lyapunov_avg,K1,K2,savefile);
}
return 0;
}