basic linked list / cell method support implemented
[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         t_3dvec dr;     /* delta r for verlet list updates */
22         int element;    /* number of element in pse */
23         double mass;    /* atom mass */
24         t_list verlet;  /* verlet neighbour list */
25 } t_atom;
26
27 typedef struct s_linkcell {
28         int nx,ny,nz;
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         double (*potential)(struct s_moldyn *moldyn);
42         int (*force)(struct s_moldyn *moldyn);
43         void *pot_params;
44         /* cut off radius, verlet list & co */
45         double cutoff;
46         double cutoff_square;
47         double r_verlet;
48         double dr_max1;
49         double dr_max2;
50         /* linked list / cell method */
51         t_linkcell lc;
52         /* temperature */
53         double t;
54         /* integration of newtons equations */
55         int (*integrate)(struct s_moldyn *moldyn);
56         int time_steps;
57         double tau;
58         /* logging & visualization */
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 } t_moldyn;
78
79 typedef struct s_ho_params {
80         double spring_constant;
81         double equilibrium_distance;
82 } t_ho_params;
83
84 typedef struct s_lj_params {
85         double sigma6;
86         double sigma12;
87         double epsilon4;
88 } t_lj_params;
89
90 /*
91  *  defines
92  */
93
94 /* general defines */
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_DUMP              0x08
100 #define MOLDYN_LVSTAT_VISUAL            0x10
101 #define MOLDYN_LVSTAT_INITIALIZED       0x80
102
103 #define MOLDYN_STAT_POTENTIAL           0x01
104 #define MOLDYN_STAT_FORCE               0x02
105
106 #define MOLDYN_TEMP                     273.0
107 #define MOLDYN_TAU                      1.0e-15
108 #define MOLDYN_RUNS                     1000000
109
110 /* phsical values */
111
112 #define K_BOLTZMANN             1.3807e-27                      /* Nm/K */
113 #define AMU                     1.660540e-27                    /* kg */
114
115 #define FCC                     0x01
116 #define DIAMOND                 0x02
117
118 #define C                       0x06
119 #define M_C                     (12.011*AMU)
120
121 #define SI                      0x0e
122 #define LC_SI                   0.543105e-9                             /* m */
123 #define M_SI                    (28.085*AMU)                            /* kg */
124 #define LJ_SIGMA_SI             ((0.25*sqrt(3.0)*LC_SI)/1.122462)       /* m */
125 #define LJ_EPSILON_SI           (2.1678*1.60e-19)                       /* Nm */
126
127 /* function prototypes */
128
129 int moldyn_usage(char **argv);
130 int moldyn_parse_argv(t_moldyn *moldyn,int argc,char **argv);
131 int moldyn_log_init(t_moldyn *moldyn,void *v);
132 int moldyn_shutdown(t_moldyn *moldyn);
133
134 int create_lattice(unsigned char type,int element,double mass,double lc,
135                    int a,int b,int c,t_atom **atom);
136 int destroy_lattice(t_atom *atom);
137 int thermal_init(t_moldyn *moldyn,t_random *random,int count);
138 int scale_velocity(t_moldyn *moldyn,int count);
139 double get_e_kin(t_atom *atom,int count);
140 double get_e_pot(t_moldyn *moldyn);
141 double get_total_energy(t_moldyn *moldyn);
142 t_3dvec get_total_p(t_atom *atom,int count);
143
144 double estimate_time_step(t_moldyn *moldyn,double nn_dist,double t);
145
146 int verlet_list_init(t_moldyn *moldyn);
147 int link_cell_init(t_moldyn *moldyn);
148 int verlet_list_update(t_moldyn *moldyn);
149 int link_cell_update(t_moldyn *moldyn);
150 int verlet_list_shutdown(t_moldyn *moldyn);
151 int link_cell_shutdown(t_moldyn *moldyn);
152
153 int moldyn_integrate(t_moldyn *moldyn);
154 int velocity_verlet(t_moldyn *moldyn);
155
156 double potential_harmonic_oscillator(t_moldyn *moldyn);
157 int force_harmonic_oscillator(t_moldyn *moldyn);
158 double potential_lennard_jones(t_moldyn *moldyn);
159 int force_lennard_jones(t_moldyn *moldyn);
160
161 #endif