diff options
author | jshalf <jshalf@bfcf8e34-485d-4d46-a995-1fd6fa6fb178> | 2000-09-26 05:05:56 +0000 |
---|---|---|
committer | jshalf <jshalf@bfcf8e34-485d-4d46-a995-1fd6fa6fb178> | 2000-09-26 05:05:56 +0000 |
commit | 5fba974c16f9bbf6e5e0cd7ec3ab09ec83a79218 (patch) | |
tree | deef203e34a327778c1e7d056be310c95ee3fa52 | |
parent | 1a826b78b503406ab21d25148e52c7547a0e578a (diff) |
More code reorganization and removal of C++ items.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IsoSurfacer/trunk@3 bfcf8e34-485d-4d46-a995-1fd6fa6fb178
-rw-r--r-- | param.ccl | 26 | ||||
-rw-r--r-- | src/IsoSurfacer.c | 127 | ||||
-rw-r--r-- | src/IsoSurfacerGH.h | 12 | ||||
-rw-r--r-- | src/IsoSurfacerInit.c | 402 |
4 files changed, 105 insertions, 462 deletions
@@ -3,10 +3,30 @@ private: -STRING isosurfacer "What to isosurface and how. Format: {(functionName) (isolevel1, isolevel2, ...) (format1, format2, ...) (itiso, resolution, firstIteration, uniqverts)} {} ..." +STRING output_format "What form to output the datasets" STEERABLE = ALWAYS { - .* :: A regex which matches everything -} "" + .* :: "Comma separated list. Can be UCD, VRML, ASCII, SOCK or None" +} "None" + +STRING output_var "What Grid Function name to output" +{ + .* :: "Eventually a comma separated list, but now a single name" +} "None" + +CCTK_REAL4 isovalue "Isosurface value" STEERABLE = ALWAYS +{ + .* :: "Any floating point value" +} 1.0 + +INT output_frequency "How often to output the isosurfaces" STEERABLE = ALWAYS +{ + .* :: "Some positive integer" +} 1 + +INT output_start "First iteration to start drawing isosurfaces. Default=1" STEERABLE = ALWAYS +{ + .* :: "Some positive integer" +} 1 INT outer_boundary_cutoff "Number of voxels to cut off the outer boundaries" STEERABLE = ALWAYS { diff --git a/src/IsoSurfacer.c b/src/IsoSurfacer.c index 0ba1c99..ab629d3 100644 --- a/src/IsoSurfacer.c +++ b/src/IsoSurfacer.c @@ -70,14 +70,14 @@ extern isotimes_st cdtimes; /***************************************************************************/ -/// Ugly global variables +/* Ugly global variables: Should move to the GH */ - static polypatch perprocessor, totals; - static GridAll_st GridAll; +static polypatch perprocessor, totals; +static GridAll_st GridAll; #ifdef CCTK_MPI - static int print_time=0; - static double taccum; - double t1; +static int print_time=0; +static double taccum; +double t1; #endif #ifndef true @@ -252,49 +252,32 @@ static int IsoSurfacerHandleCommands(cGH *GH) return 0; } -static bool doIso(int i, cGH *GH, isosurfacerGH *myGH) +static int doIso(int i, cGH *GH, isosurfacerGH *myGH) { /* need to rediscover how to mess with this */ -#if 0 - char* fullname = CCTK_FullName (i); - /* see if we are to iterate on this GH.*/ - param_map::iterator it = myGH->isoparms.find( fullname ); - free (fullname); - - if (it == myGH->isoparms.end() || !(*it).second) - return false; - - isoparms_st&myIso = *(*it).second; - - int firstiter = myIso.firstIteration; - if(GH->cctk_iteration < firstiter) - return false; - int itiso = myIso.outfreq; - if (!(itiso && (GH->cctk_iteration - firstiter) % itiso == 0)) - return false; - return true; -#endif - return false; + char *fullname = CCTK_FullName (i); + if(!strcmp(fullname,myGH->funcName)){ + if(myGH->firstIteration<=GH->cctk_iteration && + !((GH->cctk_iteration-myGH->firstIteration) % myGH->outfreq)) + return 1; + } + return 0; } static void computeIso(int i, cGH *GH, isosurfacerGH *myGH) { DECLARE_CCTK_PARAMETERS - - char* fullname = CCTK_FullName (i); - - isoparms_st*ptrIsofunc = myGH->isoparms[ fullname ]; - - if (!ptrIsofunc) - return; + /* is it really required to have this static here?? */ + static par_st parms; + char* fullname = CCTK_FullName (i); - isoparms_st&isofunc = *ptrIsofunc; + isoparms_st *isofunc = myGH->isoparms; /* if the do_iso flag is set */ /* then draw an iso for each level of surfaces requested */ - for (unsigned int j = 0; j < isofunc.isolevels.size(); j++) { + for (unsigned int j = 0; j < isofunc->isolevels.size(); j++) { /* Do the bcast for nisolevels here */ isotimes.ncalls++; #ifndef _WIN32 @@ -308,25 +291,20 @@ static void computeIso(int i, cGH *GH, isosurfacerGH *myGH) if (GridAll.timelevel > 0) GridAll.timelevel--; - - // is it really required to have this static here?? - static par_st parms; - + /* This needs to be removed. + should just use isoparms_st everywhere */ parms.outfname = NULL; - parms.outtype = isofunc.formats; - parms.isovalue = (CCTK_REAL4)isofunc.isolevels[j].value; - parms.step = isofunc.resolution; - parms.doRemoveDuplicateVertices = isofunc.uniq_verts; + parms.outtype = isofunc->formats; + parms.isovalue = isofunc->isovalue; + parms.step = isofunc->resolution; + parms.doRemoveDuplicateVertices = isofunc->uniq_verts; parms.useTree = parms.doRemoveDuplicateVertices; parms.doEliminateSmallTriangles = 0; #ifdef CCTK_MPI t1=MPI_Wtime(); #endif - if(nusurfacer) /* use the new isosurfacer */ - NuFindSurface(GH,i,parms.isovalue,&perprocessor); - else /* use the old isosurfacer */ - FindIsoSurface(GH, (void *)&GridAll, &perprocessor, &parms); + NuFindSurface(GH,i,parms.isovalue,&perprocessor); #ifdef CCTK_MPI taccum += (MPI_Wtime()-t1); if(print_time) @@ -359,23 +337,23 @@ static void computeIso(int i, cGH *GH, isosurfacerGH *myGH) printf("%d vertices, %d triangles\n", totals.nverts, totals.npolys); if(parms.outtype & BIN) - WriteBin(GH, &totals, &parms, fullname, isofunc.isolevels[j].value); + WriteBin(GH, &totals, &parms, fullname, isofunc->isolevels[j].value); if(parms.outtype & ASCII) WriteASCII(GH, &totals, &parms, fullname, - isofunc.isolevels[j].value); + isofunc->isolevels[j].value); if(parms.outtype & UCD) - WriteUCD(GH, &totals, &parms, fullname, isofunc.isolevels[j].value); + WriteUCD(GH, &totals, &parms, fullname, isofunc->isolevels[j].value); if(parms.outtype & VRML) - WriteVRML(GH, &totals, &parms, fullname,isofunc.isolevels[j].value); + WriteVRML(GH, &totals, &parms, fullname,isofunc->isolevels[j].value); if(parms.outtype & SOCK) - WriteSock(GH, &totals,&parms,fullname,j, isofunc.isolevels[j]); + WriteSock(GH, &totals,&parms,fullname,j, isofunc->isolevels[j]); if(parms.outtype & ISOHDF5) - WriteHDF5(GH, &totals,&parms,fullname,j, isofunc.isolevels[j]); + WriteHDF5(GH, &totals,&parms,fullname,j, isofunc->isolevels[j]); } else printf(" no isosurface\n"); @@ -411,7 +389,7 @@ int IsoSurfacer(cGH *GH){ /* Perhaps do a bcast for "changed" flags. which are embedded in each iso. */ for (int i = 0; i<CCTK_NumVars (); i++) { /* for each Grid */ - if (!doIso(i, GH, myGH)) + if (!doIso(i, GH, myGH)) /* JMS still must translate this GH extension flag */ continue; if (CCTK_QueryGroupStorageI(GH,CCTK_GroupIndexFromVarI(i))) { @@ -495,12 +473,14 @@ void CollectData(cGH *GH, polypatch *perprocessor, polypatch *totals) { totals->nverts /= 3; totals->npolys /= 3; - /* Kludge by M. Panea: - Allocate 3 more than necessary so as to divert the output of processors + 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. + This is problem which is particular to the T3E native + implementation of MPI. */ if(lastNverts < totals->nverts){ REALLOC(totals->verts, 3+3*totals->nverts, CCTK_REAL4); @@ -556,21 +536,24 @@ void WriteSock(cGH *GH, polypatch *totals, par_st *parms, const char *fullname, int isoindex, Isolevel&IsoL) { - // Was: parms->timestep, which was callnumber from above. + /* Was: parms->timestep, which was callnumber from above. */ sprintf(tmpstring," :%s[%u]=%f,%u range=%f:%f", full_id,isoindex,parms->isovalue, GH->cctk_iteration, parms->minval,parms->maxval); - + puts(tmpstring); /********Now write vertices**********/ *tmpstring='v'; verts = totals->nverts > 0 ? totals->verts : tmpvert; +#if 0 /* disabled for now */ DS->sendData(tmpstring,3*totals->nverts,DataType::int2type(REMOTE_IO_FLOAT32),verts); - +#endif /********Now write polygons**********/ *tmpstring='c'; polys = totals->npolys > 0 ? totals->polys : tmppoly; +#if 0 /* disabled for now */ DS->sendData(tmpstring,3*totals->npolys,DataType::int2type(REMOTE_IO_INT32),polys); +#endif } /***************************************************************************/ @@ -587,6 +570,7 @@ static void WriteHDF5(cGH *GH, polypatch *totals, par_st *parms, strlen (PUGH_pGH (GH)->identity_string) + 20); sprintf (filename, "%s/%s%s.iso.h5", outdir, fullname, PUGH_pGH (GH)->identity_string); +#if 0 /* disabled for now */ IOHDF5_WriteIsosurface (GH, filename, fullname, (CCTK_INT) GH->cctk_iteration, (CCTK_INT) GridAll.timelevel, @@ -594,8 +578,8 @@ static void WriteHDF5(cGH *GH, polypatch *totals, par_st *parms, (CCTK_REAL) parms->minval, (CCTK_REAL) parms->maxval, (int) totals->npolys, totals->polys, (int) totals->nverts, totals->verts); +#endif free (filename); - #else CCTK_WARN (1, "No HDF5 isosurface output because CactusPUGHIO/IOHDF5 was not compiled in !"); @@ -857,7 +841,7 @@ WriteUCD(cGH *GH, polypatch *totals, par_st *parms, const char *fullname, /***************************************************************************/ - +/* this is pretty redundant. Should be removed and just use doIso() */ int IsoSurfacer_TimeForOutput(cGH *GH, int i) { /* Get the GH extensions for IOUtil and IOASCII */ @@ -870,24 +854,7 @@ int IsoSurfacer_TimeForOutput(cGH *GH, int i) /* Perhaps do a bcast for "changed" flags. which are embedded in each iso. */ - return doIso(i, GH, myGH); - -/* - - if (! myGH->do_iso[i]) - return 0; - -int firstiter = myGH->isoparms[i].firstIteration; - if(GH->cctk_iteration < firstiter) - return 0; - -int itiso = myGH->isoparms[i].outfreq; - if (!(itiso && (GH->cctk_iteration - firstiter) % itiso == 0)) - return 0; - - return 1; -*/ - + return doIso(i, GH, myGH); } int IsoSurfacer_TriggerOutput(cGH *GH,int variable) diff --git a/src/IsoSurfacerGH.h b/src/IsoSurfacerGH.h index b5ef1cc..5e5de6b 100644 --- a/src/IsoSurfacerGH.h +++ b/src/IsoSurfacerGH.h @@ -38,21 +38,13 @@ struct Isolevel typedef struct isoparms_st { char *funcName; - vector<Isolevel> isolevels; + CCTK_REAL4 isolevel; short int formats; short int outfreq; short int firstIteration; short int resolution; short int uniq_verts; - - isoparms_st() - : funcName(0) - , formats(0) - , outfreq(1) - , firstIteration(1) - , resolution(1) - , uniq_verts(1) - {} + short int RunIsoSurfacer; } isoparms_st; struct isosurfacerGH diff --git a/src/IsoSurfacerInit.c b/src/IsoSurfacerInit.c index 5948426..ce2ca1c 100644 --- a/src/IsoSurfacerInit.c +++ b/src/IsoSurfacerInit.c @@ -1,7 +1,3 @@ -#ifndef TCP /* JMS addition */ -#define TCP -#endif - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -16,34 +12,14 @@ #include <cctk.h> #include <cctk_Parameters.h> -//#include <cctk_DefineThorn.h> - -//#ifdef CACTUSNET_HTTP -//#include "CactusNet/http/src/http_GHExtensions.hpp" -//#endif - #include "http_GHExtensions.hpp" - #include "IsoSurfacerGH.h" #include "IsoSurfacerInit.h" - -/* Some function forward declarations */ -CCTK_INT4 ParseIsoString(char *s, param_map&parms); -CCTK_INT4 NumberOfItems(char *s, char *d); -char *GetSubString(char *s, char *d, CCTK_INT4 n); - -isotimes_st isotimes; +isotimes_st isotimes; /* JMS: should not be a global */ isotimes_st cdtimes; -CCTK_INT4 RunIsoSurfacer; - - -#ifdef CACTUSNET_HTTP -CactusCommands::Client * IsosurfaceHttpClientCreator(CactusCommands::Reply*msgbuf, CactusCommands::CommandList&cmds ); -#endif - /***************************************************************/ void *IsoSurfacer_SetupGH (tFleshConfig *config, int convergence_level, @@ -54,6 +30,14 @@ void *IsoSurfacer_SetupGH (tFleshConfig *config, int IsoSurfacer_InitGH (cGH *GH){ DECLARE_CCTK_PARAMETERS + /* + The above string declares the following parameters + char *output_format + int output_frequency + int output_start + int outer_boundary_cutoff + char *outdir + */ int n; isosurfacerGH *myGH; myGH = (isosurfacerGH *) GH->extensions [CCTK_GHExtensionHandle ("IsoSurfacer")]; @@ -62,47 +46,40 @@ int IsoSurfacer_InitGH (cGH *GH){ /* initialize values */ myGH->funcName=0; myGH->formats=0; - myGH->outfreq=1; - myGH->firstIteration=1; + myGH->outfreq=output_frequency; + myGH->firstIteration=output_start; myGH->resolution=1; myGH->uniq_verts=1; - myGH->RunIsoSurfacer = 0; + myGH->isovalue=isovalue; - /* OK, this is ridiculous. - Separate out the isostring components into - separate things and end this craziness */ - if( (n = ParseIsoString(isosurfacer, myGH->isoparms)) == 0) - return 0; - - RunIsoSurfacer = 1; - /* - doIso = 0; - - for (i=0; i<CCTK_NumVars (); i++) { + for(i=0;i<CCTK_NumVars();i++){ char *fullname = CCTK_FullName (i); - - for(j=0; j<n; j++) - if(CCTK_Equals (fullname, allparms[j].funcName) ) { - doIso = 1; - myGH->do_iso [i] = 1; - myGH->isoparms [i] = allparms[j]; - if((allparms[j]).formats&SOCK){ - printf("usesockets**********\n"); - } - break; - } - free (fullname); + if(CCTK_Equals (fullname, output_var)) + myGH->funcName=output_var; + /* Maybe even set the GF here ? */ + free(fullname); } -*/ - - if (CCTK_MyProc (GH) == 0){ + + if(strstr(output_format,"UCD")) myGH->format|=UCD; + if(strstr(output_format,"ASCII")) myGH->format|=ASCII; + if(strstr(output_format,"BIN")) myGH->format|=BIN; + if(strstr(output_format,"SOCK")) myGH->format|=SOCK; + if(strstr(output_format,"HDF5")) myGH->format|=HDF5; + if(strstr(output_format,"VRML")) myGH->format|=VRML; + + if(myGH->funcName==0 || myGH->format==0) + myGH->RunIsoSurfacer = 0; + else + myGH->RunIsoSurfacer = 1; + + if (CCTK_MyProc (GH) == 0 && strcmp(outdir,".")){ char *cmd = (char *) malloc (strlen (outdir) + 80); - sprintf (cmd, "mkdir -p %s", outdir); if (system (cmd) < 0) CCTK_WARN (1, "Problem creating IsoSurfacer output directory"); free (cmd); } + /* otherwise, the outdir need not be created if it is '.' */ memset(&isotimes, 0, sizeof(isotimes)); memset(&cdtimes, 0, sizeof(cdtimes)); return true; @@ -114,7 +91,7 @@ void IsoSurfaceEnd(cGH *GH) { - if( RunIsoSurfacer == 0 ) + if( myGH->RunIsoSurfacer == 0 ) return; #if 0 @@ -176,319 +153,6 @@ int IsoSurfacer_rfrTraverseGH (cGH *GH, int rfrpoint) return 0; } -/*****************************************************************************/ - -CCTK_INT4 ParseIsoString(char *s, param_map&allparms) -{ - CCTK_INT4 i, j; - CCTK_INT4 n, m; - CCTK_INT4 nlevels, nformats; - char *sub0, *sub1, *sub2; - - - - /* First see how many functions we have */ - /* by simply counting the number of {} pairs */ - n = NumberOfItems(s, "{}"); - - if(n == 0) - { - printf("Isosurfacer: empty parameter string '%s'\n", s); - return 0; - } - - /* Allocate that many isoparms structs */ -// *allparms = NEW(n, isoparms_st); - - /* Now fill in each isoparms struct with the info for each function */ - for(i=0; i<n; i++) - { - sub0 = GetSubString(s, "{}", i); - - /* Check that we have the right number of () pairs */ - m = NumberOfItems(sub0, "()"); - - if(m != 4) - { - printf("Isosurfacer: improperly formed parameter string '%s'\n", s); - printf(" there should be exactly 4 () pairs\n"); - free(sub0); - return 0; - } - - /*- 1 -----------------------------------------------------------------*/ - /* The first () pair contains the function name */ - char*gridfunc = GetSubString(sub0, "()", 0); - - isoparms_st*gridparams = new isoparms_st(); - - allparms[gridfunc] = gridparams ; - - gridparams->funcName = gridfunc; - - - /*- 2 -----------------------------------------------------------------*/ - /* The second () pair contains the list of isosurface levels */ - sub1 = GetSubString(sub0, "()", 1); - - /* First see how many there are by counting the number of commas + 1 */ - nlevels = NumberOfItems(sub1, ","); - - /* and get the values */ - for(j=0; j<nlevels; j++) - { - sub2 = GetSubString(sub1, ",", j); - gridparams->isolevels.push_back( Isolevel() ); - - gridparams->isolevels.back().value = atof(sub2); - - gridparams->isolevels.back().Ncolorinfo = 0; - - char*N = strchr(sub2, ':'); - if (N) - { - N++; - int Nvalues = NumberOfItems(N, "/"); - if (Nvalues > 7 ) - Nvalues = 7; - - for(int k=0; k<Nvalues; k++) - { - char*sub3 = GetSubString(N, "/", k); - char*number = sub3; - while(*number && !isdigit(*number)) number++; - gridparams->isolevels.back().colorinfo[k] = atof(number); - free(sub3); - } - - gridparams->isolevels.back().Ncolorinfo = Nvalues; - } - - free(sub2); - } - free(sub1); - /*- 3 -----------------------------------------------------------------*/ - /* The third () pair contains the list of output formats */ - sub1 = GetSubString(sub0, "()", 2); - - /* See how many there are by counting the number of commas + 1 */ - nformats = NumberOfItems(sub1, ","); - - /* and get the values */ - gridparams->formats = 0; - for(j=0; j<nformats; j++) - { - sub2 = GetSubString(sub1, ",", j); - if( !strcmp(sub2, "BIN") ) - gridparams->formats |= BIN; - else if (!strcmp(sub2, "VRML")) - gridparams->formats |= VRML; - else if (!strcmp(sub2, "ASCII")) - gridparams->formats |= ASCII; - else if (!strcmp(sub2, "UCD")){ -#ifdef VERBOSE - printf("UCD found in formats string\n"); -#endif - gridparams->formats |= UCD; - } - else if (!strcmp(sub2,"SOCK")){ /* JMS addition */ -#ifdef VERBOSE - printf("SOCK found in formats string for %d\n",i); -#endif - gridparams->formats |= SOCK; - } - else if (!strcmp(sub2,"ISOHDF5")){ /* TR addition */ -#ifdef VERBOSE - printf("HDF5 found in formats string for %d\n",i); -#endif - gridparams->formats |= ISOHDF5; - } - else if(!strcmp(sub2,"NONE")){ -#ifdef VERBOSE - printf("NONE string found in formats string\n"); -#endif - gridparams->formats |= NONE; - } - else - { - printf("Isosurfacer: invalid output format '%s'\n", sub2); - printf(" supported formats are: BIN, VRML, ASCII, UCD, SOCK\n"); - free(sub2); - free(sub1); - free(sub0); - return 0; - } - free(sub2); - } - - free(sub1); - - - /*- 4 -----------------------------------------------------------------*/ - /* The fourth () pair contains the other various parameters */ - sub1 = GetSubString(sub0, "()", 3); - - /* Check that the amount of them is correct (=4) */ - if( NumberOfItems(sub1, ",") != 4) - { - printf("Isosurfacer: improperly formed parameter string '%s'\n", s); - printf(" there should be exactly 4 parameters in the last () pair\n"); - free(sub1); - free(sub0); - return 0; - } - - /* The first one is the frequency of output */ - sub2 = GetSubString(sub1, ",", 0); - gridparams->outfreq = (CCTK_INT4)atoi(sub2); - free(sub2); - - /* Then the first iteration */ - sub2 = GetSubString(sub1, ",", 1); - gridparams->firstIteration = (CCTK_INT4)atoi(sub2); - free(sub2); - - /* Then the resolution */ - sub2 = GetSubString(sub1, ",", 2); - gridparams->resolution = (CCTK_INT4)atoi(sub2); - free(sub2); - - /* And finally the "uniq_vertices" flag */ - sub2 = GetSubString(sub1, ",", 3); - gridparams->uniq_verts = (CCTK_INT4)atoi(sub2); - free(sub2); - - free(sub1); - - free(sub0); - } - - return n; -} - -/*****************************************************************************/ - -CCTK_INT4 -NumberOfItems(char *s, char *d) -{ - int ld, i; - int result; - char *p; - - result = 0; - ld = strlen(d); - - switch(ld) - { - case 1: - p = s; - while( *p != '\0' ) - { - if( *p++ == d[0] ) - result++; - } - if( p != s ) - result++; - return result; - - case 2: - p = s; - i = 0; - while( *p != '\0' ) - { - if ( *p++ == d[i] ) - { - result++; - i = (i==0)?1:0; - } - } - if( (result % 2) != 0 ) - return 0; - else - return result/2; - - default: - return 0; - } -} - -/*****************************************************************************/ - -char * -GetSubString(char *s, char *d, CCTK_INT4 n) -{ - int ld, count, i; - char *result; - char *p, *q = NULL; - - result = NULL; - ld = strlen(d); - - p = s; - count = 0; - switch(ld) - { - case 1: - q = p; - while( *p != '\0' ) - { - if( *p++ == d[0] ) - { - if(count == n) - break; - else - { - count++; - q = p; - } - } - } - if(*p == '\0') - p++; - break; - - case 2: - i = 0; - while( *p != '\0' ) - { - if ( *p++ == d[i] ) - { - if(i==0) - { - q = p; - } - else - { - if(count == n) - break; - else - count++; - } - i = (i==0)?1:0; - } - } - break; - - default: - return NULL; - } - - if(count == n) - { - while( *q == ' ' ) - q++; - p-=2; - while( *p == ' ' ) - p--; - p++; - result = NEW((p-q+1), char); - strncpy(result, q, p-q); - result[p-q] = '\0'; - } - return result; -} - -/**********************************************************/ |