add argument checking and handle timerstep counters with 64-bit integers properly

This commit is contained in:
Axel Kohlmeyer
2015-10-13 12:16:27 -04:00
parent d7fc1a3ff8
commit 8cdb890b10
5 changed files with 41 additions and 31 deletions

View File

@ -763,23 +763,28 @@ void colvar::disable(colvar::task const &t)
disable(task_output_applied_force); disable(task_output_applied_force);
disable(task_system_force); disable(task_system_force);
disable(task_Jacobian_force); disable(task_Jacobian_force);
tasks[t] = false;
break; break;
case task_system_force: case task_system_force:
disable(task_output_system_force); disable(task_output_system_force);
tasks[t] = false;
break; break;
case task_Jacobian_force: case task_Jacobian_force:
disable(task_report_Jacobian_force); disable(task_report_Jacobian_force);
tasks[t] = false;
break; break;
case task_fdiff_velocity: case task_fdiff_velocity:
disable(task_output_velocity); disable(task_output_velocity);
tasks[t] = false;
break; break;
case task_lower_boundary: case task_lower_boundary:
case task_upper_boundary: case task_upper_boundary:
disable(task_grid); disable(task_grid);
tasks[t] = false;
break; break;
case task_extended_lagrangian: case task_extended_lagrangian:
@ -793,15 +798,17 @@ void colvar::disable(colvar::task const &t)
case task_grid: case task_grid:
case task_lower_wall: case task_lower_wall:
case task_upper_wall: case task_upper_wall:
case task_ntot:
case task_langevin: case task_langevin:
case task_output_energy: case task_output_energy:
case task_collect_gradients: case task_collect_gradients:
case task_scripted: case task_scripted:
tasks[t] = false;
break;
default:
break; break;
} }
tasks[t] = false;
} }

View File

@ -25,6 +25,7 @@
#include "update.h" #include "update.h"
#include "respa.h" #include "respa.h"
#include "error.h" #include "error.h"
#include "force.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
@ -45,18 +46,18 @@ FixTIRS::FixTIRS(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
extvector = 1; extvector = 1;
// Time variables. // Time variables.
t_switch = atoi(arg[5]); t_switch = force->bnumeric(FLERR,arg[5]);
t_equil = atoi(arg[6]); t_equil = force->bnumeric(FLERR,arg[6]);
t0 = update->ntimestep; t0 = update->ntimestep;
if (t_switch < 0.0) error->all(FLERR,"Illegal fix ti/rs command"); if (t_switch <= 0) error->all(FLERR,"Illegal fix ti/rs command");
if (t_equil < 0.0) error->all(FLERR,"Illegal fix ti/rs command"); if (t_equil <= 0) error->all(FLERR,"Illegal fix ti/rs command");
// Coupling parameter limits and initialization. // Coupling parameter limits and initialization.
l_initial = atof(arg[3]); l_initial = force->numeric(FLERR,arg[3]);
l_final = atof(arg[4]); l_final = force->numeric(FLERR,arg[4]);
sf = 1; sf = 1;
if (narg > 7) { if (narg > 7) {
if (strcmp(arg[7], "function") == 0) sf = atoi(arg[8]); if (strcmp(arg[7], "function") == 0) sf = force->inumeric(FLERR,arg[8]);
else error->all(FLERR,"Illegal fix ti/rs switching function"); else error->all(FLERR,"Illegal fix ti/rs switching function");
if ((sf<1) || (sf>3)) if ((sf<1) || (sf>3))
error->all(FLERR,"Illegal fix ti/rs switching function"); error->all(FLERR,"Illegal fix ti/rs switching function");
@ -151,16 +152,17 @@ void FixTIRS::min_post_force(int vflag)
void FixTIRS::initial_integrate(int vflag) void FixTIRS::initial_integrate(int vflag)
{ {
// Update the coupling parameter value. // Update the coupling parameter value.
double t = update->ntimestep - (t0+t_equil); const bigint t = update->ntimestep - (t0+t_equil);
const double r_switch = 1.0/t_switch;
if( (t >= 0) && (t <= t_switch) ) { if( (t >= 0) && (t <= t_switch) ) {
lambda = switch_func(t/t_switch); lambda = switch_func(t*r_switch);
dlambda = dswitch_func(t/t_switch); dlambda = dswitch_func(t*r_switch);
} }
if( (t >= t_equil+t_switch) && (t <= (t_equil+2*t_switch)) ) { if( (t >= t_equil+t_switch) && (t <= (t_equil+2*t_switch)) ) {
lambda = switch_func(1.0 - (t - t_switch - t_equil)/t_switch); lambda = switch_func(1.0 - (t - t_switch - t_equil)*r_switch);
dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)/t_switch); dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)*r_switch);
} }
} }

