2 * moldyn.h - molecular dynamics library header file
4 * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
11 #include "math/math.h"
12 #include "random/random.h"
13 #include "list/list.h"
18 typedef unsigned char u8;
20 /* the atom of the md simulation */
22 typedef struct s_atom {
23 t_3dvec r; /* position */
24 t_3dvec v; /* velocity */
25 t_3dvec f; /* force */
26 int element; /* number of element in pse */
27 double mass; /* atom mass */
28 unsigned char attr; /* attributes */
31 #define ATOM_ATTR_FP 0x01 /* fixed position (bulk material) */
32 #define ATOM_ATTR_HB 0x02 /* coupled to heat bath (velocity scaling) */
34 #define ATOM_ATTR_1BP 0x10 /* single paricle potential */
35 #define ATOM_ATTR_2BP 0x20 /* pair potential */
36 #define ATOM_ATTR_3BP 0x40 /* 3 body potential */
40 typedef struct s_linkcell {
41 int nx,ny,nz; /* amount of cells in x, y and z direction */
42 int cells; /* total amount of cells */
43 double len; /* prefered cell edge length */
44 double x,y,z; /* the actual cell lengthes */
45 t_list *subcell; /* pointer to the cell lists */
46 int dnlc; /* direct neighbour lists counter */
47 int countn; /* amount of neighbours */
50 #include "visual/visual.h"
54 typedef struct s_moldyn {
56 int count; /* total amount of atoms */
57 t_atom *atom; /* pointer to the atoms */
59 t_3dvec dim; /* dimensions of the simulation volume */
61 /* potential force function pointer and parameters */
62 int (*pf_func1b)(struct s_moldyn *,t_atom *);
63 int (*pf_func2b)(struct s_moldyn *,t_atom *,t_atom *);
64 int (*pf_func3b)(struct s_moldyn *,t_atom *,t_atom *,t_atom *);
65 //int (*potential_force_function)(struct s_moldyn *moldyn);
66 void *pot_params; /* parameters describing the potential */
68 double cutoff; /* cutoff radius */
69 double cutoff_square; /* square of the cutoff radius */
71 t_linkcell lc; /* linked cell method */
73 double t; /* temperature */
75 /* integration function pointer */
76 int (*integrate)(struct s_moldyn *moldyn);
77 int time_steps; /* amount of iterations */
78 double tau; /* delta t */
79 double tau_square; /* delta t squared */
81 double energy; /* energy */
83 t_visual vis; /* visualization/log/save interface structure */
84 unsigned char lvstat; /* log & vis properties */
85 unsigned int ewrite; /* how often to log energy */
86 char efb[64]; /* energy log filename */
87 int efd; /* fd for energy log */
88 unsigned int mwrite; /* how often to log momentum */
89 char mfb[64]; /* momentum log filename */
90 int mfd; /* fd for momentum log */
91 unsigned int vwrite; /* how often to visualize atom information */
92 char vfb[64]; /* visualization file name base */
93 void *visual; /* pointer (hack!) */
94 unsigned int swrite; /* how often to create a save file */
96 unsigned char status; /* general moldyn properties */
98 t_random random; /* random interface */
101 #define MOLDYN_LVSTAT_TOTAL_E 0x01
102 #define MOLDYN_LVSTAT_TOTAL_M 0x02
103 #define MOLDYN_LVSTAT_SAVE 0x04
104 #define MOLDYN_LVSTAT_VISUAL 0x08
105 #define MOLDYN_LVSTAT_INITIALIZED 0x10
107 #define MOLDYN_STAT_PBX 0x08 /* periodic boudaries in x */
108 #define MOLDYN_STAT_PBY 0x10 /* y */
109 #define MOLDYN_STAT_PBZ 0x20 /* and z direction */
111 typedef struct s_ho_params {
112 double spring_constant;
113 double equilibrium_distance;
116 typedef struct s_lj_params {
122 typedef struct s_tersoff_params {
135 /* general defines */
137 #define MOLDYN_TEMP 273.0
138 #define MOLDYN_TAU 1.0e-15
139 #define MOLDYN_CUTOFF 10.0e-9
140 #define MOLDYN_RUNS 1000000
142 #define MOLDYN_INTEGRATE_VERLET 0x00
143 #define MOLDYN_INTEGRATE_DEFAULT MOLDYN_INTEGRATE_VERLET
145 #define MOLDYN_POTENTIAL_HO 0x00
146 #define MOLDYN_POTENTIAL_LJ 0x01
147 #define MOLDYN_POTENTIAL_DEFAULT MOLDYN_POTENTIAL_LJ
151 #define K_BOLTZMANN 1.3807e-27 /* Nm/K */
152 #define AMU 1.660540e-27 /* kg */
158 #define M_C (12.011*AMU)
161 #define LC_SI 0.543105e-9 /* m */
162 #define M_SI (28.085*AMU) /* kg */
163 #define LJ_SIGMA_SI ((0.25*sqrt(3.0)*LC_SI)/1.122462) /* m */
164 #define LJ_EPSILON_SI (2.1678*1.60e-19) /* Nm */
166 /* function prototypes */
168 int moldyn_usage(char **argv);
169 int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv);
170 int moldyn_log_init(t_moldyn *moldyn);
171 int moldyn_init(t_moldyn *moldyn,int argc,char **argv);
172 int moldyn_shutdown(t_moldyn *moldyn);
174 int create_lattice(unsigned char type,int element,double mass,double lc,
175 int a,int b,int c,t_atom **atom);
176 int destroy_lattice(t_atom *atom);
177 int thermal_init(t_moldyn *moldyn);
178 int scale_velocity(t_moldyn *moldyn);
179 double get_e_kin(t_atom *atom,int count);
180 double get_e_pot(t_moldyn *moldyn);
181 double get_total_energy(t_moldyn *moldyn);
182 t_3dvec get_total_p(t_atom *atom,int count);
184 double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t);
186 int link_cell_init(t_moldyn *moldyn);
187 int link_cell_update(t_moldyn *moldyn);
188 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell);
189 int link_cell_shutdown(t_moldyn *moldyn);
191 int moldyn_integrate(t_moldyn *moldyn);
192 int velocity_verlet(t_moldyn *moldyn);
194 int harmonic_oscillator(t_moldyn *moldyn);
195 int lennard_jones(t_moldyn *moldyn);