Trisurf Monte Carlo simulator
mihaf
2014-03-24 ea1cce4c80ddb68c0b46a6873ef3b64cc4a958a1
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"
fedf2b 11
626811 12 ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations, ts_uint start_iteration){
d7a113 13     ts_uint i, j;
144784 14      char filename[255];
d7a113 15
SP 16     centermass(vesicle);
17     cell_occupation(vesicle);
626811 18     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 19     for(i=start_iteration;i<inititer+iterations;i++){
d7a113 20         for(j=0;j<mcsweeps;j++){
SP 21             single_timestep(vesicle);
22         }
23         centermass(vesicle);
24         cell_occupation(vesicle);
f8e6ba 25         ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
1ab449 26             dump_state(vesicle,i);
58230a 27         if(i>=inititer){
d7a113 28             write_vertex_xml_file(vesicle,i-inititer);
144784 29         //    sprintf(filename,"timestep-%05d.pov",i-inititer);
SP 30             write_pov_file(vesicle,filename);
d7a113 31         }
SP 32     }
33     return TS_SUCCESS;
34 }
d7639a 35
SP 36 ts_bool single_timestep(ts_vesicle *vesicle){
37     ts_bool retval;
38     ts_double rnvec[3];
fedf2b 39     ts_uint i,j,b;
aec47d 40     for(i=0;i<vesicle->vlist->n;i++){
d7639a 41         rnvec[0]=drand48();
SP 42         rnvec[1]=drand48();
43         rnvec[2]=drand48();
aec47d 44         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
d7639a 45     }
SP 46
b7c9b3 47 //    ts_int cnt=0;
fedf2b 48     for(i=0;i<3*vesicle->vlist->n;i++){
dcf17d 49 //why is rnvec needed in bondflip?
SP 50 /*        rnvec[0]=drand48();
51         rnvec[1]=drand48();
52         rnvec[2]=drand48();
53 */ 
142a67 54     b=rand() % vesicle->blist->n;
d7639a 55         //find a bond and return a pointer to a bond...
SP 56         //call single_bondflip_timestep...
142a67 57         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
b7c9b3 58 //    if(retval==TS_SUCCESS) cnt++;        
fedf2b 59     }
M 60
61     for(i=0;i<vesicle->poly_list->n;i++){
58230a 62         for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
M 63             rnvec[0]=drand48();
64             rnvec[1]=drand48();
65             rnvec[2]=drand48();
66             retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
67         }
fedf2b 68     }
M 69
58230a 70
M 71     for(i=0;i<vesicle->filament_list->n;i++){
72         for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){
73             rnvec[0]=drand48();
74             rnvec[1]=drand48();
75             rnvec[2]=drand48();
76             retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec);    
77         }
fedf2b 78     }
M 79  
58230a 80
fedf2b 81 //    printf("Bondflip success rate in one sweep: %d/%d=%e\n", cnt,3*vesicle->blist->n,(double)cnt/(double)vesicle->blist->n/3.0);
41a035 82     if(retval);
d7639a 83     return TS_SUCCESS;
SP 84 }
85
86
87