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 u8 bnum; /* brand number */
29 u8 attr; /* attributes */
32 #define ATOM_ATTR_FP 0x01 /* fixed position (bulk material) */
33 #define ATOM_ATTR_HB 0x02 /* coupled to heat bath (velocity scaling) */
35 #define ATOM_ATTR_1BP 0x10 /* single paricle potential */
36 #define ATOM_ATTR_2BP 0x20 /* pair potential */
37 #define ATOM_ATTR_3BP 0x40 /* 3 body potential */
41 typedef struct s_linkcell {
42 int nx,ny,nz; /* amount of cells in x, y and z direction */
43 int cells; /* total amount of cells */
44 double len; /* prefered cell edge length */
45 double x,y,z; /* the actual cell lengthes */
46 t_list *subcell; /* pointer to the cell lists */
47 int dnlc; /* direct neighbour lists counter */
48 int countn; /* amount of neighbours */
51 #include "visual/visual.h"
55 typedef struct s_moldyn {
57 int count; /* total amount of atoms */
58 t_atom *atom; /* pointer to the atoms */
60 t_3dvec dim; /* dimensions of the simulation volume */
62 /* potential force function and parameter pointers */
63 int (*pf_func1b)(struct s_moldyn *,t_atom *);
65 int (*pf_func2b)(struct s_moldyn *,t_atom *,t_atom *);
67 int (*pf_func3b)(struct s_moldyn *,t_atom *,t_atom *,t_atom *);
69 //int (*potential_force_function)(struct s_moldyn *moldyn);
71 double cutoff; /* cutoff radius */
72 double cutoff_square; /* square of the cutoff radius */
74 t_linkcell lc; /* linked cell method */
76 double t; /* temperature */
78 /* integration function pointer */
79 int (*integrate)(struct s_moldyn *moldyn);
80 int time_steps; /* amount of iterations */
81 double tau; /* delta t */
82 double tau_square; /* delta t squared */
84 double energy; /* energy */
86 t_visual vis; /* visualization/log/save interface structure */
87 u8 lvstat; /* log & vis properties */
88 unsigned int ewrite; /* how often to log energy */
89 char efb[64]; /* energy log filename */
90 int efd; /* fd for energy log */
91 unsigned int mwrite; /* how often to log momentum */
92 char mfb[64]; /* momentum log filename */
93 int mfd; /* fd for momentum log */
94 unsigned int vwrite; /* how often to visualize atom information */
95 char vfb[64]; /* visualization file name base */
96 void *visual; /* pointer (hack!) */
97 unsigned int swrite; /* how often to create a save file */
99 u8 status; /* general moldyn properties */
101 t_random random; /* random interface */
104 #define MOLDYN_LVSTAT_TOTAL_E 0x01
105 #define MOLDYN_LVSTAT_TOTAL_M 0x02
106 #define MOLDYN_LVSTAT_SAVE 0x04
107 #define MOLDYN_LVSTAT_VISUAL 0x08
108 #define MOLDYN_LVSTAT_INITIALIZED 0x10
110 #define MOLDYN_STAT_PBX 0x08 /* periodic boudaries in x */
111 #define MOLDYN_STAT_PBY 0x10 /* y */
112 #define MOLDYN_STAT_PBZ 0x20 /* and z direction */
114 typedef struct s_ho_params {
115 double spring_constant;
116 double equilibrium_distance;
119 typedef struct s_lj_params {
125 typedef struct s_tersoff_params {
126 double S[2]; /* tersoff cutoff radii */
127 double R[2]; /* tersoff cutoff radii */
128 double Smixed /* mixed S radius */
129 double Rmixed /* mixed R radius */
143 /* general defines */
145 #define MOLDYN_TEMP 273.0
146 #define MOLDYN_TAU 1.0e-15
147 #define MOLDYN_CUTOFF 10.0e-9
148 #define MOLDYN_RUNS 1000000
150 #define MOLDYN_INTEGRATE_VERLET 0x00
151 #define MOLDYN_INTEGRATE_DEFAULT MOLDYN_INTEGRATE_VERLET
153 #define MOLDYN_POTENTIAL_HO 0x00
154 #define MOLDYN_POTENTIAL_LJ 0x01
155 #define MOLDYN_POTENTIAL_DEFAULT MOLDYN_POTENTIAL_LJ
159 #define K_BOLTZMANN 1.3807e-27 /* Nm/K */
160 #define AMU 1.660540e-27 /* kg */
166 #define M_C (12.011*AMU)
169 #define LC_SI 0.543105e-9 /* m */
170 #define M_SI (28.085*AMU) /* kg */
171 #define LJ_SIGMA_SI ((0.25*sqrt(3.0)*LC_SI)/1.122462) /* m */
172 #define LJ_EPSILON_SI (2.1678*1.60e-19) /* Nm */
174 /* function prototypes */
176 int moldyn_usage(char **argv);
177 int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv);
178 int moldyn_log_init(t_moldyn *moldyn);
179 int moldyn_init(t_moldyn *moldyn,int argc,char **argv);
180 int moldyn_shutdown(t_moldyn *moldyn);
182 int create_lattice(u8 type,int element,double mass,double lc,
183 int a,int b,int c,t_atom **atom);
184 int destroy_lattice(t_atom *atom);
185 int thermal_init(t_moldyn *moldyn);
186 int scale_velocity(t_moldyn *moldyn);
187 double get_e_kin(t_atom *atom,int count);
188 double get_e_pot(t_moldyn *moldyn);
189 double get_total_energy(t_moldyn *moldyn);
190 t_3dvec get_total_p(t_atom *atom,int count);
192 double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t);
194 int link_cell_init(t_moldyn *moldyn);
195 int link_cell_update(t_moldyn *moldyn);
196 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell);
197 int link_cell_shutdown(t_moldyn *moldyn);
199 int moldyn_integrate(t_moldyn *moldyn);
200 int velocity_verlet(t_moldyn *moldyn);
202 int harmonic_oscillator(t_moldyn *moldyn);
203 int lennard_jones(t_moldyn *moldyn);