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