Trisurf Monte Carlo simulator
Samo Penic
2014-04-21 459ff94855b2659de14ac2ac902b9658d28e19d5
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;
dc77e8 18     ts_double r0;
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     }
632960 27     fprintf(fd, "Epoch OuterLoop VertexMoveSucessRate BondFlipSuccessRate Volume Area lamdba1 lambda2 lambda3\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);
5bb6bb 59                 fd1=fopen("state.dat","w");
M 60                 fprintf(fd1,"%e %e\n",vesicle->volume, getR0(vesicle));
61                 for(k=0;k<vesicle->vlist->n;k++){
62                     fprintf(fd1,"%e %e %e %e %e\n",
63                         vesicle->vlist->vtx[k]->x,
64                         vesicle->vlist->vtx[k]->y,
65                         vesicle->vlist->vtx[k]->z,
66                         vesicle->vlist->vtx[k]->solAngle,
67                         vesicle->vlist->vtx[k]->relR
68                     );
69                 }
70                 fclose(fd1);
632960 71             }
dc77e8 72
632960 73             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 74             fflush(fd);    
144784 75         //    sprintf(filename,"timestep-%05d.pov",i-inititer);
fe24d2 76         //    write_pov_file(vesicle,filename);
d7a113 77         }
SP 78     }
37d14a 79     fclose(fd);
d7a113 80     return TS_SUCCESS;
SP 81 }
d7639a 82
37d14a 83 ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){
d7639a 84     ts_bool retval;
SP 85     ts_double rnvec[3];
fedf2b 86     ts_uint i,j,b;
37d14a 87     ts_uint vmsrcnt=0;
aec47d 88     for(i=0;i<vesicle->vlist->n;i++){
d7639a 89         rnvec[0]=drand48();
SP 90         rnvec[1]=drand48();
91         rnvec[2]=drand48();
aec47d 92         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
37d14a 93     if(retval==TS_SUCCESS) vmsrcnt++;        
d7639a 94     }
SP 95
37d14a 96     ts_int bfsrcnt=0;
fedf2b 97     for(i=0;i<3*vesicle->vlist->n;i++){
142a67 98     b=rand() % vesicle->blist->n;
d7639a 99         //find a bond and return a pointer to a bond...
SP 100         //call single_bondflip_timestep...
142a67 101         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
37d14a 102     if(retval==TS_SUCCESS) bfsrcnt++;        
fedf2b 103     }
M 104
105     for(i=0;i<vesicle->poly_list->n;i++){
58230a 106         for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
M 107             rnvec[0]=drand48();
108             rnvec[1]=drand48();
109             rnvec[2]=drand48();
110             retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
111         }
fedf2b 112     }
M 113
58230a 114
M 115     for(i=0;i<vesicle->filament_list->n;i++){
116         for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){
117             rnvec[0]=drand48();
118             rnvec[1]=drand48();
119             rnvec[2]=drand48();
120             retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec);    
121         }
fedf2b 122     }
M 123  
58230a 124
fedf2b 125 //    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 126     *vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n;
SP 127     *bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0;
d7639a 128     return TS_SUCCESS;
SP 129 }
130
131
132