Trisurf Monte Carlo simulator
Samo Penic
2014-03-05 719c9febac2eaff9483fda487b57684afbb59bb2
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
d7a113 12 ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations){
SP 13     ts_uint i, j;
14
15     centermass(vesicle);
16     cell_occupation(vesicle);
17     ts_fprintf(stdout, "Starting simulation (first %d x %d MC sweeps will not be recorded on disk)\n", inititer, mcsweeps);
18     for(i=0;i<inititer+iterations;i++){
19         for(j=0;j<mcsweeps;j++){
20             single_timestep(vesicle);
21         }
22         centermass(vesicle);
23         cell_occupation(vesicle);
f8e6ba 24         ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps);
d7a113 25         if(i>inititer){
SP 26             write_vertex_xml_file(vesicle,i-inititer);
27         }
28     }
29     return TS_SUCCESS;
30 }
d7639a 31
SP 32 ts_bool single_timestep(ts_vesicle *vesicle){
33     ts_bool retval;
34     ts_double rnvec[3];
fedf2b 35     ts_uint i,j,b;
aec47d 36     for(i=0;i<vesicle->vlist->n;i++){
d7639a 37         rnvec[0]=drand48();
SP 38         rnvec[1]=drand48();
39         rnvec[2]=drand48();
aec47d 40         retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec);
d7639a 41     }
SP 42
b7c9b3 43 //    ts_int cnt=0;
fedf2b 44     for(i=0;i<3*vesicle->vlist->n;i++){
dcf17d 45 //why is rnvec needed in bondflip?
SP 46 /*        rnvec[0]=drand48();
47         rnvec[1]=drand48();
48         rnvec[2]=drand48();
49 */ 
142a67 50     b=rand() % vesicle->blist->n;
d7639a 51         //find a bond and return a pointer to a bond...
SP 52         //call single_bondflip_timestep...
142a67 53         retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec);
b7c9b3 54 //    if(retval==TS_SUCCESS) cnt++;        
fedf2b 55     }
M 56
57     for(i=0;i<vesicle->poly_list->n;i++){
58     for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){
59         rnvec[0]=drand48();
60         rnvec[1]=drand48();
61         rnvec[2]=drand48();
62         retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec);    
63     }
64
65     }
66  
67 //    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 68     if(retval);
d7639a 69     return TS_SUCCESS;
SP 70 }
71
72
73