Bondflip doesnt segfaults anymore. Bondflip is disabled, debugging vertexmove
| | |
| | | if(vesicle->pswitch==1) delta_energy-= vesicle->pressure*dvol; |
| | | } |
| | | |
| | | retval=TS_SUCCESS; |
| | | if(vesicle->tape->constvolswitch == 1){ |
| | | retval=constvolume(vesicle, it, -dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); |
| | | retval=constvolume(vesicle, it, dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); |
| | | if(retval==TS_FAIL){ |
| | | /* restoration procedure copied from few lines below */ |
| | | for(i=0;i<4;i++){ |
| | |
| | | /* level 2 pointers are redirected*/ |
| | | } |
| | | memcpy(bond,bck_bond,sizeof(ts_bond)); |
| | | |
| | | for(i=0;i<4;i++){ |
| | | free(bck_vtx[i]); |
| | | free(bck_tria[i]); |
| | |
| | | for(j=0;j<orig_vtx[i]->neigh_no;j++) fprintf(stderr," %d", orig_vtx[i]->neigh[j]->idx); |
| | | fprintf(stderr,"\n"); */ |
| | | } |
| | | |
| | | free(bck_bond); |
| | | return TS_FAIL; |
| | | |
| | | } |
| | | |
| | | delta_energy+=delta_energy_cv; |
| | | |
| | | delta_energy+=delta_energy_cv; |
| | | } |
| | | |
| | | |
| | |
| | | //not accepted, reverting changes |
| | | //restore all backups |
| | | // fprintf(stderr,"Restoring!!!\n"); |
| | | if(vesicle->tape->constvolswitch == 1){ |
| | | constvolumerestore(constvol_vtx_moved,constvol_vtx_backup); |
| | | } |
| | | |
| | | for(i=0;i<4;i++){ |
| | | // fprintf(stderr,"Restoring vtx neigh[%d] with neighbours %d\n",i, orig_vtx[i]->neigh_no ); |
| | |
| | | |
| | | free(bck_bond); |
| | | |
| | | if(vesicle->tape->constvolswitch == 1){ |
| | | constvolumerestore(constvol_vtx_moved,constvol_vtx_backup); |
| | | } |
| | | // fprintf(stderr,"Restoration complete!!!\n"); |
| | | |
| | | return TS_FAIL; |
| | |
| | | /* IF BONDFLIP ACCEPTED, THEN RETURN SUCCESS! */ |
| | | // fprintf(stderr,"SUCCESS!!!\n"); |
| | | |
| | | if(vesicle->tape->constvolswitch == 1){ |
| | | constvolumeaccept(vesicle,constvol_vtx_moved,constvol_vtx_backup); |
| | | } |
| | | // delete all backups |
| | | for(i=0;i<4;i++){ |
| | | free(bck_vtx[i]->neigh); |
| | |
| | | */ |
| | | } |
| | | free(bck_bond); |
| | | if(vesicle->tape->constvolswitch == 1){ |
| | | constvolumeaccept(vesicle,constvol_vtx_moved,constvol_vtx_backup); |
| | | } |
| | | |
| | | return TS_SUCCESS; |
| | | } |
| | |
| | | ts_uint Ntries=20; |
| | | ts_vertex *backupvtx; |
| | | ts_double Rv, dh, dvol, voldiff, oenergy,delta_energy; |
| | | |
| | | backupvtx=(ts_vertex *)calloc(sizeof(ts_vertex),10); |
| | | ts_double l0 = (1.0 + sqrt(vesicle->dmax))/2.0; //make this a global constant if necessary |
| | | for(i=0;i<Ntries;i++){ |
| | |
| | | |
| | | for(j=0;j<vtx_moved->neigh_no;j++){ |
| | | if(vtx_moved->neigh[j]==vtx_avoid) continue; |
| | | /* for(k=0;k<vtx_moved->neigh[j]->neigh_no;k++){ |
| | | if(vtx_moved->neigh[j]->neigh[k]==vtx_avoid) continue; |
| | | } |
| | | */ |
| | | |
| | | } |
| | | |
| | | memcpy((void *)&backupvtx[0],(void *)vtx_moved,sizeof(ts_vertex)); |
| | |
| | | // fprintf(stderr,"Sprejet.\n"); |
| | | |
| | | // All checks OK! |
| | | fprintf(stderr, "Step 1 success\n"); |
| | | |
| | | // doing second and final move. |
| | | for(j=0;j<vtx_moved->neigh_no;j++){ |
| | | memcpy((void *)&backupvtx[j+1],(void *)vtx_moved->neigh[j],sizeof(ts_vertex)); |
| | | } |
| | |
| | | *retEnergy=delta_energy; |
| | | *vtx_backup=backupvtx; |
| | | *vtx_moved_retval=vtx_moved; |
| | | fprintf(stderr, "Preliminary success\n"); |
| | | return TS_SUCCESS; |
| | | } |
| | | fprintf(stderr, "Step 2 success\n"); |
| | | //do it again ;) |
| | | dh=Vol*dh/dvol; |
| | | vtx_moved=memcpy((void *)vtx_moved,(void *)&backupvtx[0],sizeof(ts_vertex)); |
| | |
| | | continue; |
| | | } |
| | | |
| | | dvol=0.0; |
| | | for(j=0;j<vtx_moved->tristar_no;j++){ |
| | | dvol-=vtx_moved->tristar[j]->volume; |
| | | triangle_normal_vector(vtx_moved->tristar[j]); |
| | | dvol+=vtx_moved->tristar[j]->volume; |
| | | } |
| | | |
| | | fprintf(stderr, "Step 3a success voldiff=%e\n",voldiff); |
| | | voldiff=dvol-Vol; |
| | | fprintf(stderr, "Step 3b success voldiff=%e\n",voldiff); |
| | | if(fabs(voldiff)/vesicle->volume < vesicle->tape->constvolprecision){ |
| | | //calculate energy, return change in energy... |
| | | oenergy=vtx_moved->energy; |
| | |
| | | *retEnergy=delta_energy; |
| | | *vtx_backup=backupvtx; |
| | | *vtx_moved_retval=vtx_moved; |
| | | fprintf(stderr, "DVOL=%e\n",voldiff); |
| | | return TS_SUCCESS; |
| | | } |
| | | |
| | | |
| | | } |
| | | free(backupvtx); |
| | | fprintf(stderr, "fail\n"); |
| | | return TS_FAIL; |
| | | } |
| | | |
| | |
| | | ts_bool single_timestep(ts_vesicle *vesicle,ts_double *vmsr, ts_double *bfsr){ |
| | | ts_bool retval; |
| | | ts_double rnvec[3]; |
| | | ts_uint i,j,b; |
| | | ts_uint i,j;//b; |
| | | ts_uint vmsrcnt=0; |
| | | for(i=0;i<vesicle->vlist->n;i++){ |
| | | rnvec[0]=drand48(); |
| | |
| | | |
| | | ts_int bfsrcnt=0; |
| | | for(i=0;i<3*vesicle->vlist->n;i++){ |
| | | b=rand() % vesicle->blist->n; |
| | | // b=rand() % vesicle->blist->n; |
| | | //find a bond and return a pointer to a bond... |
| | | //call single_bondflip_timestep... |
| | | retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec); |
| | | // retval=single_bondflip_timestep(vesicle,vesicle->blist->bond[b],rnvec); |
| | | retval=TS_FAIL; |
| | | if(retval==TS_SUCCESS) bfsrcnt++; |
| | | } |
| | | |
| | |
| | | }; |
| | | |
| | | if(vesicle->tape->constvolswitch == 1){ |
| | | retval=constvolume(vesicle, vtx, -dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); |
| | | retval=constvolume(vesicle, vtx, dvol, &delta_energy_cv, &constvol_vtx_moved,&constvol_vtx_backup); |
| | | if(retval==TS_FAIL){ // if we couldn't move the vertex to assure constant volume |
| | | vtx=memcpy((void *)vtx,(void *)&backupvtx[0],sizeof(ts_vertex)); |
| | | for(i=0;i<vtx->neigh_no;i++){ |