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" |
5a3862
|
15 |
#include<gsl/gsl_complex.h> |
M |
16 |
#include<gsl/gsl_complex_math.h> |
267db5
|
17 |
#include<string.h> |
fedf2b
|
18 |
|
626811
|
19 |
ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations, ts_uint start_iteration){ |
5a3862
|
20 |
ts_uint i, j,k,l,m; |
1665aa
|
21 |
ts_double r0,kc1,kc2,kc3,kc4; |
37d14a
|
22 |
ts_double l1,l2,l3,volume=0.0,area=0.0,vmsr,bfsr, vmsrt, bfsrt; |
SP |
23 |
ts_ulong epochtime; |
5a3862
|
24 |
FILE *fd1,*fd2=NULL; |
267db5
|
25 |
char filename[10000]; |
SP |
26 |
strcpy(filename,command_line_args.path); |
|
27 |
strcat(filename,"statistics.csv"); |
|
28 |
FILE *fd=fopen(filename,"w"); |
37d14a
|
29 |
if(fd==NULL){ |
SP |
30 |
fatal("Cannot open statistics.csv file for writing",1); |
|
31 |
} |
1665aa
|
32 |
fprintf(fd, "Epoch OuterLoop VertexMoveSucessRate BondFlipSuccessRate Volume Area lamdba1 lambda2 lambda3 Kc(2-9) Kc(6-9) Kc(2-end) Kc(3-6)\n"); |
5a3862
|
33 |
|
M |
34 |
if(vesicle->sphHarmonics!=NULL){ |
267db5
|
35 |
strcpy(filename,command_line_args.path); |
SP |
36 |
strcat(filename,"ulm2.csv"); |
|
37 |
fd2=fopen(filename,"w"); |
5a3862
|
38 |
if(fd2==NULL){ |
M |
39 |
fatal("Cannot open ulm2.csv file for writing",1); |
|
40 |
} |
|
41 |
fprintf(fd2, "Timestep u_00^2 u_10^2 u_11^2 u_20^2 ...\n"); |
|
42 |
|
|
43 |
} |
|
44 |
|
c60a49
|
45 |
/* RANDOM SEED SET BY CURRENT TIME */ |
M |
46 |
epochtime=get_epoch(); |
|
47 |
srand48(epochtime); |
5a3862
|
48 |
|
d7a113
|
49 |
centermass(vesicle); |
SP |
50 |
cell_occupation(vesicle); |
fe5069
|
51 |
vesicle_volume(vesicle); //needed for constant volume at this moment |
1121fa
|
52 |
V0=vesicle->volume; |
a54977
|
53 |
epsvol=4.0*sqrt(2.0*M_PI)/pow(3.0,3.0/4.0)*V0/pow(vesicle->tlist->n,3.0/2.0); |
SP |
54 |
// fprintf(stderr, "DVol=%1.16f (%1.16f), V0=%1.16f\n", epsvol,0.003e-2*V0,V0); |
626811
|
55 |
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 |
56 |
for(i=start_iteration;i<inititer+iterations;i++){ |
37d14a
|
57 |
vmsr=0.0; |
SP |
58 |
bfsr=0.0; |
3de289
|
59 |
/* vesicle_volume(vesicle); |
SP |
60 |
fprintf(stderr,"Volume before TS=%1.16e\n", vesicle->volume); */ |
d7a113
|
61 |
for(j=0;j<mcsweeps;j++){ |
37d14a
|
62 |
single_timestep(vesicle, &vmsrt, &bfsrt); |
SP |
63 |
vmsr+=vmsrt; |
|
64 |
bfsr+=bfsrt; |
d7a113
|
65 |
} |
3de289
|
66 |
/* |
SP |
67 |
vesicle_volume(vesicle); |
|
68 |
fprintf(stderr,"Volume after TS=%1.16e\n", vesicle->volume); */ |
37d14a
|
69 |
vmsr/=(ts_double)mcsweeps; |
SP |
70 |
bfsr/=(ts_double)mcsweeps; |
d7a113
|
71 |
centermass(vesicle); |
SP |
72 |
cell_occupation(vesicle); |
f8e6ba
|
73 |
ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps); |
1ab449
|
74 |
dump_state(vesicle,i); |
58230a
|
75 |
if(i>=inititer){ |
d7a113
|
76 |
write_vertex_xml_file(vesicle,i-inititer); |
267db5
|
77 |
write_master_xml_file(command_line_args.output_fullfilename); |
37d14a
|
78 |
epochtime=get_epoch(); |
SP |
79 |
gyration_eigen(vesicle, &l1, &l2, &l3); |
632960
|
80 |
vesicle_volume(vesicle); //calculates just volume. Area is not added to ts_vesicle yet! |
SP |
81 |
get_area_volume(vesicle, &area,&volume); //that's why I must recalculate area (and volume for no particular reason). |
dc77e8
|
82 |
r0=getR0(vesicle); |
632960
|
83 |
if(vesicle->sphHarmonics!=NULL){ |
SP |
84 |
preparationSh(vesicle,r0); |
459ff9
|
85 |
//calculateYlmi(vesicle); |
SP |
86 |
calculateUlmComplex(vesicle); |
|
87 |
storeUlmComplex2(vesicle); |
632960
|
88 |
saveAvgUlm2(vesicle); |
22cdfd
|
89 |
kc1=calculateKc(vesicle, 2,9); |
SP |
90 |
kc2=calculateKc(vesicle, 6,9); |
|
91 |
kc3=calculateKc(vesicle, 2,vesicle->sphHarmonics->l); |
1665aa
|
92 |
kc4=calculateKc(vesicle, 3,6); |
267db5
|
93 |
strcpy(filename,command_line_args.path); |
SP |
94 |
strcat(filename,"state.dat"); |
|
95 |
fd1=fopen(filename,"w"); |
5bb6bb
|
96 |
fprintf(fd1,"%e %e\n",vesicle->volume, getR0(vesicle)); |
M |
97 |
for(k=0;k<vesicle->vlist->n;k++){ |
|
98 |
fprintf(fd1,"%e %e %e %e %e\n", |
|
99 |
vesicle->vlist->vtx[k]->x, |
|
100 |
vesicle->vlist->vtx[k]->y, |
|
101 |
vesicle->vlist->vtx[k]->z, |
|
102 |
vesicle->vlist->vtx[k]->solAngle, |
|
103 |
vesicle->vlist->vtx[k]->relR |
|
104 |
); |
|
105 |
} |
|
106 |
fclose(fd1); |
5a3862
|
107 |
|
M |
108 |
fprintf(fd2,"%u ", i); |
|
109 |
for(l=0;l<vesicle->sphHarmonics->l;l++){ |
|
110 |
for(m=l;m<2*l+1;m++){ |
|
111 |
fprintf(fd2,"%e ", gsl_complex_abs2(vesicle->sphHarmonics->ulmComplex[l][m]) ); |
|
112 |
} |
|
113 |
} |
|
114 |
fprintf(fd2,"\n"); |
|
115 |
|
|
116 |
fflush(fd2); |
|
117 |
|
632960
|
118 |
} |
dc77e8
|
119 |
|
1665aa
|
120 |
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); |
5a3862
|
121 |
|
632960
|
122 |
fflush(fd); |
144784
|
123 |
// sprintf(filename,"timestep-%05d.pov",i-inititer); |
fe24d2
|
124 |
// write_pov_file(vesicle,filename); |
d7a113
|
125 |
} |
SP |
126 |
} |
37d14a
|
127 |
fclose(fd); |
5a3862
|
128 |
if(fd2!=NULL) fclose(fd2); |
d7a113
|
129 |
return TS_SUCCESS; |
SP |
130 |
} |
d7639a
|
131 |
|
37d14a
|
132 |
ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){ |
3de289
|
133 |
// vesicle_volume(vesicle); |
SP |
134 |
// fprintf(stderr,"Volume before TS=%1.16e\n", vesicle->volume); |
d7639a
|
135 |
ts_bool retval; |
SP |
136 |
ts_double rnvec[3]; |
fe5069
|
137 |
ts_uint i,j, b; |
37d14a
|
138 |
ts_uint vmsrcnt=0; |
aec47d
|
139 |
for(i=0;i<vesicle->vlist->n;i++){ |
d7639a
|
140 |
rnvec[0]=drand48(); |
SP |
141 |
rnvec[1]=drand48(); |
|
142 |
rnvec[2]=drand48(); |
aec47d
|
143 |
retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec); |
37d14a
|
144 |
if(retval==TS_SUCCESS) vmsrcnt++; |
d7639a
|
145 |
} |
SP |
146 |
|
37d14a
|
147 |
ts_int bfsrcnt=0; |
fedf2b
|
148 |
for(i=0;i<3*vesicle->vlist->n;i++){ |
fe5069
|
149 |
b=rand() % vesicle->blist->n; |
d7639a
|
150 |
//find a bond and return a pointer to a bond... |
SP |
151 |
//call single_bondflip_timestep... |
fe5069
|
152 |
retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec); |
3de289
|
153 |
// b++; retval=TS_FAIL; |
37d14a
|
154 |
if(retval==TS_SUCCESS) bfsrcnt++; |
fedf2b
|
155 |
} |
M |
156 |
|
|
157 |
for(i=0;i<vesicle->poly_list->n;i++){ |
58230a
|
158 |
for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){ |
M |
159 |
rnvec[0]=drand48(); |
|
160 |
rnvec[1]=drand48(); |
|
161 |
rnvec[2]=drand48(); |
|
162 |
retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec); |
|
163 |
} |
fedf2b
|
164 |
} |
M |
165 |
|
58230a
|
166 |
|
M |
167 |
for(i=0;i<vesicle->filament_list->n;i++){ |
|
168 |
for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){ |
|
169 |
rnvec[0]=drand48(); |
|
170 |
rnvec[1]=drand48(); |
|
171 |
rnvec[2]=drand48(); |
|
172 |
retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec); |
|
173 |
} |
fedf2b
|
174 |
} |
M |
175 |
|
58230a
|
176 |
|
fedf2b
|
177 |
// 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
|
178 |
*vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n; |
SP |
179 |
*bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0; |
3de289
|
180 |
// vesicle_volume(vesicle); |
SP |
181 |
// fprintf(stderr,"Volume after TS=%1.16e\n", vesicle->volume); |
d7639a
|
182 |
return TS_SUCCESS; |
SP |
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
|