Exporting fields#
FESTIM has convenience classes that allow users to create XDMF and VTX exports, which can then be viewed in Paraview.
Objectives:
Writing VTX files for species and temperature fields
Additional options for VTX exports
Writing XDMF files for field exports
Writing VTX files for species and temperature fields#
Users can export concentration fields to VTX using VTXSpeciesExport, and then view their exports in ParaView. This example will discuss how to define the export, and what result should you expect to see.
Let us setup a 2D, transient problem with the following boundary conditions:
/home/docs/checkouts/readthedocs.org/user_builds/festim-workshop/conda/latest/lib/python3.12/site-packages/festim/coupled_heat_hydrogen_problem.py:1: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)
import tqdm.autonotebook
We can export the concentration field by defining a VTXSpeciesExport object for our model. The required arguments are a filename path (which must end in .bp) and the field (species) you want to export:
H_export = F.VTXSpeciesExport(filename="H_concentration.bp", field=H)
Note
If we had several Species, we would create several VTXSpeciesExport objects, one per species.
If needed, we can also export the temperature field this way using VTXTemperatureExport
temp_export = F.VTXTemperatureExport(filename="temperature.bp")
Then, we just pass these exports to my_model.exports as a list:
my_model.exports = [H_export, temp_export]
my_model.initialise()
my_model.run()
We should expect to see two new folders called H_concentration.bp and temperature.bp. To view the results, we can use ParaView (see the ParaView section to learn more).
Exporting results for a discontinuous problem#
If running a multi-material discontinuous simulation, it is necessary to also specify the subdomain during the export process.
Consider the same multi-material problem in the Materials chapter, where we use HydrogenTransportProblemDiscontinuous to solve a multi-material problem:
We can specify separate export objects for the top and bottom domains using the subdomain argument, and should expect to see two new folders created named top.bp and bottom.bp:
top_export = F.VTXSpeciesExport(filename="top.bp", field=H, subdomain=top_volume)
bottom_export = F.VTXSpeciesExport(filename="bottom.bp", field=H, subdomain=bottom_volume)
my_model.exports = [
top_export,
bottom_export,
]
my_model.initialise()
my_model.run()
Finally, these .bp exports can be viewed in ParaView:
Note
For multi-material discontinuous problems, each .bp file only shows its corresponding subdomain.
Exporting fields at specific timesteps#
Users can also specify which timesteps they’d like to export using the times argument (which must be a list):
export = F.VTXSpeciesExport(filename="H_concentration.bp", field=H, times=[0, 5, 10])
If no times argument is given, the export stores results for all timesteps by default.
Checkpointing#
It may be helpful to store results from one simulation for later use in another (perhaps as an initial condition, see Initial condition from a checkpoint file). FESTIM includes this capability by incorporationg adios4dolfinx functionality, which stores mesh information and solutions into a checkpoint.bp file. Learn more about checkpointing in DOLFINx here.
To store the species field as a checkpoint file, simply set the checkpoint argument to True:
export = F.VTXSpeciesExport(filename="H_concentration.bp", field=H, checkpoint=True)
Note
Checkpointed files cannot be viewed in ParaView.
Writing XDMF files for field exports#
Warning
Exporting to VTX is preferable over XDMF, as XDMF functionality will soon be deprecated. Additionally, you cannot view transient results using XDMF.
Users can export functions to XDMF files using the XDMFExport class, which requires a filename and field:
import festim as F
H = F.Species("H")
export = F.XDMFExport(filename="my_export.xdmf", field=H)
To export this in a FESTIM simulation, add the export to your problem’s export attribute:
my_model = F.HydrogenTransportProblem()
my_model.exports = [export]
This will produce the corresponding export files (my_export.xdmf and my_export.h5).