From 616b1439ada18319248b0754247fd3a814d93af6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 10 Apr 2012 18:23:53 -0400 Subject: [PATCH 1/7] New tool (unfinished) to compare two void trees From 324322271464392d894506ca8d97aa1086c1867b Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 10 Apr 2012 18:24:03 -0400 Subject: [PATCH 2/7] Added missing cmake commands From f9bc27e88d4437e4b550adcb8c6ba955a3adba5b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Apr 2012 10:39:31 -0400 Subject: [PATCH 3/7] Made a copy of present jozov to jozov_persistent --- jozov_persistent.c | 550 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 550 insertions(+) create mode 100644 jozov_persistent.c diff --git a/jozov_persistent.c b/jozov_persistent.c new file mode 100644 index 0000000..f5fb4e7 --- /dev/null +++ b/jozov_persistent.c @@ -0,0 +1,550 @@ +#include +/* jovoz.c by Mark Neyrinck */ +#include +#include +#include + +#define BIGFLT 1e30 /* Biggest possible floating-point number */ +#define NLINKS 100 /* Number of possible links with the same rho_sl */ +#define FF fflush(stdout) + +typedef struct Particle { + float dens; + int nadj; + int ncnt; + int *adj; +} PARTICLE; + +typedef struct Zone { + int core; /* Identity of peak particle */ + int np; /* Number of particles in zone */ + int npjoin; /* Number of particles in the joined void */ + int nadj; /* Number of adjacent zones */ + int nhl; /* Number of zones in final joined void */ + float leak; /* Volume of last leak zone*/ + int *adj; /* Each adjacent zone, with ... */ + float *slv; /* Smallest Linking Volume */ + float denscontrast; /* density contrast */ + double vol; /* Total volume of all particles in the zone */ + double voljoin; /* Total volume of all particles in the joined void */ +} ZONE; + +typedef struct ZoneT { + int nadj; /* Number of zones on border */ + int *adj; /* Each adjacent zone, with ... */ + float *slv; /* Smallest Linking Volume */ +} ZONET; + +void findrtop(double *a, int na, int *iord, int nb); + +int main(int argc,char **argv) { + + FILE *adj, *vol, *zon, *zon2, *txt; + PARTICLE *p; + ZONE *z; + ZONET *zt; + char *adjfile, *volfile, *zonfile, *zonfile2, *txtfile; + int i, j,k,l, h, h2,hl,n,np, np2, nzones, nhl, nhlcount, nhl2; + int *jumper, *jumped, *numinh; + int *zonenum, *zonelist, *zonelist2; + int link[NLINKS], link2, nl; + float lowvol, voltol, prob; + + int q,q2; + + int za, nin; + int testpart; + char already, interior, *inyet, *inyet2, added, beaten; + int *nm, **m; + + float maxvol, minvol; + double *sorter, e1,maxdenscontrast; + int *iord; + + e1 = exp(1.)-1.; + + if (argc != 7) { + printf("Wrong number of arguments.\n"); + printf("arg1: adjacency file\n"); + printf("arg2: volume file\n"); + printf("arg3: output file containing particles in each zone\n"); + printf("arg4: output file containing zones in each void\n"); + printf("arg5: output text file\n"); + printf("arg6: Density threshold (0 for no threshold)\n\n"); + exit(0); + } + adjfile = argv[1]; + volfile = argv[2]; + zonfile = argv[3]; + zonfile2 = argv[4]; + txtfile = argv[5]; + if (sscanf(argv[6],"%f",&voltol) == 0) { + printf("Bad density threshold.\n"); + exit(0); + } + if (voltol <= 0.) { + printf("Proceeding without a density threshold.\n"); + voltol = 1e30; + } + + adj = fopen(adjfile, "r"); + if (adj == NULL) { + printf("Unable to open %s\n",adjfile); + exit(0); + } + fread(&np,1, sizeof(int),adj); + + printf("adj: %d particles\n", np); + FF; + + p = (PARTICLE *)malloc(np*sizeof(PARTICLE)); + /* Adjacencies*/ + for (i=0;i 0) + p[i].adj = (int *)malloc(p[i].nadj*sizeof(int)); + else p[i].adj = 0; + p[i].ncnt = 0; /* Temporarily, it's an adj counter */ + } + for (i=0;i 0) + for (k=0;k 1e30)) { + printf("Whacked-out volume found, of particle %d: %f\n",i,p[i].dens); + p[i].dens = 1.; + } + p[i].dens = 1./p[i].dens; /* Get density from volume */ + } + fclose(vol); + + jumped = (int *)malloc(np*sizeof(int)); + jumper = (int *)malloc(np*sizeof(int)); + numinh = (int *)malloc(np*sizeof(int)); + + /* find jumper */ + for (i = 0; i < np; i++) { + minvol = p[i].dens; jumper[i] = -1; + for (j=0; j< p[i].nadj; j++) { + if (p[p[i].adj[j]].dens < minvol) { + jumper[i] = p[i].adj[j]; + minvol = p[jumper[i]].dens; + } + } + numinh[i] = 0; + } + + printf("About to jump ...\n"); FF; + + /* Jump */ + for (i = 0; i < np; i++) { + jumped[i] = i; + while (jumper[jumped[i]] > -1) + jumped[i] = jumper[jumped[i]]; + numinh[jumped[i]]++; + } + printf("Post-jump ...\n"); FF; + + nzones = 0; + for (i = 0; i < np; i++) + if (numinh[i] > 0) nzones++; + printf("%d initial zones found\n", nzones); + + z = (ZONE *)malloc(nzones*sizeof(ZONE)); + if (z == NULL) { + printf("Unable to allocate z\n"); + exit(0); + } + zt = (ZONET *)malloc(nzones*sizeof(ZONET)); + if (zt == NULL) { + printf("Unable to allocate zt\n"); + exit(0); + } + zonenum = (int *)malloc(np*sizeof(int)); + if (zonenum == NULL) { + printf("Unable to allocate zonenum\n"); + exit(0); + } + + h = 0; + for (i = 0; i < np; i++) + if (numinh[i] > 0) { + z[h].core = i; + zonenum[i] = h; + h++; + } else { + zonenum[i] = -1; + } + + /* Count border particles */ + for (i = 0; i < np; i++) + for (j = 0; j < p[i].nadj; j++) { + testpart = p[i].adj[j]; + if (jumped[i] != jumped[testpart]) + zt[zonenum[jumped[i]]].nadj++; + } + + for (h=0;h p[i].dens) { + /* there could be a weakest link through testpart */ + already = 0; + for (za = 0; za < zt[h].nadj; za++) + if (zt[h].adj[za] == zonenum[jumped[testpart]]) { + already = 1; + if (p[testpart].dens < zt[h].slv[za]) { + zt[h].slv[za] = p[testpart].dens; + } + } + if (already == 0) { + zt[h].adj[zt[h].nadj] = zonenum[jumped[testpart]]; + zt[h].slv[zt[h].nadj] = p[testpart].dens; + zt[h].nadj++; + } + } else { /* There could be a weakest link through i */ + already = 0; + for (za = 0; za < zt[h].nadj; za++) + if (zt[h].adj[za] == zonenum[jumped[testpart]]) { + already = 1; + if (p[i].dens < zt[h].slv[za]) { + zt[h].slv[za] = p[i].dens; + } + } + if (already == 0) { + zt[h].adj[zt[h].nadj] = zonenum[jumped[testpart]]; + zt[h].slv[zt[h].nadj] = p[i].dens; + zt[h].nadj++; + } + } + } + } + } + printf("Found zone adjacencies\n"); FF; + + /* Free particle adjacencies */ + for (i=0;i maxvol) maxvol = p[i].dens; + if (p[i].dens < minvol) minvol = p[i].dens; + } + printf("Densities range from %e to %e.\n",minvol,maxvol);FF; + + zon2 = fopen(zonfile2,"w"); + if (zon2 == NULL) { + printf("Problem opening zonefile %s.\n\n",zonfile2); + exit(0); + } + fwrite(&nzones,1,4,zon2); + + for (h = 0; h voltol) { + beaten = 1; + z[h].leak = lowvol; + continue; + } + + for (l=0; l < nl; l++) + if (p[z[link[l]].core].dens < p[z[h].core].dens) + beaten = 1; + if (beaten == 1) { + z[h].leak = lowvol; + continue; + } + /* Add everything linked to the link(s) */ + nhl2 = 0; + for (l=0; l < nl; l++) { + if (inyet2[link[l]] == 0) { + zonelist2[nhl2] = link[l]; + inyet2[link[l]] = 1; + nhl2 ++; + added = 1; + while ((added == 1) && (beaten == 0)) { + added = 0; + for (hl = 0; (hl < nhl2) && (beaten == 0); hl++) { + h2 = zonelist2[hl]; + if (inyet2[h2] == 1) { + interior = 1; /* Guilty until proven innocent */ + for (za = 0; za < z[h2].nadj; za ++) { + link2 = z[h2].adj[za]; + if ((inyet[link2]+inyet2[link2]) == 0) { + interior = 0; + if (z[h2].slv[za] <= lowvol) { + if (p[z[link2].core].dens < p[z[h].core].dens) { + beaten = 1; + break; + } + zonelist2[nhl2] = link2; + inyet2[link2] = 1; + nhl2++; + added = 1; + } + } + } + if (interior == 1) inyet2[h2] = 2; + } + } + } + } + } + for (hl = 0; hl < nhl2; hl++) + inyet2[zonelist2[hl]] = 0; + + /* See if there's a beater */ + if (beaten == 1) { + z[h].leak = lowvol; + } else { + for (h2 = 0; h2 < nhl2; h2++) { + zonelist[nhl] = zonelist2[h2]; + inyet[zonelist2[h2]] = 1; + nhl++; + z[h].npjoin += z[zonelist2[h2]].np; + } + } + if (nhl/10000 > nhlcount) { + nhlcount = nhl/10000; + printf(" %d",nhl); FF; + } + } while((lowvol < BIGFLT) && (beaten == 0)); + + z[h].denscontrast = z[h].leak/p[z[h].core].dens; + if (z[h].denscontrast < 1.) z[h].denscontrast = 1.; + + /* find biggest denscontrast */ + if (z[h].denscontrast > maxdenscontrast) { + maxdenscontrast = (double)z[h].denscontrast; + } + + /* Don't sort; want the core zone to be first */ + + if (nhlcount > 0) { /* Outputs the number of zones in large voids */ + printf(" h%d:%d\n",h,nhl); + FF; + } + /* Calculate volume */ + z[h].voljoin = 0.; + for (q = 0; q Date: Thu, 19 Apr 2012 15:47:53 -0400 Subject: [PATCH 4/7] Added comments. Cleaned up the code --- jozov_persistent.c | 87 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/jozov_persistent.c b/jozov_persistent.c index f5fb4e7..9a76e8a 100644 --- a/jozov_persistent.c +++ b/jozov_persistent.c @@ -27,12 +27,14 @@ typedef struct Zone { float denscontrast; /* density contrast */ double vol; /* Total volume of all particles in the zone */ double voljoin; /* Total volume of all particles in the joined void */ + float smallest_saddle; /* Smallest saddle */ } ZONE; typedef struct ZoneT { int nadj; /* Number of zones on border */ int *adj; /* Each adjacent zone, with ... */ float *slv; /* Smallest Linking Volume */ + float smallest_saddle; /* Smallest saddle point value */ } ZONET; void findrtop(double *a, int na, int *iord, int nb); @@ -114,11 +116,11 @@ int main(int argc,char **argv) { fread(&j,1,sizeof(int),adj); if (j < np) { /* Set both halves of the pair */ - assert(i < j); + assert(i < j); if (p[i].ncnt == p[i].nadj) { - p[i].adj = (int *)realloc(p[i].adj, (p[i].nadj+1)*sizeof(int)); - p[i].nadj++; + p[i].adj = (int *)realloc(p[i].adj, (p[i].nadj+1)*sizeof(int)); + p[i].nadj++; } if (p[j].ncnt == p[j].nadj) { @@ -136,17 +138,17 @@ int main(int argc,char **argv) { fclose(adj); /* Check that we got all the pairs */ -// adj = fopen(adjfile, "r"); -// fread(&np,1, sizeof(int),adj); + // adj = fopen(adjfile, "r"); + // fread(&np,1, sizeof(int),adj); for (i=0;i p[i].dens) { /* there could be a weakest link through testpart */ @@ -282,8 +288,13 @@ int main(int argc,char **argv) { } } if (already == 0) { - zt[h].adj[zt[h].nadj] = zonenum[jumped[testpart]]; - zt[h].slv[zt[h].nadj] = p[i].dens; + int q = zt[h].nadj; + + zt[h].adj[q] = zonenum[jumped[testpart]]; + zt[h].slv[q] = p[i].dens; + if (zt[h].smallest_saddle > zt[h].slv[q]) + zt[h].smallest_saddle = zt[h].slv[q]; + zt[h].nadj++; } } @@ -308,6 +319,7 @@ int main(int argc,char **argv) { free(zt[h].adj); free(zt[h].slv); z[h].np = numinh[z[h].core]; + z[h].smallest_saddle = zt[h].smallest_saddle; } free(zt); free(numinh); @@ -379,6 +391,12 @@ int main(int argc,char **argv) { } fwrite(&nzones,1,4,zon2); + +#define CORE_DENSITY(a) p[z[a].core].dens +#define SADDLE_DENSITY(a) z[a].smallest_saddle +#define COMPARE_ZONES_BEATEN(a,b) (CORE_DENSITY(a) < CORE_DENSITY(b)) + + for (h = 0; h maxdenscontrast) { From e9a6b3afa04ccd2bdcb18f7dab0e10af3f29b1f1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Apr 2012 16:24:19 -0400 Subject: [PATCH 5/7] Rework the void tree to extract zone list in the other tree From 9246e04a6457f145e8c9df1512af4ffc2fbc6a8e Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Apr 2012 16:35:32 -0400 Subject: [PATCH 6/7] Do the loading of the segmented list From bbee74fff05829ebb6c614cae2ee74e410fef80a Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Apr 2012 16:35:46 -0400 Subject: [PATCH 7/7] Missing increment...