Trisurf Monte Carlo simulator
Samo Penic
2020-07-03 7d84ef2a0c3f672007317882a2d93487009d668b
commit | author | age
7f6076 1 /* vim: set ts=4 sts=4 sw=4 noet : */
d7639a 2 #ifndef _GENERAL_H
SP 3 #define _GENERAL_H
4
5 #include<stdarg.h>
7958e9 6 #include<stdio.h>
459ff9 7 #include<gsl/gsl_complex.h>
d7639a 8 /* @brief This is a header file, defining general constants and structures.
SP 9   * @file header.h
10   * @author Samo Penic
11   * @date 5.3.2001
311301 12   * 
d7639a 13   * Header file for general inclusion in all the code, defining data structures
SP 14   * and general constans. All datatypes used in the code is also defined here.
15   *
311301 16   * Miha: branch trisurf-polyel
d7639a 17   */
SP 18
19 /* Defines */
20 /** @brief Return value of type bz_bool that indiceates successful function finish 
21   *
22   * Function usualy return some value, which are the result of certain operation. Functions that don't
23   * return any parameters can return value, that indicates if the function call finished successfully.
24   * In case of successful function run, the functions should return TS_SUCCESS to the caller. This define
25   * is set here to get uniformity among all the functions used in program.
26   *
27   * Example of usage:
28   *        ts_boot somefunction(ts_int param1, ....){
29   *            ...
30   *            return TS_SUCCESS;
31   *        }
32   */
33 #define TS_SUCCESS 0
34
35 /** @brief Return value of type bz_bool that indicates unsuccessful function finish 
36   *
37   * Function usualy return some value, which are the result of certain operation. Functions that don't
38   * return any parameters can return value, that indicates if the function call finished successfully.
39   * In case of unsuccessful function run, the functions should return TS_FAIL to the caller. This define
40   * is set here to get uniformity among all the functions used in program.
41   *
42   * Example of usage:
43   *
44   *        ts_boot somefunction(ts_int param1, ....){
45   *            ...
46   *            return TS_FAIL;
47   *        }
48   */
49 #define TS_FAIL 1
50
51 /* CONSTANTS */
52
ea1cce 53 #define TS_ID_FILAMENT 1
M 54
d7639a 55 /* DATA TYPES */
SP 56 /** @brief Sets the default datatype for ts_double
57  *
58  * Requred for some functions to work, like "pow" from math.h. If ts_double is defined as
59  * float program must run with "powf". Where type dependant function is used it checks this
60  * define directive to decide which version to compile in. Available options
61  *
62  *    TS_DOUBLE_FLOAT
63  *    TS_DOUBLE_DOUBLE
64  *    TS_DOUBLE_LONGDOUBLE
65 */
66 #define TS_DOUBLE_DOUBLE
67
68 /** For the purpose of greater flexibility all data types used in the program
69  *  shouldn't use standard C types, but should use types defined here.
70  *    ts_int (uses int)
71  */
72 typedef int ts_int;
73 /** For the purpose of greater flexibility all data types used in the program
74  *  shouldn't use standard C types, but should use types defined here.
75  *    ts_uint (uses unsigned int)
76  */
77 typedef unsigned int ts_uint;
78 /** For the purpose of greater flexibility all data types used in the program
79  *  shouldn't use standard C types, but should use types defined here.
80  *    ts_long (uses long)
81  */
82 typedef long ts_long;
83 /** For the purpose of greater flexibility all data types used in the program
84  *  shouldn't use standard C types, but should use types defined here.
85  *    ts_ulong (uses unsigned long)
86  */
87 typedef unsigned long ts_ulong;
88 /** For the purpose of greater flexibility all data types used in the program
89  *  shouldn't use standard C types, but should use types defined here.
90  *    ts_float (uses float)
91  */
92 typedef float ts_float;
93 /** For the purpose of greater flexibility all data types used in the program
94  *  shouldn't use standard C types, but should use types defined here.
95  *    ts_double (uses double)
96  */
97 typedef double ts_double;
98 /** For the purpose of greater flexibility all data types used in the program
99  *  shouldn't use standard C types, but should use types defined here.
100  *    ts_char (uses char)
101  */
102 typedef char ts_char;
103 /** For the purpose of greater flexibility all data types used in the program
104  *  shouldn't use standard C types, but should use types defined here.
105  *    ts_uchar (uses unsigned char)
106  */
107 typedef unsigned char ts_uchar;
108 /** For the purpose of greater flexibility all data types used in the program
109  *  shouldn't use standard C types, but should use types defined here.
110  *    ts_bool (uses char)
111  */
112 typedef char ts_bool;
113
114
115 /* STRUCTURES */
116
523bf1 117
SP 118 /** @brief Data structure for keeping the coordinates in selected coordinate
119  * system
120  */
121 #define TS_COORD_CARTESIAN 0
122 #define TS_COORD_SPHERICAL 1
123 #define TS_COORD_CYLINDRICAL 2
124
125 typedef struct {
126     ts_double e1;
127     ts_double e2;
128     ts_double e3;
129     ts_uint coord_type;
130 } ts_coord;
131
d7639a 132 /** @brief Data structure of all data connected to a vertex
SP 133  *
8f6a69 134  *  ts_vertex holds the data for one single point (bead, vertex). To understand how to use it
d7639a 135  *  here is a detailed description of the fields in the data structure. */
8f6a69 136 struct ts_vertex {
SP 137         ts_uint idx;
a10dd5 138         ts_double x; /**< The x coordinate of vertex. */
d7639a 139         ts_double y; /**< The y coordinate of vertex. */
SP 140         ts_double z; /**< The z coordinate of vertex. */
141         ts_uint neigh_no; /**< The number of neighbours. */
a10dd5 142         struct ts_vertex **neigh; /**< The pointer that holds neigh_no pointers to this structure. */
SP 143         ts_double *bond_length; /**< Obsolete! The bond lenght is moved to ts_bond */
144         ts_double *bond_length_dual; /**< Obsolete! Bond length in dual lattice is moved to ts_bond! */
d7639a 145         ts_double curvature;
SP 146         ts_double energy;
147         ts_double energy_h;
148         ts_uint tristar_no;
a10dd5 149         struct ts_triangle **tristar; /**< The list of triangles this vertex belongs to. This is an array of pointers to ts_triangle structure of tristar_no length */
SP 150         ts_uint bond_no;
151         struct ts_bond **bond; /**< Array of pointers of lenght bond_no that stores information on bonds. */
152         struct ts_cell *cell; /**< Which cell do we belong to? */
d7639a 153         ts_double xk;
SP 154         ts_double c;
155         ts_uint id;
523bf1 156         ts_double projArea;
SP 157         ts_double relR;
158         ts_double solAngle;
759169 159         struct ts_poly *grafted_poly;
SP 160         struct ts_cluster *cluster;
7d84ef 161     ts_double edge_x[14];
SP 162     ts_double edge_y[14];
163     ts_double edge_z[14];
164
737714 165 };
d7639a 166 typedef struct ts_vertex ts_vertex;
SP 167
73f967 168 typedef struct {
SP 169     ts_uint n;
a10dd5 170     ts_vertex **vtx;
73f967 171
SP 172 } ts_vertex_list;
173
e016c4 174 struct ts_bond {
fedf2b 175         ts_uint idx;
d7639a 176     ts_vertex *vtx1;
SP 177     ts_vertex *vtx2;
58230a 178         ts_double bond_length;
M 179         ts_double bond_length_dual;
180     ts_bool tainted; //TODO: remove
fedf2b 181     ts_double energy;
58230a 182     ts_double x,y,z;
a10dd5 183 };
SP 184 typedef struct ts_bond ts_bond;
185
186 struct ts_bond_list {
187     ts_uint n;
188     ts_bond **bond;
189 };
190 typedef struct ts_bond_list ts_bond_list;
191
41a035 192 struct ts_triangle {
SP 193     ts_uint idx;
d7639a 194     ts_vertex *vertex[3];
SP 195     ts_uint neigh_no;
196     struct ts_triangle **neigh;
197     ts_double xnorm;
198     ts_double ynorm;
199     ts_double znorm;
523bf1 200     ts_double area; // firstly needed for sh.c
c9d07c 201     ts_double volume; // firstly needed for sh.c
2ae815 202     ts_double energy;
a10dd5 203 };
d7639a 204 typedef struct ts_triangle ts_triangle;
a10dd5 205
SP 206 struct ts_triangle_list{
207     ts_uint n;
7ec6fb 208     ts_double a0;
a10dd5 209     ts_triangle **tria;
SP 210 };
a2a676 211 typedef struct ts_triangle_list ts_triangle_list;
d7639a 212
SP 213
bb77ca 214 typedef struct ts_cell {
SP 215     ts_uint idx;
34d3de 216     ts_vertex **vertex;
SP 217     ts_uint nvertex;
bb77ca 218 } ts_cell; 
SP 219
220 typedef struct ts_cell_list{
221     ts_uint ncmax[3];
222     ts_uint cellno;
223     ts_cell **cell;
d7639a 224     ts_double dcell;
SP 225     ts_double shift;
42190f 226     ts_uint max_occupancy;
ea1cce 227     ts_double dmin_interspecies;
bb77ca 228 } ts_cell_list;
SP 229
230
231 typedef struct {
523bf1 232     ts_uint l;
SP 233     ts_double **ulm;
459ff9 234     gsl_complex **ulmComplex;
262607 235     ts_double **sumUlm2;
SP 236     ts_uint N;
621830 237     ts_double **co;
eb8605 238     ts_double ***Ylmi;
523bf1 239 } ts_spharm;
SP 240
241
242
1d5dff 243 struct ts_poly {
M 244     ts_vertex_list *vlist;
245     ts_bond_list *blist;
246     ts_vertex *grafted_vtx;
48bb92 247     ts_double k;
1d5dff 248 };
M 249 typedef struct ts_poly ts_poly;
250
251
252 struct ts_poly_list {
253     ts_uint    n;
254     ts_poly **poly;
255 };
256 typedef struct ts_poly_list ts_poly_list;
257
258
514ebc 259 typedef struct{
SP 260     ts_float z_max;
261     ts_float z_min;
262     ts_int force_switch;
263 } ts_confinement_plane;
1d5dff 264
9166cb 265 typedef struct {
SP 266     long int nshell;
267     long int ncxmax;
268     long int ncymax;
269     long int nczmax;
270     long int npoly;
271     long int nmono;
e98482 272     long int internal_poly;
9166cb 273     long int nfil;
SP 274     long int nfono;
275     long int R_nucleus;
37791b 276     ts_double R_nucleusX;
SP 277     ts_double R_nucleusY;
278     ts_double R_nucleusZ;
9166cb 279     long int pswitch;
SP 280     long int constvolswitch;
c0ae90 281     long int constareaswitch;
2ae815 282     long int stretchswitch;
SP 283     ts_double xkA0;
43c042 284     ts_double constvolprecision;
9166cb 285         char *multiprocessing;
SP 286        long int brezveze0;
287         long int brezveze1;
288         long int brezveze2;
289         ts_double xk0;
290     ts_double dmax;
291     ts_double dmin_interspecies;
292     ts_double stepsize;
293     ts_double kspring;
294     ts_double xi;
295     ts_double pressure;
296     long int iterations;
297     long int inititer;
298     long int mcsweeps;
299     long int quiet;
300     long int shc;
e5858f 301     long int number_of_vertices_with_c0;
SP 302     ts_double c0;
303     ts_double w;
250de4 304     ts_double F;
514ebc 305     long int plane_confinement_switch;
SP 306     ts_double plane_d;
307     ts_double plane_F;
9166cb 308 } ts_tape;
SP 309
310
311
1d5dff 312
523bf1 313 typedef struct {
bb77ca 314     ts_vertex_list *vlist;
SP 315     ts_bond_list *blist;
316     ts_triangle_list *tlist;
48bb92 317     ts_cell_list *clist;
bb77ca 318     ts_uint nshell;
48bb92 319     ts_double bending_rigidity;
M 320     ts_double dmax;
321     ts_double stepsize;
322        ts_double cm[3];
323     ts_double volume;
324     ts_spharm *sphHarmonics;
624f81 325 // Polymers outside the vesicle and attached to the vesicle membrane (polymer brush):
1d5dff 326     ts_poly_list *poly_list;
624f81 327 // Filaments inside the vesicle (not attached to the vesicel membrane:
M 328     ts_poly_list *filament_list;
329
48bb92 330     ts_double spring_constant;
e86357 331     ts_double pressure;
b866cf 332     ts_int pswitch;
514ebc 333      ts_tape *tape;
624f81 334     ts_double R_nucleus;
37791b 335     ts_double R_nucleusX;
SP 336     ts_double R_nucleusY;
337     ts_double R_nucleusZ;
4891eb 338     ts_double nucleus_center[3];
514ebc 339     ts_double area;
SP 340     ts_confinement_plane confinement_plane;
d7639a 341 } ts_vesicle;
SP 342
343
523bf1 344
759169 345 struct ts_cluster{
69a174 346     ts_uint nvtx;
SP 347     ts_uint idx;
348     ts_vertex **vtx;
759169 349 };
SP 350
351 typedef struct ts_cluster ts_cluster;
69a174 352
SP 353 typedef struct{
354     ts_uint n;
355     ts_cluster **cluster;
356 } ts_cluster_list;
357
358
d7639a 359 /* GLOBAL VARIABLES */
SP 360
361 int quiet;
1121fa 362 ts_double V0;
c0ae90 363 ts_double A0;
1121fa 364 ts_double epsvol;
c0ae90 365 ts_double epsarea;
d7639a 366 /* FUNCTIONS */
SP 367
368 /** Non-fatal error function handler:
369  *      @param text is a description of an error
370  *      @returns doesn't return anything
371 */
372 void err(char *text);
373
374 /** Fatal error function handler:
375  *      @param text is a description of an error
376  *      @param errcode is a (non-zero) error code
377  *      @returns terminates the execution of program with errcode set
378 */
379 void fatal(char *text, ts_int errcode);
380
7958e9 381 ts_uint ts_fprintf(FILE *fd, char *fmt, ...);
d7639a 382
737714 383 #define VTX(n) &(vlist->vtx[n])
SP 384 #define VTX_DATA(n) vlist->vtx[n].data
73f967 385
fbbc8e 386
SP 387 /* FOR PID GENERATION ROUTINE */
388 #define CPF_CLOEXEC 1
389
390 int createPidFile(const char *progName, const char *pidFile, int flags);
391
392 int lockRegion(int fd, int type, int whence, int start, int len);
cb2faf 393 char *libVersion();
d7639a 394 #endif