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 /* tersoff exchange structure to exchange 2bp and 3bp calculated values */
127 typedef struct s_tersoff_exchange {
151 } t_tersoff_exchange;
153 /* tersoff multi (2!) potential parameters */
155 typedef struct s_tersoff_mult_params {
156 double S[2]; /* tersoff cutoff radii */
157 double R[2]; /* tersoff cutoff radii */
158 double Smixed; /* mixed S radius */
159 double Rmixed; /* mixed R radius */
160 double A[2]; /* factor of tersoff attractive part */
161 double B[2]; /* factor of tersoff repulsive part */
162 double Amixed; /* mixed A factor */
163 double Bmixed; /* mixed B factor */
164 double lambda[2]; /* tersoff lambda */
165 double lambda_m; /* mixed lambda */
166 double mu[2]; /* tersoff mu */
167 double mu_m; /* mixed mu */
177 t_tersoff_exchange exchange; /* exchange between 2bp and 3bp calc */
184 /* general defines */
186 #define MOLDYN_TEMP 273.0
187 #define MOLDYN_TAU 1.0e-15
188 #define MOLDYN_CUTOFF 10.0e-9
189 #define MOLDYN_RUNS 1000000
191 #define MOLDYN_INTEGRATE_VERLET 0x00
192 #define MOLDYN_INTEGRATE_DEFAULT MOLDYN_INTEGRATE_VERLET
194 #define MOLDYN_POTENTIAL_HO 0x00
195 #define MOLDYN_POTENTIAL_LJ 0x01
196 #define MOLDYN_POTENTIAL_DEFAULT MOLDYN_POTENTIAL_LJ
200 #define K_BOLTZMANN 1.3807e-27 /* Nm/K */
201 #define AMU 1.660540e-27 /* kg */
207 #define M_C (12.011*AMU)
210 #define LC_SI 0.543105e-9 /* m */
211 #define M_SI (28.085*AMU) /* kg */
212 #define LJ_SIGMA_SI ((0.25*sqrt(3.0)*LC_SI)/1.122462) /* m */
213 #define LJ_EPSILON_SI (2.1678*1.60e-19) /* Nm */
215 /* function prototypes */
217 int moldyn_usage(char **argv);
218 int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv);
219 int moldyn_log_init(t_moldyn *moldyn);
220 int moldyn_init(t_moldyn *moldyn,int argc,char **argv);
221 int moldyn_shutdown(t_moldyn *moldyn);
223 int create_lattice(u8 type,int element,double mass,double lc,
224 int a,int b,int c,t_atom **atom);
225 int destroy_lattice(t_atom *atom);
226 int thermal_init(t_moldyn *moldyn);
227 int scale_velocity(t_moldyn *moldyn);
228 double get_e_kin(t_atom *atom,int count);
229 double get_e_pot(t_moldyn *moldyn);
230 double get_total_energy(t_moldyn *moldyn);
231 t_3dvec get_total_p(t_atom *atom,int count);
233 double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t);
235 int link_cell_init(t_moldyn *moldyn);
236 int link_cell_update(t_moldyn *moldyn);
237 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell);
238 int link_cell_shutdown(t_moldyn *moldyn);
240 int moldyn_integrate(t_moldyn *moldyn);
241 int velocity_verlet(t_moldyn *moldyn);
243 int harmonic_oscillator(t_moldyn *moldyn);
244 int lennard_jones(t_moldyn *moldyn);