OBJS=init/init.o visual/visual.o math/math.o random/random.o moldyn.o
-all: moldyn.o posic
+all: posic
-posic: moldyn.o $(OBJS)
+posic: $(OBJS) moldyn.o
$(CC) $(CFLAGS) -lm -o $@ $(OBJS) $(LIBS) posic.c
clean:
#include "math/math.h"
#include "init/init.h"
#include "random/random.h"
+#include "visual/visual.h"
int create_lattice(unsigned char type,int element,double mass,double lc,
}
+/*
+ *
+ * 'integration of newtons equation' - algorithms
+ *
+ */
+
+/* start the integration */
+
+int moldyn_integrate(t_moldyn *moldyn) {
+
+ int i;
+
+ /* calculate initial forces */
+ moldyn->force(moldyn);
+
+ for(i=0;i<moldyn->time_steps;i++) {
+ /* integration step */
+ moldyn->integrate(moldyn);
+
+ /* check for visualiziation */
+ // to be continued ...
+ if(!(i%100))
+ visual_atoms(moldyn->visual,i*moldyn->tau,
+ moldyn->atom,moldyn->count);
+ }
+
+ return 0;
+}
+
+/* velocity verlet */
+
+int velocity_verlet(t_moldyn *moldyn) {
+
+ int i,count;
+ double tau,tau_square;
+ t_3dvec delta;
+ t_atom *atom;
+
+ atom=moldyn->atom;
+ count=moldyn->count;
+ tau=moldyn->tau;
+
+ tau_square=tau*tau;
+
+ for(i=0;i<count;i++) {
+ /* new positions */
+ v3_scale(&delta,&(atom[i].v),tau);
+ v3_add(&(atom[i].r),&(atom[i].r),&delta);
+ v3_scale(&delta,&(atom[i].f),0.5*tau_square/atom[i].mass);
+ v3_add(&(atom[i].r),&(atom[i].r),&delta);
+ v3_per_bound(&(atom[i].r),&(moldyn->dim));
+
+ /* velocities */
+ v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
+ v3_add(&(atom[i].r),&(atom[i].r),&delta);
+ }
+
+ /* forces depending on chosen potential */
+ moldyn->force(moldyn);
+
+ for(i=0;i<count;i++) {
+ /* again velocities */
+ v3_scale(&delta,&(atom[i].f),0.5*tau/atom[i].mass);
+ v3_add(&(atom[i].v),&(atom[i].v),&delta);
+ }
+
+ return 0;
+}
+
+
/*
*
* potentials & corresponding forces
#include "math/math.h"
#include "random/random.h"
+//#include "visual/visual.h"
/* datatypes */
int (*force)(struct s_moldyn *moldyn);
double cutoff_square;
t_3dvec dim;
+ int (*integrate)(struct s_moldyn *moldyn);
+ int time_steps;
+ double tau;
+ void *visual;
unsigned char status;
} t_moldyn;
double get_total_energy(t_moldyn *moldyn);
t_3dvec get_total_p(t_atom *atom,int count);
+int moldyn_integrate(t_moldyn *moldyn);
+int velocity_verlet(t_moldyn *moldyn);
+
double potential_lennard_jones(t_moldyn *moldyn);
int force_lennard_jones(t_moldyn *moldyn);
printf("setting thermal fluctuations\n");
thermal_init(si,&random,count,t);
- /* visualize */
-
- visual_atoms(&vis,0.0,si,count);
/* check kinetic energy */
md.force=force_lennard_jones;
md.cutoff_square=((LC_SI/4.0)*(LC_SI/4.0));
md.pot_params=&lj;
- md.force=NULL;
+ md.integrate=velocity_verlet;
+ md.time_steps=RUNS;
+ md.tau=TAU;
md.status=0;
+ md.visual=&vis;
lj.sigma6=3.0/16.0*LC_SI*LC_SI;
help=lj.sigma6*lj.sigma6;
* integration of newtons equations
*/
+ /* visualize */
+ //visual_atoms(&vis,0.0,si,count);
+
+
+ moldyn_integrate(&md);
+
+ printf("total energy (after integration): %f\n",get_total_energy(&md));
+
/* close */
visual_tini(&vis);
#define POSIC_H
#define RUNS 15000
-#define TAU 0.001
+#define TAU 0.000001
#define TEMPERATURE 273.0
-#define SI_M 1
-#define SI_LC 5.43105
-#define LJ_SIGMA SI_LC
-#define LJ_SIGMA_02 (LJ_SIGMA*LJ_SIGMA)
-#define LJ_SIGMA_06 (LJ_SIGMA_02*LJ_SIGMA_02*LJ_SIGMA_02)
-#define LJ_SIGMA_12 (LJ_SIGMA_06*LJ_SIGMA_06)
-
#define LEN_X 1
#define LEN_Y 1
#define LEN_Z 1
#define R_CUTOFF 20
-#define R2_CUTOFF (R_CUTOFF*R_CUTOFF)
-
-#define AMOUNT_SI ((LEN_X/SI_LC)*(LEN_Y/SI_LC)*(LEN_Z/SI_LC)*2)
#endif
#define RAND_STAT_UDEV 0x04
#define RAND_STAT_GAUSS 0x08
-#define RAND_BUFSIZE (1024) /* 4 k byte */
+#define RAND_BUFSIZE (1024*1024) /* 4 mega byte */
#define URAND_MAX 0xffffffff
#define URAND_MAX_PLUS_ONE 0x100000000