| commit | author | age | ||
| 7f6076 | 1 | /* vim: set ts=4 sts=4 sw=4 noet : */ |
| d7639a | 2 | #include<stdlib.h> |
| SP | 3 | #include<stdio.h> |
| aec47d | 4 | #include<math.h> |
| SP | 5 | //#include "io.h" |
| 6 | #include "general.h" | |
| 7 | #include "timestep.h" | |
| 8 | #include "vertexmove.h" | |
| 30ee9c | 9 | #include "bondflip.h" |
| d7a113 | 10 | #include "frame.h" |
| SP | 11 | #include "io.h" |
| 37d14a | 12 | #include "stats.h" |
| dc77e8 | 13 | #include "sh.h" |
| 459ff9 | 14 | #include "shcomplex.h" |
| dc77e8 | 15 | #include "vesicle.h" |
| 5a3862 | 16 | #include<gsl/gsl_complex.h> |
| M | 17 | #include<gsl/gsl_complex_math.h> |
| 267db5 | 18 | #include<string.h> |
| ac9826 | 19 | #include <sys/stat.h> |
| SP | 20 | |
| fedf2b | 21 | |
| 626811 | 22 | ts_bool run_simulation(ts_vesicle *vesicle, ts_uint mcsweeps, ts_uint inititer, ts_uint iterations, ts_uint start_iteration){ |
| d5d78a | 23 | ts_uint i, j,k; //,l,m; |
| SP | 24 | ts_double kc1=0,kc2=0,kc3=0,kc4=0; |
| c0ae90 | 25 | ts_double l1,l2,l3,vmsr,bfsr, vmsrt, bfsrt; |
| 37d14a | 26 | ts_ulong epochtime; |
| 0dd5ba | 27 | ts_double max_z,min_z; |
| d5d78a | 28 | FILE *fd3=NULL; |
| 267db5 | 29 | char filename[10000]; |
| ac9826 | 30 | //struct stat st; |
| SP | 31 | strcpy(filename,command_line_args.path); |
| 32 | strcat(filename,"statistics.csv"); | |
| 33 | //int result = stat(filename, &st); | |
| 34 | FILE *fd; | |
| 35 | if(start_iteration==0) | |
| 36 | fd=fopen(filename,"w"); | |
| 37 | else | |
| 38 | fd=fopen(filename,"a"); | |
| 37d14a | 39 | if(fd==NULL){ |
| SP | 40 | fatal("Cannot open statistics.csv file for writing",1); |
| 41 | } | |
| ac9826 | 42 | if(start_iteration==0) |
| SP | 43 | 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 | 44 | |
| d5d78a | 45 | /* if(vesicle->sphHarmonics!=NULL){ |
| 267db5 | 46 | strcpy(filename,command_line_args.path); |
| SP | 47 | strcat(filename,"ulm2.csv"); |
| ac9826 | 48 | // int result = stat(filename, &st); |
| SP | 49 | if(start_iteration==0) |
| 267db5 | 50 | fd2=fopen(filename,"w"); |
| ac9826 | 51 | else |
| SP | 52 | fd2=fopen(filename,"a"); |
| 819a09 | 53 | if(fd2==NULL){ |
| S | 54 | fatal("Cannot open ulm2.csv file for writing",1); |
| d5d78a | 55 | } |
| SP | 56 | |
| 819a09 | 57 | if(start_iteration==0) //file does not exist |
| S | 58 | fprintf(fd2, "Timestep u_00^2 u_10^2 u_11^2 u_20^2 ...\n"); |
| 5a3862 | 59 | } |
| d5d78a | 60 | */ |
| 5a3862 | 61 | |
| c60a49 | 62 | /* RANDOM SEED SET BY CURRENT TIME */ |
| M | 63 | epochtime=get_epoch(); |
| 64 | srand48(epochtime); | |
| d7a113 | 65 | centermass(vesicle); |
| SP | 66 | cell_occupation(vesicle); |
| fe5069 | 67 | vesicle_volume(vesicle); //needed for constant volume at this moment |
| 88bdd7 | 68 | vesicle_area(vesicle); //needed for constant area at this moment |
| 49981c | 69 | if(V0<0.000001) |
| SP | 70 | V0=vesicle->volume; |
| 71 | ts_fprintf(stdout,"Setting volume V0=%.17f\n",V0); | |
| 72 | if(A0<0.000001) | |
| 73 | A0=vesicle->area; | |
| 819a09 | 74 | ts_fprintf(stdout,"Setting area A0=%.17f\n",A0); |
| a54977 | 75 | epsvol=4.0*sqrt(2.0*M_PI)/pow(3.0,3.0/4.0)*V0/pow(vesicle->tlist->n,3.0/2.0); |
| d5d78a | 76 | // printf("epsvol=%e\n",epsvol); |
| 88bdd7 | 77 | epsarea=A0/(ts_double)vesicle->tlist->n; |
| SP | 78 | |
| 626811 | 79 | 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 | 80 | for(i=start_iteration;i<inititer+iterations;i++){ |
| 37d14a | 81 | vmsr=0.0; |
| SP | 82 | bfsr=0.0; |
| 0dd5ba | 83 | |
| SP | 84 | //plane confinement |
| 85 | if(vesicle->tape->plane_confinement_switch){ | |
| 86 | min_z=1e10; | |
| 87 | max_z=-1e10; | |
| 88 | for(k=0;k<vesicle->vlist->n;k++){ | |
| 89 | if(vesicle->vlist->vtx[k]->z > max_z) max_z=vesicle->vlist->vtx[k]->z; | |
| 90 | if(vesicle->vlist->vtx[k]->z < min_z) min_z=vesicle->vlist->vtx[k]->z; | |
| 91 | } | |
| 92 | vesicle->confinement_plane.force_switch=0; | |
| 93 | if(max_z>=vesicle->tape->plane_d/2.0){ | |
| 94 | ts_fprintf(stdout, "Max vertex out of bounds (z>=%e). Plane set to max_z = %e.\n",vesicle->tape->plane_d/2.0,max_z); | |
| 95 | vesicle->confinement_plane.z_max = max_z; | |
| 96 | vesicle->confinement_plane.force_switch=1; | |
| 97 | } else { | |
| 98 | vesicle->confinement_plane.z_max=vesicle->tape->plane_d/2.0; | |
| 99 | } | |
| 100 | if(min_z<=-vesicle->tape->plane_d/2.0){ | |
| 101 | ts_fprintf(stdout, "Min vertex out of bounds (z<=%e). Plane set to min_z = %e.\n",-vesicle->tape->plane_d/2.0,min_z); | |
| 102 | vesicle->confinement_plane.z_min = min_z; | |
| 103 | vesicle->confinement_plane.force_switch=1; | |
| 104 | } else { | |
| 105 | vesicle->confinement_plane.z_min=-vesicle->tape->plane_d/2.0; | |
| 106 | } | |
| 107 | ts_fprintf(stdout,"Vesicle confinement by plane set to (zmin, zmax)=(%e,%e).\n",vesicle->confinement_plane.z_min,vesicle->confinement_plane.z_max); | |
| 108 | if(vesicle->confinement_plane.force_switch) ts_fprintf(stdout,"Squeezing with force %e.\n",vesicle->tape->plane_F); | |
| 109 | } | |
| 110 | ||
| 111 | //end plane confinement | |
| 112 | ||
| 3de289 | 113 | /* vesicle_volume(vesicle); |
| SP | 114 | fprintf(stderr,"Volume before TS=%1.16e\n", vesicle->volume); */ |
| d7a113 | 115 | for(j=0;j<mcsweeps;j++){ |
| 37d14a | 116 | single_timestep(vesicle, &vmsrt, &bfsrt); |
| SP | 117 | vmsr+=vmsrt; |
| 118 | bfsr+=bfsrt; | |
| d7a113 | 119 | } |
| 3de289 | 120 | /* |
| SP | 121 | vesicle_volume(vesicle); |
| 122 | fprintf(stderr,"Volume after TS=%1.16e\n", vesicle->volume); */ | |
| 37d14a | 123 | vmsr/=(ts_double)mcsweeps; |
| SP | 124 | bfsr/=(ts_double)mcsweeps; |
| d7a113 | 125 | centermass(vesicle); |
| SP | 126 | cell_occupation(vesicle); |
| d5d78a | 127 | dump_state(vesicle,i); |
| SP | 128 | vesicle_volume(vesicle); //calculates just volume. |
| 129 | vesicle_area(vesicle); //calculates area. | |
| 130 | if(vesicle->tape->constvolswitch==0){ | |
| 131 | V0=vesicle->volume; | |
| 132 | } | |
| 133 | if(vesicle->tape->constareaswitch==0){ | |
| 134 | A0=vesicle->area; | |
| 135 | } | |
| 58230a | 136 | if(i>=inititer){ |
| 0a2c81 | 137 | write_vertex_xml_file(vesicle,i-inititer,NULL); |
| 267db5 | 138 | write_master_xml_file(command_line_args.output_fullfilename); |
| 37d14a | 139 | epochtime=get_epoch(); |
| SP | 140 | gyration_eigen(vesicle, &l1, &l2, &l3); |
| d5d78a | 141 | //r0=getR0(vesicle); |
| SP | 142 | /* if(vesicle->sphHarmonics!=NULL){ |
| 632960 | 143 | preparationSh(vesicle,r0); |
| 459ff9 | 144 | //calculateYlmi(vesicle); |
| SP | 145 | calculateUlmComplex(vesicle); |
| 146 | storeUlmComplex2(vesicle); | |
| 632960 | 147 | saveAvgUlm2(vesicle); |
| 22cdfd | 148 | kc1=calculateKc(vesicle, 2,9); |
| SP | 149 | kc2=calculateKc(vesicle, 6,9); |
| 150 | kc3=calculateKc(vesicle, 2,vesicle->sphHarmonics->l); | |
| 1665aa | 151 | kc4=calculateKc(vesicle, 3,6); |
| d5d78a | 152 | |
| 267db5 | 153 | strcpy(filename,command_line_args.path); |
| SP | 154 | strcat(filename,"state.dat"); |
| 155 | fd1=fopen(filename,"w"); | |
| 5bb6bb | 156 | fprintf(fd1,"%e %e\n",vesicle->volume, getR0(vesicle)); |
| M | 157 | for(k=0;k<vesicle->vlist->n;k++){ |
| 158 | fprintf(fd1,"%e %e %e %e %e\n", | |
| 159 | vesicle->vlist->vtx[k]->x, | |
| 160 | vesicle->vlist->vtx[k]->y, | |
| 161 | vesicle->vlist->vtx[k]->z, | |
| 162 | vesicle->vlist->vtx[k]->solAngle, | |
| 163 | vesicle->vlist->vtx[k]->relR | |
| 164 | ); | |
| 165 | } | |
| 166 | fclose(fd1); | |
| 5a3862 | 167 | |
| M | 168 | fprintf(fd2,"%u ", i); |
| 169 | for(l=0;l<vesicle->sphHarmonics->l;l++){ | |
| 170 | for(m=l;m<2*l+1;m++){ | |
| 171 | fprintf(fd2,"%e ", gsl_complex_abs2(vesicle->sphHarmonics->ulmComplex[l][m]) ); | |
| 172 | } | |
| 173 | } | |
| 174 | fprintf(fd2,"\n"); | |
| 175 | ||
| 176 | fflush(fd2); | |
| 177 | ||
| d5d78a | 178 | |
| 632960 | 179 | } |
| d5d78a | 180 | */ |
| dc77e8 | 181 | |
| c0ae90 | 182 | 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,vesicle->volume, vesicle->area,l1,l2,l3,kc1, kc2, kc3,kc4); |
| 5a3862 | 183 | |
| 632960 | 184 | fflush(fd); |
| 144784 | 185 | // sprintf(filename,"timestep-%05d.pov",i-inititer); |
| fe24d2 | 186 | // write_pov_file(vesicle,filename); |
| 49981c | 187 | } //end if(inititer....) |
| SP | 188 | fd3=fopen(".status","w"); //write status file when everything is written to disk. |
| 189 | if(fd3==NULL){ | |
| 190 | fatal("Cannot open .status file for writing",1); | |
| d7a113 | 191 | } |
| 49981c | 192 | fprintf(fd3,"%d",i); |
| SP | 193 | fclose(fd3); |
| 194 | ts_fprintf(stdout,"Done %d out of %d iterations (x %d MC sweeps).\n",i+1,inititer+iterations,mcsweeps); | |
| d7a113 | 195 | } |
| 37d14a | 196 | fclose(fd); |
| d5d78a | 197 | // if(fd2!=NULL) fclose(fd2); |
| d7a113 | 198 | return TS_SUCCESS; |
| SP | 199 | } |
| d7639a | 200 | |
| 37d14a | 201 | ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){ |
| 3de289 | 202 | // vesicle_volume(vesicle); |
| SP | 203 | // fprintf(stderr,"Volume before TS=%1.16e\n", vesicle->volume); |
| d7639a | 204 | ts_bool retval; |
| SP | 205 | ts_double rnvec[3]; |
| fe5069 | 206 | ts_uint i,j, b; |
| 37d14a | 207 | ts_uint vmsrcnt=0; |
| aec47d | 208 | for(i=0;i<vesicle->vlist->n;i++){ |
| d7639a | 209 | rnvec[0]=drand48(); |
| SP | 210 | rnvec[1]=drand48(); |
| 211 | rnvec[2]=drand48(); | |
| aec47d | 212 | retval=single_verticle_timestep(vesicle,vesicle->vlist->vtx[i],rnvec); |
| 37d14a | 213 | if(retval==TS_SUCCESS) vmsrcnt++; |
| d7639a | 214 | } |
| SP | 215 | |
| 37d14a | 216 | ts_int bfsrcnt=0; |
| fedf2b | 217 | for(i=0;i<3*vesicle->vlist->n;i++){ |
| fe5069 | 218 | b=rand() % vesicle->blist->n; |
| d7639a | 219 | //find a bond and return a pointer to a bond... |
| SP | 220 | //call single_bondflip_timestep... |
| fe5069 | 221 | retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec); |
| 3de289 | 222 | // b++; retval=TS_FAIL; |
| 37d14a | 223 | if(retval==TS_SUCCESS) bfsrcnt++; |
| fedf2b | 224 | } |
| M | 225 | |
| 226 | for(i=0;i<vesicle->poly_list->n;i++){ | |
| 58230a | 227 | for(j=0;j<vesicle->poly_list->poly[i]->vlist->n;j++){ |
| M | 228 | rnvec[0]=drand48(); |
| 229 | rnvec[1]=drand48(); | |
| 230 | rnvec[2]=drand48(); | |
| 231 | retval=single_poly_vertex_move(vesicle,vesicle->poly_list->poly[i],vesicle->poly_list->poly[i]->vlist->vtx[j],rnvec); | |
| 232 | } | |
| fedf2b | 233 | } |
| M | 234 | |
| 58230a | 235 | |
| M | 236 | for(i=0;i<vesicle->filament_list->n;i++){ |
| 237 | for(j=0;j<vesicle->filament_list->poly[i]->vlist->n;j++){ | |
| 238 | rnvec[0]=drand48(); | |
| 239 | rnvec[1]=drand48(); | |
| 240 | rnvec[2]=drand48(); | |
| 241 | retval=single_filament_vertex_move(vesicle,vesicle->filament_list->poly[i],vesicle->filament_list->poly[i]->vlist->vtx[j],rnvec); | |
| 242 | } | |
| fedf2b | 243 | } |
| M | 244 | |
| 58230a | 245 | |
| fedf2b | 246 | // 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 | 247 | *vmsr=(ts_double)vmsrcnt/(ts_double)vesicle->vlist->n; |
| SP | 248 | *bfsr=(ts_double)bfsrcnt/(ts_double)vesicle->vlist->n/3.0; |
| 3de289 | 249 | // vesicle_volume(vesicle); |
| SP | 250 | // fprintf(stderr,"Volume after TS=%1.16e\n", vesicle->volume); |
| d7639a | 251 | return TS_SUCCESS; |
| SP | 252 | } |
| 253 | ||
| 254 | ||
| 255 | ||