-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created tests for the 1d flow - axisymmetric EM coupling. Tests
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
Showing
9 changed files
with
144 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters