Trisurf Monte Carlo simulator
Samo Penic
2014-04-10 632960fbf1ebde72860966058354f7a6b61f5267
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     }
632960 25     fprintf(fd, "Epoch OuterLoop VertexMoveSucessRate BondFlipSuccessRate Volume Area lamdba1 lambda2 lambda3\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);
632960 48             vesicle_volume(vesicle); //calculates just volume. Area is not added to ts_vesicle yet!
SP 49             get_area_volume(vesicle, &area,&volume); //that's why I must recalculate area (and volume for no particular reason).
dc77e8 50             r0=getR0(vesicle);
632960 51             if(vesicle->sphHarmonics!=NULL){
SP 52                 preparationSh(vesicle,r0);
53                 calculateYlmi(vesicle);
54                 calculateUlm(vesicle);
55                 storeUlm2(vesicle);
56                 saveAvgUlm2(vesicle);
57             }
dc77e8 58
632960 59             fprintf(fd, "%lu %u %e %e %1.16e %1.16e %1.16e %1.16e %1.16e\n",epochtime,i,vmsr,bfsr,volume, area,l1,l2,l3);
SP 60             fflush(fd);    
144784 61         //    sprintf(filename,"timestep-%05d.pov",i-inititer);
fe24d2 62         //    write_pov_file(vesicle,filename);
d7a113 63         }
SP 64     }
37d14a 65     fclose(fd);
d7a113 66     return TS_SUCCESS;
SP 67 }
d7639a 68
37d14a 69 ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){
d7639a 70     ts_bool retval;
SP 71     ts_double rnvec[3];
fedf2b 72     ts_uint i,j,b;
37d14a 73     ts_uint vmsrcnt=0;
aec47d 74     for(i=0;i<vesicle->vlist->n;i++){
d7639a 75         rnvec[0]=drand48();
SP 76         rnvec[1]=drand48();
77         rnvec[2]=drand48();
aec47d 78         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
37d14a 79     if(retval==TS_SUCCESS) vmsrcnt++;        
d7639a 80     }
SP 81
37d14a 82     ts_int bfsrcnt=0;
fedf2b 83     for(i=0;i<3*vesicle->vlist->n;i++){
142a67 84     b=rand() % vesicle->blist->n;
d7639a 85         //find a bond and return a pointer to a bond...
SP 86         //call single_bondflip_timestep...
142a67 87         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
37d14a 88     if(retval==TS_SUCCESS) bfsrcnt++;        
fedf2b 89     }
M 90
91     for(i=0;i<vesicle->poly_list->n;i++){
58230a 92         for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
M 93             rnvec[0]=drand48();
94             rnvec[1]=drand48();
95             rnvec[2]=drand48();
96             retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
97         }
fedf2b 98     }
M 99
58230a 100
M 101     for(i=0;i<vesicle->filament_list->n;i++){
102         for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){
103             rnvec[0]=drand48();
104             rnvec[1]=drand48();
105             rnvec[2]=drand48();
106             retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec);    
107         }
fedf2b 108     }
M 109  
58230a 110
fedf2b 111 //    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 112     *vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n;
SP 113     *bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0;
d7639a 114     return TS_SUCCESS;
SP 115 }
116
117
118