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