Trisurf Monte Carlo simulator
mihaf
2014-04-16 5bb6bb1c525a0503f8eb2b1c0fa64a5d3cc6e9bf
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){
5bb6bb 16     ts_uint i, j,k;
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;
5bb6bb 20     FILE *fd1;
fe24d2 21 //     char filename[255];
37d14a 22     FILE *fd=fopen("statistics.csv","w");
SP 23     if(fd==NULL){
24         fatal("Cannot open statistics.csv file for writing",1);
25     }
632960 26     fprintf(fd, "Epoch OuterLoop VertexMoveSucessRate BondFlipSuccessRate Volume Area lamdba1 lambda2 lambda3\n");
d7a113 27     centermass(vesicle);
SP 28     cell_occupation(vesicle);
626811 29     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 30     for(i=start_iteration;i<inititer+iterations;i++){
37d14a 31         vmsr=0.0;
SP 32         bfsr=0.0;
d7a113 33         for(j=0;j<mcsweeps;j++){
37d14a 34             single_timestep(vesicle, &vmsrt, &bfsrt);
SP 35             vmsr+=vmsrt;
36             bfsr+=bfsrt;
d7a113 37         }
37d14a 38         vmsr/=(ts_double)mcsweeps;
SP 39         bfsr/=(ts_double)mcsweeps;
d7a113 40         centermass(vesicle);
SP 41         cell_occupation(vesicle);
f8e6ba 42         ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
1ab449 43             dump_state(vesicle,i);
58230a 44         if(i>=inititer){
d7a113 45             write_vertex_xml_file(vesicle,i-inititer);
37d14a 46             write_master_xml_file("test.pvd");
SP 47             epochtime=get_epoch();            
48             gyration_eigen(vesicle, &l1, &l2, &l3);
632960 49             vesicle_volume(vesicle); //calculates just volume. Area is not added to ts_vesicle yet!
SP 50             get_area_volume(vesicle, &area,&volume); //that's why I must recalculate area (and volume for no particular reason).
dc77e8 51             r0=getR0(vesicle);
632960 52             if(vesicle->sphHarmonics!=NULL){
SP 53                 preparationSh(vesicle,r0);
54                 calculateYlmi(vesicle);
55                 calculateUlm(vesicle);
56                 storeUlm2(vesicle);
57                 saveAvgUlm2(vesicle);
5bb6bb 58                 fd1=fopen("state.dat","w");
M 59                 fprintf(fd1,"%e %e\n",vesicle->volume, getR0(vesicle));
60                 for(k=0;k<vesicle->vlist->n;k++){
61                     fprintf(fd1,"%e %e %e %e %e\n",
62                         vesicle->vlist->vtx[k]->x,
63                         vesicle->vlist->vtx[k]->y,
64                         vesicle->vlist->vtx[k]->z,
65                         vesicle->vlist->vtx[k]->solAngle,
66                         vesicle->vlist->vtx[k]->relR
67                     );
68                 }
69                 fclose(fd1);
632960 70             }
dc77e8 71
632960 72             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 73             fflush(fd);    
144784 74         //    sprintf(filename,"timestep-%05d.pov",i-inititer);
fe24d2 75         //    write_pov_file(vesicle,filename);
d7a113 76         }
SP 77     }
37d14a 78     fclose(fd);
d7a113 79     return TS_SUCCESS;
SP 80 }
d7639a 81
37d14a 82 ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){
d7639a 83     ts_bool retval;
SP 84     ts_double rnvec[3];
fedf2b 85     ts_uint i,j,b;
37d14a 86     ts_uint vmsrcnt=0;
aec47d 87     for(i=0;i<vesicle->vlist->n;i++){
d7639a 88         rnvec[0]=drand48();
SP 89         rnvec[1]=drand48();
90         rnvec[2]=drand48();
aec47d 91         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
37d14a 92     if(retval==TS_SUCCESS) vmsrcnt++;        
d7639a 93     }
SP 94
37d14a 95     ts_int bfsrcnt=0;
fedf2b 96     for(i=0;i<3*vesicle->vlist->n;i++){
142a67 97     b=rand() % vesicle->blist->n;
d7639a 98         //find a bond and return a pointer to a bond...
SP 99         //call single_bondflip_timestep...
142a67 100         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
37d14a 101     if(retval==TS_SUCCESS) bfsrcnt++;        
fedf2b 102     }
M 103
104     for(i=0;i<vesicle->poly_list->n;i++){
58230a 105         for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
M 106             rnvec[0]=drand48();
107             rnvec[1]=drand48();
108             rnvec[2]=drand48();
109             retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
110         }
fedf2b 111     }
M 112
58230a 113
M 114     for(i=0;i<vesicle->filament_list->n;i++){
115         for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){
116             rnvec[0]=drand48();
117             rnvec[1]=drand48();
118             rnvec[2]=drand48();
119             retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec);    
120         }
fedf2b 121     }
M 122  
58230a 123
fedf2b 124 //    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 125     *vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n;
SP 126     *bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0;
d7639a 127     return TS_SUCCESS;
SP 128 }
129
130
131