View File

@ -53,9 +53,9 @@ class FixTIRS : public Fix {
double l_initial; // Lambda initial value. double l_initial; // Lambda initial value.
double l_final; // Lambda final value. double l_final; // Lambda final value.
double linfo[2]; // Current lambda status. double linfo[2]; // Current lambda status.
int t_switch; // Total switching steps. bigint t_switch; // Total switching steps.
int t_equil; // Equilibration time. bigint t_equil; // Equilibration time.
int t0; // Initial time. bigint t0; // Initial time.
int sf; // Switching function option. int sf; // Switching function option.
int nlevels_respa; int nlevels_respa;
}; };

View File

@ -73,16 +73,16 @@ FixTISpring::FixTISpring(LAMMPS *lmp, int narg, char **arg) :
} }
// Time variables. // Time variables.
t_switch = atoi(arg[4]); // Switching time. t_switch = force->bnumeric(FLERR,arg[4]); // Number of steps for switching.
t_equil = atoi(arg[5]); // Equilibration time. t_equil = force->bnumeric(FLERR,arg[5]); // Number of steps for equilibration.
t0 = update->ntimestep; // Initial time. t0 = update->ntimestep; // Initial time.
if (t_switch <= 0.0) error->all(FLERR,"Illegal fix ti/spring command"); if (t_switch <= 0) error->all(FLERR,"Illegal fix ti/spring command");
if (t_equil <= 0.0) error->all(FLERR,"Illegal fix ti/spring command"); if (t_equil <= 0) error->all(FLERR,"Illegal fix ti/spring command");
// Coupling parameter initialization. // Coupling parameter initialization.
sf = 1; sf = 1;
if (narg > 6) { if (narg > 6) {
if (strcmp(arg[6], "function") == 0) sf = atoi(arg[7]); if (strcmp(arg[6], "function") == 0) sf = force->inumeric(FLERR,arg[7]);
else error->all(FLERR,"Illegal fix ti/spring switching function"); else error->all(FLERR,"Illegal fix ti/spring switching function");
if ((sf!=1) && (sf!=2)) if ((sf!=1) && (sf!=2))
error->all(FLERR,"Illegal fix ti/spring switching function"); error->all(FLERR,"Illegal fix ti/spring switching function");
@ -151,7 +151,7 @@ void FixTISpring::min_setup(int vflag)
void FixTISpring::post_force(int vflag) void FixTISpring::post_force(int vflag)
{ {
// If on the first equilibration do not calculate forces. // If on the first equilibration do not calculate forces.
int t = update->ntimestep - t0; bigint t = update->ntimestep - t0;
if(t < t_equil) return; if(t < t_equil) return;
double **x = atom->x; double **x = atom->x;
@ -199,16 +199,17 @@ void FixTISpring::min_post_force(int vflag)
void FixTISpring::initial_integrate(int vflag) void FixTISpring::initial_integrate(int vflag)
{ {
// Update the coupling parameter value. // Update the coupling parameter value.
double t = update->ntimestep - (t0+t_equil); const bigint t = update->ntimestep - (t0+t_equil);
const double r_switch = 1.0/t_switch;
if( (t >= 0) && (t <= t_switch) ) { if( (t >= 0) && (t <= t_switch) ) {
lambda = switch_func(t/t_switch); lambda = switch_func(t*r_switch);
dlambda = dswitch_func(t/t_switch); dlambda = dswitch_func(t*r_switch);
} }
if( (t >= t_equil+t_switch) && (t <= (t_equil+2*t_switch)) ) { if( (t >= t_equil+t_switch) && (t <= (t_equil+2*t_switch)) ) {
lambda = switch_func(1.0 - (t - t_switch - t_equil)/t_switch ); lambda = switch_func(1.0 - (t - t_switch - t_equil)*r_switch);
dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)/t_switch ); dlambda = - dswitch_func(1.0 - (t - t_switch - t_equil)*r_switch);
} }
} }

View File

@ -65,9 +65,9 @@ class FixTISpring : public Fix {
double lambda; // Coupling parameter. double lambda; // Coupling parameter.
double dlambda; // Lambda variation with t. double dlambda; // Lambda variation with t.
double linfo[2]; // Current lambda status. double linfo[2]; // Current lambda status.
int t_switch; // Total switching steps. bigint t_switch; // Total switching steps.
int t_equil; // Equilibration time. bigint t_equil; // Equilibration time.
int t0; // Initial time. bigint t0; // Initial time.
int sf; // Switching function option. int sf; // Switching function option.
int nlevels_respa; int nlevels_respa;
}; };