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