Trisurf Monte Carlo simulator
Samo Penic
2013-11-30 2f8ee74e6933b979b964260f9f0d62d5339290e6
step in rewritting
4 files modified
50 ■■■■■ changed files
src/cell.c 2 ●●● patch | view | raw | blame | history
src/initial_distribution.c 36 ●●●● patch | view | raw | blame | history
src/vertex.c 9 ●●●● patch | view | raw | blame | history
src/vertex.h 3 ●●●● patch | view | raw | blame | history
src/cell.c
@@ -105,7 +105,7 @@
/* resize memory. potentionally time consuming */
    cell->nvertex--;
    cell->vertex=(ts_vertex **)realloc(cell->vertex,cell->nvertex*sizeof(ts_vertex *));
    if(vtx->neigh == NULL && vtx->neigh_no!=0)
    if(vtx->neigh == NULL && vtx->neigh->n!=0)
        if(cell->vertex == NULL){
            fatal("Reallocation of memory failed during removal of vertex in cell_remove_vertex",3);
        }
src/initial_distribution.c
@@ -172,16 +172,16 @@
    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_cneighbour(blist,tvtx[k], tvtx[vtx[i]->neigh[0]->idx+1]); //always add 1st
           vtx_add_cneighbour(blist,tvtx[k], tvtx[vtx[i]->neigh->vtx[0]->idx+1]); //always add 1st
           jjj=1;
           jj=1;
           for(l=2;l<=vtx[i]->neigh_no;l++){
               for(j=2;j<=vtx[i]->neigh_no;j++){
                   dist2=vtx_distance_sq(vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]);
                   direct=vtx_direct(vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]);
           for(l=2;l<=vtx[i]->neigh->n;l++){
               for(j=2;j<=vtx[i]->neigh->n;j++){
                   dist2=vtx_distance_sq(vtx[i]->neigh->vtx[j-1],vtx[i]->neigh->vtx[jj-1]);
                   direct=vtx_direct(vtx[i],vtx[i]->neigh->vtx[j-1],vtx[i]->neigh->vtx[jj-1]);
// TODO: check if fabs can be used with all floating point types!!
                   if( (fabs(dist2-A0*A0)<=eps) && (direct>0.0) && (j!=jjj) ){
                       vtx_add_cneighbour(blist,tvtx[k],tvtx[vtx[i]->neigh[j-1]->idx+1]);
                       vtx_add_cneighbour(blist,tvtx[k],tvtx[vtx[i]->neigh->vtx[j-1]->idx+1]);
                       jjj=jj;
                       jj=j;
                       break;
@@ -213,8 +213,8 @@
    ts_uint i,j,k;
    for(i=1;i<=vlist->n;i++){
        for(j=i+1;j<=vlist->n;j++){
            for(k=0;k<vtx[i]->neigh_no;k++){ // has changed 0 to < instead of 1 and <=
                if(vtx[i]->neigh[k]==vtx[j]){  //if addresses matches it is the same
            for(k=0;k<vtx[i]->neigh->n;k++){ // has changed 0 to < instead of 1 and <=
                if(vtx[i]->neigh->vtx[k]==vtx[j]){  //if addresses matches it is the same
                    bond_add(blist,vtx[i],vtx[j]);
                    break;
                }
@@ -239,15 +239,15 @@
    ts_double eps=0.001; // can we use EPS from math.h?
    k=0;
    for(i=1;i<=vesicle->vlist->n;i++){
        for(j=1;j<=vtx[i]->neigh_no;j++){
            for(jj=1;jj<=vtx[i]->neigh_no;jj++){
        for(j=1;j<=vtx[i]->neigh->n;j++){
            for(jj=1;jj<=vtx[i]->neigh->n;jj++){
        //        ts_fprintf(stderr,"%u: (%u,%u) neigh_no=%u ",i,j,jj,vtx[i].neigh_no);
        //      ts_fprintf(stderr,"%e, %e",vtx[i].neigh[j-1]->x,vtx[i].neigh[jj-1]->x);
                dist=vtx_distance_sq(vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]);
                direct=vtx_direct(vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]);
                dist=vtx_distance_sq(vtx[i]->neigh->vtx[j-1],vtx[i]->neigh->vtx[jj-1]);
                direct=vtx_direct(vtx[i],vtx[i]->neigh->vtx[j-1],vtx[i]->neigh->vtx[jj-1]);
// TODO: same as above                
                if(fabs(dist-A0*A0)<=eps && direct < 0.0 && vtx[i]->neigh[j-1]->idx+1 > i && vtx[i]->neigh[jj-1]->idx+1 >i){
                    triangle_add(tlist,vtx[i],vtx[i]->neigh[j-1],vtx[i]->neigh[jj-1]);
                if(fabs(dist-A0*A0)<=eps && direct < 0.0 && vtx[i]->neigh->vtx[j-1]->idx+1 > i && vtx[i]->neigh->vtx[jj-1]->idx+1 >i){
                    triangle_add(tlist,vtx[i],vtx[i]->neigh->vtx[j-1],vtx[i]->neigh->vtx[jj-1]);
                }    
            }    
        }
@@ -342,11 +342,11 @@
    ts_triangle **tria=tlist->tria -1;
    for(i=1;i<=vesicle->vlist->n;i++){
        for(j=1;j<=vtx[i]->neigh_no;j++){
            k1=vtx[i]->neigh[j-1];
        for(j=1;j<=vtx[i]->neigh->n;j++){
            k1=vtx[i]->neigh->vtx[j-1];
            jp=j+1;
            if(j == vtx[i]->neigh_no) jp=1;
            k2=vtx[i]->neigh[jp-1];
            if(j == vtx[i]->neigh->n) jp=1;
            k2=vtx[i]->neigh->vtx[jp-1];
            for(k=1;k<=tlist->n;k++){        // VERY NON-OPTIMAL!!! too many loops (vlist.n * vtx.neigh * tlist.n )!
                k3=tria[k]->vertex[0];
                k4=tria[k]->vertex[1];
src/vertex.c
@@ -91,7 +91,14 @@
    return TS_SUCCESS;
}
ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex_list *vlist, ts_vertex *vtx1, ts_vertex *vtx2){
ts_bool vtx_add_neighbour(ts_vertex *vtx1, ts_vertex *vtx2){
        vertex_list_add_vtx(vtx1->neigh, vtx2);
        vertex_list_add_vtx(vtx2->neigh, vtx1);
    return TS_SUCCESS;
}
ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex *vtx1, ts_vertex *vtx2){
    ts_bool retval;
    retval=vertex_list_add_vtx(vtx1->neigh, vtx2);
    retval=vertex_list_add_vtx(vtx2->neigh, vtx1);
src/vertex.h
@@ -16,7 +16,8 @@
ts_vertex_list *init_vertex_list(ts_uint N);
ts_bool vertex_list_add_vtx(ts_vertex_list *vlist, ts_vertex *vtx);
ts_bool vertex_list_remove_vtx(ts_vertex_list *vlist, ts_vertex *vtx);
ts_bool vtx_add_cneighbour(ts_bond_list *blist,ts_vertex_list *vlist, ts_vertex *vtx1,ts_vertex *vtx2);
ts_bool vtx_add_neighbour(ts_vertex *vtx1, ts_vertex *vtx2);
ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex *vtx1,ts_vertex *vtx2);
ts_bool vtx_add_bond(ts_bond_list *blist,ts_vertex *vtx1,ts_vertex *vtx2);
ts_bool vtx_free(ts_vertex *vtx);