It seems bondflip is fixed. Before 'for' loops I had to set j=0 in vertex.c and triangle.c in remove_neighbour
| | |
| | | // for(i=0;i<kp->neigh_no;i++) oldenergy+=kp->neigh[i]->xk*kp->neigh[i]->energy; |
| | | // for(i=0;i<km->neigh_no;i++) oldenergy+=km->neigh[i]->xk*km->neigh[i]->energy; |
| | | // for(i=0;i<it->neigh_no;i++) oldenergy+=it->neigh[i]->xk*it->neigh[i]->energy; |
| | | |
| | | /* |
| | | fprintf(stderr,"*** Naslov k=%ld\n",(long)k); |
| | | fprintf(stderr,"*** Naslov it=%ld\n",(long)it); |
| | | fprintf(stderr,"*** Naslov km=%ld\n",(long)km); |
| | |
| | | fprintf(stderr,"kp sosed=%ld\n",(long)kp->neigh[i]); |
| | | |
| | | |
| | | |
| | | fprintf(stderr,"I WAS HERE! Before bondflip!\n"); |
| | | */ |
| | | // fprintf(stderr,"I WAS HERE! Before bondflip!\n"); |
| | | ts_flip_bond(k,it,km,kp, bond); |
| | | fprintf(stderr,"I WAS HERE! Bondflip successful!\n"); |
| | | // fprintf(stderr,"I WAS HERE! Bondflip successful!\n"); |
| | | |
| | | /* Calculating the new energy */ |
| | | delta_energy=0; |
| | |
| | | */ |
| | | if(lm2==NULL || lp1==NULL) fatal("ts_flip_bond: Cannot find triangles lm2 and lp1!",999); |
| | | |
| | | |
| | | /* |
| | | //DEBUG TESTING |
| | | fprintf(stderr,"1. step: lm, lm2, lp1 and lp found!\n"); |
| | | fprintf(stderr,"--- Naslov lm=%ld",(long)lm); |
| | |
| | | for(i=0;i<lp->neigh_no;i++) |
| | | fprintf(stderr,"lp sosed=%ld\n",(long)lp->neigh[i]); |
| | | // END DEBUG TESTING |
| | | |
| | | */ |
| | | /* |
| | | // DEBUG TESTING! |
| | | |
| | |
| | | // 2. step. We change the triangle vertices... (actual bond flip) |
| | | for(i=0;i<3;i++) if(lm->vertex[i]== it) lm->vertex[i]= kp; |
| | | for(i=0;i<3;i++) if(lp->vertex[i]== k) lp->vertex[i]= km; |
| | | fprintf(stderr,"2. step: actual bondflip made\n"); |
| | | //fprintf(stderr,"2. step: actual bondflip made\n"); |
| | | // 2a. step. If any changes in triangle calculations must be done, do it here! |
| | | // * normals are recalculated here |
| | | triangle_normal_vector(lp); |
| | | triangle_normal_vector(lm); |
| | | fprintf(stderr,"2a. step: triangle normals recalculated\n"); |
| | | //fprintf(stderr,"2a. step: triangle normals recalculated\n"); |
| | | // 3. step. Correct neighbours in vertex_list |
| | | |
| | | |
| | | vtx_remove_neighbour(k,it); |
| | | // vtx_remove_neighbour(it,k); |
| | | fprintf(stderr,"3. step (PROGRESS): removed k and it neighbours\n"); |
| | | //fprintf(stderr,"3. step (PROGRESS): removed k and it neighbours\n"); |
| | | |
| | | //Tukaj pa nastopi tezava... Kam dodati soseda? |
| | | vtx_insert_neighbour(km,kp,k); |
| | | vtx_insert_neighbour(kp,km,it); |
| | | // vertex_add_neighbour(km,kp); //pazi na vrstni red. |
| | | // vertex_add_neighbour(kp,km); |
| | | fprintf(stderr,"3. step: vertex neighbours corrected\n"); |
| | | //fprintf(stderr,"3. step: vertex neighbours corrected\n"); |
| | | |
| | | // 3a. step. If any changes to ts_vertex, do it here! |
| | | // bond_length calculatons not required for it is done in energy.c |
| | |
| | | retval=vtx_add_cneighbour(blist,vlist->vtx[1],vlist->vtx[0]); |
| | | if(retval==TS_FAIL) printf("1. already a member or vertex is null!\n"); |
| | | |
| | | retval=vtx_add_cneighbour(blist,vlist->vtx[0],vlist->vtx[1]); |
| | | retval=vtx_add_neighbour(vlist->vtx[0],vlist->vtx[1]); |
| | | if(retval==TS_FAIL) printf("2. already a member or vertex is null!\n"); |
| | | fprintf(stderr,"Was here"); |
| | | retval=vtx_remove_neighbour(vlist->vtx[0],vlist->vtx[1]); |
| | | retval=vtx_remove_neighbour(vlist->vtx[1],vlist->vtx[0]); |
| | | vtx_add_neighbour(vlist->vtx[0],vlist->vtx[1]); |
| | | fprintf(stderr,"Was here too!\n"); |
| | | |
| | |
| | | //fatal("In triangle_remove_neighbour: Specified neighbour does not exist for given triangle",3); |
| | | } |
| | | tria->neigh_no--; |
| | | // fprintf(stderr,"*** tria_number=%d\n",tria->neigh_no); |
| | | tria->neigh=(ts_triangle **)realloc(tria->neigh,tria->neigh_no*sizeof(ts_triangle *)); |
| | | if(tria->neigh == NULL){ |
| | | fatal("Reallocation of memory failed during removal of vertex neighbour in triangle_remove_neighbour",100); |
| | | } |
| | | /* we repeat the procedure for neighbour */ |
| | | j=0; |
| | | for(i=0;i<ntria->neigh_no;i++){ |
| | | if(ntria->neigh[i]!=tria){ |
| | | ntria->neigh[j]=ntria->neigh[i]; |
| | |
| | | //fatal("In triangle_remove_neighbour: Specified neighbour does not exist for given triangle",3); |
| | | } |
| | | ntria->neigh_no--; |
| | | // fprintf(stderr,"*** ntria_number=%d\n",ntria->neigh_no); |
| | | ntria->neigh=(ts_triangle **)realloc(ntria->neigh,ntria->neigh_no*sizeof(ts_triangle *)); |
| | | if(ntria->neigh == NULL){ |
| | | fatal("Reallocation of memory failed during removal of vertex neighbour in triangle_remove_neighbour",100); |
| | |
| | | ts_bool vtx_remove_neighbour(ts_vertex *vtx, ts_vertex *nvtx){ |
| | | /* find a neighbour */ |
| | | /* remove it from the list while shifting remaining neighbours up */ |
| | | ts_int i,j=-1; |
| | | ts_uint i,j=0; |
| | | for(i=0;i<vtx->neigh_no;i++){ |
| | | // fprintf(stderr,"neigh_addr=%ld\n", (long)vtx->neigh[i]); |
| | | if(vtx->neigh[i]!=nvtx){ |
| | | vtx->neigh[j]=vtx->neigh[i]; |
| | | j++; |
| | | } |
| | | } |
| | | if(j==0) { |
| | | fatal("vtx_remove_neighbour: Error, vertices are not neighbours", 100); |
| | | } |
| | | // fprintf(stderr,"remove_neighbour: vtx1_addr=%ld, vtx2_addr=%ld\n",(long)vtx,(long)nvtx); |
| | | /* resize memory. potentionally time consuming */ |
| | | vtx->neigh_no--; |
| | | vtx->neigh=(ts_vertex **)realloc(vtx->neigh,vtx->neigh_no*sizeof(ts_vertex *)); |
| | | if(vtx->neigh == NULL && vtx->neigh_no!=0) |
| | | fatal("Reallocation of memory failed during removal of vertex neighbour in vtx_remove_neighbour",100); |
| | | fprintf(stderr,"first alloc"); |
| | | fatal("(1) Reallocation of memory failed during removal of vertex neighbour in vtx_remove_neighbour",100); |
| | | //fprintf(stderr,"first alloc"); |
| | | /* repeat for the neighbour */ |
| | | /* find a neighbour */ |
| | | /* remove it from the list while shifting remaining neighbours up */ |
| | | j=0; |
| | | for(i=0;i<nvtx->neigh_no;i++){ |
| | | if(nvtx->neigh[i]!=vtx){ |
| | | nvtx->neigh[j]=nvtx->neigh[i]; |
| | |
| | | } |
| | | } |
| | | /* resize memory. potentionally time consuming. */ |
| | | // fprintf(stderr,"Neigbours=%d\n",nvtx->neigh_no); |
| | | nvtx->neigh_no--; |
| | | nvtx->neigh=(ts_vertex **)realloc(nvtx->neigh,nvtx->neigh_no*sizeof(ts_vertex *)); |
| | | // fprintf(stderr,"Neigbours=%d\n",nvtx->neigh_no); |
| | | if(nvtx->neigh == NULL && nvtx->neigh_no!=0) |
| | | fatal("Reallocation of memory failed during removal of vertex neighbour in vtx_remove_neighbour",100); |
| | | fatal("(2) Reallocation of memory failed during removal of vertex neighbour in vtx_remove_neighbour",100); |
| | | |
| | | return TS_SUCCESS; |
| | | } |
| | |
| | | ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex *vtx1, ts_vertex *vtx2){ |
| | | ts_bool retval; |
| | | retval=vtx_add_neighbour(vtx1,vtx2); |
| | | // retval=vtx_add_neighbour(vtx2,vtx1); |
| | | if(retval==TS_SUCCESS) |
| | | retval=vtx_add_bond(blist,vtx1,vtx2); |
| | | return retval; |