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