From 14f9d04ad78c2d548a38655c766b603cb86a251a Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 27 Feb 2019 17:11:16 -0600 Subject: [PATCH] Changing zyx ordering of voxel files to xyz and updating the voxel-to-vtk script. Adding check for version number in the script to avoid incorrect conversion of older voxel files. --- scripts/openmc-voxel-to-vtk | 15 ++++++++++++++- src/plot.cpp | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/scripts/openmc-voxel-to-vtk b/scripts/openmc-voxel-to-vtk index c43f60b68..afac8984f 100755 --- a/scripts/openmc-voxel-to-vtk +++ b/scripts/openmc-voxel-to-vtk @@ -8,6 +8,9 @@ import numpy as np import h5py import vtk +_min_version = (0,10,0) + + def main(): # Process command line arguments parser = ArgumentParser() @@ -18,6 +21,17 @@ def main(): # Read data from voxel file fh = h5py.File(args.voxel_file, 'r') + + # check version + version = tuple(fh.attrs['openmc_version']) + if version < _min_version: + old_version = ".".join(map(str,version)) + min_version = ".".join(map(str,_min_version)) + err_msg = "This voxel file was generated using OpenMC " \ + "version {}. Please re-generate using "\ + "version {} or higher.".format(old_version, min_version) + raise ValueError(err_msg) + dimension = fh.attrs['num_voxels'] width = fh.attrs['voxel_width'] lower_left = fh.attrs['lower_left'] @@ -34,7 +48,6 @@ def main(): # and flatten to 1-D array print("Reading and translating data...") h5data = fh['data'][...] - h5data = h5data.T.copy() data = vtk.vtkIntArray() data.SetName("id") diff --git a/src/plot.cpp b/src/plot.cpp index ec486ae27..0fb418848 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -884,9 +884,9 @@ void create_voxel(Plot pl) // Create dataset for voxel data -- note that the dimensions are reversed // since we want the order in the file to be z, y, x hsize_t dims[3]; - dims[0] = pl.pixels_[0]; + dims[0] = pl.pixels_[2]; dims[1] = pl.pixels_[1]; - dims[2] = pl.pixels_[2]; + dims[2] = pl.pixels_[0]; hid_t dspace, dset, memspace; voxel_init(file_id, &(dims[0]), &dspace, &dset, &memspace); @@ -895,33 +895,33 @@ void create_voxel(Plot pl) ll[1] = ll[1] + vox[1] / 2.; ll[2] = ll[2] + vox[2] / 2.; - int data[pl.pixels_[1]][pl.pixels_[2]]; + int data[pl.pixels_[1]][pl.pixels_[0]]; ProgressBar pb; RGBColor rgb; int id; - for (int x = 0; x < pl.pixels_[0]; x++) { - pb.set_value(100.*(double)x/(double)(pl.pixels_[0]-1)); + for (int z = 0; z < pl.pixels_[2]; z++) { + pb.set_value(100.*(double)z/(double)(pl.pixels_[2]-1)); for (int y = 0; y < pl.pixels_[1]; y++) { - for (int z = 0; z < pl.pixels_[2]; z++) { + for (int x = 0; x < pl.pixels_[0]; x++) { // get voxel color position_rgb(p, pl, rgb, id); // write to plot data - data[y][z] = id; - // advance particle in z direction - p.coord[0].xyz[2] = p.coord[0].xyz[2] + vox[2]; + data[y][x] = id; + // advance particle in x direction + p.coord[0].xyz[0] = p.coord[0].xyz[0] + vox[0]; } // advance particle in y direction p.coord[0].xyz[1] = p.coord[0].xyz[1] + vox[1]; - p.coord[0].xyz[2] = ll[2]; + p.coord[0].xyz[0] = ll[0]; } - // advance particle in x direction - p.coord[0].xyz[0] = p.coord[0].xyz[0] + vox[0]; + // advance particle in z direction + p.coord[0].xyz[2] = p.coord[0].xyz[2] + vox[2]; p.coord[0].xyz[1] = ll[1]; - p.coord[0].xyz[2] = ll[2]; + p.coord[0].xyz[0] = ll[0]; // Write to HDF5 dataset - voxel_write_slice(x, dspace, dset, memspace, &(data[0])); + voxel_write_slice(z, dspace, dset, memspace, &(data[0])); } voxel_finalize(dspace, dset, memspace);