From 9fa10c8db42ab21709c35d5c5c6a8ac109b7e897 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Thu, 7 Nov 2024 14:39:03 -0500 Subject: [PATCH] print_alpha --- README.md | 3 +++ src/main.c | 14 +++++++++++++- src/navier-stokes.c | 3 ++- src/navier-stokes.h | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98e1b58..810e3ef 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,9 @@ should be a `;` sperated list of `key=value` pairs. The possible keys are * `keep_en_cst` (0 or 1, default 0): impose that the enstrophy is constant at each step (only really useful for the reversible equation). +* `print_alpha` (0 or 1, default 0): if this is set to 1, then whenever alpha + is negative, its value is printed as a comment. + # Interrupting and resuming the computation diff --git a/src/main.c b/src/main.c index 6b5079e..eebdaca 100644 --- a/src/main.c +++ b/src/main.c @@ -58,6 +58,7 @@ typedef struct nstrophy_parameters { FILE* drivingfile; double lyapunov_reset; double D_epsilon; + bool print_alpha; } nstrophy_parameters; // usage message @@ -277,7 +278,7 @@ int main ( // register signal handler to handle aborts signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); - enstrophy(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, u0, g, parameters.irreversible, parameters.keep_en_cst, parameters.init_en, parameters.algorithm, parameters.print_freq, parameters.starting_time, nthreads, savefile, utfile, (char*)argv[0], dstring_to_str_noinit(¶m_str), dstring_to_str_noinit(&savefile_str), dstring_to_str_noinit(&utfile_str)); + enstrophy(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, u0, g, parameters.irreversible, parameters.keep_en_cst, parameters.init_en, parameters.algorithm, parameters.print_freq, parameters.starting_time, parameters.print_alpha, nthreads, savefile, utfile, (char*)argv[0], dstring_to_str_noinit(¶m_str), dstring_to_str_noinit(&savefile_str), dstring_to_str_noinit(&utfile_str)); } else if(command==COMMAND_QUIET){ quiet(parameters.K1, parameters.K2, parameters.N1, parameters.N2, parameters.final_time, parameters.nu, parameters.delta, parameters.L, parameters.adaptive_tolerance, parameters.adaptive_factor, parameters.max_delta, parameters.adaptive_norm, parameters.starting_time, u0, g, parameters.irreversible, parameters.keep_en_cst, parameters.init_en, parameters.algorithm, nthreads, savefile); @@ -554,6 +555,8 @@ int set_default_params( parameters->initfile=NULL; parameters->algorithm=ALGORITHM_RK4; parameters->keep_en_cst=false; + + parameters->print_alpha=false; return(0); } @@ -885,6 +888,15 @@ int set_parameter( } parameters->keep_en_cst=(tmp==1); } + else if (strcmp(lhs,"print_alpha")==0){ + int tmp; + ret=sscanf(rhs,"%d",&tmp); + if(ret!=1 || (tmp!=0 && tmp!=1)){ + fprintf(stderr, "error: parameter 'print_alpha' should be 0 or 1\n got '%s'\n",rhs); + return(-1); + } + parameters->print_alpha=(tmp==1); + } else{ fprintf(stderr, "error: unrecognized parameter '%s'\n",lhs); return(-1); diff --git a/src/navier-stokes.c b/src/navier-stokes.c index 8b68506..476ec4e 100644 --- a/src/navier-stokes.c +++ b/src/navier-stokes.c @@ -145,6 +145,7 @@ int enstrophy( unsigned int algorithm, double print_freq, double starting_time, + bool print_alpha, unsigned int nthreads, FILE* savefile, FILE* utfile, @@ -236,7 +237,7 @@ int enstrophy( } // print alpha when it gets negative - if(alpha<0){ + if(print_alpha && alpha<0){ fprintf(stderr,"## negative alpha: % .8e at time % .8e\n",alpha, time); printf("## negative alpha: % .15e at time % .15e\n",alpha, time); } diff --git a/src/navier-stokes.h b/src/navier-stokes.h index 8c7e87b..9d9f989 100644 --- a/src/navier-stokes.h +++ b/src/navier-stokes.h @@ -34,7 +34,7 @@ typedef struct fft_vects { int uk( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, bool keep_en_cst, double target_en, unsigned int algorithm, double print_freq, double starting_time, unsigned int nthreadsl, FILE* savefile); // compute enstrophy and alpha -int enstrophy( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, bool keep_en_cst, double target_en, unsigned int algorithm, double print_freq, double starting_time, unsigned int nthreads, FILE* savefile, FILE* utfile, const char* cmd_string, const char* params_string, const char* savefile_string, const char* utfile_string); +int enstrophy( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, _Complex double* u0, _Complex double* g, bool irreversible, bool keep_en_cst, double target_en, unsigned int algorithm, double print_freq, double starting_time, bool print_alpha, unsigned int nthreads, FILE* savefile, FILE* utfile, const char* cmd_string, const char* params_string, const char* savefile_string, const char* utfile_string); // compute solution as a function of time, but do not print anything (useful for debugging) int quiet( int K1, int K2, int N1, int N2, double final_time, double nu, double delta, double L, double adaptive_tolerance, double adaptive_factor, double max_delta, unsigned int adaptive_norm, double starting_time, _Complex double* u0, _Complex double* g, bool irreversible, bool keep_en_cst, double target_en, unsigned int algorithm, unsigned int nthreads, FILE* savefile);