+/* potential */
+#include "potentials/harmonic_oscillator.h"
+#include "potentials/lennard_jones.h"
+#include "potentials/albe.h"
+#ifdef TERSOFF_ORIG
+#include "potentials/tersoff_orig.h"
+#else
+#include "potentials/tersoff.h"
+#endif
+
+typedef struct s_hp {
+ int prerun_count; /* prerun count */
+ int insert_count; /* insert count */
+ int postrun_count; /* post run count */
+ unsigned char state; /* current state */
+ int argc; /* arg count */
+ char **argv; /* args */
+} t_hp;
+
+#define STATE_PRERUN 0x00
+#define STATE_INSERT 0x01
+#define STATE_POSTRUN 0x02
+
+/* include the config file */
+#include "config.h"
+
+int insert_atoms(t_moldyn *moldyn) {
+
+ int i,j;
+ u8 run;
+ t_3dvec r,v,dist;
+ double d,dmin;
+
+ t_atom *atom;
+
+ atom=moldyn->atom;
+
+ v.x=0; v.y=0; v.z=0;
+
+ for(j=0;j<INS_ATOMS;j++) {
+ run=1;
+ while(run) {
+#ifdef INS_TETRA
+ // tetrahedral
+ r.x=0.0;
+ r.y=0.0;
+ r.z=0.0;
+#endif
+#ifdef INS_HEXA
+ // hexagonal
+ r.x=-1.0/8.0*ALBE_LC_SI;
+ r.y=-1.0/8.0*ALBE_LC_SI;
+ r.z=1.0/8.0*ALBE_LC_SI;
+#endif
+#ifdef INS_110DB
+ // 110 dumbbell
+ r.x=(-0.5+0.25+0.125)*ALBE_LC_SI;
+ r.y=(-0.5+0.25+0.125)*ALBE_LC_SI;
+ r.z=(-0.5+0.25)*ALBE_LC_SI;
+ moldyn->atom[4372].r.x=(-0.5+0.125+0.125)*ALBE_LC_SI;
+ moldyn->atom[4372].r.y=(-0.5+0.125+0.125)*ALBE_LC_SI;
+#endif
+#ifdef INS_001DB
+ // 001 dumbbell
+ r.x=(-0.5+0.25)*ALBE_LC_SI;
+ r.y=(-0.5+0.25)*ALBE_LC_SI;
+ r.z=(-0.1)*ALBE_LC_SI;
+ moldyn->atom[4372].r.z=(-0.4)*ALBE_LC_SI;
+#endif
+#ifdef INS_USER
+ // 001 dumbbell
+ r.x=INS_UX*ALBE_LC_SI;
+ r.y=INS_UY*ALBE_LC_SI;
+ r.z=INS_UZ*ALBE_LC_SI;
+#endif
+#ifdef INS_RAND
+ // random
+#ifdef INS_DYNAMIC_LEN
+ r.x=(rand_get_double(&(moldyn->random))-0.5)*\
+ moldyn->dim.x;
+ r.y=(rand_get_double(&(moldyn->random))-0.5)*\
+ moldyn->dim.y;
+ r.z=(rand_get_double(&(moldyn->random))-0.5)*\
+ moldyn->dim.z;
+#else
+ r.x=(rand_get_double(&(moldyn->random))-0.5)*INS_LENX;
+ r.y=(rand_get_double(&(moldyn->random))-0.5)*INS_LENY;
+ r.z=(rand_get_double(&(moldyn->random))-0.5)*INS_LENZ;
+#endif
+#endif
+ // offset
+ r.x+=INS_OFFSET;
+ r.y+=INS_OFFSET;
+ r.z+=INS_OFFSET;
+ /* assume valid coordinates */
+ run=0;
+ dmin=10000000000.0; // for sure too high!
+ for(i=0;i<moldyn->count;i++) {
+ atom=&(moldyn->atom[i]);
+ v3_sub(&dist,&(atom->r),&r);
+ check_per_bound(moldyn,&dist);
+ d=v3_absolute_square(&dist);
+ /* reject coordinates */
+ if(d<INS_R_C) {
+ //printf("atom %d - %f\n",i,d);
+ run=1;
+ break;
+ }
+ if(d<dmin)
+ dmin=d;
+ }
+ }
+ add_atom(moldyn,INS_TYPE,INS_BRAND,
+ ATOM_ATTR_1BP|ATOM_ATTR_2BP|ATOM_ATTR_3BP|\
+ INS_ATTR,
+ &r,&v);
+ printf(" %02d: atom %d | %f %f %f | %f\n",
+ j,moldyn->count-1,r.x,r.y,r.z,dmin);
+ }
+
+ return 0;
+}
+
+int sic_hook(void *moldyn,void *hook_params) {
+
+ t_hp *hp;
+ t_moldyn *md;
+ int steps;
+ double tau;
+ double dt;
+ double dp;
+
+ hp=hook_params;
+ md=moldyn;
+
+ tau=1.0;
+ steps=0;
+
+ /* switch on t scaling */
+ if(md->schedule.count==0)
+ set_pt_scale(md,P_SCALE_BERENDSEN,P_SCALE_TAU,
+ T_SCALE_BERENDSEN,T_SCALE_TAU);
+
+ /* my lousy state machine ! */
+
+ /* switch to insert state immediately */
+ if(hp->state==STATE_PRERUN)
+ hp->state=STATE_INSERT;
+
+ switch(hp->state) {
+ case STATE_INSERT:
+ goto insert;
+ break;
+ case STATE_POSTRUN:
+ goto postrun;
+ break;
+ default:
+ printf("[sic hook] unknown state\n");
+ return -1;
+ }
+
+ /* act according to state */
+
+insert:
+
+ /* assigne values */
+ steps=INS_RELAX;
+ tau=INS_TAU;
+
+ /* check temperature */
+ dt=md->t_avg-md->t_ref;
+ dp=md->p_avg-md->p_ref;
+ if(dt<0)
+ dt=-dt;
+ if(dp<0)
+ dp=-dp;
+ if((dt>INS_DELTA_TC)|(dp>INS_DELTA_PC))
+ goto addsched;
+
+ /* immediately go on if no job is to be done */
+ if(hp->insert_count==INS_RUNS) {
+ printf(" --- leaving insert state ---\n");
+ hp->state=STATE_POSTRUN;
+ goto postrun;
+ }
+
+ /* 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:
+
+ /* assigne values */
+ steps=POST_RELAX;
+ tau=POST_TAU;
+
+ /* check temperature */
+ dt=md->t_avg-md->t_ref;
+ dp=md->p_avg-md->p_ref;
+ if(dt<0)
+ dt=-dt;
+ if(dp<0)
+ dp=-dp;
+ if((dt>POST_DELTA_TC)|(dp>POST_DELTA_PC))
+ goto addsched;
+
+ /* immediately return if no job is to be done */
+ if(hp->postrun_count==POST_RUNS) {
+ printf(" --- leaving post run state ---\n");
+ return 0;
+ }
+
+ /* 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);
+
+ /* add schedule */
+ moldyn_add_schedule(md,steps,tau);
+
+ return 0;
+}