src/bond.c | ●●●●● patch | view | raw | blame | history | |
src/cell.c | ●●●●● patch | view | raw | blame | history | |
src/energy.c | ●●●●● patch | view | raw | blame | history | |
src/initial_distribution.c | ●●●●● patch | view | raw | blame | history | |
src/initial_distribution.h | ●●●●● patch | view | raw | blame | history | |
src/main.c | ●●●●● patch | view | raw | blame | history | |
src/vertex.c | ●●●●● patch | view | raw | blame | history | |
src/vertex.h | ●●●●● patch | view | raw | blame | history |
src/bond.c
@@ -10,10 +10,15 @@ } ts_bond *bond_add(ts_bond_list *blist, ts_vertex *vtx1, ts_vertex *vtx2){ ts_uint i; /* no vertices must be null! */ if(vtx1==NULL || vtx2==NULL) return NULL; /* TODO: Verify if the bond already exists... Don't do multiple bonds */ /* Verify if the bond already exists... Don't do multiple bonds */ for(i=0;i<blist->n;i++){ if((blist->bond[i]->data->vtx1==vtx1 || blist->bond[i]->data->vtx1==vtx2) &&(blist->bond[i]->data->vtx2==vtx1 || blist->bond[i]->data->vtx2==vtx2)) return blist->bond[i]; } blist->n++; blist->bond=(ts_bond **)realloc(blist->bond,blist->n*sizeof(ts_bond *)); if(blist->bond==NULL) fatal("Cannot reallocate memory for additional **ts_bond.",100); src/cell.c
@@ -77,7 +77,7 @@ cell->data->nvertex++; cell->data->vertex=(ts_vertex **)realloc(cell->data->vertex,cell->data->nvertex*sizeof(ts_vertex *)); if(vtx->data->neigh == NULL){ fatal("Reallocation of memory failed during insertion of vertex neighbour in vertex_add_neighbour",3); fatal("Reallocation of memory failed during insertion of vertex in cell_add_vertex",3); } cell->data->vertex[cell->data->nvertex-1]=vtx; return TS_SUCCESS; src/energy.c
@@ -13,6 +13,7 @@ for(i=0;i<vlist->n;i++){ energy_vertex(vtx[i]); } return TS_SUCCESS; @@ -38,6 +39,7 @@ j=data->neigh[jj-1]; jp=data->neigh[jjp-1]; jm=data->neigh[jjm-1]; // printf("tristar_no=%u, neigh_no=%u, jj=%u\n",data->tristar_no,data->neigh_no,jj); jt=data->tristar[jj-1]; x1=vtx_distance_sq(vtx,jp); //shouldn't be zero! x2=vtx_distance_sq(j,jp); // shouldn't be zero! src/initial_distribution.c
@@ -20,8 +20,8 @@ retval = vtx_set_global_values(vesicle); retval = pentagonal_dipyramid_vertex_distribution(vesicle->vlist); retval = init_vertex_neighbours(vesicle->vlist); retval = init_sort_neighbours(vesicle->vlist); retval = init_vesicle_bonds(vesicle); vesicle->vlist = init_sort_neighbours(vesicle->blist,vesicle->vlist); // retval = init_vesicle_bonds(vesicle); // bonds are created in sort_neigh retval = init_triangles(vesicle); retval = init_triangle_neighbours(vesicle); retval = init_common_vertex_triangle_neighbours(vesicle); @@ -150,21 +150,21 @@ return TS_SUCCESS; } // TODO: with new datastructure can be rewritten. ts_bool init_sort_neighbours(ts_vertex_list *vlist){ // TODO: with new datastructure can be rewritten. Partially it is done, but it is complicated. ts_vertex_list *init_sort_neighbours(ts_bond_list *blist,ts_vertex_list *vlist){ ts_vertex **vtx=vlist->vtx -1; // take a look at dipyramid function for comment. ts_uint i,l,j,jj,jjj,k=0; ts_double eps=0.001; // Take a look if EPS from math.h can be used /*lets initialize memory for temporary vertex_list. Should we write a function instead */ ts_vertex_list *tvlist=init_vertex_list(vlist->n); ts_vertex_list *tvlist=vertex_list_copy(vlist); ts_vertex **tvtx=tvlist->vtx -1; /* again to compensate for 0-indexing */ ts_double dist2; // Square of distance of neighbours ts_double direct; // Something, dont know what, but could be normal of some kind for(i=1;i<=vlist->n;i++){ k++; // WHY i IS NOT GOOD?? vtx_add_neighbour(tvtx[k], tvtx[vtx[i]->data->neigh[0]->idx+1]); //always add 1st vtx_add_cneighbour(blist,tvtx[k], tvtx[vtx[i]->data->neigh[0]->idx+1]); //always add 1st jjj=1; jj=1; for(l=2;l<=vtx[i]->data->neigh_no;l++){ @@ -172,7 +172,7 @@ dist2=vtx_distance_sq(vtx[i]->data->neigh[j-1],vtx[i]->data->neigh[jj-1]); direct=vtx_direct(vtx[i],vtx[i]->data->neigh[j-1],vtx[i]->data->neigh[jj-1]); if( (fabs(dist2-A0*A0)<=eps) && (direct>0.0) && (j!=jjj) ){ vtx_add_neighbour(tvtx[k],tvtx[vtx[i]->data->neigh[j-1]->idx+1]); vtx_add_cneighbour(blist,tvtx[k],tvtx[vtx[i]->data->neigh[j-1]->idx+1]); jjj=jj; jj=j; break; @@ -180,24 +180,19 @@ } } } for(i=1;i<=vlist->n;i++){ for(j=1;j<=vtx[i]->data->neigh_no;j++){ if(vtx[i]->data->neigh_no!=tvtx[i]->data->neigh_no){ //doesn't work with nshell=1! // fprintf(stderr,"data1=%u data2=%u\n",vtx[i]->data->neigh_no,tvtx[i]->data->neigh_no); fatal("Number of neighbours not the same in init_sort_neighbours.",4); } //we must correct the pointers in original to point to their //neighbours according to indexes. Must be sure not to do it any //other way! Also, we need to repair the collection of bonds... vtx[i]->data->neigh[j-1]=vtx[tvtx[i]->data->neigh[j-1]->idx+1]; } /* We use the temporary vertex for our main vertices and we abandon main * vertices, because their neighbours are not correctly ordered */ // tvtx=vlist->vtx; // vlist->vtx=tvtx; // tvlist->vtx=vtx; vtx_list_free(vlist); /* Let's make a check if the number of bonds is correct */ if((blist->n)!=3*(tvlist->n-2)){ ts_fprintf(stderr,"Number of bonds is %u should be %u!\n", blist->n, 3*(tvlist->n-2)); fatal("Number of bonds is not 3*(no_vertex-2).",4); } // Must free memory for temporary vertex array to avoid memory leak! HERE! NOW! // free_vertex(tvlist.vertex,tvlist.n); vtx_list_free(tvlist); return TS_SUCCESS; return tvlist; } @@ -350,7 +345,10 @@ if((vtx[i]==k3 && k1==k4 && k2==k5) || (vtx[i]==k4 && k1==k5 && k2==k3) || (vtx[i]==k5 && k1==k3 && k2==k4)){ // ts_fprintf(stderr, "Added to tristar! "); //TODO: probably something wrong with neighbour distribution. // if(vtx[i]==k3 || vtx[i]==k4 || vtx[i]==k5){ if(i==6) ts_fprintf(stdout, "Vtx[%u] > Added to tristar!\n",i); vertex_add_tristar(vtx[i],tria[k]); } } src/initial_distribution.h
@@ -27,7 +27,7 @@ //ts_bool init_vertex_neighbours(ts_vertex_list *vlist); /** interior sites and their neighbours in circ. order + the triangles they are holding together */ ts_bool init_sort_neighbours(ts_vertex_list *vlist); ts_vertex_list *init_sort_neighbours(ts_bond_list *blist,ts_vertex_list *vlist); ts_bool init_vesicle_bonds(ts_vesicle *vesicle); ts_bool init_triangles(ts_vesicle *vesicle); ts_bool init_triangle_neighbours(ts_vesicle *vesicle); src/main.c
@@ -18,6 +18,7 @@ int main(int argv, char *argc[]){ ts_bool retval; ts_vertex_list *vlist=init_vertex_list(5); ts_vertex_list *vlist1; ts_bond_list *blist=init_bond_list(); ts_triangle_list *tlist=init_triangle_list(); ts_cell_list *clist=init_cell_list(3,3,3,0.3); @@ -34,7 +35,7 @@ vlist->vtx[0]->data->x=1.0; vlist->vtx[0]->data->x=1.1; vlist1=vertex_list_copy(vlist); bond_add(blist, vlist->vtx[1],vlist->vtx[0]); triangle_add(tlist,vlist->vtx[1],vlist->vtx[2],vlist->vtx[3]); @@ -53,8 +54,9 @@ bond_list_free(blist); vtx_list_free(vlist); cell_list_free(clist); printf("Tests complete.\n"); vtx_list_free(vlist1); printf("Tests complete.\n"); vesicle=initial_distribution_dipyramid(7,10,10,10,0.3); write_vertex_xml_file(vesicle,0); write_master_xml_file("test.pvd"); src/vertex.c
@@ -156,7 +156,7 @@ ts_bool vtx_list_free(ts_vertex_list *vlist){ int i; for(i=0;i<vlist->n;i++){ vtx_data_free(vlist->vtx[i]->data); if(vlist->vtx[i]->data!=NULL) vtx_data_free(vlist->vtx[i]->data); } free(*(vlist->vtx)); free(vlist->vtx); @@ -219,8 +219,7 @@ /* ***** New vertex copy operations. Inherently they are slow. ***** */ /* ****************************************************************** */ ts_vertex *vtx_copy(ts_vertex *ovtx){ ts_vertex *cvtx=(ts_vertex *)malloc(sizeof(ts_vertex)); ts_bool vtx_copy(ts_vertex *cvtx, ts_vertex *ovtx){ memcpy((void *)cvtx,(void *)ovtx,sizeof(ts_vertex)); cvtx->data=(ts_vertex_data *)malloc(sizeof(ts_vertex_data)); memcpy((void *)cvtx->data,(void *)ovtx->data,sizeof(ts_vertex_data)); @@ -231,7 +230,7 @@ cvtx->data->tristar=NULL; cvtx->data->bond=NULL; cvtx->data->cell=NULL; return cvtx; return TS_SUCCESS; } //TODO: needs to be done ts_vertex **vtx_neigh_copy(ts_vertex_list *vlist,ts_vertex *ovtx){ @@ -241,10 +240,17 @@ ts_vertex_list *vertex_list_copy(ts_vertex_list *ovlist){ ts_uint i; ts_vertex_list *vlist=(ts_vertex_list *)malloc(sizeof(ts_vertex_list)); memcpy((void *)vlist, (void *)ovlist, sizeof(ts_vertex_list)); vlist=memcpy((void *)vlist, (void *)ovlist, sizeof(ts_vertex_list)); ts_vertex **vtx=(ts_vertex **)malloc(vlist->n*sizeof(ts_vertex *)); ts_vertex *tlist=(ts_vertex *)calloc(vlist->n,sizeof(ts_vertex)); vlist->vtx=vtx; if(vlist->vtx==NULL || tlist==NULL) fatal("Fatal error reserving memory space for vertex list! Could number of requsted vertices be too large?", 100); for(i=0;i<vlist->n;i++){ vtx[i]=vtx_copy(ovlist->vtx[i]); vlist->vtx[i]=&tlist[i]; vlist->vtx[i]->idx=i; vtx_copy(vlist->vtx[i],ovlist->vtx[i]); } return vlist; } src/vertex.h
@@ -27,7 +27,7 @@ inline ts_double vtx_direct(ts_vertex *vtx1, ts_vertex *vtx2, ts_vertex *vtx3); inline ts_bool vertex_add_tristar(ts_vertex *vtx, ts_triangle *tristarmem); ts_vertex *vtx_copy(ts_vertex *ovtx); ts_bool vtx_copy(ts_vertex *cvtx,ts_vertex *ovtx); ts_vertex **vtx_neigh_copy(ts_vertex_list *vlist,ts_vertex *ovtx); ts_vertex_list *vertex_list_copy(ts_vertex_list *ovlist);