Trisurf Monte Carlo simulator
Samo Penic
2016-07-05 8c91d2bcad7df7c647f1379483673183329ddfe8
Fixed some bugs in cluster.c, added a line in cluster.h
3 files modified
29 ■■■■ changed files
src/cluster.c 23 ●●●●● patch | view | raw | blame | history
src/cluster.h 1 ●●●● patch | view | raw | blame | history
src/tspoststat.c 5 ●●●●● patch | view | raw | blame | history
src/cluster.c
@@ -39,12 +39,14 @@
    
    for(i=0;i<cstlist->n;i++){
        if(cstlist->cluster[i]==NULL){
            if(i>=n) break;
            //printf("Have to do compacting n=%d\n ",n);
            do{
                n--;
            } while(cstlist->cluster[n]==NULL && n>i);
            if(i<=n) break;
            cstlist->cluster[i]=cstlist->cluster[n];
            cstlist->cluster[n]=NULL;
            //printf("After compacting n=%d\n",n);
        }
    }
    cstlist->cluster=(ts_cluster **)realloc(cstlist->cluster,n*sizeof(ts_cluster *));
@@ -53,7 +55,7 @@
}
ts_bool cluster_join(ts_cluster *cluster1, ts_cluster *cluster2){
ts_bool cluster_join(ts_cluster_list *cstlist, ts_cluster *cluster1, ts_cluster *cluster2){
    ts_cluster *master_cluster,*slave_cluster;
    ts_uint i;
    if(cluster1->idx<cluster2->idx){
@@ -66,8 +68,13 @@
    for(i=0;i<slave_cluster->nvtx;i++){
        cluster_add_vertex(master_cluster,slave_cluster->vtx[i]);
    }
    cluster_free(slave_cluster);
    slave_cluster=NULL;
    //find cluster in the list and free the location of the cluster
    for(i=0;i<cstlist->n;i++){
        if(cstlist->cluster[i]==slave_cluster){
            cluster_free(slave_cluster);
            cstlist->cluster[i]=NULL;
        }
    }
    return TS_SUCCESS;
}
@@ -113,13 +120,13 @@
    return NULL;
}
ts_bool cluster_vertex_neighbor_check(ts_vertex *vtx){
ts_bool cluster_vertex_neighbor_check(ts_cluster_list *cstlist, ts_vertex *vtx){
    int j;
    for(j=0;j<vtx->neigh_no;j++){
        if(vtx->neigh[j]->cluster!=NULL){
            if(vtx->neigh[j]->cluster!=vtx->cluster){
                cluster_join(vtx->cluster, vtx->neigh[j]->cluster);
                cluster_join(cstlist, vtx->cluster, vtx->neigh[j]->cluster);
            }
        }
    }
@@ -136,7 +143,7 @@
    //for each vertex
        vtx=vesicle->vlist->vtx[i];
        if(is_clusterable(vtx)){
            if(vtx->cluster!=NULL){
            if(vtx->cluster==NULL){
                //find first neigbor with cluster index
                cst=cluster_vertex_neighbor(vtx);
                if(cst==NULL){
@@ -146,7 +153,7 @@
                } else {
                    //we are added to the first cluster found
                    cluster_add_vertex(cst,vtx);
                    cluster_vertex_neighbor_check(vtx);
                    cluster_vertex_neighbor_check(cstlist, vtx);
                    cluster_list_compact(cstlist);
                }
src/cluster.h
@@ -5,4 +5,5 @@
ts_bool cluster_add_vertex(ts_cluster *cluster, ts_vertex *vtx);
ts_bool cluster_free(ts_cluster *cluster);
ts_bool cluster_list_free(ts_cluster_list *cstlist);
ts_bool clusterize_vesicle(ts_vesicle *vesicle, ts_cluster_list *cstlist);
#endif
src/tspoststat.c
@@ -18,6 +18,7 @@
#include "shcomplex.h"
#include "dumpstate.h"
#include "restore.h"
#include "cluster.h"
#include <string.h>
#include <getopt.h>
#include <sys/stat.h>
@@ -103,6 +104,10 @@
            fprintf(stdout,"%d %.17e %.17e %.17e %.17e %.17e %.17e\n",atoi(number),vesicle->volume, vesicle->area,l1,l2,l3, (ts_double)count_bonds_with_energy(vesicle->blist)/(ts_double)vesicle->blist->n),
                        tstep++;
            ts_cluster_list *cstlist=init_cluster_list();
            clusterize_vesicle(vesicle,cstlist);
            printf("No clusters=%d\n",cstlist->n);
            cluster_list_free(cstlist);
                    free(number);
            tape_free(vesicle->tape);
            vesicle_free(vesicle);