mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
write_data_to_vtk rectilinear mesh
This commit is contained in:
parent
722b572dc3
commit
5ecac76b69
1 changed files with 34 additions and 7 deletions
|
|
@ -895,7 +895,7 @@ class RectilinearMesh(StructuredMesh):
|
|||
|
||||
return element
|
||||
|
||||
def vtk_grid(self, filename=None):
|
||||
def write_data_to_vtk(self, filename, datasets, volume_normalization=True):
|
||||
"""Creates a VTK object of the mesh
|
||||
|
||||
Args:
|
||||
|
|
@ -908,6 +908,19 @@ class RectilinearMesh(StructuredMesh):
|
|||
import vtk
|
||||
from vtk.util import numpy_support as nps
|
||||
|
||||
if self.volumes is None and volume_normalization:
|
||||
raise RuntimeError("No volume data is present on this "
|
||||
"unstructured mesh. Please load the "
|
||||
" mesh information from a statepoint file.")
|
||||
|
||||
# check that the data sets are appropriately sized
|
||||
for label, dataset in datasets.items():
|
||||
if isinstance(dataset, np.ndarray):
|
||||
assert dataset.size == self.dimension[0] * self.dimension[1]* self.dimension[2]
|
||||
else:
|
||||
assert len(dataset) == self.dimension[0] * self.dimension[1]* self.dimension[2]
|
||||
cv.check_type('label', label, str)
|
||||
|
||||
x_vals = self.x_grid
|
||||
y_vals = self.y_grid
|
||||
z_vals = self.z_grid
|
||||
|
|
@ -922,12 +935,26 @@ class RectilinearMesh(StructuredMesh):
|
|||
vtkPts.SetData(nps.numpy_to_vtk(pts_cartesian, deep=True))
|
||||
vtk_grid.SetPoints(vtkPts)
|
||||
|
||||
if filename:
|
||||
# write the .vtk file
|
||||
writer = vtk.vtkStructuredGridWriter()
|
||||
writer.SetFileName(filename)
|
||||
writer.SetInputData(vtk_grid)
|
||||
writer.Write()
|
||||
# create VTK arrays for each of
|
||||
# the data sets
|
||||
for label, dataset in datasets.items():
|
||||
dataset = np.asarray(dataset).flatten()
|
||||
|
||||
if volume_normalization:
|
||||
dataset /= self.volumes.flatten()
|
||||
|
||||
dataset_array = vtk.vtkDoubleArray()
|
||||
dataset_array.SetName(label)
|
||||
dataset_array.SetArray(nps.numpy_to_vtk(dataset),
|
||||
dataset.size,
|
||||
True)
|
||||
vtk_grid.GetCellData().AddArray(dataset_array)
|
||||
|
||||
# write the .vtk file
|
||||
writer = vtk.vtkStructuredGridWriter()
|
||||
writer.SetFileName(filename)
|
||||
writer.SetInputData(vtk_grid)
|
||||
writer.Write()
|
||||
|
||||
return vtk_grid
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue