Trisurf Monte Carlo simulator
Samo Penic
2014-04-09 dc77e8ef10378188ee0a9657cedd1b7991a0a29f
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"
SP 13 #include "vesicle.h"
fedf2b 14
626811 15 ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations, ts_uint start_iteration){
d7a113 16     ts_uint i, j;
dc77e8 17     ts_double r0;
37d14a 18     ts_double l1,l2,l3,volume=0.0,area=0.0,vmsr,bfsr, vmsrt, bfsrt;
SP 19     ts_ulong epochtime;
fe24d2 20 //     char filename[255];
37d14a 21     FILE *fd=fopen("statistics.csv","w");
SP 22     if(fd==NULL){
23         fatal("Cannot open statistics.csv file for writing",1);
24     }
25     fprintf(fd, "Epoch OuterLoop VertexMoveSucessRate BondFlipSuccessRate Volume Area lamdba1 lambda2 lmabda3\n");
d7a113 26     centermass(vesicle);
SP 27     cell_occupation(vesicle);
626811 28     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 29     for(i=start_iteration;i<inititer+iterations;i++){
37d14a 30         vmsr=0.0;
SP 31         bfsr=0.0;
d7a113 32         for(j=0;j<mcsweeps;j++){
37d14a 33             single_timestep(vesicle, &vmsrt, &bfsrt);
SP 34             vmsr+=vmsrt;
35             bfsr+=bfsrt;
d7a113 36         }
37d14a 37         vmsr/=(ts_double)mcsweeps;
SP 38         bfsr/=(ts_double)mcsweeps;
d7a113 39         centermass(vesicle);
SP 40         cell_occupation(vesicle);
f8e6ba 41         ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
1ab449 42             dump_state(vesicle,i);
58230a 43         if(i>=inititer){
d7a113 44             write_vertex_xml_file(vesicle,i-inititer);
37d14a 45             write_master_xml_file("test.pvd");
SP 46             epochtime=get_epoch();            
47             gyration_eigen(vesicle, &l1, &l2, &l3);
48             get_area_volume(vesicle, &area,&volume);
dc77e8 49             vesicle_volume(vesicle);
SP 50             r0=getR0(vesicle);
51             preparationSh(vesicle,r0);
52             calculateYlmi(vesicle);
53             calculateUlm(vesicle);
54             storeUlm2(vesicle);
55             saveAvgUlm2(vesicle);
56
37d14a 57             fprintf(fd, "%lu %u %e %e %e %e %e %e %e\n",epochtime,i,vmsr,bfsr,volume, area,l1,l2,l3);
SP 58             
144784 59         //    sprintf(filename,"timestep-%05d.pov",i-inititer);
fe24d2 60         //    write_pov_file(vesicle,filename);
d7a113 61         }
SP 62     }
37d14a 63     fclose(fd);
d7a113 64     return TS_SUCCESS;
SP 65 }
d7639a 66
37d14a 67 ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){
d7639a 68     ts_bool retval;
SP 69     ts_double rnvec[3];
fedf2b 70     ts_uint i,j,b;
37d14a 71     ts_uint vmsrcnt=0;
aec47d 72     for(i=0;i<vesicle->vlist->n;i++){
d7639a 73         rnvec[0]=drand48();
SP 74         rnvec[1]=drand48();
75         rnvec[2]=drand48();
aec47d 76         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
37d14a 77     if(retval==TS_SUCCESS) vmsrcnt++;        
d7639a 78     }
SP 79
37d14a 80     ts_int bfsrcnt=0;
fedf2b 81     for(i=0;i<3*vesicle->vlist->n;i++){
142a67 82     b=rand() % vesicle->blist->n;
d7639a 83         //find a bond and return a pointer to a bond...
SP 84         //call single_bondflip_timestep...
142a67 85         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
37d14a 86     if(retval==TS_SUCCESS) bfsrcnt++;        
fedf2b 87     }
M 88
89     for(i=0;i<vesicle->poly_list->n;i++){
58230a 90         for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
M 91             rnvec[0]=drand48();
92             rnvec[1]=drand48();
93             rnvec[2]=drand48();
94             retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
95         }
fedf2b 96     }
M 97
58230a 98
M 99     for(i=0;i<vesicle->filament_list->n;i++){
100         for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){
101             rnvec[0]=drand48();
102             rnvec[1]=drand48();
103             rnvec[2]=drand48();
104             retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec);    
105         }
fedf2b 106     }
M 107  
58230a 108
fedf2b 109 //    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 110     *vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n;
SP 111     *bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0;
d7639a 112     return TS_SUCCESS;
SP 113 }
114
115
116