Skip to content

Commit

Permalink
Created tests for the 1d flow - axisymmetric EM coupling. Tests
Browse files Browse the repository at this point in the history
verify the code executes without error and matches a reference solution.
It does not check for accuracy to a known or manufactured solution.
  • Loading branch information
jbigmanUT committed Aug 26, 2024
1 parent 5177edb commit 27abd90
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ test/ref_solns/interpInlet/restart_output.sol.h5 filter=lfs diff=lfs merge=lfs -
test/meshes/spongeBox.msh filter=lfs diff=lfs merge=lfs -text
test/ref_solns/sgsLoMach/restart_output.sol.h5 filter=lfs diff=lfs merge=lfs -text
test/ref_solns/aveLoMach/restart_output.sol.h5 filter=lfs diff=lfs merge=lfs -text
test/ref_solns/flow1d_coupling.sol.h5 filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions docker/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ RUN yum -y install boost-gnu9-mpich-ohpc

RUN yum -y install python38-pip
RUN pip3 install matplotlib
RUN pip3 install h5py

RUN yum -y install procps-ng
RUN yum -y install diffutils
Expand Down
47 changes: 0 additions & 47 deletions src/flow1d-coupling.py

This file was deleted.

10 changes: 8 additions & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ EXTRA_DIST = tap-driver.sh test_tps_splitcomm.py soln_differ inputs meshes lte-
ref_solns/reactBinDiff/*.h5 \
ref_solns/reactSingleRx/*.h5 \
ref_solns/reactTable/*.h5 \
ref_solns/flow1d_coupling.sol.h5 \
vpath.sh die.sh count_gpus.sh sniff_mpirun.sh \
cyl3d.gpu.test cyl3d.mflow.gpu.test wedge.gpu.test \
averaging.gpu.test cyl3d.test cyl3d.gpu.python.test cyl3d.mflow.test cyl3d.dtconst.test \
Expand All @@ -50,8 +51,8 @@ EXTRA_DIST = tap-driver.sh test_tps_splitcomm.py soln_differ inputs meshes lte-
sgsSmag.test sgsSigma.test heatEq.test sponge.test plate.test pipe.mix.test lte2noneq-restart.test \
coupled-3d.interface.test plasma.axisym.test plasma.axisym.lte1d.test \
lomach-flow.test lomach-lequere.test interpInlet.test sgsLoMach.test autoPeriodic.test aveLoMach.test \
reactFlow-binDiff.test reactFlow-singleRx.test reactFlow-table.test

reactFlow-binDiff.test reactFlow-singleRx.test reactFlow-table.test \
test_flow1d_coupling.py flow1d-coupling.python.test

TESTS = vpath.sh
XFAIL_TESTS =
Expand Down Expand Up @@ -129,6 +130,11 @@ if PYTHON_ENABLED
TESTS += cyl3d.python.test \
cyl3d.python.splitcomm.test \
coupled-3d.py-loop.test

if GSLIB_ENABLED
TESTS += flow1d-coupling.python.test
endif

endif

endif
Expand Down
41 changes: 41 additions & 0 deletions test/flow1d-coupling.python.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!./bats
# -*- mode: sh -*-

TEST="flow1d-coupling"
RUNFILE="inputs/qms-axisym.flow1dcoupling.ini"
EXE="./test_flow1d_coupling.py"

setup() {
SOLN_FILE=flow1d_coupling.sol.h5
REF_FILE=ref_solns/flow1d_coupling.h5
}

@test "[$TEST] check for input file $RUNFILE" {
test -s $RUNFILE
}

@test "[$TEST] run interface with input -> $RUNFILE" {
rm -f $SOLN_FILE
$EXE --runFile $RUNFILE
test -s $SOLN_FILE
}

@test "[$TEST] verify interface output with input -> $RUNFILE" {
test -s $SOLN_FILE
test -s $REF_FILE
h5diff --report --relative=1e-12 $SOLN_FILE $REF_FILE /output/joule_heating
}

@test "[$TEST] verify Joule heating is read only" {
# Should raise error
run WRITE_JOULE=True $EXE --runFile $RUNFILE
[ "$status" -ne 0 ]
}

@test "[$TEST] verify total power input is 20 kW with input -> $RUNFILE {
TOTAL_POWER=True $EXE --runFile $RUNFILE
}
@test "[$TEST] verify 1d and 2d total power inputs are equal with input -> $RUNFILE {
COMPARE_JOULE=True $EXE --runFile $RUNFILE
}
26 changes: 26 additions & 0 deletions test/inputs/qms-axisym.flow1dcoupling.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#---------------------
# TPS runtime controls
#---------------------

# choice of solver
[solver]
type = em-axi # options are (flow, em, em-axi, or coupled)

# controls for standalone EM-only solver
[em]
mesh = meshes/torch-em-coarse2.msh # mesh filename
order = 2 # FE order (polynomial degree)
max_iter = 60 # max number of iterations
rtol = 1.0e-13 # solver relative tolerance
atol = 1.0e-15 # solver absolute tolerance
top_only = false # run current through top branch only
bot_only = false # run current through bottom branch only
yinterp_min = -2.0 # minimum y interpolation value
yinterp_max = 2.0 # maximum y interpolation value
nBy = 129 # of interpolation points
By_file = ref_solns/By.h5 # file for By interpolant output

# chosen for ~20 kW power input
current_amplitude = 4.575e7 # A/m^2
current_frequency = 6e6 # 1/s
permeability = 1.25663706e-6 # m * kg / s^2 / A^2
Binary file added test/ref_solns/flow1d_coupling.h5
Binary file not shown.
66 changes: 66 additions & 0 deletions test/test_flow1d_coupling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
""" This is a driver to test the interface between a Python 1d flow solver
and the 2d axisymmetric EM solver. The 1d flow solver is emulated by defining
the plasma conductivity"""
import sys
import os
import numpy as np
import h5py
from mpi4py import MPI
# set path to C++ TPS library
path = os.path.abspath(os.path.dirname(sys.argv[0]))
sys.path.append(path + "/../src/.libs")
import libtps

comm = MPI.COMM_WORLD
# TPS solver
tps = libtps.Tps(comm)
tps.parseCommandLineArgs(sys.argv)
tps.parseInput()
tps.chooseDevices()

# 1d flow - 2d EM interface
interface = libtps.Qms2Flow1d(tps)

# Initialize MFEM vectors with number of 1d points
N_POINTS = 1000
interface.initialize(N_POINTS)

# Access vectors through NumPy
cond_1d = np.array(interface.PlasmaConductivity1d(), copy = False)
joule_1d = np.array(interface.JouleHeating1d(), copy = False)
radius_1d = np.array(interface.TorchRadius1d(), copy = False)
z_1d = np.array(interface.Coordinates1d(), copy = False)

# Check that Joule heating is read only
if 'WRITE_JOULE' in os.environ:
joule_1d[0] = 1

# Example vector data
R_TORCH = 2.75e-2
L_TORCH = 0.315
z_1d[0:N_POINTS] = np.linspace(0, L_TORCH, N_POINTS)
cond_1d[0:N_POINTS] = np.ones(N_POINTS)
radius_1d[0:N_POINTS] = R_TORCH

# Solve
N_INTERP = 100
interface.set_n_interp(N_INTERP)
interface.solve()

if 'TOTAL_POWER' in os.environ:
power = interface.total_joule_2d()/1e3
assert np.abs(power - 20)/20 < 0.05, 'Total power should be 20 kW'

if 'COMPARE_JOULE' in os.environ:
power_1d = interface.total_joule_1d()/1e3
power_2d = interface.total_joule_2d()/1e3
error = np.abs(power_1d - power_2d)/np.abs(power_2d)
assert error < 1e-5, '1d and 2d Joule heating integrals should match'

# Save output with hdf5
with h5py.File("flow1d_coupling.sol.h5", "w") as f:
_ = f.create_dataset('input/axial_coordinates', data=z_1d)
_ = f.create_dataset('input/torch_radius', data=radius_1d)
_ = f.create_dataset('input/plasma_conductivity', data=cond_1d)
_ = f.create_dataset('output/joule_heating', data=joule_1d)
1 change: 1 addition & 0 deletions test/vpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fi
# necessary binaries
binaries="bats die.sh soln_differ count_gpus.sh sniff_mpirun.sh "
binaries+="../src/tps.py ../src/tps-time-loop.py ../src/tps-bte_0d3v.py ../test/test_tps_splitcomm.py"
binaries+=" ../test/test_flow1d_coupling.py"
for binary in $binaries; do
if [ ! -x $binary ];then
if [ -x $testDir/$binary ];then
Expand Down

0 comments on commit 27abd90

Please sign in to comment.