int main( int argc, char* argv[]) { char tmpBuf[PATH_MAX]; FILE* nxnzIn; FILE* timeStepIn; unsigned int rank; unsigned int dumpIteration, junk; float time; unsigned int nrec=0, step=0, stepMin=0, stepMax=0; if( argc < 2 || argc > 4 ) { fprintf(stderr,"usage: flac2vtk path [step_min [step_max]]\n\n" "Processing flac data output to VTK format.\n" "If step_max is not given, processing to latest steps\n" "If both step_min and step_max are not given, processing all steps\n"); exit(1); } /* * Set the default input/output path and range of time steps to process. */ sprintf( path, "%s", argv[1] ); /* Read the max steps */ sprintf( tmpBuf, "%s/_contents.0", path ); if( (timeStepIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } while(!feof(timeStepIn)) { fscanf( timeStepIn, "%d %d %g", &nrec, &step, &time ); } rewind( timeStepIn ); /* Set the range of steps to process. */ if( argc == 3 ) { /* Read steps from arguments */ stepMin = (unsigned int) atoi(argv[2]); stepMax = nrec; } else if( argc == 4 ) { /* Read steps from arguments */ stepMin = (unsigned int) atoi(argv[2]); stepMax = (unsigned int) atoi(argv[3]); if(stepMax > nrec) stepMax = nrec; } else { /* all steps */ stepMin = 1; stepMax = nrec; } /* Get mesh size */ sprintf( tmpBuf, "%s/nxnz.0", path ); if( (nxnzIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } fscanf( nxnzIn, "%d %d", &elementNumber[0], &elementNumber[1] ); fclose( nxnzIn ); nodeNumber[0] = elementNumber[0] + 1; nodeNumber[1] = elementNumber[1] + 1; globalNodeNumber = nodeNumber[0]*nodeNumber[1]; globalElementNumber = elementNumber[0]*elementNumber[1]; /* Print out some information */ fprintf(stderr, "Time step range: %u <-> %u, # of steps=%d\n", stepMin, stepMax, stepMax-stepMin+1 ); fprintf(stderr, "nnode:%u nelem:%u nx:%u nz:%u ex:%u ez:%u\n", globalNodeNumber, globalElementNumber, nodeNumber[0], nodeNumber[1], elementNumber[0], elementNumber[1]); /* Start processing for each rank */ rank = 0; sprintf( tmpBuf, "%s/mesh.%u", path, rank ); if( (coordIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/vel.%u", path, rank ); if( (velIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/temperature.%u", path, rank ); if( (tempIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/srII.%u", path, rank ); if( (strainRateIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/eI.%u", path, rank ); if( (eIIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/eII.%u", path, rank ); if( (eIIIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/phase.%u", path, rank ); if( (phaseIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/aps.%u", path, rank ); if( (apsIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/sII.%u", path, rank ); if( (stressIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/sxx.%u", path, rank ); if( (sxxIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/szz.%u", path, rank ); if( (szzIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/sxz.%u", path, rank ); if( (sxzIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/pres.%u", path, rank ); if( ( pressureIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); doHPr = 0; } sprintf( tmpBuf, "%s/visc.%u", path, rank ); if( (viscIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/density.%u", path, rank ); if( (densIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/src.%u", path, rank ); if( (srcIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/diss.%u", path, rank ); if( (dissIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } /* * Read in loop information and write VTK files for wanted time steps. */ for( dumpIteration = 1; dumpIteration < stepMin; dumpIteration++ ) { fscanf( timeStepIn, "%d %d %g", &junk, &step, &time ); } for( dumpIteration = stepMin-1; dumpIteration < stepMax; dumpIteration++ ) { fscanf( timeStepIn, "%d %d %g", &junk, &step, &time ); fprintf(stderr,"trying %d-th conversion: model time=%.2e Myr)\n", dumpIteration+1, time); ConvertTimeStep( rank, dumpIteration, time, globalNodeNumber, globalElementNumber, nodeNumber, elementNumber ); } /* * Close the input files */ fclose( timeStepIn ); fclose( coordIn ); fclose( velIn ); fclose( apsIn ); fclose( phaseIn ); fclose( eIIn ); fclose( eIIIn ); fclose( strainRateIn ); fclose( pressureIn ); fclose( stressIn ); fclose( sxxIn ); fclose( szzIn ); fclose( sxzIn ); fclose( tempIn ); fclose( viscIn ); fclose( densIn ); fclose( srcIn ); fclose( dissIn ); return 0; }
int main( int argc, char* argv[]) { char tmpBuf[PATH_MAX]; FILE* simIn; FILE* timeStepIn; unsigned int rank; unsigned int simTimeStep; unsigned int dumpIteration; double time; double dt; /* TODO, get from arg 1 */ sprintf( path, "./" ); rank = 0; while( 1 ) { /* open the input files */ sprintf( tmpBuf, "%s/sim.%u", path, rank ); if( (simIn = fopen( tmpBuf, "r" )) == NULL ) { if( rank == 0 ) { assert( simIn /* failed to open file for reading */ ); } else { break; } } sprintf( tmpBuf, "%s/timeStep.%u", path, rank ); if( (timeStepIn = fopen( tmpBuf, "r" )) == NULL ) { assert( timeStepIn /* failed to open file for reading */ ); } sprintf( tmpBuf, "%s/strainRate.%u", path, rank ); if( (strainRateIn = fopen( tmpBuf, "r" )) == NULL ) { assert( strainRateIn /* failed to open file for reading */ ); } sprintf( tmpBuf, "%s/stress.%u", path, rank ); if( (stressIn = fopen( tmpBuf, "r" )) == NULL ) { assert( stressIn /* failed to open file for reading */ ); } sprintf( tmpBuf, "%s/hydroPressure.%u", path, rank ); if( ( pisosIn = fopen( tmpBuf, "r" )) == NULL ) { printf( "Warning, no hydropressure.%u found... assuming the new context is not written.\n", rank ); doHPr = 0; } sprintf( tmpBuf, "%s/coord.%u", path, rank ); if( (coordIn = fopen( tmpBuf, "r" )) == NULL ) { assert( coordIn /* failed to open file for reading */ ); } sprintf( tmpBuf, "%s/vel.%u", path, rank ); if( (velIn = fopen( tmpBuf, "r" )) == NULL ) { assert( velIn /* failed to open file for reading */ ); } sprintf( tmpBuf, "%s/force.%u", path, rank ); if( (forceIn = fopen( tmpBuf, "r" )) == NULL ) { assert( forceIn /* failed to open file for reading */ ); printf( "Warning, no force.%u found... assuming force outputting not enabled.\n", rank ); doForce = 0; } sprintf( tmpBuf, "%s/phaseIndex.%u", path, rank ); if( (phaseIn = fopen( tmpBuf, "r" )) == NULL ) { assert( phaseIn /* failed to open file for reading */ ); } sprintf( tmpBuf, "%s/temperature.%u", path, rank ); if( (tempIn = fopen( tmpBuf, "r" )) == NULL ) { printf( "Warning, no temperature.%u found... assuming temperature plugin not used.\n", rank ); doTemp = 0; } sprintf( tmpBuf, "%s/plStrain.%u", path, rank ); if( (apsIn = fopen( tmpBuf, "r" )) == NULL ) { printf( "Warning, no plstrain.%u found... assuming plastic plugin not used.\n", rank ); doAps = 0; } sprintf( tmpBuf, "%s/irheology.%u", path, rank ); if( (irhIn = fopen( tmpBuf, "r" )) == NULL ) { printf( "Warning, no irheology.%u found... assuming plasticMaxwell plugin not used.\n", rank ); doIRh = 0; } sprintf( tmpBuf, "%s/viscosity.%u", path, rank ); if( (viscIn = fopen( tmpBuf, "r" )) == NULL ) { printf( "Warning, no viscosity.%u found... assuming maxwell plugin not used.\n", rank ); doVisc = 0; } /* Read in simulation information... TODO: assumes nproc=1 */ fscanf( simIn, "%u %u %u\n", &elementGlobalSize[0], &elementGlobalSize[1], &elementGlobalSize[2] ); /* Read in loop information */ dumpIteration = 0; while( !feof( timeStepIn ) ) { fscanf( timeStepIn, "%16u %16lg %16lg\n", &simTimeStep, &time, &dt ); if( argc == 3 ) if( simTimeStep < atoi(argv[1]) || simTimeStep > atoi(argv[2]) ) { dumpIteration++; continue; } ConvertTimeStep( rank, dumpIteration, simTimeStep, time ); dumpIteration++; } /* Close the input files */ if( apsIn ) { fclose( apsIn ); } if( viscIn ) { fclose( viscIn ); } if( tempIn ) { fclose( tempIn ); } if( forceIn ) { fclose( forceIn ); } if( pisosIn ) { fclose( pisosIn ); } if( irhIn ) { fclose( irhIn ); } fclose( velIn ); fclose( coordIn ); fclose( stressIn ); fclose( strainRateIn ); fclose( timeStepIn ); fclose( simIn ); /* do next rank */ rank++; } return 0; }
int main( int argc, char* argv[]) { char tmpBuf[PATH_MAX]; FILE* simIn; FILE* timeStepIn; unsigned int rank; unsigned int simTimeStep; unsigned int dumpIteration; double time; double dt; int gnode[3]; int rank_array[3]; unsigned int rankI,rankJ,rankK; unsigned int stepMin=-1,stepMax=0; float Ex=0.0; if( argc<7 || argc>10 ) { fprintf(stderr,"snac2vtk global-mesh-size-x global-mesh-size-y global-mesh-size-z num-processors-x num-processors-y num-processors-z [start-step[max-step]] [end-step[max-step]] [failure-angle[30 (degrees)]]\n"); exit(1); } /* * TODO, get from arg list */ sprintf( path, "." ); gnode[0] = atoi(argv[1]); gnode[1] = atoi(argv[2]); gnode[2] = atoi(argv[3]); rank_array[0] = atoi(argv[4]); rank_array[1] = atoi(argv[5]); rank_array[2] = atoi(argv[6]); for( rankK=0; rankK < rank_array[2]; rankK++ ) for( rankJ=0; rankJ < rank_array[1]; rankJ++ ) for( rankI=0; rankI < rank_array[0]; rankI++ ) { rank = rankI + rankJ*rank_array[0] + rankK*rank_array[0]*rank_array[1]; sprintf( tmpBuf, "%s/sim.%u", path, rank ); if( (simIn = fopen( tmpBuf, "r" )) == NULL ) { if( rank == 0 ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } else { break; } } sprintf( tmpBuf, "%s/timeStep.%u", path, rank ); if( (timeStepIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/stressTensor.%u", path, rank ); if( (stressTensorIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found\n", tmpBuf ); exit(1); } sprintf( tmpBuf, "%s/plStrain.%u", path, rank ); if( (apsIn = fopen( tmpBuf, "r" )) == NULL ) { fprintf(stderr, "\"%s\" not found... assuming plastic plugin not used\n", tmpBuf ); doAps = 0; } /* * Read in simulation information... TODO: assumes nproc=1 */ fscanf( simIn, "%u %u %u\n", &elementLocalSize[0], &elementLocalSize[1], &elementLocalSize[2] ); /* if( feof(timeStepIn) ) { */ /* fprintf(stderr, "Time step file zero length\n" ); */ /* assert(timeStepIn); */ /* } else { */ /* fscanf( timeStepIn, "%16u %16lg %16lg\n", &simTimeStep, &time, &dt ); */ /* } */ while( !feof( timeStepIn ) ) { fscanf( timeStepIn, "%16u %16lg %16lg\n", &simTimeStep, &time, &dt ); /* fprintf(stderr, "Time step: %u <-> %g\n", simTimeStep, time ); */ if(stepMin==-1) stepMin=simTimeStep; if(stepMax<simTimeStep) stepMax=simTimeStep; } if( stepMin==-1 ) { fprintf(stderr, "Time step file zero length\n" ); exit(1); } /* fseek( timeStepIn, 0, SEEK_SET ); */ rewind(timeStepIn); if(argc>=8) { if(atoi(argv[7])>stepMin) stepMin=atoi(argv[7]); } else { stepMin=stepMax; } if(argc>=9) { if(atoi(argv[8])<stepMax) stepMax=atoi(argv[8]); }/* else { */ /* stepMax=stepMin; */ /* } */ if (stepMax<stepMin) { fprintf(stderr, "Error in time step range (start/stop reversed): %u <-> %u\n", stepMin, stepMax ); exit(1); } fprintf(stderr, "Time step range: %u <-> %u\n", stepMin, stepMax ); /* * Parse angle used to compute failure potential - using global variable (ick) */ if(argc>=10) { failureAngle=atof(argv[9]); fprintf(stderr, "Failure angle = %g\n", failureAngle ); } /* * Read in loop information */ dumpIteration = 0; sprintf( tmpBuf, "%s/snac_soln.dat", path ); snacOut = fopen( tmpBuf, "w" ); while( !feof( timeStepIn ) ) { fscanf( timeStepIn, "%16u %16lg %16lg\n", &simTimeStep, &time, &dt ); if( simTimeStep <stepMin || simTimeStep > stepMax ) { dumpIteration++; continue; } fprintf(snacOut,"%e\t",Ex+(1.0e-05*time)/1.0); fprintf(stderr,"%d %e %e\t",simTimeStep,time,Ex+(1.0e-05*time)/1.0); ConvertTimeStep( rank, dumpIteration, simTimeStep, time, gnode, rank_array, rankI, rankJ, rankK ); dumpIteration++; } fclose( snacOut ); rank++; } return 0; }