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