]> hackdaworld.org Git - physik/posic.git/commitdiff
rewritten state machine
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 13 Feb 2008 15:16:39 +0000 (16:16 +0100)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 13 Feb 2008 15:16:39 +0000 (16:16 +0100)
sic.c

diff --git a/sic.c b/sic.c
index 406ad537ea11953e3ed4671583192f9874a9b454..77e3c79b4a9912808c23269d3800842baae73e90 100644 (file)
--- a/sic.c
+++ b/sic.c
@@ -133,51 +133,75 @@ int sic_hook(void *moldyn,void *hook_params) {
        /* switch to insert state immediately */
        if(hp->state==STATE_PRERUN)
                hp->state=STATE_INSERT;
-
-       /* act according to state */
+       
        switch(hp->state) {
                case STATE_INSERT:
-                       /* assigne values */
-                       steps=INS_RELAX;
-                       tau=INS_TAU;
-                       /* check temperature */
-                       dt=md->t_avg-md->t_ref;
-                       if(dt<0)
-                               dt=-dt;
-                       if(dt>INS_DELTA_TC)
-                               break;
-                       /* insert atoms */
-                       hp->insert_count+=1;
-                       printf("   ### insert atoms (%d/%d) ###\n",
-                              hp->insert_count*INS_ATOMS,INS_RUNS*INS_ATOMS);
-                       insert_atoms(md);
-                       /* change state after last insertion */
-                       if(hp->insert_count==INS_RUNS)
-                               hp->state=STATE_POSTRUN;
+                       goto insert;
                        break;
                case STATE_POSTRUN:
-                       /* assigne values */
-                       steps=POST_RELAX;
-                       tau=POST_TAU;
-                       /* check temperature */
-                       dt=md->t_avg-md->t_ref;
-                       if(dt<0)
-                               dt=-dt;
-                       if(dt>POST_DELTA_TC)
-                               break;
-                       /* decrease temperature */
-                       hp->postrun_count+=1;
-                       printf(" ### postrun (%d/%d) ###\n",
-                              hp->postrun_count,POST_RUNS);
-                       set_temperature(md,md->t_ref-POST_DT);
-                       if(hp->postrun_count==POST_RUNS)
-                               return 0;
+                       goto postrun;
                        break;
                default:
-                       printf("[hook] FATAL (default case!?!)\n");
-                       break;
+                       printf("[sic hook] unknown state\n");
+                       return -1;
        }
 
+       /* act according to state */
+
+insert:
+
+       /* immediately go on if no job is to be done */
+       if(hp->insert_count==INS_RUNS) {
+printf("immediate insert run return!\n");
+               hp->state=STATE_POSTRUN;
+               goto postrun;
+       }
+
+       /* assigne values */
+       steps=INS_RELAX;
+       tau=INS_TAU;
+
+       /* check temperature */
+       dt=md->t_avg-md->t_ref;
+       if(dt<0)
+               dt=-dt;
+       if(dt>INS_DELTA_TC)
+               goto addsched;
+
+       /* else -> insert atoms */
+       hp->insert_count+=1;
+       printf("   ### insert atoms (%d/%d) ###\n",
+              hp->insert_count*INS_ATOMS,INS_RUNS*INS_ATOMS);
+       insert_atoms(md);
+       goto addsched;
+
+postrun:
+
+       /* immediately return if no job is to be done */
+       if(hp->postrun_count==POST_RUNS) {
+printf("immediate post run return!\n");
+               return 0;
+       }
+
+       /* assigne values */
+       steps=POST_RELAX;
+       tau=POST_TAU;
+
+       /* check temperature */
+       dt=md->t_avg-md->t_ref;
+       if(dt<0)
+               dt=-dt;
+       if(dt>POST_DELTA_TC)
+               goto addsched;
+
+       /* postrun action */
+       hp->postrun_count+=1;
+       printf(" ### postrun (%d/%d) ###\n",
+              hp->postrun_count,POST_RUNS);
+       set_temperature(md,md->t_ref-POST_DT);
+
+addsched:
+
        /* reset the average counters */
        average_reset(md);