Paraview with Alamo and HDF5
Last updated
Was this helpful?
With the HDF5 capability of Alamo, we can now visualize results using Paraview rather than VisIt (although we can still use VisIt if that is your preference). However, there are some nuances:
When opening .h5 files via the GUI, files that should be grouped in a "time series" are opened individually, thus each time step has its own pipeline for filters, etc.
Vector variables are not automatically defined based on x/y/z suffixes, so each directional variable is only accessible as scalar quantities.
In order to assist with these limitations, below is a python script that will force the grouped .h5 files to load in a single time series and will automatically search for variables with x/y/z suffixes and build corresponding vector variables for them.
The script can used by either passing it as an argument if opening Paraview from the command line or as a macro within the GUI itself.
To run the script from the command line, first enter the directory containing the Alamo output file you wish to visualize.
cd /path/to/celloutput.visit
Then, assuming Paraview is accessible in PATH , simply open with the --script flag followed by the path to the Python script.
paraview --script /path/to/paraview_load_alamo.py
To run the script as a macro, first open Paraview from the directory containing the Alamo output file you wish to visualize.
cd /path/to/celloutput.visit
paraviewand from the top menu select Macros->Import new macro...
Locate the Python script and select Ok.
Then once again from the top menu, select Macros->paraview_load_alamo
Last updated
Was this helpful?
Was this helpful?
from paraview.simple import *
import re
import sys
# ------------------------------------------------------------
# Read Chombo file list from celloutput.visit
# ------------------------------------------------------------
output = "celloutput.visit"
files = []
with open(output, "r") as f:
for line in f:
line = line.strip()
if line and not line.startswith("!"):
files.append(line)
# ------------------------------------------------------------
# Create Chombo reader
# ------------------------------------------------------------
reader = VisItChomboReader(FileName=files)
reader.UpdatePipelineInformation()
# ------------------------------------------------------------
# Enable all available cell variables
# ------------------------------------------------------------
all_cell_arrays = []
try:
cell_array_info = reader.GetProperty("CellArrayInfo")
if cell_array_info is not None:
all_cell_arrays = [
cell_array_info.GetElement(i)
for i in range(cell_array_info.GetNumberOfElements())
]
except Exception as e:
print("CellArrayInfo unavailable:")
print(e)
# Fallback
if len(all_cell_arrays) == 0:
print("Using CellArrayStatus fallback")
status = reader.GetProperty("CellArrayStatus")
all_cell_arrays = [
status.GetElement(i)
for i in range(status.GetNumberOfElements())
]
if len(all_cell_arrays) == 0:
raise RuntimeError("No cell arrays found")
reader.CellArrayStatus = all_cell_arrays
reader.UpdatePipelineInformation()
# ------------------------------------------------------------
# Detect vector components
#
# Supports:
# velocityx velocityy velocityz
# solid.momentumx solid.momentumy solid.momentumz
#
# Also supports:
# velocity.x velocity.y velocity.z
# solid.momentum.x ...
# ------------------------------------------------------------
vectors = {}
for name in all_cell_arrays:
# Case 1: suffix x/y/z
m = re.match(r"^(.*)(x|y|z)$", name)
if m:
base, component = m.groups()
vectors.setdefault(base, {})[component] = name
continue
# Case 2: suffix .x/.y/.z
m = re.match(r"^(.*)\.(x|y|z)$", name)
if m:
base, component = m.groups()
vectors.setdefault(base, {})[component] = name
vector_defs = {}
for base, comps in vectors.items():
if "x" in comps and "y" in comps:
vector_defs[base] = comps
# ------------------------------------------------------------
# Chain Calculator filters
# ------------------------------------------------------------
current_input = reader
for vec_name, comps in vector_defs.items():
calc = Calculator(
Input=current_input,
AttributeType="Cell Data",
ResultArrayName=vec_name
)
if "z" in comps:
calc.Function = (
f'iHat*"{comps['x']}" + '
f'jHat*"{comps['y']}" + '
f'kHat*"{comps['z']}"'
)
else:
calc.Function = (
f'iHat*"{comps['x']}" + '
f'jHat*"{comps['y']}"'
)
current_input = calc
# ------------------------------------------------------------
# Enable animation
# ------------------------------------------------------------
animation = GetAnimationScene()
animation.UpdateAnimationUsingDataTimeSteps()
timekeeper = GetTimeKeeper()
# ------------------------------------------------------------
# Convert cell data to point data
# ------------------------------------------------------------
current_input = CellDatatoPointData(Input=current_input)
current_input.UpdatePipeline()
display = Show(current_input)
display.Representation = "Surface"
SetActiveSource(current_input)
Render()