more updates
[physik/posic.git] / moldyn.h
1 /*
2  * moldyn.h - molecular dynamics library header file
3  *
4  * author: Frank Zirkelbach <frank.zirkelbach@physik.uni-augsburg.de>
5  *
6  */
7
8 #ifndef MOLDYN_H
9 #define MOLDYN_H
10
11 #include "math/math.h"
12 #include "random/random.h"
13 #include "list/list.h"
14
15
16 /* datatypes */
17
18
19 /* the atom of the md simulation */
20
21 typedef struct s_atom {
22         t_3dvec r;              /* position */
23         t_3dvec v;              /* velocity */
24         t_3dvec f;              /* force */
25         int element;            /* number of element in pse */
26         double mass;            /* atom mass */
27         unsigned char attr;     /* attributes */
28 } t_atom;
29
30 #define ATOM_ATTR_FP    0x01    /* fixed position (bulk material) */
31 #define ATOM_ATTR_HB    0x02    /* coupled to heat bath (velocity scaling) */
32
33 /* cell lists */
34
35 typedef struct s_linkcell {
36         int nx,ny,nz;           /* amount of cells in x, y and z direction */
37         int cells;              /* total amount of cells */
38         double len;             /* prefered cell edge length */
39         double x,y,z;           /* the actual cell lengthes */
40         t_list *subcell;        /* pointer to the cell lists */
41         int dnlc;               /* direct neighbour lists counter */
42         int countn;             /* amount of neighbours */
43 } t_linkcell;
44
45 #include "visual/visual.h"
46
47 # moldyn structure */
48
49 typedef struct s_moldyn {
50
51         int count;              /* total amount of atoms */
52         t_atom *atom;           /* pointer to the atoms */
53
54         t_3dvec dim;            /* dimensions of the simulation volume */
55
56         /* potential force function pointer and parameters */
57         int (*pf_func1b)(struct s_moldyn *,t_atom *);
58         int (*pf_func2b)(struct s_moldyn *,t_atom *,t_atom *);
59         int (*pf_func3b)(struct s_moldyn *,t_atom *,t_atom *,t_atom *);
60         //int (*potential_force_function)(struct s_moldyn *moldyn);
61         void *pot_params;       /* parameters describing the potential */ 
62
63         double cutoff;          /* cutoff radius */
64         double cutoff_square;   /* square of the cutoff radius */
65
66         t_linkcell lc;          /* linked cell method */
67
68         double t;               /* temperature */
69
70         /* integration function pointer */
71         int (*integrate)(struct s_moldyn *moldyn);
72         int time_steps;         /* amount of iterations */
73         double tau;             /* delta t */
74         double tau_square;      /* delta t squared */
75
76         double energy;          /* energy */
77
78         t_visual vis;           /* visualization/log/save interface structure */
79         unsigned char lvstat;   /* log & vis properties */
80         unsigned int ewrite;    /* how often to log energy */
81         char efb[64];           /* energy log filename */
82         int efd;                /* fd for energy log */
83         unsigned int mwrite;    /* how often to log momentum */
84         char mfb[64];           /* momentum log filename */
85         int mfd;                /* fd for momentum log */
86         unsigned int vwrite;    /* how often to visualize atom information */
87         char vfb[64];           /* visualization file name base */
88         void *visual;           /* pointer (hack!) */
89         unsigned int swrite;    /* how often to create a save file */
90
91         unsigned char status;   /* general moldyn properties */
92
93         t_random random;        /* random interface */
94 } t_moldyn;
95
96 #define MOLDYN_LVSTAT_TOTAL_E           0x01
97 #define MOLDYN_LVSTAT_TOTAL_M           0x02
98 #define MOLDYN_LVSTAT_SAVE              0x04
99 #define MOLDYN_LVSTAT_VISUAL            0x08
100 #define MOLDYN_LVSTAT_INITIALIZED       0x10
101
102 #define MOLDYN_STAT_1BP                 0x01
103 #define MOLDYN_STAT_2BP                 0x02    /* define for pair potentials */
104 #define MOLDYN_STAT_3BP                 0x04    /* define for 3 body pot */ 
105 #define MOLDYN_STAT_PBX                 0x08    /* periodic boudaries in x */
106 #define MOLDYN_STAT_PBY                 0x10    /* y */
107 #define MOLDYN_STAT_PBZ                 0x20    /* and z direction */
108
109 typedef struct s_ho_params {
110         double spring_constant;
111         double equilibrium_distance;
112 } t_ho_params;
113
114 typedef struct s_lj_params {
115         double sigma6;
116         double sigma12;
117         double epsilon4;
118 } t_lj_params;
119
120 typedef struct s_tersoff_params {
121         double l_1,l_2;
122         double m_1,m_2;
123         double a_1,a_2;
124         double b_1,b_2;
125         double r_1,r_2;
126         double s_1,s_2;
127 } t_tersoff_params;
128
129 /*
130  *  defines
131  */
132
133 /* general defines */
134
135 #define MOLDYN_TEMP                     273.0
136 #define MOLDYN_TAU                      1.0e-15
137 #define MOLDYN_CUTOFF                   10.0e-9
138 #define MOLDYN_RUNS                     1000000
139
140 #define MOLDYN_INTEGRATE_VERLET         0x00
141 #define MOLDYN_INTEGRATE_DEFAULT        MOLDYN_INTEGRATE_VERLET
142
143 #define MOLDYN_POTENTIAL_HO             0x00
144 #define MOLDYN_POTENTIAL_LJ             0x01
145 #define MOLDYN_POTENTIAL_DEFAULT        MOLDYN_POTENTIAL_LJ
146
147 /* phsical values */
148
149 #define K_BOLTZMANN             1.3807e-27                      /* Nm/K */
150 #define AMU                     1.660540e-27                    /* kg */
151
152 #define FCC                     0x01
153 #define DIAMOND                 0x02
154
155 #define C                       0x06
156 #define M_C                     (12.011*AMU)
157
158 #define SI                      0x0e
159 #define LC_SI                   0.543105e-9                             /* m */
160 #define M_SI                    (28.085*AMU)                            /* kg */
161 #define LJ_SIGMA_SI             ((0.25*sqrt(3.0)*LC_SI)/1.122462)       /* m */
162 #define LJ_EPSILON_SI           (2.1678*1.60e-19)                       /* Nm */
163
164 /* function prototypes */
165
166 int moldyn_usage(char **argv);
167 int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv);
168 int moldyn_log_init(t_moldyn *moldyn);
169 int moldyn_init(t_moldyn *moldyn,int argc,char **argv);
170 int moldyn_shutdown(t_moldyn *moldyn);
171
172 int create_lattice(unsigned char type,int element,double mass,double lc,
173                    int a,int b,int c,t_atom **atom);
174 int destroy_lattice(t_atom *atom);
175 int thermal_init(t_moldyn *moldyn);
176 int scale_velocity(t_moldyn *moldyn);
177 double get_e_kin(t_atom *atom,int count);
178 double get_e_pot(t_moldyn *moldyn);
179 double get_total_energy(t_moldyn *moldyn);
180 t_3dvec get_total_p(t_atom *atom,int count);
181
182 double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t);
183
184 int link_cell_init(t_moldyn *moldyn);
185 int link_cell_update(t_moldyn *moldyn);
186 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell);
187 int link_cell_shutdown(t_moldyn *moldyn);
188
189 int moldyn_integrate(t_moldyn *moldyn);
190 int velocity_verlet(t_moldyn *moldyn);
191
192 int harmonic_oscillator(t_moldyn *moldyn);
193 int lennard_jones(t_moldyn *moldyn);
194
195 #endif