added set_temp and set_timestep stages
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 21 Aug 2008 11:37:28 +0000 (13:37 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 21 Aug 2008 11:37:28 +0000 (13:37 +0200)
mdrun.c
mdrun.h

diff --git a/mdrun.c b/mdrun.c
index af8a352..b5abe87 100644 (file)
--- a/mdrun.c
+++ b/mdrun.c
@@ -111,6 +111,12 @@ int add_stage(t_mdrun *mdrun,u8 type,void *params) {
                case STAGE_CHSATTR:
                        psize=sizeof(t_chsattr_params);
                        break;
+               case STAGE_SET_TEMP:
+                       psize=sizeof(t_set_temp_params);
+                       break;
+               case STAGE_SET_TIMESTEP:
+                       psize=sizeof(t_set_timestep_params);
+                       break;
                default:
                        printf("%s unknown stage type: %02x\n",ME,type);
                        return -1;
@@ -155,6 +161,8 @@ int mdrun_parse_config(t_mdrun *mdrun) {
        t_anneal_params ap;
        t_chaattr_params cap;
        t_chsattr_params csp;
+       t_set_temp_params stp;
+       t_set_timestep_params stsp;
 
        /* open config file */
        fd=open(mdrun->cfile,O_RDONLY);
@@ -184,6 +192,8 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                memset(&ap,0,sizeof(t_anneal_params));
                memset(&cap,0,sizeof(t_chaattr_params));
                memset(&csp,0,sizeof(t_chsattr_params));
+               memset(&stp,0,sizeof(t_set_temp_params));
+               memset(&stsp,0,sizeof(t_set_timestep_params));
 
                // get command + args
                wcnt=0;
@@ -509,6 +519,21 @@ int mdrun_parse_config(t_mdrun *mdrun) {
                                ap.dt=atof(word[3]);
                                add_stage(mdrun,STAGE_ANNEAL,&ap);
                        }
+                       else if(!strncmp(word[1],"set_temp",8)) {
+                               if(word[2][0]=='c') {
+                                       stp.type=SET_TEMP_CURRENT;
+                                       stp.val=0.0;
+                               }
+                               else {
+                                       stp.type=SET_TEMP_VALUE;
+                                       stp.val=atof(word[2]);
+                               }
+                               add_stage(mdrun,STAGE_SET_TEMP,&stp);
+                       }
+                       else if(!strncmp(word[1],"set_timestep",12)) {
+                               stsp.tau=atof(word[2]);
+                               add_stage(mdrun,STAGE_SET_TIMESTEP,&stsp);
+                       }
                        else {
                                printf("%s unknown stage type: %s\n",
                                       ME,word[1]);
@@ -836,7 +861,6 @@ int chaatr(t_moldyn *moldyn,t_mdrun *mdrun) {
                }
                atom->attr=cap->attr;
        }
-       printf("     atom attributes: %02x\n\n",cap->attr);
 
        return 0;
 }
@@ -898,13 +922,14 @@ int mdrun_hook(void *ptr1,void *ptr2) {
        t_stage *stage;
        t_list *sl;
        int steps;
-       double tau;
        u8 change_stage;
 
        t_insert_atoms_params *iap;
        t_insert_mixed_atoms_params *imp;
        t_continue_params *cp;
        t_anneal_params *ap;
+       t_set_temp_params *stp;
+       t_set_timestep_params *stsp;
 
        moldyn=ptr1;
        mdrun=ptr2;
@@ -920,9 +945,8 @@ int mdrun_hook(void *ptr1,void *ptr2) {
        /* get stage description */
        stage=sl->current->data;
 
-       /* default steps and tau values */
+       /* steps in next schedule */
        steps=mdrun->relax_steps;
-       tau=mdrun->timestep;
 
        /* check whether relaxation steps are necessary */
        if((check_pressure(moldyn,mdrun)==TRUE)&\
@@ -984,15 +1008,32 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                ap->count+=1;
                                break;
                        case STAGE_CHAATTR:
-                               stage_print("  -> chaattr\n\n");
+                               stage_print("  -> change atom attributes\n\n");
                                chaatr(moldyn,mdrun);
                                change_stage=TRUE;
                                break;
                        case STAGE_CHSATTR:
-                               stage_print("  -> chsattr\n\n");
+                               stage_print("  -> change sys attributes\n\n");
                                chsattr(moldyn,mdrun);
                                change_stage=TRUE;
                                break;
+                       case STAGE_SET_TEMP:
+                               stage_print("  -> set temperature\n\n");
+                               stp=stage->params;
+                               if(stp->type&SET_TEMP_CURRENT) {
+                                       set_temperature(moldyn,moldyn->t_avg);
+                               }
+                               else {
+                                       set_temperature(moldyn,stp->val);
+                               }
+                               change_stage=TRUE;
+                               break;
+                       case STAGE_SET_TIMESTEP:
+                               stage_print("  -> set timestep\n\n");
+                               stsp=stage->params;
+                               mdrun->timestep=stsp->tau;
+                               change_stage=TRUE;
+                               break;
                        default:
                                printf("%s unknwon stage type\n",ME);
                                break;
@@ -1009,7 +1050,6 @@ int mdrun_hook(void *ptr1,void *ptr2) {
                                return 0;
                        }
                        steps=0;
-                       tau=mdrun->timestep;
                }
 
        }
@@ -1022,7 +1062,7 @@ int mdrun_hook(void *ptr1,void *ptr2) {
        }
 
        /* continue simulation */
-       moldyn_add_schedule(moldyn,steps,tau);
+       moldyn_add_schedule(moldyn,steps,mdrun->timestep);
 
        return 0;
 }
diff --git a/mdrun.h b/mdrun.h
index acd2331..9030072 100644 (file)
--- a/mdrun.h
+++ b/mdrun.h
@@ -48,6 +48,8 @@ typedef struct s_stage {
 #define STAGE_ANNEAL                           0x04
 #define STAGE_CHAATTR                          0x05
 #define STAGE_CHSATTR                          0x06
+#define STAGE_SET_TEMP                         0x07
+#define STAGE_SET_TIMESTEP                     0x08
 
 typedef struct s_mdrun {
        char cfile[128];                        // config file
@@ -176,6 +178,18 @@ typedef struct s_chsattr_params {
 #define CHSATTR_AVGRST                         0x10
 #define CHSATTR_RSTEPS                         0x20
 
+typedef struct s_set_temp_params {
+       u8 type;
+       double val;
+} t_set_temp_params;
+
+#define SET_TEMP_CURRENT                       0x01
+#define SET_TEMP_VALUE                         0x02
+
+typedef struct s_set_timestep_params {
+       double tau;
+} t_set_timestep_params;
+
 /*
  * function prototypes
  */