Trisurf Monte Carlo simulator
Samo Penic
2014-05-06 7d5e22d9eda3020e8b2b3fd8a70f25306561b401
commit | author | age
d7639a 1 #include<stdlib.h>
SP 2 #include<stdio.h>
aec47d 3 #include<math.h>
SP 4 //#include "io.h"
5 #include "general.h"
6 #include "timestep.h"
7 #include "vertexmove.h"
30ee9c 8 #include "bondflip.h"
d7a113 9 #include "frame.h"
SP 10 #include "io.h"
37d14a 11 #include "stats.h"
dc77e8 12 #include "sh.h"
459ff9 13 #include "shcomplex.h"
dc77e8 14 #include "vesicle.h"
fedf2b 15
626811 16 ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations, ts_uint start_iteration){
5bb6bb 17     ts_uint i, j,k;
1665aa 18     ts_double r0,kc1,kc2,kc3,kc4;
37d14a 19     ts_double l1,l2,l3,volume=0.0,area=0.0,vmsr,bfsr, vmsrt, bfsrt;
SP 20     ts_ulong epochtime;
5bb6bb 21     FILE *fd1;
fe24d2 22 //     char filename[255];
37d14a 23     FILE *fd=fopen("statistics.csv","w");
SP 24     if(fd==NULL){
25         fatal("Cannot open statistics.csv file for writing",1);
26     }
1665aa 27     fprintf(fd, "Epoch OuterLoop VertexMoveSucessRate BondFlipSuccessRate Volume Area lamdba1 lambda2 lambda3 Kc(2-9) Kc(6-9) Kc(2-end) Kc(3-6)\n");
d7a113 28     centermass(vesicle);
SP 29     cell_occupation(vesicle);
fe5069 30     vesicle_volume(vesicle); //needed for constant volume at this moment
626811 31     if(start_iteration<inititer) ts_fprintf(stdout, "Starting simulation (first %d x %d MC sweeps will not be recorded on disk)\n", inititer, mcsweeps);
SP 32     for(i=start_iteration;i<inititer+iterations;i++){
37d14a 33         vmsr=0.0;
SP 34         bfsr=0.0;
3de289 35 /*    vesicle_volume(vesicle);
SP 36     fprintf(stderr,"Volume before TS=%1.16e\n", vesicle->volume); */
d7a113 37         for(j=0;j<mcsweeps;j++){
37d14a 38             single_timestep(vesicle, &vmsrt, &bfsrt);
SP 39             vmsr+=vmsrt;
40             bfsr+=bfsrt;
d7a113 41         }
3de289 42 /*
SP 43     vesicle_volume(vesicle);
44     fprintf(stderr,"Volume after TS=%1.16e\n", vesicle->volume); */
37d14a 45         vmsr/=(ts_double)mcsweeps;
SP 46         bfsr/=(ts_double)mcsweeps;
d7a113 47         centermass(vesicle);
SP 48         cell_occupation(vesicle);
f8e6ba 49         ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
1ab449 50             dump_state(vesicle,i);
58230a 51         if(i>=inititer){
d7a113 52             write_vertex_xml_file(vesicle,i-inititer);
37d14a 53             write_master_xml_file("test.pvd");
SP 54             epochtime=get_epoch();            
55             gyration_eigen(vesicle, &l1, &l2, &l3);
632960 56             vesicle_volume(vesicle); //calculates just volume. Area is not added to ts_vesicle yet!
SP 57             get_area_volume(vesicle, &area,&volume); //that's why I must recalculate area (and volume for no particular reason).
dc77e8 58             r0=getR0(vesicle);
632960 59             if(vesicle->sphHarmonics!=NULL){
SP 60                 preparationSh(vesicle,r0);
459ff9 61                 //calculateYlmi(vesicle);
SP 62                 calculateUlmComplex(vesicle);
63                 storeUlmComplex2(vesicle);
632960 64                 saveAvgUlm2(vesicle);
22cdfd 65                 kc1=calculateKc(vesicle, 2,9);
SP 66                 kc2=calculateKc(vesicle, 6,9);
67                 kc3=calculateKc(vesicle, 2,vesicle->sphHarmonics->l);
1665aa 68                 kc4=calculateKc(vesicle, 3,6);
22cdfd 69             
5bb6bb 70                 fd1=fopen("state.dat","w");
M 71                 fprintf(fd1,"%e %e\n",vesicle->volume, getR0(vesicle));
72                 for(k=0;k<vesicle->vlist->n;k++){
73                     fprintf(fd1,"%e %e %e %e %e\n",
74                         vesicle->vlist->vtx[k]->x,
75                         vesicle->vlist->vtx[k]->y,
76                         vesicle->vlist->vtx[k]->z,
77                         vesicle->vlist->vtx[k]->solAngle,
78                         vesicle->vlist->vtx[k]->relR
79                     );
80                 }
81                 fclose(fd1);
632960 82             }
dc77e8 83
1665aa 84             fprintf(fd, "%lu %u %e %e %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e %1.16e\n",epochtime,i,vmsr,bfsr,volume, area,l1,l2,l3,kc1, kc2, kc3,kc4);
632960 85             fflush(fd);    
144784 86         //    sprintf(filename,"timestep-%05d.pov",i-inititer);
fe24d2 87         //    write_pov_file(vesicle,filename);
d7a113 88         }
SP 89     }
37d14a 90     fclose(fd);
d7a113 91     return TS_SUCCESS;
SP 92 }
d7639a 93
37d14a 94 ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){
3de289 95 //    vesicle_volume(vesicle);
SP 96 //    fprintf(stderr,"Volume before TS=%1.16e\n", vesicle->volume);
d7639a 97     ts_bool retval;
SP 98     ts_double rnvec[3];
fe5069 99     ts_uint i,j, b;
37d14a 100     ts_uint vmsrcnt=0;
aec47d 101     for(i=0;i<vesicle->vlist->n;i++){
d7639a 102         rnvec[0]=drand48();
SP 103         rnvec[1]=drand48();
104         rnvec[2]=drand48();
aec47d 105         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
37d14a 106     if(retval==TS_SUCCESS) vmsrcnt++;        
d7639a 107     }
SP 108
37d14a 109     ts_int bfsrcnt=0;
fedf2b 110     for(i=0;i<3*vesicle->vlist->n;i++){
fe5069 111     b=rand() % vesicle->blist->n;
d7639a 112         //find a bond and return a pointer to a bond...
SP 113         //call single_bondflip_timestep...
fe5069 114         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
3de289 115        //     b++; retval=TS_FAIL;
37d14a 116     if(retval==TS_SUCCESS) bfsrcnt++;        
fedf2b 117     }
M 118
119     for(i=0;i<vesicle->poly_list->n;i++){
58230a 120         for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
M 121             rnvec[0]=drand48();
122             rnvec[1]=drand48();
123             rnvec[2]=drand48();
124             retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
125         }
fedf2b 126     }
M 127
58230a 128
M 129     for(i=0;i<vesicle->filament_list->n;i++){
130         for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){
131             rnvec[0]=drand48();
132             rnvec[1]=drand48();
133             rnvec[2]=drand48();
134             retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec);    
135         }
fedf2b 136     }
M 137  
58230a 138
fedf2b 139 //    printf("Bondflip success rate in one sweep: %d/%d=%e\n", cnt,3*vesicle->blist->n,(double)cnt/(double)vesicle->blist->n/3.0);
37d14a 140     *vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n;
SP 141     *bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0;
3de289 142 //    vesicle_volume(vesicle);
SP 143 //    fprintf(stderr,"Volume after TS=%1.16e\n", vesicle->volume);
d7639a 144     return TS_SUCCESS;
SP 145 }
146
147
148