How to Export Simulation Results for ParaView Using Phasefieldx
The phasefieldx library automatically generates ParaView-compatible VTU and XDMF files during simulations, writing indexed time-series data to dedicated output folders that open directly in ParaView without manual conversion.
The phasefieldx repository provides open-source solvers for phase-field fracture simulations built on FEniCSx. When you run a simulation, the framework automatically handles the export simulation results for ParaView workflow by generating standardized VTK output files alongside your computation.
Automatic Export Architecture
The export functionality is embedded directly in the solver classes. When a simulation starts, the code creates two distinct output directories to maximize compatibility with different post-processing workflows.
VTU Output Structure
During initialization in src/phasefieldx/Element/Phase_Field_Fracture/solver/solver.py, the solver creates a paraview-solutions_vtu folder inside your result directory. It instantiates a dolfinx.io.VTKFile writer that produces a PVD index file and individual VTU files for each time step:
# src/phasefieldx/Element/Phase_Field_Fracture/solver/solver.py
paraview_solution_folder_name_vtu = os.path.join(
result_folder_name, "paraview-solutions_vtu")
if rank == 0:
os.makedirs(paraview_solution_folder_name_vtu, exist_ok=True)
vtk_sol = dolfinx.io.VTKFile(msh.comm,
os.path.join(paraview_solution_folder_name_vtu,
"phasefieldx.pvd"), "w")
At each time step, the solver writes a file named fenicsx_p0_<step>.vtu. The phasefieldx.pvd file acts as a manifest that ParaView uses to load the entire time series as a single animated dataset.
XDMF Output Structure
Simultaneously, the solver creates a paraview-solutions_xdmf folder containing phi.xdmf and u.xdmf files. These XDMF files provide high-performance access to the phase-field variable and displacement fields, respectively, and are particularly useful for large-scale simulations where VTU overhead becomes significant.
Locating and Opening Results in ParaView
Once your simulation completes, follow this workflow to visualize the results:
-
Navigate to the output folder. The solver organizes results under your specified
result_folder_name, creating subdirectoriesparaview-solutions_vtuandparaview-solutions_xdmf. -
Open the PVD file. In ParaView, select File → Open and choose
phasefieldx.pvdfrom theparaview-solutions_vtufolder. This loads the complete time series. -
Visualize fields. Apply the Warp By Vector filter to the displacement field
u, or use volume rendering to inspect the phase-field variablephirepresenting crack evolution.
Programmatic Access with ParaviewResult
For automated post-processing or custom analysis pipelines, the ParaviewResult class in src/phasefieldx/PostProcessing/paraview.py handles VTU file discovery and loading:
from phasefieldx.PostProcessing.paraview import ParaviewResult
import numpy as np
import os
folder = "my_simulation"
# Discover available steps from the VTU files
vtu_dir = os.path.join(folder, "paraview-solutions_vtu")
steps = sorted({int(f.split('_')[-1].split('.')[0])
for f in os.listdir(vtu_dir) if f.endswith('.vtu')})
# Load the results
result = ParaviewResult(folder, steps)
# Access the final time step's mesh and data
final_mesh = result.data[-1]
phi_values = final_mesh['phi'] # Extract phase-field values
The class automatically constructs the file naming pattern fenicsx_p0_<step>.vtu and uses PyVista to read the meshes into memory.
Post-Processing Utilities
The repository includes specialized tools that consume the same VTU output structure. For example, the 2D crack length measurement utility expects data in the standard paraview-solutions_vtu folder:
from phasefieldx.PostProcessing.measure_crack_length_2d import measure_crack
measure_crack("my_simulation",
physical_horizontal=1.0,
physical_vertical=0.5)
This script converts each VTU to a PNG, extracts the crack geometry using the phase-field variable, and writes crack_lengths.txt alongside an animated GIF of crack propagation.
Summary
- Automatic export: The phasefieldx solver generates
paraview-solutions_vtuandparaview-solutions_xdmffolders without manual configuration. - File formats: VTU files with a PVD index provide full time-series support in ParaView, while XDMF offers high-performance alternatives.
- Programmatic access: The
ParaviewResultclass insrc/phasefieldx/PostProcessing/paraview.pysimplifies loading VTU data into Python for custom analysis. - Integrated tools: Post-processing utilities like the crack length measurer consume the standard VTU output directly.
Frequently Asked Questions
What file formats does phasefieldx export for ParaView?
The framework exports VTU (VTK Unstructured Grid) files organized under paraview-solutions_vtu with a master .pvd index file, and XDMF files under paraview-solutions_xdmf. The VTU format is the standard route for ParaView visualization, while XDMF provides optimized I/O for large datasets.
Where are the ParaView output files located?
After a simulation completes, the files reside in two subdirectories within your specified result folder: paraview-solutions_vtu/ contains the time-series VTU files and phasefieldx.pvd, while paraview-solutions_xdmf/ holds phi.xdmf and u.xdmf. These paths are hardcoded in the solver logic at src/phasefieldx/Element/Phase_Field_Fracture/solver/solver.py.
Can I load phasefieldx results without using ParaView?
Yes. The ParaviewResult class in src/phasefieldx/PostProcessing/paraview.py allows you to load VTU files directly into Python using PyVista. This enables custom analysis, plotting with Matplotlib, or integration into automated post-processing pipelines without opening the ParaView GUI.
How do I export only specific time steps for ParaView?
The solver currently writes every time step to disk automatically. To work with a subset, use the ParaviewResult class to load specific steps by passing a filtered list of step numbers, or manually copy the desired fenicsx_p0_<step>.vtu files from the paraview-solutions_vtu folder to a new location. The PVD file is XML-based and can be edited to reference only the steps you wish to visualize.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →