diff --git a/.github/workflows/floatingpoint.yml b/.github/workflows/floatingpoint.yml new file mode 100644 index 000000000..381fc36bc --- /dev/null +++ b/.github/workflows/floatingpoint.yml @@ -0,0 +1,32 @@ +name: floating-point + +on: + pull_request: + branches: [main] + workflow_dispatch: + +jobs: + floatingpoint: + name: Check for floating point exceptions + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + id: setup_python + uses: conda-incubator/setup-miniconda@v3 + with: + activate-environment: vplanet + environment-file: environment.yml + python-version: 3.9 + + - name: Run + shell: bash -l {0} + run: | + cd tests/ + python floatingpoint.py diff --git a/.gitignore b/.gitignore index 3cb3ec8ba..8c490cacd 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ gcov/* *.so *.valgrind *.cache +*.floatingpoint # Documentation docs/.build diff --git a/src/distrot.c b/src/distrot.c index a42e524dd..a5bd28ca7 100644 --- a/src/distrot.c +++ b/src/distrot.c @@ -1146,6 +1146,8 @@ void WriteBodyDYoblDtDistRot(BODY *body, CONTROL *control, OUTPUT *output, /* Ensure that we don't overwrite derivative */ dDeriv = 0; + dDeriv = pow(10, 300); + dDeriv *= dDeriv; for (iPert = 0; iPert <= body[iBody].iGravPerts; iPert++) { dDeriv += *(update[iBody].padDYoblDtDistRot[iPert]); } diff --git a/src/vplanet.c b/src/vplanet.c index 99d977f3e..9f41346e5 100644 --- a/src/vplanet.c +++ b/src/vplanet.c @@ -32,6 +32,7 @@ int main_impl(int argc, char *argv[]) { // feenableexcept(FE_INVALID | FE_OVERFLOW); _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID); _MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_OVERFLOW); + fprintf(stderr, "INFO: Floating point trapping enabled.\n"); #else fprintf(stderr, "WARNING: Floating point trapping only enabled for x86 " diff --git a/tests/AtmescEqtideStellar/Lopez12CPL/vpl.in b/tests/AtmescEqtideStellar/Lopez12CPL/vpl.in index b0df9683d..76ae0df07 100644 --- a/tests/AtmescEqtideStellar/Lopez12CPL/vpl.in +++ b/tests/AtmescEqtideStellar/Lopez12CPL/vpl.in @@ -1,6 +1,6 @@ sSystemName Lopez12CPL -iVerbose 0 +iVerbose 5 bOverwrite 1 saBodyFiles star.in $ # The star diff --git a/tests/AtmescEqtideStellar/WaterLossCPL/vpl.in b/tests/AtmescEqtideStellar/WaterLossCPL/vpl.in index 1f6049406..e29ddbb3e 100644 --- a/tests/AtmescEqtideStellar/WaterLossCPL/vpl.in +++ b/tests/AtmescEqtideStellar/WaterLossCPL/vpl.in @@ -1,7 +1,7 @@ # Primary input file to demonstrate coupling between AtmEsc and EqTide with # water present sSystemName WaterCPL -iVerbose 0 +iVerbose 5 bOverwrite 1 saBodyFiles star.in b.in diff --git a/tests/AtmescEqtideStellar/WaterLossCTL/vpl.in b/tests/AtmescEqtideStellar/WaterLossCTL/vpl.in index a97626948..be32eb388 100644 --- a/tests/AtmescEqtideStellar/WaterLossCTL/vpl.in +++ b/tests/AtmescEqtideStellar/WaterLossCTL/vpl.in @@ -1,7 +1,7 @@ # Primary input file to demonstrate coupling between AtmEsc and EqTide with # water present sSystemName WaterCTL -iVerbose 0 +iVerbose 5 bOverwrite 1 saBodyFiles star.in b.in diff --git a/tests/AtmescSpinbody/NBodyAtmEsc/vpl.in b/tests/AtmescSpinbody/NBodyAtmEsc/vpl.in index 5491b696e..ccf6c6870 100644 --- a/tests/AtmescSpinbody/NBodyAtmEsc/vpl.in +++ b/tests/AtmescSpinbody/NBodyAtmEsc/vpl.in @@ -14,7 +14,7 @@ sUnitAngle deg # Options: deg, rad bDoLog 1 # Write a log file? iDigits 5 # Maximum number of digits to right of decimal dMinValue 1e-10 # Minimum value of eccentricity/obliquity -iVerbose 0 # Verbosity level max=5 +iVerbose 5 # Verbosity level max=5 #Evolution Parameters bDoForward 1 # Perform a forward evolution? diff --git a/tests/AtmescStellar/DiffLimWaterEscape/vpl.in b/tests/AtmescStellar/DiffLimWaterEscape/vpl.in index 6a28b602b..910d9cee4 100755 --- a/tests/AtmescStellar/DiffLimWaterEscape/vpl.in +++ b/tests/AtmescStellar/DiffLimWaterEscape/vpl.in @@ -1,6 +1,6 @@ sSystemName trappist1 -iVerbose 0 +iVerbose 5 bOverwrite 1 saBodyFiles star.in b.in e.in sUnitMass solar diff --git a/tests/AtmescStellar/MiniNeptuneEvapDyn/vpl.in b/tests/AtmescStellar/MiniNeptuneEvapDyn/vpl.in index 570b461f1..6c332bcbe 100644 --- a/tests/AtmescStellar/MiniNeptuneEvapDyn/vpl.in +++ b/tests/AtmescStellar/MiniNeptuneEvapDyn/vpl.in @@ -1,7 +1,7 @@ # Example from Fig. 3 from Lehmer & Catling (2017), but with evolving properties sSystemName dynamic -iVerbose 0 +iVerbose 5 bOverwrite 1 saBodyFiles star.in planet.in diff --git a/tests/BinaryEqtideStellar/STEEP_CBP_CPL/vpl.in b/tests/BinaryEqtideStellar/STEEP_CBP_CPL/vpl.in index ffb7c4a83..81567558e 100644 --- a/tests/BinaryEqtideStellar/STEEP_CBP_CPL/vpl.in +++ b/tests/BinaryEqtideStellar/STEEP_CBP_CPL/vpl.in @@ -1,6 +1,6 @@ # Primary input file for VPLANET sSystemName STEEP_CPL # System Name -iVerbose 0 # Verbosity level +iVerbose 5 # Verbosity level bOverwrite 1 # Allow file overwrites? # List of "body files" that contain body-specific parameters diff --git a/tests/DistorbDistrotEqtide/CTL_LL2/vpl.in b/tests/DistorbDistrotEqtide/CTL_LL2/vpl.in index 15d3854b0..4248ea90d 100644 --- a/tests/DistorbDistrotEqtide/CTL_LL2/vpl.in +++ b/tests/DistorbDistrotEqtide/CTL_LL2/vpl.in @@ -1,6 +1,6 @@ # Primary input file for VPLANET sSystemName TGard # System Name -iVerbose 0 # Verbosity level +iVerbose 5 # Verbosity level bOverwrite 1 # Allow file overwrites? # All space after a # is ignored, as is white space diff --git a/tests/DistorbDistrotEqtide/CTL_RD4/vpl.in b/tests/DistorbDistrotEqtide/CTL_RD4/vpl.in index 15d3854b0..4248ea90d 100644 --- a/tests/DistorbDistrotEqtide/CTL_RD4/vpl.in +++ b/tests/DistorbDistrotEqtide/CTL_RD4/vpl.in @@ -1,6 +1,6 @@ # Primary input file for VPLANET sSystemName TGard # System Name -iVerbose 0 # Verbosity level +iVerbose 5 # Verbosity level bOverwrite 1 # Allow file overwrites? # All space after a # is ignored, as is white space diff --git a/tests/floatingpoint.py b/tests/floatingpoint.py new file mode 100644 index 000000000..b5720915f --- /dev/null +++ b/tests/floatingpoint.py @@ -0,0 +1,102 @@ +import os +import subprocess +import sys + + +# XXX Near duplicates in maketest.py, 02/06/24 +def Main(): + BuildVPLanet() + dir_list = CollectAllTests() + RemoveOldOutputFiles(dir_list) + + print(" ", flush=True) + tot_fail = 0 + tot_test = 0 + tot_error = 0 + for dir in dir_list: + tot_test += 1 + sys.stdout.write(dir) + sys.stdout.write(": ") + sys.stdout.flush() + os.chdir(dir) + subdirs = dir.split("/") + test = subdirs[1] + outfile = test + ".floatingpoint" + cmd = "../../../bin/vplanet vpl.in" + + with open(outfile, "w+") as f: + subprocess.run(cmd, shell=True, stdout=f, stderr=f) + f = open(outfile, "r") + try: + last_line = f.readlines()[-1] + except: + print("Error") + os.chdir("../../") + tot_error += 1 + continue + # print(last_line) + f.close() + if last_line != "Simulation completed.\n": + tot_fail += 1 + print("Fail", flush=True) + else: + print("Pass", flush=True) + os.chdir("../../") + + print("") + + if tot_fail == 0 and tot_error == 0: + print("No floating point errors found!") + assert True + else: + print( + repr(tot_fail) + + "/" + + repr(tot_test) + + " test(s) failed; " + + repr(tot_error) + + "/" + + repr(tot_test) + + " test(s) errored." + ) + assert False + exit(0) + + +def BuildVPLanet(): + sys.stdout.write("Building VPLanet...") + sys.stdout.flush() + os.chdir("../") + subprocess.check_output(["make", "debug"]) + print("done.", flush=True) + os.chdir("tests") + + +def CollectAllTests(): + top_list = sorted(next(os.walk("."))[1]) + dir_list = [] + for top in top_list: + subdirs = [ + os.path.join(top, subdir) for subdir in sorted(next(os.walk(top))[1]) + ] + for subdir in subdirs: + if "pycache" not in subdir: + dir_list.append(subdir) + + return dir_list + + +def RemoveOldOutputFiles(dir_list): + for dir in dir_list: + os.chdir(dir) + subdirs = dir.split("/") + test = subdirs[1] + outfile = test + ".floatingpoint" + # print (test,outfile) + if os.path.exists(outfile): + os.remove(outfile) + os.chdir("../../") + + +if __name__ == "__main__": + Main()