began rewrite ...
[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 } t_linkcell;
43
44 #include "visual/visual.h"
45
46 # moldyn properties structure */
47
48 typedef struct s_moldyn {
49
50         int count;              /* total amount of atoms */
51         t_atom *atom;           /* pointer to the atoms */
52         t_3dvec dim;            /* dimensions of the simulation volume */
53         /* potential, force & parameters */
54
55         /* potential force funtion created by the user */
56         int (*potential_force_function)(struct s_moldyn *moldyn);
57         void *pot_params;       /* parameters describing the potential */ 
58
59         double cutoff;
60         double cutoff_square;
61         /* linked list / cell method */
62         t_linkcell lc;
63         /* temperature */
64         double t;
65         /* integration of newtons equations */
66         int (*integrate)(struct s_moldyn *moldyn);
67         int time_steps;
68         double tau;
69         double tau_square;
70         /* energy */
71         double energy;
72         /* logging & visualization */
73         t_visual vis;
74         unsigned char lvstat;
75         unsigned int ewrite;
76         char efb[64];
77         int efd;
78         unsigned int mwrite;
79         char mfb[64];
80         int mfd;
81         unsigned int swrite;
82         char sfb[64];
83         int sfd;
84         unsigned int dwrite;
85         char dfb[64];
86         int dfd;
87         unsigned int vwrite;
88         char vfb[64];
89         void *visual;
90         /* moldyn general status */
91         unsigned char status;
92         /* random */
93         t_random random;
94 } t_moldyn;
95
96 typedef struct s_ho_params {
97         double spring_constant;
98         double equilibrium_distance;
99 } t_ho_params;
100
101 typedef struct s_lj_params {
102         double sigma6;
103         double sigma12;
104         double epsilon4;
105 } t_lj_params;
106
107 typedef struct s_tersoff_params {
108         double l_1,l_2;
109         double m_1,m_2;
110         double a_1,a_2;
111         double b_1,b_2;
112         double r_1,r_2;
113         double s_1,s_2;
114 } t_tersoff_params;
115
116 /*
117  *  defines
118  */
119
120 /* general defines */
121
122 #define MOLDYN_LVSTAT_TOTAL_E           0x01
123 #define MOLDYN_LVSTAT_TOTAL_M           0x02
124 #define MOLDYN_LVSTAT_SAVE              0x04
125 #define MOLDYN_LVSTAT_DUMP              0x08
126 #define MOLDYN_LVSTAT_VISUAL            0x10
127 #define MOLDYN_LVSTAT_INITIALIZED       0x80
128
129 #define MOLDYN_STAT_POTENTIAL           0x01
130 #define MOLDYN_STAT_FORCE               0x02
131
132 #define MOLDYN_TEMP                     273.0
133 #define MOLDYN_TAU                      1.0e-15
134 #define MOLDYN_CUTOFF                   10.0e-9
135 #define MOLDYN_RUNS                     1000000
136
137 #define MOLDYN_INTEGRATE_VERLET         0x00
138 #define MOLDYN_INTEGRATE_DEFAULT MOLDYN_INTEGRATE_VERLET
139
140 #define MOLDYN_POTENTIAL_HO             0x00
141 #define MOLDYN_POTENTIAL_LJ             0x01
142 #define MOLDYN_POTENTIAL_DEFAULT MOLDYN_POTENTIAL_LJ
143
144 /* phsical values */
145
146 #define K_BOLTZMANN             1.3807e-27                      /* Nm/K */
147 #define AMU                     1.660540e-27                    /* kg */
148
149 #define FCC                     0x01
150 #define DIAMOND                 0x02
151
152 #define C                       0x06
153 #define M_C                     (12.011*AMU)
154
155 #define SI                      0x0e
156 #define LC_SI                   0.543105e-9                             /* m */
157 #define M_SI                    (28.085*AMU)                            /* kg */
158 #define LJ_SIGMA_SI             ((0.25*sqrt(3.0)*LC_SI)/1.122462)       /* m */
159 #define LJ_EPSILON_SI           (2.1678*1.60e-19)                       /* Nm */
160
161 /* function prototypes */
162
163 int moldyn_usage(char **argv);
164 int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv);
165 int moldyn_log_init(t_moldyn *moldyn);
166 int moldyn_init(t_moldyn *moldyn,int argc,char **argv);
167 int moldyn_shutdown(t_moldyn *moldyn);
168
169 int create_lattice(unsigned char type,int element,double mass,double lc,
170                    int a,int b,int c,t_atom **atom);
171 int destroy_lattice(t_atom *atom);
172 int thermal_init(t_moldyn *moldyn);
173 int scale_velocity(t_moldyn *moldyn);
174 double get_e_kin(t_atom *atom,int count);
175 double get_e_pot(t_moldyn *moldyn);
176 double get_total_energy(t_moldyn *moldyn);
177 t_3dvec get_total_p(t_atom *atom,int count);
178
179 double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t);
180
181 int link_cell_init(t_moldyn *moldyn);
182 int link_cell_update(t_moldyn *moldyn);
183 int link_cell_neighbour_index(t_moldyn *moldyn,int i,int j,int k,t_list *cell);
184 int link_cell_shutdown(t_moldyn *moldyn);
185
186 int moldyn_integrate(t_moldyn *moldyn);
187 int velocity_verlet(t_moldyn *moldyn);
188
189 int harmonic_oscillator(t_moldyn *moldyn);
190 int lennard_jones(t_moldyn *moldyn);
191
192 #endif