diff options
Diffstat (limited to 'src/IsoSurfacer.c')
-rw-r--r-- | src/IsoSurfacer.c | 123 |
1 files changed, 56 insertions, 67 deletions
diff --git a/src/IsoSurfacer.c b/src/IsoSurfacer.c index 3e3f120..f779eb9 100644 --- a/src/IsoSurfacer.c +++ b/src/IsoSurfacer.c @@ -1,14 +1,14 @@ -/*@@ +/*@@ @file IsoSurfacer.c @date Wed Oct 8 11:30:45 MET 2000 @author Joe Blow - @desc + @desc Gutted original isosurfacer code from SC97. Has completely new implementation for marching - cubes and sockets are integrated in Sockets.c + cubes and sockets are integrated in Sockets.c rather than coming from TCP++ or other external modules. - @enddesc + @enddesc @@*/ #include <stdio.h> @@ -77,7 +77,7 @@ static int IsoSurfacerHandleCommands(const cGH *GH) /* 0)For each command bcast catenated string to all processors - + Command to change existing isovalue is of format "isosurf",<gridname>[<instance>],<newvalue> 1) Select GF @@ -133,7 +133,7 @@ static int IsoSurfacerHandleCommands(const cGH *GH) new_isovalue = isovalue; } - tmpval=new_isovalue; + tmpval=new_isovalue; CACTUS_MPI_ERROR(MPI_Bcast(&tmpval,1, PUGH_MPI_REAL,0, /* ugh. nor REAL8 */ pughGH->PUGH_COMM_WORLD)); @@ -144,7 +144,7 @@ static int IsoSurfacerHandleCommands(const cGH *GH) /* Steer the parameter */ CCTK_ParameterSet("isovalue","isosurfacer",stringval); } -#else +#else if(Iso_PollCommand(GH,&command)){ if (CCTK_Equals (verbose, "full")) { @@ -165,10 +165,10 @@ static int doIso(int vindex, const cGH *GH, isosurfacerGH *myGH) if(!myGH->RunIsoSurfacer) return 0; - fullname = CCTK_FullName (vindex); + fullname = CCTK_FullName (vindex); /* printf("Check doIso: fullname[%s]:[%s]",fullname,myGH->funcName);*/ if(CCTK_Equals(fullname,myGH->funcName)){ - if(myGH->firstIteration<=GH->cctk_iteration && + if(myGH->firstIteration<=GH->cctk_iteration && !((GH->cctk_iteration-myGH->firstIteration) % myGH->outfreq)){ free(fullname); return 1; @@ -189,19 +189,10 @@ static void computeIso(int vindex, const cGH *GH, isosurfacerGH *myGH) int nx,ny,nz; CCTK_REAL *xcoords,*ycoords,*zcoords,*data; int timelevel=0; - /*** FIXME: can CCTK_Reduce() have a 'const cGH *' parameter ?? ***/ - union - { - const cGH *const_ptr; - cGH *non_const_ptr; - } GH_fake_const; - - - GH_fake_const.const_ptr = GH; if(!myGH->RunIsoSurfacer) return; /* not running */ - + fullname = CCTK_FullName (vindex); data = (CCTK_REAL *) GH->data [vindex][timelevel]; nx=GH->cctk_lsh[0]; ny=GH->cctk_lsh[1]; nz=GH->cctk_lsh[2]; @@ -224,13 +215,11 @@ static void computeIso(int vindex, const cGH *GH, isosurfacerGH *myGH) if(myGH->formats & (SOCK|ISOHDF5|BIN)){ int handle; handle = CCTK_ReductionHandle ("minimum"); - CCTK_Reduce (GH_fake_const.non_const_ptr, 0,handle,1,CCTK_VARIABLE_REAL, - &(myGH->minval),1, vindex); + CCTK_Reduce (GH, 0,handle,1,CCTK_VARIABLE_REAL, &myGH->minval,1, vindex); handle = CCTK_ReductionHandle ("maximum"); - CCTK_Reduce (GH_fake_const.non_const_ptr, 0, handle, 1, CCTK_VARIABLE_REAL, - &(myGH->maxval), 1, vindex); + CCTK_Reduce (GH, 0, handle, 1, CCTK_VARIABLE_REAL, &myGH->maxval, 1, vindex); } - + if (CCTK_MyProc (GH) == 0){ CCTK_INT4 tmppolys[3] = {0,0,0}; CCTK_REAL4 tmpverts[3] = {0.0,0.0,0.0}; @@ -245,31 +234,31 @@ static void computeIso(int vindex, const cGH *GH, isosurfacerGH *myGH) if (CCTK_Equals (verbose, "full")) printf(" | IsoSurfacer: GF=%s, value %f,", fullname, myGH->isovalue); - + if(myGH->totals.nverts > 0) { - + if (CCTK_Equals (verbose, "full")) printf("%d vertices, %d triangles\n", myGH->totals.nverts, myGH->totals.npolys); - + if(myGH->formats & BIN) WriteBin(GH, &myGH->totals, myGH, fullname, myGH->isovalue); - + if(myGH->formats & ASCII) WriteASCII(GH, &myGH->totals, fullname, myGH->isovalue); - + if(myGH->formats & UCD) WriteUCD(GH, &myGH->totals,fullname, myGH->isovalue); - + if(myGH->formats & VRML) WriteVRML(GH, &myGH->totals, fullname,myGH->isovalue); - + /* !!!!!!!!!!!!!!!!!! what is J representing???? */ if(myGH->formats & SOCK) WriteSock(GH, &myGH->totals,myGH,fullname,0, myGH->isovalue); - + if(myGH->formats & ISOHDF5) WriteHDF5(GH, &myGH->totals,myGH,fullname,0, myGH->isovalue); - + } else { @@ -277,7 +266,7 @@ static void computeIso(int vindex, const cGH *GH, isosurfacerGH *myGH) "No isosurface for '%s' isolevel %f", fullname, myGH->isovalue); } - + /* !!!!!!!!!!!!!!!! Why the hell are we doing this? !!!!!!!!!!!! */ if(polybackup || vertbackup){ /* copy back datastructures */ myGH->totals.polys=polybackup; @@ -304,15 +293,15 @@ int IsoSurfacer (const cGH *GH) IsoSurfacerHandleCommands (GH); myGH->isovalue=isovalue; /* take the contents of the "steered" isosurface value and put it here */ /* do a check for new isosurfaces */ - /* Perhaps do a bcast for "changed" flags. + /* Perhaps do a bcast for "changed" flags. which are embedded in each iso. */ /* for each Grid */ for (i = retval = 0, n = CCTK_NumVars (); i < n; i++) { - if (! doIso (i, GH, myGH)) + if (! doIso (i, GH, myGH)) { - continue; + continue; } if (CCTK_QueryGroupStorageI(GH,CCTK_GroupIndexFromVarI(i))) { @@ -323,7 +312,7 @@ int IsoSurfacer (const cGH *GH) { CCTK_VWarn (9, __LINE__, __FILE__, CCTK_THORNSTRING, "No storage assigned for '%s'", CCTK_VarName (i)); - } + } } return (retval); @@ -334,14 +323,14 @@ int IsoSurfacer (const cGH *GH) void CollectData(const cGH *GH, polypatch *perprocessor, polypatch *totals) { DECLARE_CCTK_PARAMETERS #ifdef CCTK_MPI - + /* Collect the isosurface data onto processor 0 */ /* First collect the numbers of vertices (MPI_Gather)*/ /* Then the vertices themselves (MPI_Gatherv)*/ /* Then the number of polygons (MPI_Gather)*/ /* Then the polygon list. This needs to be offset by the number of vertices ahead of me, so do that after collection. */ - + static int a, b; static int *vcount = NULL; static int *pcount = NULL; @@ -352,7 +341,7 @@ void CollectData(const cGH *GH, polypatch *perprocessor, polypatch *totals) { static CCTK_INT4 my_vpcount [2]; static CCTK_INT4 *vpcount = NULL; pGH *pughGH; - + pughGH = PUGH_pGH (GH); /* Allocate temporary arrays for the MPI_Gatherv() operation */ if(pughGH->myproc == 0) { @@ -364,41 +353,41 @@ void CollectData(const cGH *GH, polypatch *perprocessor, polypatch *totals) { pdispl = &vcount[3*pughGH->nprocs]; } } - + /* **** Gather counts of vertex and polygon lists in one wash */ my_vpcount [0] = 3*perprocessor->nverts; my_vpcount [1] = 3*perprocessor->npolys; CACTUS_MPI_ERROR (MPI_Gather (my_vpcount, 2, PUGH_MPI_INT4, vpcount, 2, PUGH_MPI_INT4, 0, pughGH->PUGH_COMM_WORLD)); - + /* Allocate for the vertices */ if(pughGH->myproc == 0){ totals->nverts = 0; totals->npolys = 0; - + for (a = 0; a < pughGH->nprocs; a++) { /* now sort out the vcounts and pcounts into the int-arrays used in MPI_Gatherv() */ vcount [a] = vpcount [2*a + 0]; pcount [a] = vpcount [2*a + 1]; - + /* compute the displacements and total number of elements */ vdispl[a] = totals->nverts; pdispl[a] = totals->npolys; totals->nverts += vcount[a]; totals->npolys += pcount[a]; } - + totals->nverts /= 3; totals->npolys /= 3; if(compute_normals) totals->nnorms=totals->nverts; else totals->nnorms=0; - + /* Kludge: - Allocate 3 more than necessary so as to divert + Allocate 3 more than necessary so as to divert the output of processors with nverts=0 to a dummy area in the upper part of totals->verts. Otherwise the MPI_Gatherv routine gives lots of problems. @@ -415,19 +404,19 @@ void CollectData(const cGH *GH, polypatch *perprocessor, polypatch *totals) { if(lastNpolys < totals->npolys){ REALLOC(totals->polys, 3+3*totals->npolys, CCTK_INT4); lastNpolys = totals->npolys; - } + } } /* end processor 0 setup */ - + /* Gather the vertex lists from all processors */ CACTUS_MPI_ERROR (MPI_Gatherv (perprocessor->verts, perprocessor->nverts*3, PUGH_MPI_REAL4, totals->verts, vcount, vdispl, PUGH_MPI_REAL4, 0, pughGH->PUGH_COMM_WORLD)); - + /* Gather the polygon lists from all processors */ CACTUS_MPI_ERROR (MPI_Gatherv (perprocessor->polys, perprocessor->npolys*3, PUGH_MPI_INT4, totals->polys, pcount, pdispl, PUGH_MPI_INT4, 0, pughGH->PUGH_COMM_WORLD)); - if(compute_normals){ + if(compute_normals){ CACTUS_MPI_ERROR (MPI_Gatherv (perprocessor->norms, perprocessor->nnorms*3, PUGH_MPI_REAL4, totals->norms, vcount, vdispl, PUGH_MPI_REAL4, 0, pughGH->PUGH_COMM_WORLD)); @@ -445,7 +434,7 @@ void CollectData(const cGH *GH, polypatch *perprocessor, polypatch *totals) { } } } - + #else /* !MPI */ GH = GH; *totals = *perprocessor; @@ -454,8 +443,8 @@ void CollectData(const cGH *GH, polypatch *perprocessor, polypatch *totals) { /**************************************************************/ -int IsoWriteDataToClients(char *metadata, - CCTK_INT8 size, +int IsoWriteDataToClients(char *metadata, + CCTK_INT8 size, IsoType type, void *data); @@ -478,20 +467,20 @@ void WriteSock(const cGH *GH, polypatch *totals, isosurfacerGH *myGH, fullname,myGH->isovalue, GH->cctk_iteration, myGH->minval,myGH->maxval); - /*puts("sock out+++++++++++++++++"); - puts(tmpstring); */ + /*puts("sock out+++++++++++++++++"); + puts(tmpstring); */ /********Now write vertices**********/ *tmpstring='v'; verts = totals->nverts > 0 ? totals->verts : tmpverts; - IsoWriteDataToClients(tmpstring, - 3*totals->nverts, + IsoWriteDataToClients(tmpstring, + 3*totals->nverts, Int32, (CCTK_INT4 *)verts); /********Now write polygons**********/ *tmpstring='c'; polys = totals->npolys > 0 ? totals->polys : tmppolys; - IsoWriteDataToClients(tmpstring, - 3*totals->npolys, + IsoWriteDataToClients(tmpstring, + 3*totals->npolys, Float32, (CCTK_INT4 *)polys); } @@ -600,7 +589,7 @@ void WriteVRML(const cGH *GH, polypatch *totals, const char *fullname, CCTK_REAL4 isolevel) { - /* Write isosurfaces in VRML 1.0 ASCII format + /* Write isosurfaces in VRML 1.0 ASCII format (can be read by ivview) */ DECLARE_CCTK_PARAMETERS @@ -646,12 +635,12 @@ WriteVRML(const cGH *GH, polypatch *totals, const char *fullname, sprintf(tmps, "]\n\t}\n\tIndexedFaceSet {\n\t\tcoordIndex [ "); Append_Or_EnlargeAndAppend(outs, tmps); - sprintf (tmps, "%d, %d, %d, -1", + sprintf (tmps, "%d, %d, %d, -1", totals->polys[0], totals->polys[1], totals->polys[2]); Append_Or_EnlargeAndAppend(outs, tmps); for (a = 3; a<3*totals->npolys; a += 3) { - sprintf (tmps, ", \n\t\t%d, %d, %d, -1", + sprintf (tmps, ", \n\t\t%d, %d, %d, -1", totals->polys[a], totals->polys[a+1], totals->polys[a+2]); Append_Or_EnlargeAndAppend(outs, tmps); } @@ -711,7 +700,7 @@ WriteASCII(const cGH *GH, polypatch *totals, const char *fullname, for (a = 0; a<3*totals->npolys; a += 3) { - sprintf (tmps, "%d %d %d\n", + sprintf (tmps, "%d %d %d\n", totals->polys[a], totals->polys[a+1], totals->polys[a+2]); Append_Or_EnlargeAndAppend(outs, tmps); } @@ -736,7 +725,7 @@ WriteUCD(const cGH *GH, polypatch *totals, const char *fullname, static char tmps[256]; static CCTK_INT4 efs = 0, lfs = 0; - sprintf(fname, "%s/%s%s_%3.3f_%d.iso.inp", + sprintf(fname, "%s/%s%s_%3.3f_%d.iso.inp", out_dir, fullname, PUGH_pGH (GH)->identity_string, isolevel, GH->cctk_iteration); @@ -797,7 +786,7 @@ int IsoSurfacer_TimeForOutput(const cGH *GH, int i){ if (!myGH ||!myGH->RunIsoSurfacer) return 0; /* do a check for new isosurfaces */ - /* Perhaps do a bcast for "changed" flags. + /* Perhaps do a bcast for "changed" flags. which are embedded in each iso. */ return doIso(i, GH, myGH); } |