Visualization¶
The voids.visualization sub-package provides network rendering via Plotly and
PyVista, plus reusable scalar/vector field plotting and ParaView export helpers
for map-based validation workflows.
PyVista dependency
PyVista is installed as a core dependency of voids and is available by
default when you install the package.
Plotly¶
voids.visualization.plotly
¶
plot_network_plotly
¶
plot_network_plotly(
net,
*,
point_scalars=None,
cell_scalars=None,
point_sizes=None,
throat_sizes=None,
point_size=None,
line_width=None,
line_opacity=0.4,
size_scale=1.0,
point_size_limits=None,
throat_size_limits=None,
max_throats=1000,
title=None,
show_colorbar=True,
layout_kwargs=None,
)
Create an interactive Plotly visualization of a pore-throat network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to render. |
required |
point_scalars
|
str | ndarray | None
|
Pore field name or explicit pore-valued array with shape |
None
|
cell_scalars
|
str | ndarray | None
|
Throat field name or explicit throat-valued array with shape |
None
|
point_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
throat_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
point_size
|
float | None
|
Constant marker size for pores when explicit size rendering is disabled. When size-driven rendering is active, this acts as the reference marker size for median-sized pores. |
None
|
line_width
|
float | None
|
Constant line width for throats when explicit size rendering is disabled. When size-driven rendering is active, this acts as the reference width for median-sized throats. |
None
|
line_opacity
|
float
|
Opacity applied to throat lines. |
0.4
|
size_scale
|
float
|
Multiplicative factor applied to size-driven pore markers and throat widths. |
1.0
|
point_size_limits
|
tuple[float | None, float | None] | None
|
Optional |
None
|
throat_size_limits
|
tuple[float | None, float | None] | None
|
Optional |
None
|
max_throats
|
int | None
|
Maximum number of throats to draw. Large networks are downsampled for responsiveness. |
1000
|
title
|
str | None
|
Figure title. |
None
|
show_colorbar
|
bool
|
If |
True
|
layout_kwargs
|
dict[str, Any] | None
|
Optional Plotly layout overrides. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
Interactive 3D figure. |
Notes
If only pore scalars are given, each throat is colored by the arithmetic mean of its endpoint pore values:
s_throat = 0.5 * (s_i + s_j)
The throat colormap is normalized with the same scalar bounds as the pore markers so that equal numerical values map to equal colors across pores and throats.
Source code in src/voids/visualization/plotly.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
PyVista¶
voids.visualization.pyvista
¶
network_to_pyvista_polydata
¶
network_to_pyvista_polydata(
net,
*,
point_scalars=None,
cell_scalars=None,
include_all_numeric_fields=False,
)
Convert a network to pyvista.PolyData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to convert. |
required |
point_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
cell_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
include_all_numeric_fields
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
PolyData
|
PolyData with pores as points and throats as line cells. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a requested scalar field name is missing. |
ValueError
|
If an explicit scalar array has the wrong shape. |
Source code in src/voids/visualization/pyvista.py
plot_network_pyvista
¶
plot_network_pyvista(
net,
*,
point_scalars=None,
cell_scalars=None,
point_sizes=None,
throat_sizes=None,
show_points=True,
show_lines=True,
line_width=None,
point_size=None,
render_tubes=False,
tube_radius=None,
size_scale=1.0,
off_screen=False,
screenshot=None,
show_axes=True,
notebook=None,
**add_mesh_kwargs,
)
Render a pore network with PyVista.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
net
|
Network
|
Network to render. |
required |
point_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
cell_scalars
|
str | ndarray | None
|
Pore/throat scalar field name or explicit array. |
None
|
point_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
throat_sizes
|
str | ndarray | bool | None
|
Pore/throat characteristic size field name, explicit size array, |
None
|
show_points
|
bool
|
Toggle pore and throat rendering. |
True
|
show_lines
|
bool
|
Toggle pore and throat rendering. |
True
|
line_width
|
float | None
|
Width used for line rendering when throat sizes are not rendered with tubes. |
None
|
point_size
|
float | None
|
Marker size used for pores when size-driven sphere rendering is disabled. |
None
|
render_tubes
|
bool
|
If |
False
|
tube_radius
|
float | None
|
Optional tube radius when |
None
|
size_scale
|
float
|
Multiplicative factor applied to point diameters and throat radii in world units. |
1.0
|
off_screen
|
bool
|
If |
False
|
screenshot
|
str | None
|
Optional screenshot output path. When provided, the plot is rendered and saved. |
None
|
show_axes
|
bool
|
If |
True
|
notebook
|
bool | None
|
Optional PyVista notebook flag. Defaults to |
None
|
**add_mesh_kwargs
|
Any
|
Additional keyword arguments forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
tuple
|
Pair |
Notes
For throat rendering, scalar selection follows this priority:
- explicit throat/cell scalar data
- pore/point scalar data, reused on the line representation
This allows pore-defined pressure fields to color both pores and throats in a consistent network visualization.
When tube rendering is requested (via render_tubes, tube_radius, or
automatically detected variable throat sizes) but the PyVista tube filter is
unavailable or raises an exception, rendering falls back to line geometry with
render_lines_as_tubes=True so that a tube-like appearance is preserved.
Variable throat radii cannot be accurately represented in this fallback mode;
a :class:UserWarning is emitted to notify callers.
Source code in src/voids/visualization/pyvista.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
Field Plots And Exports¶
The field helpers are intended for pressure and velocity diagnostics generated
by finite-volume, finite-element, and lattice-Boltzmann single-phase workflows.
Velocity midplane plots draw velocity magnitude as the scalar background and
in-plane quiver arrows as the vector overlay. Structured vector fields can be
written as VTU/VTK cell data, and DOLFINx functions can be written as XDMF/HDF5
after interpolation to first-order visualization spaces for ParaView
compatibility. For pressure diagnostics, reference_pressure_to_outlet removes
arbitrary pressure gauges by shifting the field so the outlet layer has a
prescribed reference pressure, while preserving all pressure differences.
voids.visualization.fields
¶
vector_magnitude
¶
Return the Euclidean magnitude of a dim-first vector field.
reference_pressure_to_outlet
¶
reference_pressure_to_outlet(
pressure,
*,
flow_axis="x",
reference_pressure=100000.0,
pressure_outlet=0.0,
)
Shift a pressure field so the outlet layer has a reference pressure.
In incompressible Darcy, Brinkman, and Stokes solves, pressure is only
determined up to an additive constant. This helper preserves the computed
pressure differences and adds the constant needed to make the mean outlet
layer pressure equal to reference_pressure + pressure_outlet.
The outlet layer is assumed to be the maximum-index face along
flow_axis, matching the pressure convention used by the map-based
validation notebooks.
Source code in src/voids/visualization/fields.py
reconstruct_tpfa_cell_velocity
¶
reconstruct_tpfa_cell_velocity(
pressure,
permeability,
*,
flow_axis="x",
viscosity=1.0,
pressure_inlet=1.0,
pressure_outlet=0.0,
cell_size=None,
)
Reconstruct a cell-centered Darcy velocity field from a TPFA pressure solve.
The reconstruction uses the same two-point face fluxes as the TPFA balance:
harmonic permeability on interior faces, half-cell Dirichlet transmissibility
on inlet/outlet faces, and zero transverse boundary flux. The returned field
is a dim-first array with shape (ndim, *pressure.shape).
Source code in src/voids/visualization/fields.py
write_structured_vector_field
¶
write_structured_vector_field(
vector,
grid,
path,
*,
name="velocity",
extra_cell_data=None,
file_format=None,
)
Write a regular-grid vector field to a ParaView-readable mesh file.
The output uses the structured map mesh representation in voids.mesh and
stores the vector as cell data. Use a .vtu or .vtk suffix for common
ParaView workflows.
Source code in src/voids/visualization/fields.py
write_dolfinx_function_xdmf
¶
Write a DOLFINx function to an XDMF/HDF5 file readable by ParaView.
DOLFINx XDMF output expects a function layout compatible with the mesh geometry. To make high-order and discontinuous fields robustly viewable, the function is first interpolated to a first-order Lagrange visualization space.
Source code in src/voids/visualization/fields.py
sample_dolfinx_function_on_grid
¶
Sample a DOLFINx scalar or vector function at regular cell centers.
Source code in src/voids/visualization/fields.py
plot_scalar_midplanes
¶
plot_scalar_midplanes(
scalar,
*,
title,
path=None,
cmap="viridis",
colorbar_label=None,
vmin=None,
vmax=None,
colorbar_use_offset=True,
)
Plot scalar-field mid-slices and optionally save the figure.
Source code in src/voids/visualization/fields.py
plot_vector_midplanes
¶
plot_vector_midplanes(
vector,
*,
title,
path=None,
quiver_stride=3,
cmap="magma",
colorbar_label="velocity magnitude",
vmin=None,
vmax=None,
)
Plot vector-field magnitude mid-slices with in-plane quiver arrows.