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