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