From e19e790e95f14ca69a7ce9c5e45d815fe21df36e Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Tue, 10 Jul 2012 12:33:43 +0000 Subject: [PATCH] It seems bondflip is fixed. Before 'for' loops I had to set j=0 in vertex.c and triangle.c in remove_neighbour --- src/main.c | 4 ++-- src/vertex.c | 19 +++++++++++-------- src/bondflip.c | 22 +++++++++++----------- src/triangle.c | 3 +++ 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/bondflip.c b/src/bondflip.c index 02d3186..478027d 100644 --- a/src/bondflip.c +++ b/src/bondflip.c @@ -83,7 +83,7 @@ // 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); @@ -100,10 +100,10 @@ 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; @@ -233,7 +233,7 @@ */ 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); @@ -252,7 +252,7 @@ for(i=0;i<lp->neigh_no;i++) fprintf(stderr,"lp sosed=%ld\n",(long)lp->neigh[i]); // END DEBUG TESTING - +*/ /* // DEBUG TESTING! @@ -270,25 +270,25 @@ // 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 @@ -302,7 +302,7 @@ // 5. step. Correct neighbouring triangles triangle_remove_neighbour(lp,lp1); - // fprintf(stderr,".\n"); + // fprintf(stderr,".\n"); triangle_remove_neighbour(lp1,lp); // fprintf(stderr,".\n"); triangle_remove_neighbour(lm,lm2); diff --git a/src/main.c b/src/main.c index 758bbfa..ca9ed07 100644 --- a/src/main.c +++ b/src/main.c @@ -30,10 +30,10 @@ 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"); diff --git a/src/triangle.c b/src/triangle.c index e051316..dc53487 100644 --- a/src/triangle.c +++ b/src/triangle.c @@ -147,11 +147,13 @@ //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]; @@ -163,6 +165,7 @@ //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); diff --git a/src/vertex.c b/src/vertex.c index 694ee84..38647aa 100644 --- a/src/vertex.c +++ b/src/vertex.c @@ -72,25 +72,25 @@ 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]; @@ -98,10 +98,12 @@ } } /* 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 *)); + 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; } @@ -128,6 +130,7 @@ 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; -- Gitblit v1.9.3