mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Add a voxel plot to test_plot
This commit is contained in:
parent
cc26157544
commit
a5f2d67892
4 changed files with 69 additions and 46 deletions
|
|
@ -1,11 +1,71 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import glob
|
||||
import hashlib
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.pardir)
|
||||
from testing_harness import PlotTestHarness
|
||||
from testing_harness import TestHarness
|
||||
|
||||
import h5py
|
||||
|
||||
from openmc import Executor
|
||||
|
||||
|
||||
class PlotTestHarness(TestHarness):
|
||||
"""Specialized TestHarness for running OpenMC plotting tests."""
|
||||
def __init__(self, plot_names):
|
||||
super(PlotTestHarness, self).__init__(None, False)
|
||||
self._plot_names = plot_names
|
||||
|
||||
def _run_openmc(self):
|
||||
executor = Executor()
|
||||
returncode = executor.plot_geometry(openmc_exec=self._opts.exe)
|
||||
assert returncode == 0, 'OpenMC did not exit successfully.'
|
||||
|
||||
def _test_output_created(self):
|
||||
"""Make sure *.ppm has been created."""
|
||||
for fname in self._plot_names:
|
||||
assert os.path.exists(os.path.join(os.getcwd(), fname)), \
|
||||
'Plot output file does not exist.'
|
||||
|
||||
def _cleanup(self):
|
||||
super(PlotTestHarness, self)._cleanup()
|
||||
for fname in self._plot_names:
|
||||
path = os.path.join(os.getcwd(), fname)
|
||||
if os.path.exists(path):
|
||||
#os.remove(path)
|
||||
pass
|
||||
|
||||
def _get_results(self):
|
||||
"""Return a string hash of the plot files."""
|
||||
outstr = bytes()
|
||||
|
||||
# Add PPM output to results
|
||||
ppm_files = glob.glob(os.path.join(os.getcwd(), '*.ppm'))
|
||||
for fname in sorted(ppm_files):
|
||||
with open(fname, 'rb') as fh:
|
||||
outstr += fh.read()
|
||||
|
||||
# Add voxel data to results
|
||||
voxel_files = glob.glob(os.path.join(os.getcwd(), '*.voxel'))
|
||||
for fname in sorted(voxel_files):
|
||||
with h5py.File(fname, 'r') as fh:
|
||||
outstr += fh['filetype'].value
|
||||
outstr += fh['num_voxels'].value.tobytes()
|
||||
outstr += fh['lower_left'].value.tobytes()
|
||||
outstr += fh['voxel_width'].value.tobytes()
|
||||
outstr += fh['data'].value.tobytes()
|
||||
|
||||
# Hash the information and return.
|
||||
sha512 = hashlib.sha512()
|
||||
sha512.update(outstr)
|
||||
outstr = sha512.hexdigest()
|
||||
|
||||
return outstr
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
harness = PlotTestHarness(('1_plot.ppm', '2_plot.ppm', '3_plot.ppm'))
|
||||
harness = PlotTestHarness(('1_plot.ppm', '2_plot.ppm', '3_plot.ppm',
|
||||
'4_plot.voxel'))
|
||||
harness.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue