diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 793d944e1..85809ca49 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -48,6 +48,8 @@ Notable changes include: * Clang C++ warnings have eliminated, so the Clang CI tests have been updated to treat warnings as errors. * Fix for installing libraries when building individual package WITH ENABLE_DEV_BUILD=On. * Bugfix for RZ solid CRKSPH with compatible energy. + * Parsing of None string now always becomes None python type. Tests have been updated accordingly. + * IO for checkpoints and visuzalization can now be properly turned off through SpheralController input options. Version v2024.06.1 -- Release date 2024-07-09 ============================================== diff --git a/src/PYB11/Utilities/Utilities_PYB11.py b/src/PYB11/Utilities/Utilities_PYB11.py index 2f409cded..706ed6392 100644 --- a/src/PYB11/Utilities/Utilities_PYB11.py +++ b/src/PYB11/Utilities/Utilities_PYB11.py @@ -819,7 +819,7 @@ def clippedVolume(poly = "const Dim<3>::FacetedVolume&", ("long", "Long"), ("double", "Scalar"), ("std::string", "String")): - exec(""" -adiak_value%(label)s = PYB11TemplateFunction(adiak_value, "%(value)s") -adiak_value2%(label)s = PYB11TemplateFunction(adiak_value2, "%(value)s", pyname="adiak_value%(label)s") -""" % {"label" : label, "value" : value}) + exec(f""" +adiak_value{label} = PYB11TemplateFunction(adiak_value, "{value}", pyname="adiak_value") +adiak_value2{label} = PYB11TemplateFunction(adiak_value2, "{value}", pyname="adiak_value") +""") diff --git a/src/SimulationControl/CMakeLists.txt b/src/SimulationControl/CMakeLists.txt index 4310e577a..32f7ca438 100644 --- a/src/SimulationControl/CMakeLists.txt +++ b/src/SimulationControl/CMakeLists.txt @@ -60,6 +60,7 @@ spheral_install_python_files( SpheralPolytopeSiloDump.py Spheral1dVizDump.py SpheralMatplotlib.py + SpheralTimingParser.py findLastRestart.py Pnorm.py filearraycmp.py diff --git a/src/SimulationControl/SpheralController.py b/src/SimulationControl/SpheralController.py index 7e903af17..033bc6bb9 100644 --- a/src/SimulationControl/SpheralController.py +++ b/src/SimulationControl/SpheralController.py @@ -5,6 +5,7 @@ from SpheralCompiledPackages import * from SpheralTimer import SpheralTimer +from SpheralUtilities import adiak_value from SpheralConservation import SpheralConservation from GzipFileIO import GzipFileIO from SpheralTestUtilities import globalFrame @@ -52,6 +53,7 @@ def __init__(self, integrator, volumeType = RKVolumeType.RKVoronoiVolume, facetedBoundaries = None, printAllTimers = False): + self.restartBaseName = restartBaseName self.restart = RestartableObject(self) self.integrator = integrator self.restartObjects = restartObjects @@ -80,6 +82,7 @@ def __init__(self, integrator, # Determine the dimensionality of this run, based on the integrator. self.dim = "%id" % self.integrator.dataBase.nDim + adiak_value("dim", self.dim) # Determine the visualization method. if self.dim == "1d": @@ -100,8 +103,11 @@ def __init__(self, integrator, self.insertDistributedBoundary(integrator.physicsPackages()) # Should we look for the last restart set? - if restoreCycle == -1: - restoreCycle = findLastRestart(restartBaseName) + if restartBaseName: + if restoreCycle == -1: + restoreCycle = findLastRestart(restartBaseName) + else: + restoreCycle = None # Generic initialization work. self.reinitializeProblem(restartBaseName, @@ -181,7 +187,8 @@ def reinitializeProblem(self, restartBaseName, vizBaseName, self._periodicTimeWork = [] # Set the restart file base name. - self.setRestartBaseName(restartBaseName) + if restartBaseName: + self.setRestartBaseName(restartBaseName) # Set the simulation time. self.integrator.currentTime = initialTime @@ -393,9 +400,12 @@ def advance(self, goalTime, maxSteps=None): numActualGhostNodes = 0 for bc in bcs: numActualGhostNodes += bc.numGhostNodes - print("Total number of (internal, ghost, active ghost) nodes : (%i, %i, %i)" % (mpi.allreduce(db.numInternalNodes, mpi.SUM), - mpi.allreduce(db.numGhostNodes, mpi.SUM), - mpi.allreduce(numActualGhostNodes, mpi.SUM))) + numInternal = db.globalNumInternalNodes + numGhost = db.globalNumGhostNodes + numActGhost = mpi.allreduce(numActualGhostNodes, mpi.SUM) + print(f"Total number of (internal, ghost, active ghost) nodes : ({numInternal}, {numGhost}, {numActGhost})") + adiak_value("total_internal_nodes", numInternal) + adiak_value("total_ghost_nodes", numGhost) # Print how much time was spent per integration cycle. self.stepTimer.printStatus() @@ -566,6 +576,8 @@ def findname(thing): #-------------------------------------------------------------------------- def dropRestartFile(self): + if not self.restartBaseName: + return # First find out if the requested directory exists. import os dire = os.path.dirname(os.path.abspath(self.restartBaseName)) @@ -594,6 +606,8 @@ def dropRestartFile(self): def loadRestartFile(self, restoreCycle, frameDict=None): + if not self.restartBaseName: + return # Find out if the requested file exists. import os fileName = self.restartBaseName + "_cycle%i" % restoreCycle diff --git a/src/SimulationControl/SpheralOptionParser.py b/src/SimulationControl/SpheralOptionParser.py index 7f45e26c0..7903f5273 100644 --- a/src/SimulationControl/SpheralOptionParser.py +++ b/src/SimulationControl/SpheralOptionParser.py @@ -7,16 +7,26 @@ from SpheralCompiledPackages import * from SpheralTestUtilities import globalFrame -from SpheralUtilities import TimerMgr +import SpheralTimingParser + +def parse_value(value): + gd = globalFrame().f_globals + try: + return eval(value, gd) + except: + return value def commandLine(**options): # Build a command line parser with the keyword arguments passed to us. parser = argparse.ArgumentParser() - for key in options: - parser.add_argument("--" + key, - dest = key, - default = options[key]) + for key, default in options.items(): + if default == "None": + raise SyntaxError(f"ERROR: {key}, None as a default value cannot be a string") + elif type(default) is str: + parser.add_argument(f"--{key}", type = str, default = default) + else: + parser.add_argument(f"--{key}", type = parse_value, default = default) # Add the universal options supported by all Spheral++ scripts. parser.add_argument("-v", "--verbose", @@ -24,19 +34,14 @@ def commandLine(**options): dest = "verbose", default = False, help = "Verbose output -- print all options that were set.") - parser.add_argument("--caliperConfig", default="", type=str) - parser.add_argument("--caliperFilename", default="", type=str) - parser.add_argument("--caliperConfigJSON", default="", type=str) + + # Parse Caliper and Adiak inputs + SpheralTimingParser.add_timing_args(parser) + # Evaluate the command line. args = parser.parse_args() arg_dict = vars(args) - if (not TimerMgr.timers_usable()): - if (args.caliperConfig or args.caliperFilename or args.caliperConfigJSON): - print("WARNING: Caliper command line inputs provided for "+\ - "non-timer install. Reconfigure the install with "+\ - "-DENABLE_TIMER=ON to be able to use Caliper timers.") - # Verbose output? if args.verbose: print("All parameters set:") @@ -46,46 +51,12 @@ def commandLine(**options): print(" * ", key, " = ", val) else: print(" ", key, " = ", val) - if (args.caliperConfig): - print(" * caliperConfig = ", args.caliperConfig) - if (args.caliperFilename): - print(" * caliperFilename = ", args.caliperFilename) - if (args.caliperConfigJSON): - print(" * caliperConfigJSON = ", args.caliperConfigJSON) # Set all the variables. gd = globalFrame().f_globals for key, val in arg_dict.items(): - if key in options: - if (type(val) != type(options[key])): - val = eval(val, gd) + if val == "None": + val = None gd[key] = val - # Initialize timers - InitTimers(args.caliperConfig, args.caliperFilename, args.caliperConfigJSON) - return - -def InitTimers(caliper_config, filename, caliper_json): - if(caliper_json): - TimerMgr.load(caliper_json) - if(not caliper_config): - raise RuntimeError("SpheralOptionParser: specifying a configuration file without using one of the configurations means no timers are started") - off_tests = ["none", "off", "disable", "disabled", "0"] - if (caliper_config.lower() in off_tests): - return - elif (caliper_config): - TimerMgr.add(caliper_config) - TimerMgr.start() - else: - import os, sys - if (filename): - testname = filename - else: - from datetime import datetime - # Append the current day and time to the filename - unique_digits = datetime.now().strftime("_%Y_%m_%d_%H%M%S_%f") - # Name file based on name of python file being run - testname = os.path.splitext(os.path.basename(sys.argv[0]))[0] - testname += unique_digits + ".cali" - TimerMgr.default_start(testname) - adiak_valueInt("threads_per_rank", omp_get_num_threads()) - adiak_valueInt("num_ranks", mpi.procs) + # Initialize timers and add inputs as Adiak metadata + SpheralTimingParser.init_timer(args) return diff --git a/src/SimulationControl/SpheralTimingParser.py b/src/SimulationControl/SpheralTimingParser.py new file mode 100644 index 000000000..af1935fdb --- /dev/null +++ b/src/SimulationControl/SpheralTimingParser.py @@ -0,0 +1,100 @@ +#------------------------------------------------------------------------------- +# Functions for adding Caliper and Adiak parsing arguments and initializing +# the timer manager +#------------------------------------------------------------------------------- + +import argparse, mpi +from SpheralUtilities import TimerMgr +from SpheralUtilities import adiak_value +import SpheralOpenMP + +cali_args = ["caliperConfig", "caliperFilename", "caliperConfigJSON"] + +def parse_dict(string): + """ + Function to parse a dictionary provided through the command line + """ + try: + inp_dict = dict(item.split(":") for item in string.split(",")) + except: + raise SyntaxError("Input to --adiakData must be in key:value format, separated by commas") + new_dict = {} + for ikey, ival in inp_dict.items(): + try: + key = eval(ikey) + except: + key = ikey.strip() + try: + val = eval(ival) + except: + val = ival.strip() + new_dict.update({key: val}) + return new_dict + +def add_timing_args(parser): + """ + Add Caliper and Adiak arguments to the parser + """ + # Allow Adiak values to be set on the command line + # Inputs are a string that can be evaluated into a dictionary + # For example, --adiakData "testname: ShockTube1, testing:3" + parser.add_argument("--adiakData", default=None, + type=parse_dict) + # This logic checks if the user already set a Caliper + # argument and default value and prevents adding the argument + # if it already exists + arg_list = [action.dest for action in parser._actions] + for ca in cali_args: + if (ca not in arg_list): + parser.add_argument(f"--{ca}", default="", type=str) + +def init_timer(args): + """ + Initializes the timing manager and adds input values to Adiak from parsed arguments + """ + if args.verbose: + if (args.caliperConfig): + print(" * caliperConfig = ", args.caliperConfig) + if (args.caliperFilename): + print(" * caliperFilename = ", ars.caliperFilename) + if (args.caliperConfigJSON): + print(" * caliperConfigJSON = ", args.caliperConfigJSON) + if (not TimerMgr.timers_usable()): + if (args.caliperConfig or args.caliperFilename or args.caliperConfigJSON): + print("WARNING: Caliper command line inputs provided for "+\ + "non-timer install. Reconfigure the install with "+\ + "-DENABLE_TIMER=ON to be able to use Caliper timers.") + if(args.caliperConfigJSON): + TimerMgr.load(args.caliperConfigJSON) + if(not args.caliperConfig): + raise RuntimeError("SpheralOptionParser: specifying a configuration file without "+\ + "using one of the configurations means no timers are started") + off_tests = ["none", "off", "disable", "disabled", "0"] + # Check if Caliper is turned off + if (args.caliperConfig): + if (args.caliperConfig.lower() in off_tests): + return + TimerMgr.add(args.caliperConfig) + TimerMgr.start() + else: + import os, sys + # If output name for Caliper is given, use it + if (args.caliperFilename): + testname = args.caliperFilename + else: + from datetime import datetime + # Append the current day and time to the filename + unique_digits = datetime.now().strftime("_%Y_%m_%d_%H%M%S_%f") + # Name file based on name of python file being run + testname = os.path.splitext(os.path.basename(sys.argv[0]))[0] + testname += unique_digits + ".cali" + TimerMgr.default_start(testname) + # Add number of ranks and threads per rank + adiak_value("threads_per_rank", SpheralOpenMP.omp_get_num_threads()) + adiak_value("num_ranks", mpi.procs) + + # Add --adiakData inputs as Adiak metadata + if (args.adiakData): + for key, val in args.adiakData.items(): + adiak_value(key, val) + return diff --git a/tests/functional/Damage/TensileDisk/TensileDisk-2d.py b/tests/functional/Damage/TensileDisk/TensileDisk-2d.py index 94c35df66..e512ad874 100644 --- a/tests/functional/Damage/TensileDisk/TensileDisk-2d.py +++ b/tests/functional/Damage/TensileDisk/TensileDisk-2d.py @@ -75,7 +75,7 @@ plotFlaws = False, clearDirectories = False, dataDirBase = "dumps-TensileDisk-2d", - outputFile = "None", + outputFile = None, # Should we restart (-1 => find most advanced available restart) restoreCycle = -1, diff --git a/tests/functional/Damage/TensileRod/TensileRod-1d.py b/tests/functional/Damage/TensileRod/TensileRod-1d.py index 4610a2c2c..eb1478c9f 100644 --- a/tests/functional/Damage/TensileRod/TensileRod-1d.py +++ b/tests/functional/Damage/TensileRod/TensileRod-1d.py @@ -171,8 +171,8 @@ def restoreState(self, file, path): clearDirectories = False, referenceFile = "Reference/TensileRod-GradyKippOwen-1d-1proc-reproducing-20240816.gnu", dataDirBase = "dumps-TensileRod-1d", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, ) # On the IBM BlueOS machines we have some tolerance issues... @@ -744,7 +744,7 @@ def restoreState(self, file, path): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: from SpheralTestUtilities import multiSort state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) @@ -786,7 +786,7 @@ def restoreState(self, file, path): # Also we can optionally compare the current results with another file for # bit level consistency. #--------------------------------------------------------------------------- - if comparisonFile != "None" and BuildData.cxx_compiler_id != "IntelLLVM": + if comparisonFile and BuildData.cxx_compiler_id != "IntelLLVM": comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Damage/TensileRod/TensileRod-2d.py b/tests/functional/Damage/TensileRod/TensileRod-2d.py index 65dd5fadd..efc9a3283 100644 --- a/tests/functional/Damage/TensileRod/TensileRod-2d.py +++ b/tests/functional/Damage/TensileRod/TensileRod-2d.py @@ -166,7 +166,7 @@ def restoreState(self, file, path): clearDirectories = False, dataDirBase = "dumps-TensileRod-2d", - outputFile = "None", + outputFile = None, ) dx = xlength/nx diff --git a/tests/functional/Gravity/CollisionlessSphereCollapse.py b/tests/functional/Gravity/CollisionlessSphereCollapse.py index 13545182f..e30313858 100644 --- a/tests/functional/Gravity/CollisionlessSphereCollapse.py +++ b/tests/functional/Gravity/CollisionlessSphereCollapse.py @@ -263,7 +263,7 @@ #------------------------------------------------------------------------------- # If requested, write out the profiles #------------------------------------------------------------------------------- -if outputFile != "None" and mpi.rank == 0: +if outputFile and mpi.rank == 0: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 14*"%15s " + "\n") % ("r", "x", "y", "z", "vx", "vy", "vz", "Hxx", "Hxy", "Hxz", "Hyy", "Hyz", "Hzz", "phi")) diff --git a/tests/functional/Hydro/AcousticWave/AcousticWave-1d.py b/tests/functional/Hydro/AcousticWave/AcousticWave-1d.py index e9318205f..761c5f21c 100644 --- a/tests/functional/Hydro/AcousticWave/AcousticWave-1d.py +++ b/tests/functional/Hydro/AcousticWave/AcousticWave-1d.py @@ -469,7 +469,7 @@ def printTotalEnergy(cycle,time,dt): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mprof = mpi.reduce(nodes1.mass().internalValues(), mpi.SUM) @@ -500,7 +500,7 @@ def printTotalEnergy(cycle,time,dt): # While we're at it compute and report the error norms. import Pnorm print("\tQuantity \t\tL1 \t\t\tL2 \t\t\tLinf") - if normOutputFile != "None": + if normOutputFile: f = open(normOutputFile, "a") if writeOutputLabel: f.write(("#" + 13*"%17s " + "\n") % ('"nx"', @@ -522,12 +522,12 @@ def printTotalEnergy(cycle,time,dt): L2 = Pn.gridpnorm(2, xmin, xmax) Linf = Pn.gridpnorm("inf", xmin, xmax) print("\t%s \t\t%g \t\t%g \t\t%g" % (name, L1, L2, Linf)) - if normOutputFile != "None": + if normOutputFile: f.write((3*"%16.12e ") % (L1, L2, Linf)) # if name == "Mass Density": # pickleDumpL1 = L1 - if normOutputFile != "None": + if normOutputFile: f.write("\n") f.close() diff --git a/tests/functional/Hydro/AcousticWave/AcousticWave-1d_gamma2.py b/tests/functional/Hydro/AcousticWave/AcousticWave-1d_gamma2.py index a4ad8b963..fb170d66c 100644 --- a/tests/functional/Hydro/AcousticWave/AcousticWave-1d_gamma2.py +++ b/tests/functional/Hydro/AcousticWave/AcousticWave-1d_gamma2.py @@ -96,7 +96,7 @@ def smooth(x,window_len=11,window='hanning'): clearDirectories = True, dataDirBase = "dumps-planar-AcousticWave-1d", outputFile = "AcousticWave-planar-1d.gnu", - normOutputFile = "None", + normOutputFile = None, writeOutputLabel = True, graphics = "gnu", @@ -424,7 +424,7 @@ def __call__(self, x): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mprof = mpi.reduce(nodes1.mass().internalValues(), mpi.SUM) @@ -459,7 +459,7 @@ def __call__(self, x): # While we're at it compute and report the error norms. import Pnorm print("\tQuantity \t\tL1 \t\t\tL2 \t\t\tLinf") - if normOutputFile != "None": + if normOutputFile: f = open(normOutputFile, "a") if writeOutputLabel: f.write(("#" + 13*"%17s " + "\n") % ('"nx"', @@ -480,9 +480,9 @@ def __call__(self, x): L2 = Pn.pnormAverage(2, xmin, xmax) Linf = Pn.pnormAverage("inf", xmin, xmax) print("\t%s \t\t%g \t\t%g \t\t%g" % (name, L1, L2, Linf)) - if normOutputFile != "None": + if normOutputFile: f.write((3*"%16.12e ") % (L1, L2, Linf)) - if normOutputFile != "None": + if normOutputFile: f.write("\n") f.close() diff --git a/tests/functional/Hydro/AcousticWave/StandingWave-1d.py b/tests/functional/Hydro/AcousticWave/StandingWave-1d.py index 4cfa18521..8cf0d6a7f 100644 --- a/tests/functional/Hydro/AcousticWave/StandingWave-1d.py +++ b/tests/functional/Hydro/AcousticWave/StandingWave-1d.py @@ -70,7 +70,7 @@ clearDirectories = True, dataDirBase = "dumps-planar-StandingWave-1d", outputFile = "StandingWave-planar-1d.gnu", - normOutputFile = "None", + normOutputFile = None, writeOutputLabel = True, graphics = "gnu", @@ -369,7 +369,7 @@ def Minterval(xi0, xi1): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mprof = mpi.reduce(nodes1.mass().internalValues(), mpi.SUM) @@ -405,7 +405,7 @@ def Minterval(xi0, xi1): # While we're at it compute and report the error norms. import Pnorm print("\tQuantity \t\tL1 \t\t\tL2 \t\t\tLinf") - if normOutputFile != "None": + if normOutputFile: f = open(normOutputFile, "a") if writeOutputLabel: f.write(("#" + 13*"%17s " + "\n") % ('"nx"', @@ -426,9 +426,9 @@ def Minterval(xi0, xi1): L2 = Pn.gridpnorm(2, xmin, xmax) Linf = Pn.gridpnorm("inf", xmin, xmax) print("\t%s \t\t%g \t\t%g \t\t%g" % (name, L1, L2, Linf)) - if normOutputFile != "None": + if normOutputFile: f.write((3*"%16.12e ") % (L1, L2, Linf)) - if normOutputFile != "None": + if normOutputFile: f.write("\n") f.close() diff --git a/tests/functional/Hydro/ConvectionTest/ConvectionTest.py b/tests/functional/Hydro/ConvectionTest/ConvectionTest.py index 59a15aaab..ef547f40b 100644 --- a/tests/functional/Hydro/ConvectionTest/ConvectionTest.py +++ b/tests/functional/Hydro/ConvectionTest/ConvectionTest.py @@ -151,9 +151,6 @@ def finalize(self, t, dt, db, state, derivs): redistributeStep = 500, checkRestart = False, dataDir = "dumps-Convection-Test-2d", - outputFile = "None", - comparisonFile = "None", - serialDump = False, #whether to dump a serial ascii file at the end for viz bArtificialConduction = False, diff --git a/tests/functional/Hydro/Discontinuity/Discontinuity.py b/tests/functional/Hydro/Discontinuity/Discontinuity.py index eab0bd9b8..1f40ee886 100644 --- a/tests/functional/Hydro/Discontinuity/Discontinuity.py +++ b/tests/functional/Hydro/Discontinuity/Discontinuity.py @@ -2,8 +2,8 @@ #ATS:t1 = testif(t0, SELF, "--graphics None --clearDirectories False --checkError False --restartStep 20 --restoreCycle 20 --steps 20 --checkRestart True", label="Planar Noh problem -- 1-D (serial) RESTART CHECK") #ATS:t2 = test( SELF, "--graphics None --clearDirectories True --checkError True --dataDir 'dumps-planar-restartcheck' --restartStep 20", np=2, label="Planar Noh problem -- 1-D (parallel)") #ATS:t3 = testif(t2, SELF, "--graphics None --clearDirectories False --checkError False --dataDir 'dumps-planar-restartcheck' --restartStep 20 --restoreCycle 20 --steps 20 --checkRestart True", np=2, label="Planar Noh problem -- 1-D (parallel) RESTART CHECK") -#ATS:t4 = test( SELF, "--graphics None --clearDirectories True --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True --outputFile 'Noh-planar-1proc-reproducing.txt'", label="Planar Noh problem -- 1-D (serial reproducing test setup)") -#ATS:t5 = testif(t4, SELF, "--graphics None --clearDirectories False --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True --outputFile 'Noh-planar-4proc-reproducing.txt' --comparisonFile 'Noh-planar-1proc-reproducing.txt'", np=4, label="Planar Noh problem -- 1-D (4 proc reproducing test)") +#ATS:t4 = test( SELF, "--graphics None --clearDirectories True --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True", label="Planar Noh problem -- 1-D (serial reproducing test setup)") +#ATS:t5 = testif(t4, SELF, "--graphics None --clearDirectories False --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True", np=4, label="Planar Noh problem -- 1-D (4 proc reproducing test)") #------------------------------------------------------------------------------- # The Planar Noh test case run in 1-D. # @@ -91,8 +91,6 @@ restartStep = 10000, dataDir = "dumps-planar", restartBaseName = "Noh-planar-1d", - outputFile = "None", - comparisonFile = "None", # Parameters for the test scalePressure = 5.0, diff --git a/tests/functional/Hydro/Discontinuity/Discontinuity2d.py b/tests/functional/Hydro/Discontinuity/Discontinuity2d.py index 42305e3bb..afe76d223 100644 --- a/tests/functional/Hydro/Discontinuity/Discontinuity2d.py +++ b/tests/functional/Hydro/Discontinuity/Discontinuity2d.py @@ -2,8 +2,8 @@ #ATS:t1 = testif(t0, SELF, "--graphics None --clearDirectories False --checkError False --restartStep 20 --restoreCycle 20 --steps 20 --checkRestart True", label="Planar Noh problem -- 1-D (serial) RESTART CHECK") #ATS:t2 = test( SELF, "--graphics None --clearDirectories True --checkError True --dataDir 'dumps-planar-restartcheck' --restartStep 20", np=2, label="Planar Noh problem -- 1-D (parallel)") #ATS:t3 = testif(t2, SELF, "--graphics None --clearDirectories False --checkError False --dataDir 'dumps-planar-restartcheck' --restartStep 20 --restoreCycle 20 --steps 20 --checkRestart True", np=2, label="Planar Noh problem -- 1-D (parallel) RESTART CHECK") -#ATS:t4 = test( SELF, "--graphics None --clearDirectories True --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True --outputFile 'Noh-planar-1proc-reproducing.txt'", label="Planar Noh problem -- 1-D (serial reproducing test setup)") -#ATS:t5 = testif(t4, SELF, "--graphics None --clearDirectories False --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True --outputFile 'Noh-planar-4proc-reproducing.txt' --comparisonFile 'Noh-planar-1proc-reproducing.txt'", np=4, label="Planar Noh problem -- 1-D (4 proc reproducing test)") +#ATS:t4 = test( SELF, "--graphics None --clearDirectories True --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True", label="Planar Noh problem -- 1-D (serial reproducing test setup)") +#ATS:t5 = testif(t4, SELF, "--graphics None --clearDirectories False --checkError True --dataDir 'dumps-planar-reproducing' --domainIndependent True", np=4, label="Planar Noh problem -- 1-D (4 proc reproducing test)") #------------------------------------------------------------------------------- # The Planar Noh test case run in 1-D. # @@ -100,9 +100,7 @@ redistributeStep = 200, dataDir = "dumps-planar", restartBaseName = "Noh-planar-1d", - outputFile = "None", - comparisonFile = "None", - + # Parameters for the test scalePressure = 5.0, scaleEnergy = 2.0, diff --git a/tests/functional/Hydro/FreeExpansion/FreeExpansion-1d.py b/tests/functional/Hydro/FreeExpansion/FreeExpansion-1d.py index d0a758fe5..89107c71f 100644 --- a/tests/functional/Hydro/FreeExpansion/FreeExpansion-1d.py +++ b/tests/functional/Hydro/FreeExpansion/FreeExpansion-1d.py @@ -309,7 +309,7 @@ def smooth(x,window_len=11,window='hanning'): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mprof = mpi.reduce(nodes1.mass().internalValues(), mpi.SUM) diff --git a/tests/functional/Hydro/FreeExpansion/FreeExpansion-2d.py b/tests/functional/Hydro/FreeExpansion/FreeExpansion-2d.py index 131da235c..eb58918ce 100644 --- a/tests/functional/Hydro/FreeExpansion/FreeExpansion-2d.py +++ b/tests/functional/Hydro/FreeExpansion/FreeExpansion-2d.py @@ -369,7 +369,7 @@ def smooth(x,window_len=11,window='hanning'): # #------------------------------------------------------------------------------- # # If requested, write out the state in a global ordering to a file. # #------------------------------------------------------------------------------- -# if outputFile != "None": +# if outputFile: # outputFile = os.path.join(dataDir, outputFile) # from SpheralTestUtilities import multiSort # mprof = mpi.reduce(nodes1.mass().internalValues(), mpi.SUM) diff --git a/tests/functional/Hydro/GreshoVortex/GreshoVortex.py b/tests/functional/Hydro/GreshoVortex/GreshoVortex.py index e8c83f091..74935250f 100644 --- a/tests/functional/Hydro/GreshoVortex/GreshoVortex.py +++ b/tests/functional/Hydro/GreshoVortex/GreshoVortex.py @@ -130,7 +130,7 @@ dataDir = "dumps-greshovortex-xy", graphics = True, smooth = None, - outputFile = "None", + outputFile = None, ) assert not(boolReduceViscosity and boolCullenViscosity) @@ -547,7 +547,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(baseDir, outputFile) from SpheralTestUtilities import multiSort P = ScalarField("pressure", nodes) diff --git a/tests/functional/Hydro/GreshoVortex/GreshoVortexOverlay.py b/tests/functional/Hydro/GreshoVortex/GreshoVortexOverlay.py index 14be3257d..13c17d458 100644 --- a/tests/functional/Hydro/GreshoVortex/GreshoVortexOverlay.py +++ b/tests/functional/Hydro/GreshoVortex/GreshoVortexOverlay.py @@ -123,7 +123,6 @@ dataDir = "dumps-greshovortex-xy", graphics = True, smooth = None, - outputFile = "None", ) assert not(boolReduceViscosity and boolCullenViscosity) diff --git a/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d.py b/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d.py index 51d7ae2ed..7bce63678 100644 --- a/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d.py +++ b/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d.py @@ -146,8 +146,7 @@ redistributeStep = 500, checkRestart = False, dataDir = "dumps-KelvinHelmholtz-2d", - outputFile = "None", - comparisonFile = "None", + serialDump = False, #whether to dump a serial ascii file at the end for viz ) diff --git a/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d_McNally.py b/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d_McNally.py index b0f2ce737..8108fc867 100644 --- a/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d_McNally.py +++ b/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-2d_McNally.py @@ -151,8 +151,6 @@ redistributeStep = None, checkRestart = False, dataDir = "dumps-KelvinHelmholtz-2d_McNally", - outputFile = "None", - comparisonFile = "None", graphMixing = False, mixInterval = 0.02, mixFile = "MixingModeAmp.gnu", diff --git a/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-3d.py b/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-3d.py index 4091c56fa..c17ca4d32 100644 --- a/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-3d.py +++ b/tests/functional/Hydro/KelvinHelmholtz/KelvinHelmholtz-3d.py @@ -106,8 +106,7 @@ redistributeStep = 500, checkRestart = False, dataDir = "dumps-KelvinHelmholtz-3d", - outputFile = "None", - + bArtificialConduction = False, arCondAlpha = 0.5, ) diff --git a/tests/functional/Hydro/KeplerDisk/TwoMatDisk.py b/tests/functional/Hydro/KeplerDisk/TwoMatDisk.py index 26b529200..4fcd27303 100644 --- a/tests/functional/Hydro/KeplerDisk/TwoMatDisk.py +++ b/tests/functional/Hydro/KeplerDisk/TwoMatDisk.py @@ -160,8 +160,8 @@ def __call__(self, cycle, time, dt): dataDir = "twomat-%i", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, vizCycle = None, vizTime = 1.0, @@ -503,7 +503,7 @@ def __call__(self,r): else: control.step(steps) -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort P1 = ScalarField("pressure",diskNodes1) @@ -558,7 +558,7 @@ def __call__(self,r): f.write((7*"%16.12e "+"\n") % (ri,xi,yi,rhoi,Pi,vi,mi)) f.close() - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile,comparisonFile) diff --git a/tests/functional/Hydro/Noh/Noh-RZ.py b/tests/functional/Hydro/Noh/Noh-RZ.py index 6e5be1246..0a7c94353 100644 --- a/tests/functional/Hydro/Noh/Noh-RZ.py +++ b/tests/functional/Hydro/Noh/Noh-RZ.py @@ -118,8 +118,8 @@ restartStep = 10000, dataDirBase = "dump-rz-Noh", outputFile = "Noh-RZ.gnu", - comparisonFile = "None", - normOutputFile = "None", + comparisonFile = None, + normOutputFile = None, writeOutputLabel = True, graphics = True, @@ -453,7 +453,7 @@ for i in range(len(rho)): L1 = L1 + abs(rho[i]-rhoans[i]) L1_tot = L1 / len(rho) -# if mpi.rank == 0 and outputFile != "None": +# if mpi.rank == 0 and outputFile: # print "L1=",L1_tot,"\n" # with open("Converge.txt", "a") as myfile: # myfile.write("%s %s\n" % (nz, L1_tot)) @@ -567,7 +567,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) @@ -582,7 +582,7 @@ # failure = False # hD = [] -# if normOutputFile != "None": +# if normOutputFile: # f = open(normOutputFile, "a") # if writeOutputLabel: # f.write(("#" + 13*"%17s " + "\n") % ('"n"', @@ -605,7 +605,7 @@ # L2 = Pn.gridpnorm(2, rmin, rmax) # Linf = Pn.gridpnorm("inf", rmin, rmax) # print "\t%s \t\t%g \t\t%g \t\t%g" % (name, L1, L2, Linf) -# if normOutputFile != "None": +# if normOutputFile: # f.write((3*"%16.12e ") % (L1, L2, Linf)) # hD.append([L1,L2,Linf]) @@ -627,7 +627,7 @@ # # failure = True # # if failure: # # raise ValueError, "Error bounds violated." -# # if normOutputFile != "None": +# # if normOutputFile: # # f.write("\n") # # # print "%d\t %g\t %g\t %g\t %g\t %g\t %g\t %g\t %g\t %g\t %g\t %g\t %g\t" % (nz,hD[0][0],hD[1][0],hD[2][0],hD[3][0], diff --git a/tests/functional/Hydro/Noh/Noh-cylindrical-2d.py b/tests/functional/Hydro/Noh/Noh-cylindrical-2d.py index 4cbb98ea8..26c06cffc 100644 --- a/tests/functional/Hydro/Noh/Noh-cylindrical-2d.py +++ b/tests/functional/Hydro/Noh/Noh-cylindrical-2d.py @@ -169,8 +169,9 @@ restartStep = 1000, checkRestart = False, dataDir = "dumps-cylindrical-Noh", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, + doCompare = True, graphics = True, ) @@ -219,19 +220,23 @@ if solid: hydroname = "Solid" + hydroname -dataDir = os.path.join(dataDir, - hydroname, - "nPerh=%f" % nPerh, - "compatibleEnergy=%s" % compatibleEnergy, - "Cullen=%s" % boolCullenViscosity, - "xfilter=%f" % xfilter, - "fhourglass=%f" % fhourglass, - "%s" % nodeMotion, - "nrad=%i_ntheta=%i" % (nRadial, nTheta)) -restartDir = os.path.join(dataDir, "restarts") -restartBaseName = os.path.join(restartDir, "Noh-cylindrical-2d-%ix%i" % (nRadial, nTheta)) - -vizDir = os.path.join(dataDir, "visit") +if dataDir: + dataDir = os.path.join(dataDir, + hydroname, + "nPerh=%f" % nPerh, + "compatibleEnergy=%s" % compatibleEnergy, + "Cullen=%s" % boolCullenViscosity, + "xfilter=%f" % xfilter, + "fhourglass=%f" % fhourglass, + "%s" % nodeMotion, + "nrad=%i_ntheta=%i" % (nRadial, nTheta)) + restartDir = os.path.join(dataDir, "restarts") + restartBaseName = os.path.join(restartDir, "Noh-cylindrical-2d-%ix%i" % (nRadial, nTheta)) + vizDir = os.path.join(dataDir, "visit") +else: + restartBaseName = None + vizDir = None + if vizTime is None and vizCycle is None: vizBaseName = None else: @@ -240,7 +245,7 @@ #------------------------------------------------------------------------------- # Check if the necessary output directories exist. If not, create them. #------------------------------------------------------------------------------- -if mpi.rank == 0: +if mpi.rank == 0 and dataDir: if clearDirectories and os.path.exists(dataDir): shutil.rmtree(dataDir) if not os.path.exists(restartDir): @@ -613,6 +618,10 @@ control.updateViz(control.totalSteps, integrator.currentTime, 0.0) control.dropRestartFile() +# If running the performance test, stop here +if not doCompare: + sys.exit(0) + #------------------------------------------------------------------------------- # Plot the results. #------------------------------------------------------------------------------- @@ -726,7 +735,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort P = ScalarField("pressure", nodes1) @@ -780,7 +789,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Hydro/Noh/Noh-planar-1d.py b/tests/functional/Hydro/Noh/Noh-planar-1d.py index bd4fd33d6..a60cdf04a 100644 --- a/tests/functional/Hydro/Noh/Noh-planar-1d.py +++ b/tests/functional/Hydro/Noh/Noh-planar-1d.py @@ -174,10 +174,11 @@ restartBaseName = "Noh-planar-1d", restartFileConstructor = SiloFileIO, SPIOFileCountPerTimeslice = None, - outputFile = "None", - comparisonFile = "None", - normOutputFile = "None", + outputFile = None, + comparisonFile = None, + normOutputFile = None, writeOutputLabel = True, + doCompare = True, # Parameters for the test acceptance., tol = 1.0e-5, @@ -206,15 +207,20 @@ if solid: hydroPath = "Solid" + hydroPath -dataDir = os.path.join(dataDirBase, - hydroPath, - "nPerh=%f" % nPerh, - "compatibleEnergy=%s" % compatibleEnergy, - "fhourglass=%s" % fhourglass, - "Cullen=%s" % boolCullenViscosity, - "filter=%f" % filter) -restartDir = os.path.join(dataDir, "restarts") -restartBaseName = os.path.join(restartDir, "Noh-planar-1d-%i" % nx1) +if dataDirBase: + dataDir = os.path.join(dataDirBase, + hydroPath, + "nPerh=%f" % nPerh, + "compatibleEnergy=%s" % compatibleEnergy, + "fhourglass=%s" % fhourglass, + "Cullen=%s" % boolCullenViscosity, + "filter=%f" % filter) + restartDir = os.path.join(dataDir, "restarts") + restartBaseName = os.path.join(restartDir, "Noh-planar-1d-%i" % nx1) +else: + dataDir = None + restartDir = None + restartBaseName = None dx = (x1 - x0)/nx1 @@ -672,6 +678,9 @@ control.step(5) control.advance(goalTime, maxSteps) +# If running the performance test, stop here +if not doCompare: + sys.exit(0) #------------------------------------------------------------------------------- # Compute the analytic answer. @@ -699,12 +708,12 @@ Aans = [Pi/rhoi**gamma for (Pi, rhoi) in zip(Pans, rhoans)] L1 = 0.0 for i in range(len(rho)): - L1 = L1 + abs(rho[i]-rhoans[i]) + L1 = L1 + abs(rho[i]-rhoans[i]) L1_tot = L1 / len(rho) -if mpi.rank == 0 and outputFile != "None": - print("L1=",L1_tot,"\n") - with open("Converge.txt", "a") as myfile: - myfile.write("%s %s\n" % (nx1, L1_tot)) +if mpi.rank == 0 and outputFile: + print("L1=",L1_tot,"\n") + with open("Converge.txt", "a") as myfile: + myfile.write("%s %s\n" % (nx1, L1_tot)) #------------------------------------------------------------------------------- # Plot the final state. @@ -778,7 +787,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mof = mortonOrderIndices(db) @@ -815,7 +824,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) @@ -830,7 +839,7 @@ print("Quantity \t\tL1 \t\t\t\tL2 \t\t\t\tLinf") failure = False - if normOutputFile != "None": + if normOutputFile: f = open(normOutputFile, "a") if writeOutputLabel: f.write(("#" + 13*"%17s " + "\n") % ('"nx"', @@ -852,7 +861,7 @@ L2 = Pn.gridpnorm(2, rmin, rmax) Linf = Pn.gridpnorm("inf", rmin, rmax) print(f"{name}\t\t{L1} \t\t{L2} \t\t{Linf}") - if normOutputFile != "None": + if normOutputFile: f.write((3*"%16.12e ") % (L1, L2, Linf)) if checkError and not (np.allclose(L1, LnormRef[hydroType][name]["L1"], tol, tol) and @@ -861,7 +870,7 @@ print("Failing Lnorm tolerance for ", name, (L1, L2, Linf), LnormRef[hydroType][name]) failure = True - if normOutputFile != "None": + if normOutputFile: f.write("\n") if checkError and failure: diff --git a/tests/functional/Hydro/Noh/Noh-shear-2d.py b/tests/functional/Hydro/Noh/Noh-shear-2d.py index 848ad2e93..b099d8892 100644 --- a/tests/functional/Hydro/Noh/Noh-shear-2d.py +++ b/tests/functional/Hydro/Noh/Noh-shear-2d.py @@ -115,28 +115,33 @@ dataRoot = "dumps-shearingNoh-2d", graphics = True, - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, ) assert not(boolReduceViscosity and boolCullenViscosity) hydroType = hydroType.upper() -dataDir = os.path.join(dataRoot, - hydroType, - Qconstructor.__name__, - "basaraShearCorrection=%s_Qlimiter=%s" % (balsaraCorrection, Qlimiter), - "nperh=%4.2f" % nPerh, - "XSPH=%s" % XSPH, - "densityUpdate=%s" % densityUpdate, - "compatibleEnergy=%s" % compatibleEnergy, - "Cullen=%s" % boolCullenViscosity, - "gradhCorrection=%s" % gradhCorrection, - "nx=%i_ny=%i" % (nx, ny)) -restartDir = os.path.join(dataDir, "restarts") -vizDir = os.path.join(dataDir, "visit") -restartBaseName = os.path.join(restartDir, "Noh-shear-2d-%ix%i" % (nx, ny)) +if dataRoot: + dataDir = os.path.join(dataRoot, + hydroType, + Qconstructor.__name__, + "basaraShearCorrection=%s_Qlimiter=%s" % (balsaraCorrection, Qlimiter), + "nperh=%4.2f" % nPerh, + "XSPH=%s" % XSPH, + "densityUpdate=%s" % densityUpdate, + "compatibleEnergy=%s" % compatibleEnergy, + "Cullen=%s" % boolCullenViscosity, + "gradhCorrection=%s" % gradhCorrection, + "nx=%i_ny=%i" % (nx, ny)) + restartDir = os.path.join(dataDir, "restarts") + vizDir = os.path.join(dataDir, "visit") + restartBaseName = os.path.join(restartDir, "Noh-shear-2d-%ix%i" % (nx, ny)) +else: + restartDir = None + vizDir = None + restartBaseName = None if vizTime is None and vizCycle is None: vizBaseName = None else: @@ -495,7 +500,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort P = ScalarField("pressure", nodes1) @@ -538,7 +543,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Hydro/Noh/Noh-spherical-1d.py b/tests/functional/Hydro/Noh/Noh-spherical-1d.py index 5d4d2b95b..c552dace7 100644 --- a/tests/functional/Hydro/Noh/Noh-spherical-1d.py +++ b/tests/functional/Hydro/Noh/Noh-spherical-1d.py @@ -133,9 +133,9 @@ restartStep = 10000, dataDirBase = "dumps-spherical-Noh", restartBaseName = "Noh-spherical-1d", - outputFile = "None", - comparisonFile = "None", - normOutputFile = "None", + outputFile = None, + comparisonFile = None, + normOutputFile = None, writeOutputLabel = True, # Parameters for the test acceptance., @@ -506,7 +506,7 @@ for i in range(len(rho)): L1 = L1 + abs(rho[i]-rhoans[i]) L1_tot = L1 / len(rho) -if mpi.rank == 0 and outputFile != "None": +if mpi.rank == 0 and outputFile: print("L1=",L1_tot,"\n") with open("Converge.txt", "a") as myfile: myfile.write("%s %s\n" % (nr, L1_tot)) @@ -583,7 +583,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mof = mortonOrderIndices(db) @@ -620,7 +620,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) @@ -635,7 +635,7 @@ failure = False hD = [] - if normOutputFile != "None": + if normOutputFile: f = open(normOutputFile, "a") if writeOutputLabel: f.write(("#" + 13*"%17s " + "\n") % ('"nx"', @@ -658,7 +658,7 @@ L2 = Pn.gridpnorm(2, rmin, rmax) Linf = Pn.gridpnorm("inf", rmin, rmax) print("\t%s \t\t%g \t\t%g \t\t%g" % (name, L1, L2, Linf)) - if normOutputFile != "None": + if normOutputFile: f.write((3*"%16.12e ") % (L1, L2, Linf)) hD.append([L1,L2,Linf]) @@ -697,7 +697,7 @@ Linf, Linfexpect)) failure = True - if normOutputFile != "None": + if normOutputFile: f.write("\n") if failure: diff --git a/tests/functional/Hydro/Noh/Noh-spherical-3d.py b/tests/functional/Hydro/Noh/Noh-spherical-3d.py index 66aa574fa..715817ba1 100644 --- a/tests/functional/Hydro/Noh/Noh-spherical-3d.py +++ b/tests/functional/Hydro/Noh/Noh-spherical-3d.py @@ -88,7 +88,7 @@ XSPH = False, epsilonTensile = 0.0, nTensile = 8, - filter = 0.0, + xfilter = 0.0, IntegratorConstructor = CheapSynchronousRK2Integrator, goalTime = 0.6, @@ -123,7 +123,8 @@ checkRestart = False, dataDir = "dumps-spherical-Noh", outputFile = "Noh_spherical_profiles.gnu", - comparisonFile = "None", + comparisonFile = None, + doCompare = True, graphics = True, ) @@ -158,17 +159,20 @@ if solid: hydroname = "Solid" + hydroname -dataDir = os.path.join(dataDir, - hydroname, - "nPerh=%f" % nPerh, - "compatibleEnergy=%s" % compatibleEnergy, - "Cullen=%s" % boolCullenViscosity, - "filter=%f" % filter, - "nx=%i_ny=%i_nz=%i" % (nx, ny, nz)) -restartDir = os.path.join(dataDir, "restarts") -restartBaseName = os.path.join(restartDir, "Noh-spherical-3d-%ix%ix%i" % (nx, ny, nz)) - -vizDir = os.path.join(dataDir, "visit") +if dataDir: + dataDir = os.path.join(dataDir, + hydroname, + "nPerh=%f" % nPerh, + "compatibleEnergy=%s" % compatibleEnergy, + "Cullen=%s" % boolCullenViscosity, + "xfilter=%f" % xfilter, + "nx=%i_ny=%i_nz=%i" % (nx, ny, nz)) + restartDir = os.path.join(dataDir, "restarts") + restartBaseName = os.path.join(restartDir, "Noh-spherical-3d-%ix%ix%i" % (nx, ny, nz)) + vizDir = os.path.join(dataDir, "visit") +else: + restartBaseName = None + vizDir = None if vizTime is None and vizCycle is None: vizBaseName = None else: @@ -177,7 +181,7 @@ #------------------------------------------------------------------------------- # Check if the necessary output directories exist. If not, create them. #------------------------------------------------------------------------------- -if mpi.rank == 0: +if mpi.rank == 0 and dataDir: if clearDirectories and os.path.exists(dataDir): shutil.rmtree(dataDir) if not os.path.exists(restartDir): @@ -276,7 +280,7 @@ elif crksph: hydro = CRKSPH(dataBase = db, W = WT, - filter = filter, + filter = xfilter, cfl = cfl, compatibleEnergyEvolution = compatibleEnergy, XSPH = XSPH, @@ -351,7 +355,7 @@ elif psph: hydro = PSPH(dataBase = db, W = WT, - filter = filter, + filter = xfilter, cfl = cfl, compatibleEnergyEvolution = compatibleEnergy, evolveTotalEnergy = evolveTotalEnergy, @@ -364,7 +368,7 @@ else: hydro = SPH(dataBase = db, W = WT, - filter = filter, + filter = xfilter, cfl = cfl, compatibleEnergyEvolution = compatibleEnergy, evolveTotalEnergy = evolveTotalEnergy, @@ -528,6 +532,9 @@ control.updateViz(control.totalSteps, integrator.currentTime, 0.0) control.dropRestartFile() +if not doCompare: + sys.exit(0) + #------------------------------------------------------------------------------- # Plot the results. #------------------------------------------------------------------------------- @@ -636,7 +643,7 @@ rmaxnorm = 0.35 rminnorm = 0.05 -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort P = ScalarField("pressure", nodes1) @@ -697,7 +704,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Hydro/RayleighTaylor/Hydrostatic-1d.py b/tests/functional/Hydro/RayleighTaylor/Hydrostatic-1d.py index 31925b0e7..16a0e13a3 100644 --- a/tests/functional/Hydro/RayleighTaylor/Hydrostatic-1d.py +++ b/tests/functional/Hydro/RayleighTaylor/Hydrostatic-1d.py @@ -97,9 +97,7 @@ def __call__(self, r): redistributeStep = 500, checkRestart = False, dataDir = "dumps-Rayleigh-Taylor-1d_hopkins", - outputFile = "None", - comparisonFile = "None", - + serialDump = False, #whether to dump a serial ascii file at the end for viz graphics = True, diff --git a/tests/functional/Hydro/RayleighTaylor/RT-2d.py b/tests/functional/Hydro/RayleighTaylor/RT-2d.py index c0203ce2e..652d1ba16 100644 --- a/tests/functional/Hydro/RayleighTaylor/RT-2d.py +++ b/tests/functional/Hydro/RayleighTaylor/RT-2d.py @@ -164,8 +164,8 @@ def __call__(self, r): redistributeStep = 50000, checkRestart = False, dataDir = "dumps-Rayleigh-Taylor-2d", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, serialDump = False, #whether to dump a serial ascii file at the end for viz ) diff --git a/tests/functional/Hydro/RayleighTaylor/RT-2d_Hopkins.py b/tests/functional/Hydro/RayleighTaylor/RT-2d_Hopkins.py index 3175acd48..01c7d7b69 100644 --- a/tests/functional/Hydro/RayleighTaylor/RT-2d_Hopkins.py +++ b/tests/functional/Hydro/RayleighTaylor/RT-2d_Hopkins.py @@ -157,7 +157,7 @@ def __call__(self, r): sampleFreq = 20, dataDir = "dumps-Rayleigh-Taylor-2d_hopkins", outputFile = "RT_Hopkins.txt", - comparisonFile = "None", + comparisonFile = None, serialDump = False, #whether to dump a serial ascii file at the end for viz useVoronoiOutput = False, diff --git a/tests/functional/Hydro/RayleighTaylor/RT-const-rho.py b/tests/functional/Hydro/RayleighTaylor/RT-const-rho.py index 57edc18a6..e13ce6200 100644 --- a/tests/functional/Hydro/RayleighTaylor/RT-const-rho.py +++ b/tests/functional/Hydro/RayleighTaylor/RT-const-rho.py @@ -119,8 +119,8 @@ def __call__(self, r): redistributeStep = 500, checkRestart = False, dataDir = "dumps-Rayleigh-Taylor-2d-constRho", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, serialDump = False, #whether to dump a serial ascii file at the end for viz diff --git a/tests/functional/Hydro/Riemann/Riemann.py b/tests/functional/Hydro/Riemann/Riemann.py index 9ecbdf04f..15d824ebe 100644 --- a/tests/functional/Hydro/Riemann/Riemann.py +++ b/tests/functional/Hydro/Riemann/Riemann.py @@ -87,7 +87,7 @@ restoreCycle = -1, restartStep = 10000, dataDirBase = "dumps-", - outputFile = "None", + outputFile = None, checkRestart = False, graphics = True, @@ -515,7 +515,7 @@ def createList(x): rmax = x2 if mpi.rank == 0: multiSort(mo, xprof, rhoprof, Pprof, vprof, epsprof, hprof) - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 19*"'%s' " + "\n") % ("x", "rho", "P", "v", "eps", "A", "h", "mo", diff --git a/tests/functional/Hydro/Sedov/Sedov-2d-ratio.py b/tests/functional/Hydro/Sedov/Sedov-2d-ratio.py index 20322965c..62dd5d5bf 100644 --- a/tests/functional/Hydro/Sedov/Sedov-2d-ratio.py +++ b/tests/functional/Hydro/Sedov/Sedov-2d-ratio.py @@ -104,7 +104,7 @@ useVoronoiOutput = False, clearDirectories = False, dataDirBase = "dumps-cylindrical-Sedov", - outputFile = "None", + outputFile = None, serialDump=True, xlmin = 0.4, @@ -527,7 +527,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None" and mpi.rank == 0: +if outputFile and mpi.rank == 0: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 17*"%16s " + "\n") % ("r", "x", "y", "rho", "m", "P", "v", "eps", "A", "hr", "ht", diff --git a/tests/functional/Hydro/Sedov/Sedov-RZ.py b/tests/functional/Hydro/Sedov/Sedov-RZ.py index ec41a93d8..faa1948c8 100644 --- a/tests/functional/Hydro/Sedov/Sedov-RZ.py +++ b/tests/functional/Hydro/Sedov/Sedov-RZ.py @@ -89,8 +89,8 @@ checkEnergy = False, restoreCycle = -1, restartStep = 10000, - comparisonFile = "None", - normOutputFile = "None", + comparisonFile = None, + normOutputFile = None, writeOutputLabel = True, graphics = True, @@ -460,7 +460,7 @@ for i in range(len(rho)): L1 = L1 + abs(rho[i]-rhoans[i]) L1_tot = L1 / len(rho) -# if mpi.rank == 0 and outputFile != "None": +# if mpi.rank == 0 and outputFile: # print "L1=",L1_tot,"\n" # with open("Converge.txt", "a") as myfile: # myfile.write("%s %s\n" % (nz, L1_tot)) @@ -513,7 +513,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mof = mortonOrderIndices(db) @@ -551,7 +551,7 @@ # #--------------------------------------------------------------------------- # # Also we can optionally compare the current results with another file. # #--------------------------------------------------------------------------- - # if comparisonFile != "None": + # if comparisonFile: # comparisonFile = os.path.join(dataDir, comparisonFile) # import filecmp # assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Hydro/Sedov/Sedov-cylindrical-2d.py b/tests/functional/Hydro/Sedov/Sedov-cylindrical-2d.py index 29a6472f4..8e54c4988 100644 --- a/tests/functional/Hydro/Sedov/Sedov-cylindrical-2d.py +++ b/tests/functional/Hydro/Sedov/Sedov-cylindrical-2d.py @@ -115,7 +115,7 @@ useVoronoiOutput = False, clearDirectories = False, dataDirBase = "dumps-cylindrical-Sedov", - outputFile = "None", + outputFile = None, serialDump=True, ) @@ -590,7 +590,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None" and mpi.rank == 0: +if outputFile and mpi.rank == 0: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 17*"%16s " + "\n") % ("r", "x", "y", "rho", "m", "P", "v", "eps", "A", "hr", "ht", diff --git a/tests/functional/Hydro/Sedov/Sedov-planar-1d.py b/tests/functional/Hydro/Sedov/Sedov-planar-1d.py index 4f08c37d4..894a456cf 100644 --- a/tests/functional/Hydro/Sedov/Sedov-planar-1d.py +++ b/tests/functional/Hydro/Sedov/Sedov-planar-1d.py @@ -96,7 +96,7 @@ graphics = True, clearDirectories = False, dataDirBase = "dumps-planar-Sedov", - outputFile = "None", + outputFile = None, ) if smallPressure: @@ -454,7 +454,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None" and mpi.rank == 0: +if outputFile and mpi.rank == 0: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 14*"%15s " + "\n") % ("r", "x", "rho", "P", "v", "eps", "A", "hr", diff --git a/tests/functional/Hydro/Sedov/Sedov-spherical-1d.py b/tests/functional/Hydro/Sedov/Sedov-spherical-1d.py index 079e18dfb..da8ad66c8 100644 --- a/tests/functional/Hydro/Sedov/Sedov-spherical-1d.py +++ b/tests/functional/Hydro/Sedov/Sedov-spherical-1d.py @@ -66,7 +66,7 @@ graphics = True, clearDirectories = True, dataDirBase = "dumps-spherical-Sedov", - outputFile = "None", + outputFile = None, ) if smallPressure: @@ -332,7 +332,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None" and mpi.rank == 0: +if outputFile and mpi.rank == 0: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 16*"%15s " + "\n") % ("r", "x", "y", "z", "rho", "m", "P", "v", "eps", "A", diff --git a/tests/functional/Hydro/Sedov/Sedov-spherical-3d.py b/tests/functional/Hydro/Sedov/Sedov-spherical-3d.py index ac15f2855..a62e231e2 100644 --- a/tests/functional/Hydro/Sedov/Sedov-spherical-3d.py +++ b/tests/functional/Hydro/Sedov/Sedov-spherical-3d.py @@ -110,7 +110,7 @@ graphics = True, clearDirectories = False, dataDirBase = "dumps-spherical-Sedov", - outputFile = "None", + outputFile = None, ) if smallPressure: @@ -509,7 +509,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None" and mpi.rank == 0: +if outputFile and mpi.rank == 0: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 16*"%15s " + "\n") % ("r", "x", "y", "z", "rho", "m", "P", "v", "eps", "A", diff --git a/tests/functional/Hydro/ShockBubble/ShockBubble-Variant-2d.py b/tests/functional/Hydro/ShockBubble/ShockBubble-Variant-2d.py index 197b2b6d6..43fbbc9a4 100644 --- a/tests/functional/Hydro/ShockBubble/ShockBubble-Variant-2d.py +++ b/tests/functional/Hydro/ShockBubble/ShockBubble-Variant-2d.py @@ -98,7 +98,7 @@ checkRestart = False, dataDir = "dumps-bubbleShock-variant-2d", vizName = "ShockBubble-variant-2d", - outputFile = "None", + outputFile = None, ) airEnergy = airPressure/((airGamma - 1.0)*airDensity) diff --git a/tests/functional/Hydro/Sod/Sod-RZ.py b/tests/functional/Hydro/Sod/Sod-RZ.py index 0a54a8258..c14368975 100644 --- a/tests/functional/Hydro/Sod/Sod-RZ.py +++ b/tests/functional/Hydro/Sod/Sod-RZ.py @@ -114,9 +114,9 @@ checkEnergy = False, restoreCycle = -1, restartStep = 100, - outputFile = "None", - comparisonFile = "None", - normOutputFile = "None", + outputFile = None, + comparisonFile = None, + normOutputFile = None, writeOutputLabel = True, graphics = True, diff --git a/tests/functional/Hydro/Sod/Sod-planar-1d-WaterGas.py b/tests/functional/Hydro/Sod/Sod-planar-1d-WaterGas.py index 471c3c3e2..95a3f8cb1 100644 --- a/tests/functional/Hydro/Sod/Sod-planar-1d-WaterGas.py +++ b/tests/functional/Hydro/Sod/Sod-planar-1d-WaterGas.py @@ -130,7 +130,7 @@ restartStep = 10000, dataDirBase = "dumps-Sod-planar", restartBaseName = "Sod-planar-1d-restart", - outputFile = "None", + outputFile = None, checkRestart = False, graphics = True, ) @@ -610,7 +610,7 @@ def createList(x): rmax = x2 if mpi.rank == 0: multiSort(mo, xprof, rhoprof, Pprof, vprof, epsprof, hprof) - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 17*"'%s' " + "\n") % ("x", "rho", "P", "v", "eps", "h", "mo", diff --git a/tests/functional/Hydro/Sod/Sod-planar-1d.py b/tests/functional/Hydro/Sod/Sod-planar-1d.py index f87859be0..771d2e2cc 100644 --- a/tests/functional/Hydro/Sod/Sod-planar-1d.py +++ b/tests/functional/Hydro/Sod/Sod-planar-1d.py @@ -133,7 +133,7 @@ restartStep = 10000, dataDirBase = "dumps-Sod-planar", restartBaseName = "Sod-planar-1d-restart", - outputFile = "None", + outputFile = None, checkRestart = False, graphics = True, @@ -739,7 +739,7 @@ def createList(x): rmax = x2 if mpi.rank == 0: multiSort(mo, xprof, rhoprof, Pprof, vprof, epsprof, hprof) - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 19*"'%s' " + "\n") % ("x", "rho", "P", "v", "eps", "A", "h", "mo", diff --git a/tests/functional/Hydro/Sod/Sod-planar-2d-WaterGas.py b/tests/functional/Hydro/Sod/Sod-planar-2d-WaterGas.py index 9a318fb7a..d2e4f3dcf 100644 --- a/tests/functional/Hydro/Sod/Sod-planar-2d-WaterGas.py +++ b/tests/functional/Hydro/Sod/Sod-planar-2d-WaterGas.py @@ -129,7 +129,7 @@ restartStep = 100, dataDirBase = "dumps-Sod-planar-2d", restartBaseName = "Sod-planar-2d-restart", - outputFile = "None", + outputFile = None, checkRestart = False, vizCycle = None, @@ -623,7 +623,7 @@ def createList(x): rmin = x0 rmax = x2 if mpi.rank == 0: - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("#" + 10*" '%s'" + "\n") % ("x", "rho", "P", "v", "eps", "h", diff --git a/tests/functional/Hydro/Sod/Sod-planar-2d.py b/tests/functional/Hydro/Sod/Sod-planar-2d.py index 50e37cd62..dba9add79 100644 --- a/tests/functional/Hydro/Sod/Sod-planar-2d.py +++ b/tests/functional/Hydro/Sod/Sod-planar-2d.py @@ -108,7 +108,7 @@ restartStep = 100, dataDirBase = "dumps-Sod-planar-2d", restartBaseName = "Sod-planar-2d-restart", - outputFile = "None", + outputFile = None, checkRestart = False, vizCycle = None, @@ -709,7 +709,7 @@ def createList(x): rmin = x0 rmax = x2 if mpi.rank == 0: - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("#" + 12*" '%s'" + "\n") % ("x", "rho", "P", "v", "eps", "A", "h", diff --git a/tests/functional/Hydro/Sod/Sod-planar-3d.py b/tests/functional/Hydro/Sod/Sod-planar-3d.py index 80480592c..5b3e36d37 100644 --- a/tests/functional/Hydro/Sod/Sod-planar-3d.py +++ b/tests/functional/Hydro/Sod/Sod-planar-3d.py @@ -126,7 +126,7 @@ restartStep = 100, dataDirBase = "dumps-Sod-planar-3d", restartBaseName = "Sod-planar-3d-restart", - outputFile = "None", + outputFile = None, checkRestart = False, vizCycle = None, @@ -677,7 +677,7 @@ def createList(x): rmin = x0 rmax = x2 if mpi.rank == 0: - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("#" + 14*" '%s'" + "\n") % ("x", "rho", "P", "vx", "vy", "vz", "eps", "A", "h", diff --git a/tests/functional/Hydro/Sod/Sod-spherical-1d.py b/tests/functional/Hydro/Sod/Sod-spherical-1d.py index f229fcd41..6b7db95a1 100644 --- a/tests/functional/Hydro/Sod/Sod-spherical-1d.py +++ b/tests/functional/Hydro/Sod/Sod-spherical-1d.py @@ -116,7 +116,7 @@ restartStep = 10000, dataDirBase = "dumps-Sod-spherical", restartBaseName = "Sod-spherical-1d-restart", - outputFile = "None", + outputFile = None, checkRestart = False, graphics = True, @@ -601,7 +601,7 @@ def createList(x): # rmax = x2 # if mpi.rank == 0: # multiSort(mo, xprof, rhoprof, Pprof, vprof, epsprof, hprof) -# if outputFile != "None": +# if outputFile: # outputFile = os.path.join(dataDir, outputFile) # f = open(outputFile, "w") # f.write(("# " + 19*"'%s' " + "\n") % ("x", "rho", "P", "v", "eps", "A", "h", "mo", diff --git a/tests/functional/Hydro/Sod/convSod-planar-1d.py b/tests/functional/Hydro/Sod/convSod-planar-1d.py index c980a07da..4c000457b 100644 --- a/tests/functional/Hydro/Sod/convSod-planar-1d.py +++ b/tests/functional/Hydro/Sod/convSod-planar-1d.py @@ -77,7 +77,7 @@ restartStep = 200, dataDirBase = "Sod-planar-1d", restartBaseName = "Sod-planar-1d-restart", - outputFile = "None", + outputFile = None, graphics = "gnu", serialDump = False, #whether to dump a serial ascii file at the end for viz @@ -466,7 +466,7 @@ def createList(x): rmax = x2 if mpi.rank == 0: multiSort(mo, xprof, rhoprof, Pprof, vprof, epsprof, hprof) - if outputFile != "None": + if outputFile: outputFile = os.path.join(dataDir, outputFile) f = open(outputFile, "w") f.write(("# " + 17*"'%s' " + "\n") % ("x", "rho", "P", "v", "eps", "h", "mo", diff --git a/tests/functional/Hydro/SphericalCollapse/SphericalCollapse.py b/tests/functional/Hydro/SphericalCollapse/SphericalCollapse.py index ab5cdd428..3e06cf8e0 100644 --- a/tests/functional/Hydro/SphericalCollapse/SphericalCollapse.py +++ b/tests/functional/Hydro/SphericalCollapse/SphericalCollapse.py @@ -107,7 +107,7 @@ graphics = True, clearDirectories = False, dataRoot = "dumps-spherical-collapse", - outputFile = "None", + outputFile = None, ) diff --git a/tests/functional/Hydro/Turbulence/Stir-3d.py b/tests/functional/Hydro/Turbulence/Stir-3d.py index 53e1d963b..dbb7e5c95 100644 --- a/tests/functional/Hydro/Turbulence/Stir-3d.py +++ b/tests/functional/Hydro/Turbulence/Stir-3d.py @@ -93,8 +93,8 @@ redistributeStep = 500, checkRestart = False, dataDir = "stir-3d", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, serialDump = False, #whether to dump a serial ascii file at the end for viz ) diff --git a/tests/functional/Hydro/YeeVortex/YeeVortex.py b/tests/functional/Hydro/YeeVortex/YeeVortex.py index 0f7b51829..af8af494a 100644 --- a/tests/functional/Hydro/YeeVortex/YeeVortex.py +++ b/tests/functional/Hydro/YeeVortex/YeeVortex.py @@ -163,7 +163,7 @@ def __call__(self, r): dataDir = "dumps-yeevortex-xy", graphics = True, smooth = False, - outputFileBase = ".out", + outputFile = ".out", convergenceFileBase = "xstaglattice_converge.txt", ) @@ -598,7 +598,7 @@ def __call__(self, r): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(baseDir, outputFile) from SpheralTestUtilities import multiSort P = ScalarField("pressure", nodes) diff --git a/tests/functional/Interpolation/one-mass.py b/tests/functional/Interpolation/one-mass.py index 81f13fcfc..ae56e2c19 100644 --- a/tests/functional/Interpolation/one-mass.py +++ b/tests/functional/Interpolation/one-mass.py @@ -94,8 +94,8 @@ restartStep = 10000, dataDir = "dumps-planar", restartBaseName = "Noh-planar-1d", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, graphics = True, serialDump = False #whether to dump a serial ascii file at the end for viz @@ -354,7 +354,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mof = mortonOrderIndices(db) @@ -391,7 +391,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Interpolation/one-node.py b/tests/functional/Interpolation/one-node.py index f3fab14b2..9dfcef329 100644 --- a/tests/functional/Interpolation/one-node.py +++ b/tests/functional/Interpolation/one-node.py @@ -94,8 +94,8 @@ restartStep = 10000, dataDir = "dumps-planar", restartBaseName = "Noh-planar-1d", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, graphics = True, serialDump = False #whether to dump a serial ascii file at the end for viz @@ -187,7 +187,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mof = mortonOrderIndices(db) @@ -224,7 +224,7 @@ #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Interpolation/two-nodes.py b/tests/functional/Interpolation/two-nodes.py index dd16dae1b..42c46d19b 100644 --- a/tests/functional/Interpolation/two-nodes.py +++ b/tests/functional/Interpolation/two-nodes.py @@ -82,8 +82,8 @@ restartStep = 10000, dataDir = "dumps-2p", restartBaseName = "2p", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, graphics = True, serialDump = True #whether to dump a serial ascii file at the end for viz diff --git a/tests/functional/Porosity/PlanarCompaction/PlanarCompaction-1d.py b/tests/functional/Porosity/PlanarCompaction/PlanarCompaction-1d.py index 725a83be1..6f2b2e314 100644 --- a/tests/functional/Porosity/PlanarCompaction/PlanarCompaction-1d.py +++ b/tests/functional/Porosity/PlanarCompaction/PlanarCompaction-1d.py @@ -106,8 +106,8 @@ dataDirBase = "dumps-PlanarCompaction-1d", checkError = False, checkRestart = False, - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, # Parameters for the test acceptance., tol = 1.0e-5, diff --git a/tests/functional/Strength/CollidingPlates/CollidingPlates-1d.py b/tests/functional/Strength/CollidingPlates/CollidingPlates-1d.py index db0827488..14abf8ee3 100644 --- a/tests/functional/Strength/CollidingPlates/CollidingPlates-1d.py +++ b/tests/functional/Strength/CollidingPlates/CollidingPlates-1d.py @@ -83,8 +83,8 @@ clearDirectories = False, referenceFile = "Reference/CollidingPlates-1d-reference-compatible-20220422.txt", dataDirBase = "dumps-CollidingPlates-1d", - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, ) if crksph: @@ -350,7 +350,7 @@ #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) pos = state.vectorFields(HydroFieldNames.position) @@ -384,7 +384,7 @@ #--------------------------------------------------------------------------- # Check the floating values for the state against reference data. #--------------------------------------------------------------------------- - if referenceFile != "None": + if referenceFile: import filearraycmp as fcomp assert fcomp.filearraycmp(outputFile, referenceFile, testtol, testtol) print("Floating point comparison test passed.") @@ -393,7 +393,7 @@ # Also we can optionally compare the current results with another file for # bit level consistency. #--------------------------------------------------------------------------- - if comparisonFile != "None" and BuildData.cxx_compiler_id != "IntelLLVM": + if comparisonFile and BuildData.cxx_compiler_id != "IntelLLVM": import filecmp print("Compare files : %s <---> %s" % (outputFile, comparisonFile)) assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Strength/Piston/Piston.py b/tests/functional/Strength/Piston/Piston.py index 359dea456..acc0ddcec 100644 --- a/tests/functional/Strength/Piston/Piston.py +++ b/tests/functional/Strength/Piston/Piston.py @@ -129,7 +129,7 @@ restartStep = 10000, dataDirBase = "dumps-Piston-1d-Cu", restartBaseName = "Piston-1d-Cu-restart", - outputFile = "None", + outputFile = None, checkRestart = False, graphics = True, ) diff --git a/tests/functional/Strength/PlateImpact/PlateImpact-1d.py b/tests/functional/Strength/PlateImpact/PlateImpact-1d.py index 0bc8a2d87..13cd0f8c7 100644 --- a/tests/functional/Strength/PlateImpact/PlateImpact-1d.py +++ b/tests/functional/Strength/PlateImpact/PlateImpact-1d.py @@ -93,8 +93,8 @@ # Should we run in domain independent mode, and if so should we check # for domain independence? domainIndependent = False, - outputFile = "None", - comparisonFile = "None", + outputFile = None, + comparisonFile = None, ) Sapphire1Range = (0.0, Sapphire1Thickness) @@ -639,7 +639,7 @@ def restoreState(self, file, path): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(restartDir, outputFile) pos = db.fluidPosition rho = db.fluidMassDensity @@ -672,7 +672,7 @@ def restoreState(self, file, path): #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(restartDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Strength/PlateImpact/TP106-1d.py b/tests/functional/Strength/PlateImpact/TP106-1d.py index 4528edd81..b69dd48eb 100644 --- a/tests/functional/Strength/PlateImpact/TP106-1d.py +++ b/tests/functional/Strength/PlateImpact/TP106-1d.py @@ -394,7 +394,7 @@ def tp106tracersample(nodes, indices): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: from SpheralTestUtilities import multiSort state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) diff --git a/tests/functional/Strength/Verney/Verney-2d.py b/tests/functional/Strength/Verney/Verney-2d.py index 200efc1c0..a409e69f7 100644 --- a/tests/functional/Strength/Verney/Verney-2d.py +++ b/tests/functional/Strength/Verney/Verney-2d.py @@ -428,7 +428,7 @@ def verneySample(nodes, indices): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: from SpheralTestUtilities import multiSort state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) diff --git a/tests/functional/Strength/Verney/Verney-3d.py b/tests/functional/Strength/Verney/Verney-3d.py index e80582190..08cdec3e7 100644 --- a/tests/functional/Strength/Verney/Verney-3d.py +++ b/tests/functional/Strength/Verney/Verney-3d.py @@ -437,7 +437,7 @@ def verneySample(nodes, indices): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: from SpheralTestUtilities import multiSort state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) diff --git a/tests/functional/Strength/Verney/Verney-RZ.py b/tests/functional/Strength/Verney/Verney-RZ.py index 6c0dea1a5..6e8d830d6 100644 --- a/tests/functional/Strength/Verney/Verney-RZ.py +++ b/tests/functional/Strength/Verney/Verney-RZ.py @@ -430,7 +430,7 @@ def verneySample(nodes, indices): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: from SpheralTestUtilities import multiSort state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) diff --git a/tests/functional/Strength/Verney/Verney-spherical.py b/tests/functional/Strength/Verney/Verney-spherical.py index 846af0e5a..f4efee7e5 100644 --- a/tests/functional/Strength/Verney/Verney-spherical.py +++ b/tests/functional/Strength/Verney/Verney-spherical.py @@ -121,7 +121,7 @@ def __call__(self, x): clearDirectories = False, dataDirBase = "dumps-Verney-Be-R", outputFile = "Verney-Be-R.gnu", - comparisonFile = "None", + comparisonFile = None, # Testing checkRestart = False, @@ -432,7 +432,7 @@ def verneySample(nodes, indices): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: from SpheralTestUtilities import multiSort state = State(db, integrator.physicsPackages()) outputFile = os.path.join(dataDir, outputFile) @@ -475,7 +475,7 @@ def verneySample(nodes, indices): #--------------------------------------------------------------------------- # Also we can optionally compare the current results with another file. #--------------------------------------------------------------------------- - if comparisonFile != "None": + if comparisonFile: comparisonFile = os.path.join(dataDir, comparisonFile) import filecmp assert filecmp.cmp(outputFile, comparisonFile) diff --git a/tests/functional/Surfaces/1d.py b/tests/functional/Surfaces/1d.py index 424723c69..9faab7d79 100644 --- a/tests/functional/Surfaces/1d.py +++ b/tests/functional/Surfaces/1d.py @@ -352,7 +352,7 @@ def smooth(x,window_len=11,window='hanning'): #------------------------------------------------------------------------------- # If requested, write out the state in a global ordering to a file. #------------------------------------------------------------------------------- -if outputFile != "None": +if outputFile: outputFile = os.path.join(dataDir, outputFile) from SpheralTestUtilities import multiSort mprof = mpi.reduce(nodes1.mass().internalValues(), mpi.SUM) diff --git a/tests/integration.ats b/tests/integration.ats index a937cbbfa..02efa2297 100644 --- a/tests/integration.ats +++ b/tests/integration.ats @@ -8,6 +8,9 @@ glue(fsisph = False) glue(gsph = False) glue(svph = False) +# Fail test to make sure tests are working +source("unit/Utilities/testFails.py") + # Geometry unit tests source("unit/Geometry/testVector.py") source("unit/Geometry/testTensor.py") diff --git a/tests/unit/CRKSPH/testConsistency.py b/tests/unit/CRKSPH/testConsistency.py index 229f40aeb..bf62113b6 100644 --- a/tests/unit/CRKSPH/testConsistency.py +++ b/tests/unit/CRKSPH/testConsistency.py @@ -74,12 +74,11 @@ graphics = True, graphBij = False, plotKernels = False, - outputFile = "None", + outputFile = None, plotSPH = True, dataCut = False, dataCutMin = 0.0, dataCutMax = 1.0, - outfile = "None", ) assert testCase in ("linear", "quadratic", "cubic", "step") @@ -843,13 +842,13 @@ Pnorm(errxBRKSPHIV, xans).pnorm(1))) print("Maximum errors: CRKSPH = %g, RKSPH I = %g, RKSPH II = %g, RKSPH IV = %g, RKSPH V = %g, SPH = %g, BCRKSPH = %g, BRKSPHII = %g, BRKSPHIV = %g" % (maxaxCRKSPHerror, maxaxRKSPHIerror, maxaxRKSPHIIerror, maxaxRKSPHIVerror, maxaxRKSPHVerror, maxaxSPHerror, maxaxBCRKSPHerror, maxaxBRKSPHIIerror, maxaxBRKSPHIVerror)) print("L1 Interpolation Error RK = %g, Max err = %g, L1 Derivative Error Rk = %g, Max err = %g" % (Pnorm(errfRK, xans).pnorm(1),maxfRKerror, Pnorm(errgfRK, xans).pnorm(1),maxgfRKerror)) -if outfile != "None": - fl = open(outfile+".ascii", "w") +if outputFile: + fl = open(outputFile+".ascii", "w") fl.write(("# " + 8*"%15s \t " + "\n") % ("x", "Dv/Dt", "CRK", "RK Type 1", "SPH", "CRK Error (difference)", "RK Error", "SPH Error")) for i in range(len(xidx)): fl.write((8*"%16.12e " + "\n") % (xans[i], axans[i], accCRKSPH[i], accRKSPHI[i], accSPH[i], errxCRKSPH[i], errxRKSPHI[i], errxSPH[i])) fl.close() - fl = open(outfile+"_interpolate.ascii", "w") + fl = open(outputFile+"_interpolate.ascii", "w") fl.write(("# " + 7*"%15s \t" + "\n") % ("x", "P", "grad P", "RK (P estimate)", "RK (grad P estimate)", "SPH (P estimate)", "SPH (grad P estimate)")) for i in range(len(xidx)): fl.write((7*"%16.12e " + "\n") % (xans[i], f[i], gf[i], fRK[i], gfRK[i], fSPH[i], gfSPH[i])) diff --git a/tests/unit/CRKSPH/testInterpolation.py b/tests/unit/CRKSPH/testInterpolation.py index 45844bc81..1cb0bed40 100644 --- a/tests/unit/CRKSPH/testInterpolation.py +++ b/tests/unit/CRKSPH/testInterpolation.py @@ -67,7 +67,7 @@ graphics = True, plotKernels = False, - outputFile = "None", + outputFile = None, ) assert testCase in ("linear", "quadratic", "step") @@ -465,7 +465,7 @@ def flattenFieldList(fl): p7.plot(xvals, WR, "g-", label="RK") p7.axes.legend() plt.title("Kernel") - if outputFile != "None": + if outputFile: f = open("Kernel_" + outputFile, "w") f.write(("#" + 3*' "%20s"' + "\n") % ("eta", "Wj", "WRj")) for xi, Wi, WRi in zip(xvals, W, WR): @@ -473,7 +473,7 @@ def flattenFieldList(fl): f.close() # We may want a gnu/pdv style text file. - if outputFile != "None" and testDim == "2d": + if outputFile and testDim == "2d": of = open(outputFile, "w") of.write(('#' + 7*' "%20s"' + '\n') % ("x", "interp answer", "grad answer", "interp SPH", "interp CRK", "grad SPH", "grad CRK")) for iNodeList, nodes in enumerate(db.nodeLists()): diff --git a/tests/unit/SPH/testLinearVelocityGradient.py b/tests/unit/SPH/testLinearVelocityGradient.py index 9acce429f..02b5b5e51 100644 --- a/tests/unit/SPH/testLinearVelocityGradient.py +++ b/tests/unit/SPH/testLinearVelocityGradient.py @@ -64,7 +64,6 @@ graphics = True, plotKernels = False, - outputFile = "None", plotSPH = True, ) diff --git a/tests/unit/Utilities/testFails.py b/tests/unit/Utilities/testFails.py new file mode 100644 index 000000000..e4c3fa4df --- /dev/null +++ b/tests/unit/Utilities/testFails.py @@ -0,0 +1,5 @@ +#ATS:~test(SELF, label="Failing test") + +import sys + +sys.exit(1) diff --git a/tests/unit/Utilities/testTimers.py.in b/tests/unit/Utilities/testTimers.py.in index 53fb21506..09fc0c9ad 100644 --- a/tests/unit/Utilities/testTimers.py.in +++ b/tests/unit/Utilities/testTimers.py.in @@ -1,8 +1,8 @@ # # #ATS:test(SELF, "--caliperFilename 'timer_test_1.cali'", label="Timer test 1", np=8) -#ATS:test(SELF, "--caliperConfig 'None'", label="Timer test 2", np=8) -#ATS:test(SELF, "--caliperFilename 'timer_test_3.cali'", label="Timer test 3", np=1) +#ATS:test(SELF, "--caliperConfig 'none'", label="Timer test 2", np=8) +#ATS:test(SELF, "--caliperFilename 'timer_test_3.cali' --adiakData 'adiak_test: 1, test_adiak: two'", label="Timer test 3", np=1) # import Spheral @@ -14,6 +14,17 @@ import mpi import sys, os, time +# Test set Adiak inputs +test_dict = {"perf_test": "weak_scaling", + "rank_count": mpi.procs, + "fake_float": 2.141} +for key, val in test_dict.items(): + adiak_value(key, val) + +# Test the --adiakData input. This must match what is +# hard-coded in the ATS magic lines +adiak_data_dict = {"adiak_test": 1, "test_adiak": "two"} + commandLine() # Remove cali files from previous test runs @@ -25,21 +36,7 @@ if (os.path.exists(caliper_file)): do_timers = False if (TimerMgr.is_started()): do_timers = True -test_dict_0 = {"perf_test": "weak_scaling"} -adiak_valueString("perf_test", test_dict_0["perf_test"], - adiak_categories.performance) -# Caliperreader reads everything as strings for some terrible reason -# So the test have to be hacked up - -# Correct method: -# test_dict_1 = {"rank_count": mpi.procs} -# adiak_valueInt("rank_count", test_dict_1["rank_count"]) -# Hacked method to have tests pass with caliperreader: -test_dict_1 = {"rank_count": str(mpi.procs)} -adiak_valueString("rank_count", test_dict_1["rank_count"]) - -test_dicts = [test_dict_0, test_dict_1] run_count = 8 sleep_time = 1.E-4 fake_timer_name = "test_timer" @@ -48,6 +45,8 @@ for i in range(run_count): TimerMgr.timer_start(fake_timer_name) time.sleep(sleep_time) TimerMgr.timer_end(fake_timer_name) + +# Read in Caliper file and process it if (do_timers and TimerMgr.get_filename()): adiak_fini() TimerMgr.fini() @@ -60,25 +59,30 @@ if (do_timers and TimerMgr.get_filename()): r = cr.CaliperReader() r.read(caliper_file) records = r.records - found_errors = 0 + # Test for timer name - if (fake_timer_name in records[1]['region']): - print(f"Found {fake_timer_name} timer") - else: - found_errors += 1 + assert fake_timer_name in records[1]['region'], f"{fake_timer_name} timer not found" + # Test for function count count_val = int(eval(records[1]["avg#sum#rc.count"])) - if (count_val == run_count): - print("Run count in Caliper file is correct") - else: - found_errors += 1 - # Test for adiak values - for td in test_dicts: - if (td.items() <= r.globals.items()): - print(f"Found {td.items()}") - else: - found_errors += 1 - if (found_errors > 0): - raise ValueError("Caliper file not correct") - else: - print("No errors found for TimerMgr") + assert count_val == run_count, "Caliper function count is off" + + # Note: CaliperReader reads everything as strings for some terrible reason + # we must convert the Adiak values first + adiak_inp = {} + for key, val in r.globals.items(): + try: + newval = eval(val) + except: + newval = val + adiak_inp.update({key: newval}) + + # Test Adiak output for explicitly set values + assert test_dict.items() <= adiak_inp.items(),\ + "incorrect Adiak values found in Caliper file" + + # Test --adiakData command line input + if ("adiakData" in adiak_inp): + assert adiak_data_dict.items() <= adiak_inp.items(),\ + "incorrect adiakData inputs found in Caliper file Adiak values" +