From 3291e2e1ab0d59a6cf99dd63b126fcf0e151b808 Mon Sep 17 00:00:00 2001 From: Umberto Villa Date: Thu, 27 Jul 2023 17:26:13 -0500 Subject: [PATCH] Add python time stepper --- src/tps-time-loop.py | 36 ++++++++++++++++++++++++++++++++++++ src/tps.py | 1 + test/Makefile.am | 6 ++++-- test/coupled-3d.py-loop.test | 21 +++++++++++++++++++++ test/vpath.sh | 2 +- 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100755 src/tps-time-loop.py create mode 100755 test/coupled-3d.py-loop.test diff --git a/src/tps-time-loop.py b/src/tps-time-loop.py new file mode 100755 index 000000000..1153212e2 --- /dev/null +++ b/src/tps-time-loop.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +import sys +import os + +from mpi4py import MPI + +# set path to C++ TPS library +path = os.path.abspath(os.path.dirname(sys.argv[0])) +sys.path.append(path + "/.libs") +import libtps as tps + +comm = MPI.COMM_WORLD +# TPS solver +tps = tps.Tps(comm) + +tps.parseCommandLineArgs(sys.argv) +tps.parseInput() +tps.chooseDevices() +tps.chooseSolver() +tps.initialize() + + +it = 0 +max_iters = tps.getRequiredInput("flow/maxIters") +print("Max Iters: ", max_iters) +tps.solveBegin() + +while it < max_iters: + tps.solveStep() + it = it+1 + print("it, ", it) + +tps.solveEnd() + + +sys.exit (tps.getStatus()) diff --git a/src/tps.py b/src/tps.py index f1dc28df0..46b69aa14 100755 --- a/src/tps.py +++ b/src/tps.py @@ -17,6 +17,7 @@ tps.parseInput() tps.chooseDevices() tps.chooseSolver() +tps.initialize() tps.solve() sys.exit (tps.getStatus()) diff --git a/test/Makefile.am b/test/Makefile.am index aaed387d8..ffaa6e79a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -35,7 +35,8 @@ EXTRA_DIST = tap-driver.sh test_tps_splitcomm.py soln_differ inputs meshes inflow_outflow.test mms.ternary_2d.test mms.ternary_2d_wall.test \ mms.ternary_2d_inout.test cuda-memcheck.test mms.general_wall.test \ independent_coupling.test interp_em.test mms.euler_2d.test mms.cns_2d.test \ - gradient.test coupled-3d.test coupled-3d.splitcomm.test tabulated.test lte_mixture.test distance_fcn.test \ + gradient.test coupled-3d.test coupled-3d.splitcomm.test coupled-3d.py-loop.test \ + tabulated.test lte_mixture.test distance_fcn.test \ sgsSmag.test sgsSigma.test plate.test pipe.mix.test TESTS = vpath.sh @@ -91,7 +92,8 @@ TESTS += cyl3d.test \ if PYTHON_ENABLED TESTS += cyl3d.python.test \ - cyl3d.python.splitcomm.test + cyl3d.python.splitcomm.test \ + coupled-3d.py-loop.test endif endif diff --git a/test/coupled-3d.py-loop.test b/test/coupled-3d.py-loop.test new file mode 100755 index 000000000..9a7ce06d7 --- /dev/null +++ b/test/coupled-3d.py-loop.test @@ -0,0 +1,21 @@ +#!./bats +# -*- mode: sh -*- + +TEST="coupling/cycle-avg-joule-coupling-py-loop" +RUNFILE="inputs/coupled-3d.ini" +EXE="../src/tps-time-loop.py" + +setup() { + SOLN_FILE=restart_output-coupled-3d.sol.h5 + REF_FILE=ref_solns/coupled-3d.sol.h5 +} + +@test "[$TEST] verify tps runs in cylce-avg-joule-coupling mode (3D)" { + test -s $RUNFILE + mpirun -np 2 $EXE --runFile $RUNFILE + + test -s $SOLN_FILE + test -s $REF_FILE + + ./soln_differ -r $SOLN_FILE $REF_FILE +} diff --git a/test/vpath.sh b/test/vpath.sh index 2b01faa24..f93f1a9eb 100755 --- a/test/vpath.sh +++ b/test/vpath.sh @@ -22,7 +22,7 @@ if [ ! -d ref_solns ];then fi # necessary binaries -binaries="bats die.sh soln_differ ../src/tps.py ../test/test_tps_splitcomm.py" +binaries="bats die.sh soln_differ ../src/tps.py ../src/tps-time-loop.py ../test/test_tps_splitcomm.py" for binary in $binaries; do if [ ! -x $binary ];then if [ -x $testDir/$binary ];then