Skip to content

Commit b5486c9

Browse files
authored
Add CLI visualization command (./mfc.sh viz) (#1233)
1 parent ab5082e commit b5486c9

File tree

55 files changed

+4855
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4855
-496
lines changed

.typos.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ choises = "choises" # appears in comment explaining validation purpose
2828
ordr = "ordr" # typo for "order" in "weno_ordr" - tests param suggestions
2929
unknwn = "unknwn" # typo for "unknown" - tests unknown param detection
3030
tru = "tru" # typo for "true" in "when_tru" - tests dependency keys
31+
PNGs = "PNGs"
3132

3233
[files]
33-
extend-exclude = ["docs/documentation/references*", "docs/references.bib", "tests/", "toolchain/cce_simulation_workgroup_256.sh", "build-docs/"]
34+
extend-exclude = ["docs/documentation/references*", "docs/references.bib", "tests/", "toolchain/cce_simulation_workgroup_256.sh", "build-docs/", "build/", "build_test/"]

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ IMPORTANT: Follow this loop for ALL code changes. Do not skip steps.
108108
YOU MUST run `./mfc.sh precheck` before any commit. This is enforced by pre-commit hooks.
109109
YOU MUST run tests relevant to your changes before claiming work is done.
110110
NEVER commit code that does not compile or fails tests.
111+
NEVER use heredocs for git commit messages. Use simple `git commit -m "message"` instead.
111112

112113
## Architecture
113114

docs/documentation/case.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ To restart the simulation from $k$-th time step, see @ref running "Restarting Ca
651651

652652
The table lists formatted database output parameters. The parameters define variables that are outputted from simulation and file types and formats of data as well as options for post-processing.
653653

654-
- `format` specifies the choice of the file format of data file outputted by MFC by an integer of 1 and 2. `format = 1` and `2` correspond to Silo-HDF5 format and binary format, respectively.
654+
- `format` specifies the choice of the file format of data file outputted by MFC by an integer of 1 and 2. `format = 1` and `2` correspond to Silo-HDF5 format and binary format, respectively. Both formats are supported by `./mfc.sh viz` (see @ref visualization "Flow Visualization"). Silo-HDF5 requires the h5py Python package; binary has no extra dependencies.
655655

656656
- `precision` specifies the choice of the floating-point format of the data file outputted by MFC by an integer of 1 and 2. `precision = 1` and `2` correspond to single-precision and double-precision formats, respectively.
657657

docs/documentation/getting-started.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,24 @@ MFC is **unit-agnostic**: the solver performs no internal unit conversions. What
204204

205205
The only requirement is **consistency** — all inputs must use the same unit system. Note that some parameters use **transformed stored forms** rather than standard physical values (e.g., `gamma` expects \f$1/(\gamma-1)\f$, not \f$\gamma\f$ itself). See @ref sec-stored-forms for details.
206206

207+
## Visualizing Results
208+
209+
After running post_process, visualize the output directly from the command line:
210+
211+
```shell
212+
# List available variables
213+
./mfc.sh viz examples/2D_shockbubble/ --list-vars --step 0
214+
215+
# Render a pressure snapshot
216+
./mfc.sh viz examples/2D_shockbubble/ --var pres --step 1000
217+
218+
# Generate a video
219+
./mfc.sh viz examples/2D_shockbubble/ --var pres --step all --mp4
220+
```
221+
222+
Output images and videos are saved to the `viz/` subdirectory of the case.
223+
For more options, see @ref visualization "Flow Visualization" or run `./mfc.sh viz -h`.
224+
207225
## Helpful Tools
208226

209227
### Parameter Lookup

docs/documentation/running.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ using 4 cores:
7373
./mfc.sh run examples/2D_shockbubble/case.py -t simulation post_process -n 4
7474
```
7575

76+
- Visualizing post-processed output:
77+
78+
```shell
79+
./mfc.sh viz examples/2D_shockbubble/ --var pres --step 1000
80+
```
81+
82+
See @ref visualization "Flow Visualization" for the full set of visualization options.
83+
7684
---
7785

7886
## Running on GPUs

docs/documentation/troubleshooting.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ This guide covers debugging tools, common issues, and troubleshooting workflows
3737
./mfc.sh run case.py -v # Run with verbose output
3838
./mfc.sh test --only <UUID> # Run a specific test
3939
./mfc.sh clean # Clean and start fresh
40+
./mfc.sh viz case_dir/ --list-vars --step 0 # Inspect post-processed data
4041
```
4142

4243
---
@@ -457,6 +458,47 @@ Common issues:
457458

458459
---
459460

461+
## Visualization Issues
462+
463+
### "No 'binary/' or 'silo_hdf5/' directory found"
464+
465+
**Cause:** Post-processing has not been run, or the case directory path is wrong.
466+
467+
**Fix:**
468+
1. Run post_process first:
469+
```bash
470+
./mfc.sh run case.py -t post_process
471+
```
472+
2. Verify the path points to the case directory (containing `binary/` or `silo_hdf5/`)
473+
474+
### "Variable 'X' not found"
475+
476+
**Cause:** The requested variable was not written during post-processing.
477+
478+
**Fix:**
479+
1. List available variables:
480+
```bash
481+
./mfc.sh viz case_dir/ --list-vars --step 0
482+
```
483+
2. Ensure your case file enables the desired output (e.g., ``prim_vars_wrt = 'T'``, ``cons_vars_wrt = 'T'``)
484+
485+
### "h5py is required to read Silo-HDF5 files"
486+
487+
**Cause:** The case was post-processed with `format=1` (Silo-HDF5) but `h5py` is not installed.
488+
489+
**Fix:**
490+
- Install h5py: `pip install h5py`
491+
- Or re-run post_process with `format=2` in your case file to produce binary output
492+
493+
### Visualization looks wrong or has artifacts
494+
495+
**Possible causes and fixes:**
496+
1. **Color range:** Try setting explicit `--vmin` and `--vmax` values
497+
2. **Wrong variable:** Use `--list-vars` to check available variables
498+
3. **3D slice position:** Adjust `--slice-axis` and `--slice-value` to view the correct plane
499+
500+
---
501+
460502
## Getting Help
461503

462504
If you can't resolve an issue:

docs/documentation/visualization.md

Lines changed: 198 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,206 @@
22

33
# Flow visualization
44

5-
A post-processed database in Silo-HDF5 format can be visualized and analyzed using Paraview and VisIt.
6-
After the post-processing of simulation data (see section @ref running "Running"), a directory named `silo_hdf5` contains a silo-HDF5 database.
7-
Here, `silo_hdf5/` includes a directory named `root/` that contains index files for flow field data at each saved time step.
5+
After running `post_process` on a simulation (see @ref running "Running"), MFC produces output in either Silo-HDF5 format (`format=1`) or binary format (`format=2`).
6+
These can be visualized using MFC's built-in CLI tool or external tools like ParaView and VisIt.
87

9-
### Visualizing with Paraview
8+
---
109

11-
Paraview is an open-source interactive parallel visualization and graphical analysis tool for viewing scientific data.
10+
## Quick visualization with `./mfc.sh viz`
11+
12+
MFC includes a built-in visualization command that renders images and videos directly from post-processed output — no external GUI tools needed.
13+
14+
### Basic usage
15+
16+
```bash
17+
# Launch the terminal UI (default mode)
18+
./mfc.sh viz case_dir/
19+
20+
# Launch with a specific variable pre-selected
21+
./mfc.sh viz case_dir/ --var pres
22+
```
23+
24+
The command auto-detects the output format (binary or Silo-HDF5) and dimensionality (1D, 2D, or 3D).
25+
By default it launches an interactive terminal UI that works over SSH.
26+
Use `--interactive` for a browser-based UI (supports 3D), `--png` to save images, or `--mp4` for video.
27+
28+
### Exploring available data
29+
30+
Before plotting, you can inspect what data is available:
31+
32+
```bash
33+
# List all available timesteps
34+
./mfc.sh viz case_dir/ --list-steps
35+
36+
# List all available variables at a given timestep
37+
./mfc.sh viz case_dir/ --list-vars --step 0
38+
```
39+
40+
### Timestep selection
41+
42+
The `--step` argument accepts several formats:
43+
44+
| Format | Example | Description |
45+
|--------|---------|-------------|
46+
| Single | `--step 1000` | One timestep |
47+
| Range | `--step 0:10000:500` | Start:end:stride (inclusive) |
48+
| Last | `--step last` | Most recent available timestep |
49+
| All | `--step all` | Every available timestep |
50+
51+
### Rendering options
52+
53+
Customize the appearance of plots:
54+
55+
```bash
56+
# Custom colormap and color range
57+
./mfc.sh viz case_dir/ --var rho --step 1000 --png --cmap RdBu --vmin 0.5 --vmax 2.0
58+
59+
# Higher resolution
60+
./mfc.sh viz case_dir/ --var pres --step 500 --png --dpi 300
61+
62+
# Logarithmic color scale
63+
./mfc.sh viz case_dir/ --var pres --step 1000 --png --log-scale
64+
```
65+
66+
| Option | Description | Default |
67+
|--------|-------------|---------|
68+
| `--cmap` | Matplotlib colormap name | `viridis` |
69+
| `--vmin` | Minimum color scale value | auto |
70+
| `--vmax` | Maximum color scale value | auto |
71+
| `--dpi` | Image resolution (dots per inch) | 150 |
72+
| `--log-scale` | Use logarithmic color scale | off |
73+
| `--output` | Output directory for images | `case_dir/viz/` |
74+
75+
### 3D slicing
76+
77+
For 3D simulations, `viz` extracts a 2D slice for plotting.
78+
By default, it slices at the midplane along the z-axis.
79+
80+
> [!NOTE]
81+
> To limit memory use, 3D batch rendering is capped at 500 timesteps and
82+
> `--interactive` mode at 50. Use `--step start:end:stride` to stay within
83+
> these limits when processing many steps.
84+
85+
```bash
86+
# Default z-midplane slice
87+
./mfc.sh viz case_dir/ --var pres --step 500 --png
88+
89+
# Slice along the x-axis at x=0.25
90+
./mfc.sh viz case_dir/ --var pres --step 500 --png --slice-axis x --slice-value 0.25
91+
92+
# Slice by array index
93+
./mfc.sh viz case_dir/ --var pres --step 500 --png --slice-axis y --slice-index 50
94+
```
95+
96+
### Video generation
97+
98+
Generate MP4 videos from a range of timesteps:
99+
100+
```bash
101+
# Basic video (10 fps)
102+
./mfc.sh viz case_dir/ --var pres --step 0:10000:100 --mp4
103+
104+
# Custom frame rate
105+
./mfc.sh viz case_dir/ --var rho --step all --mp4 --fps 24
106+
107+
# Video with fixed color range
108+
./mfc.sh viz case_dir/ --var rho --step 0:5000:50 --mp4 --vmin 0.1 --vmax 1.0
109+
```
110+
111+
Videos are saved as `case_dir/viz/<varname>.mp4`.
112+
The color range is automatically computed from the first, middle, and last frames unless `--vmin`/`--vmax` are specified.
113+
114+
### Tiled 1D rendering
115+
116+
For 1D cases, omitting `--var` (or passing `--var all`) renders all variables in a single tiled figure:
117+
118+
```bash
119+
# Tiled plot of all variables at the last timestep
120+
./mfc.sh viz case_dir/ --step last --png
121+
122+
# Equivalent explicit form
123+
./mfc.sh viz case_dir/ --var all --step last --png
124+
```
125+
126+
Each variable gets its own subplot with automatic LaTeX-style axis labels.
127+
Tiled mode is available for 1D and 2D data. For 3D data, omitting `--var` auto-selects the first variable.
128+
129+
### Interactive mode
130+
131+
Launch a browser-based interactive viewer with `--interactive`:
132+
133+
```bash
134+
./mfc.sh viz case_dir/ --interactive
135+
136+
# Custom port
137+
./mfc.sh viz case_dir/ --interactive --port 9000
138+
```
139+
140+
The interactive viewer provides a Dash web UI with:
141+
- Variable and timestep selection
142+
- Live plot updates
143+
- Pan, zoom, and hover inspection
144+
145+
> [!NOTE]
146+
> Interactive mode requires the `dash` Python package.
147+
148+
### Terminal UI (TUI)
149+
150+
The default mode launches a live terminal UI that works over SSH with no browser or port-forwarding needed:
151+
152+
```bash
153+
./mfc.sh viz case_dir/
154+
155+
# Start with a specific variable pre-selected
156+
./mfc.sh viz case_dir/ --var pres
157+
```
158+
159+
The TUI loads all timesteps and renders plots directly in the terminal using Unicode block characters.
160+
It supports 1D and 2D data only (use `--interactive` for 3D).
161+
162+
**Keyboard shortcuts:**
163+
164+
| Key | Action |
165+
|-----|--------|
166+
| `.` / `` | Next timestep |
167+
| `,` / `` | Previous timestep |
168+
| `Space` | Toggle autoplay |
169+
| `l` | Toggle logarithmic scale |
170+
| `f` | Freeze / unfreeze color range |
171+
| `` / `` | Select variable (in sidebar) |
172+
| `c` | Cycle colormap |
173+
| `q` | Quit |
174+
175+
### Plot styling
176+
177+
Axis labels use LaTeX-style math notation — for example, `pres` is labeled as \f$p\f$, `vel1` as \f$u\f$, and `alpha1` as \f$\alpha_1\f$.
178+
Plots use serif fonts and the Computer Modern math font for consistency with publication figures.
179+
180+
### Format selection
181+
182+
The output format is auto-detected from the case directory.
183+
To override:
184+
185+
```bash
186+
./mfc.sh viz case_dir/ --var pres --step 0 --format binary
187+
./mfc.sh viz case_dir/ --var pres --step 0 --format silo
188+
```
189+
190+
> [!NOTE]
191+
> Reading Silo-HDF5 files requires the `h5py` Python package.
192+
> If it is not installed, you will see a clear error message with installation instructions.
193+
> Alternatively, use `format=2` (binary) in your case file to produce binary output, which has no extra dependencies.
194+
195+
### Complete option reference
196+
197+
Run `./mfc.sh viz -h` for a full list of options.
198+
199+
---
200+
201+
## Visualizing with ParaView
202+
203+
ParaView is an open-source interactive parallel visualization and graphical analysis tool for viewing scientific data.
204+
Post-processed data in Silo-HDF5 format (`format=1`) can be opened directly in ParaView.
12205
Paraview 5.11.0 has been confirmed to work with the MFC databases for some parallel environments.
13206
Nevertheless, the installation and configuration of Paraview can be environment-dependent and are left to the user.
14207

0 commit comments

Comments
 (0)