mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Creating a separate test for the voxel script.
This commit is contained in:
parent
2ef7ea8fe0
commit
cba6c5ad63
10 changed files with 124 additions and 22 deletions
|
|
@ -24,7 +24,7 @@
|
|||
</plot>
|
||||
|
||||
<plot id="4" type="voxel">
|
||||
<pixels>50 50 10</pixels>
|
||||
<pixels>100 100 10</pixels>
|
||||
<origin>0. 0. 0.</origin>
|
||||
<width>20 20 10</width>
|
||||
</plot>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
3337721f8f6d3777dd36c404ed117fe5bc07b1d9691a0c91131d48e7e73e21191e72401cf9bb621e3250ca51345514f90ea612e0fb6236bec33ce78655988dec
|
||||
01ecda0f3820a49c8a41d8dc47d1e5c58767a04301621c2437231fcc04401ddea47b67d0529ca56a32d4d97b4f1416a2e0b6120d3bdc87d74a7e9889758a8808
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import glob
|
||||
import hashlib
|
||||
import os
|
||||
from subprocess import call
|
||||
|
||||
import h5py
|
||||
import openmc
|
||||
|
|
@ -19,15 +18,6 @@ class PlotTestHarness(TestHarness):
|
|||
def _run_openmc(self):
|
||||
openmc.plot_geometry(openmc_exec=config['exe'])
|
||||
|
||||
# TEMP: this should always be checked once vtk is added
|
||||
# to Python3.7
|
||||
try:
|
||||
import vtk
|
||||
call(['../../../scripts/openmc-voxel-to-vtk'] +
|
||||
glob.glob('plot_4.h5'))
|
||||
except:
|
||||
pass
|
||||
|
||||
def _test_output_created(self):
|
||||
"""Make sure *.ppm has been created."""
|
||||
for fname in self._plot_names:
|
||||
|
|
@ -66,14 +56,6 @@ class PlotTestHarness(TestHarness):
|
|||
|
||||
|
||||
def test_plot():
|
||||
expected_plots = ['plot_1.ppm', 'plot_2.ppm', 'plot_3.ppm', 'plot_4.h5']
|
||||
# TEMP: this should always be checked once vtk is added
|
||||
# to Python3.7
|
||||
try:
|
||||
import vtk
|
||||
expected_plots.append('plot.vti')
|
||||
except:
|
||||
pass
|
||||
|
||||
harness = PlotTestHarness(expected_plots)
|
||||
harness = PlotTestHarness(('plot_1.ppm', 'plot_2.ppm', 'plot_3.ppm',
|
||||
'plot_4.h5'))
|
||||
harness.main()
|
||||
|
|
|
|||
0
tests/regression_tests/plot_voxel/__init__.py
Normal file
0
tests/regression_tests/plot_voxel/__init__.py
Normal file
13
tests/regression_tests/plot_voxel/geometry.xml
Normal file
13
tests/regression_tests/plot_voxel/geometry.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<geometry>
|
||||
|
||||
<surface id="1" type="z-cylinder" coeffs="0 0 2" />
|
||||
<surface id="2" type="z-cylinder" coeffs="0 0 5" />
|
||||
<surface id="3" type="z-cylinder" coeffs="0 0 10" boundary="vacuum" />
|
||||
<surface id="4" type="y-plane" coeffs="5" boundary="vacuum" />
|
||||
|
||||
<cell id="1" material="1" region=" -1 -4" />
|
||||
<cell id="2" material="3" region="1 -2 -4" />
|
||||
<cell id="3" material="2" region="2 -3 -4" />
|
||||
|
||||
</geometry>
|
||||
19
tests/regression_tests/plot_voxel/materials.xml
Normal file
19
tests/regression_tests/plot_voxel/materials.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0"?>
|
||||
<materials>
|
||||
|
||||
<material id="1">
|
||||
<density value="4.5" units="g/cc" />
|
||||
<nuclide name="U235" ao="1.0" />
|
||||
</material>
|
||||
|
||||
<material id="2">
|
||||
<density value="4.5" units="g/cc" />
|
||||
<nuclide name="U235" ao="1.0" />
|
||||
</material>
|
||||
|
||||
<material id="3">
|
||||
<density value="4.5" units="g/cc" />
|
||||
<nuclide name="U235" ao="1.0" />
|
||||
</material>
|
||||
|
||||
</materials>
|
||||
10
tests/regression_tests/plot_voxel/plots.xml
Normal file
10
tests/regression_tests/plot_voxel/plots.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<plots>
|
||||
|
||||
<plot id="4" type="voxel">
|
||||
<pixels>50 50 10</pixels>
|
||||
<origin>0. 0. 0.</origin>
|
||||
<width>20 20 10</width>
|
||||
</plot>
|
||||
|
||||
</plots>
|
||||
1
tests/regression_tests/plot_voxel/results_true.dat
Normal file
1
tests/regression_tests/plot_voxel/results_true.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
20a0c3598bb698efa4bba65c5e55d71f4385e5b1bcf0067964e45001c12f5c0a729935a96409c760dbd3ec439ae6c676fce77d6e578b41f8f3e0ac68c9277acb
|
||||
13
tests/regression_tests/plot_voxel/settings.xml
Normal file
13
tests/regression_tests/plot_voxel/settings.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<settings>
|
||||
|
||||
<run_mode>plot</run_mode>
|
||||
|
||||
<mesh id="1">
|
||||
<dimension>5 4 3</dimension>
|
||||
<lower_left>-10 -10 -10</lower_left>
|
||||
<upper_right>10 10 10</upper_right>
|
||||
</mesh>
|
||||
<entropy_mesh>1</entropy_mesh>
|
||||
|
||||
</settings>
|
||||
64
tests/regression_tests/plot_voxel/test.py
Normal file
64
tests/regression_tests/plot_voxel/test.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import glob
|
||||
import hashlib
|
||||
import os
|
||||
from subprocess import run
|
||||
import importlib
|
||||
import h5py
|
||||
import openmc
|
||||
import pytest
|
||||
|
||||
from tests.testing_harness import TestHarness
|
||||
from tests.regression_tests import config
|
||||
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
importlib.util.find_spec('vtk') is None,
|
||||
reason="vtk module is not installed.")
|
||||
class PlotVoxelTestHarness(TestHarness):
|
||||
"""Specialized TestHarness for running OpenMC voxel plot tests."""
|
||||
def __init__(self, plot_names):
|
||||
super().__init__(None)
|
||||
self._plot_names = plot_names
|
||||
|
||||
def _run_openmc(self):
|
||||
openmc.plot_geometry(openmc_exec=config['exe'])
|
||||
|
||||
run(['../../../scripts/openmc-voxel-to-vtk'] +
|
||||
glob.glob('plot_4.h5'), check=True)
|
||||
|
||||
def _test_output_created(self):
|
||||
"""Make sure *.ppm has been created."""
|
||||
for fname in self._plot_names:
|
||||
assert os.path.exists(fname), 'Plot output file does not exist.'
|
||||
|
||||
def _cleanup(self):
|
||||
super()._cleanup()
|
||||
for fname in self._plot_names:
|
||||
if os.path.exists(fname):
|
||||
os.remove(fname)
|
||||
|
||||
def _get_results(self):
|
||||
"""Return a string hash of the plot files."""
|
||||
outstr = bytes()
|
||||
|
||||
for fname in self._plot_names:
|
||||
if fname.endswith('.h5'):
|
||||
# Add voxel data to results
|
||||
with h5py.File(fname, 'r') as fh:
|
||||
outstr += fh.attrs['filetype']
|
||||
outstr += fh.attrs['num_voxels'].tostring()
|
||||
outstr += fh.attrs['lower_left'].tostring()
|
||||
outstr += fh.attrs['voxel_width'].tostring()
|
||||
outstr += fh['data'].value.tostring()
|
||||
|
||||
# Hash the information and return.
|
||||
sha512 = hashlib.sha512()
|
||||
sha512.update(outstr)
|
||||
outstr = sha512.hexdigest()
|
||||
|
||||
return outstr
|
||||
|
||||
|
||||
def test_plot():
|
||||
harness = PlotVoxelTestHarness(('plot_4.h5', 'plot.vti'))
|
||||
harness.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue