Trisurf Monte Carlo simulator
Samo Penic
2014-02-11 6aec63272fd6fe35a6ded508c2f2e3e19e107215
commit | author | age
a0f0a3 1 #include<stdio.h>
S 2 #include<math.h>
3 #include "general.h"
4 #include "vertex.h"
5 #include "bond.h"
6 #include "triangle.h"
7 #include "cell.h"
8 #include "vesicle.h"
9 #include "io.h"
10 #include "initial_distribution.h"
11 #include "frame.h"
12 #include "timestep.h"
13 #include "sh.h"
14
15 /** Entrance function to the program
16   * @param argv is a number of parameters used in program call (including the program name
17   * @param argc is a pointer to strings (character arrays) which holds the arguments
18   * @returns returns 0 on success, any other number on fail.
19 */
20 ts_bool saveAvgUlm2(ts_vesicle *vesicle);
21 int main(int argv, char *argc[]){
22 ts_uint i,j;
23 ts_vesicle *vesicle;
24 ts_double r0;
25 vesicle=initial_distribution_dipyramid(17,60,60,60,0.15);
26 //parsetape(vesicle,&i);
27
28 //these four must come from parsetype!
29 vesicle->dmax=1.67*1.67;
30 vesicle->stepsize=0.15;
31 vesicle->clist->max_occupancy=8;
32 vesicle->bending_rigidity=30.0*30.0;
33 for(i=0;i<vesicle->vlist->n;i++){
34     vesicle->vlist->vtx[i]->xk=vesicle->bending_rigidity;
35 }
36 //fprintf(stderr,"xk=%f",vesicle->bending_rigidity);
37
38     centermass(vesicle);
39 vesicle->sphHarmonics=sph_init(vesicle->vlist, 21);
40
41 vesicle_volume(vesicle);
42 r0=getR0(vesicle);
43
44 preparationSh(vesicle,r0);
45 calculateYlmi(vesicle);
46 calculateUlm(vesicle);
47 for(i=0;i<500;i++){
48     cell_occupation(vesicle);
49     for(j=0;j<1000;j++){
50         single_timestep(vesicle);
51     }    
52     centermass(vesicle);
53     fprintf(stderr, "Preloop %d completed.\n",i+1);
54 }
55
56 vesicle->bending_rigidity=25.0;
57 for(i=0;i<vesicle->vlist->n;i++){
58     vesicle->vlist->vtx[i]->xk=vesicle->bending_rigidity;
59 }
60
61
62 for(i=0;i<10000;i++){
63     cell_occupation(vesicle);
64     for(j=0;j<1000;j++){
65         single_timestep(vesicle);
66     }    
67     centermass(vesicle);
68     vesicle_volume(vesicle);
69     r0=getR0(vesicle);
70
71     preparationSh(vesicle,r0);
72     calculateYlmi(vesicle);
73     calculateUlm(vesicle);
74
75     storeUlm2(vesicle);
76     saveAvgUlm2(vesicle);
77
78     write_vertex_xml_file(vesicle,i);
79     fprintf(stderr, "Loop %d completed.\n",i+1);
80 }
81 write_master_xml_file("test.pvd");
82 write_dout_fcompat_file(vesicle,"dout");
83 vesicle_free(vesicle);
84
85 return 0; //program finished perfectly ok. We return 0.
86 }
87
88
89
90 ts_bool saveAvgUlm2(ts_vesicle *vesicle){
91
92     FILE *fh;
93     
94     fh=fopen("sph2out.dat", "w");
95     if(fh==NULL){
96         err("Cannot open file %s for writing");
97         return TS_FAIL;
98     }
99
100     ts_spharm *sph=vesicle->sphHarmonics;
101     ts_int i,j;
102     fprintf(fh,"l,\tm,\tulm^2avg\n");
103     for(i=0;i<sph->l;i++){
104             for(j=0;j<2*i+1;j++){
105         fprintf(fh,"%d,\t%d,\t%e\n", i, j-i, sph->sumUlm2[i][j]/(ts_double)sph->N);
106
107             }
108     fprintf(fh,"\n");
109     }
110     fclose(fh);
111     return TS_SUCCESS;
112 }