Visualization¶
Introduction¶
To visualize a field represented by a coefficient function, we can use the
mufem.FieldExporter class.
This class provides methods to export coefficient functions to the VTK file
format that can be visualized in tools like
ParaView.
Generally, all fields provided by the CoefficientManager can be exported to a VTK file using following syntax:
Field Exporter¶
The mufem.FieldExporter class is used to export coefficient functions to a VTK
file format:
field_exporter = sim.get_field_exporter()
field_exporter.add_field_output("Cell Volume")
field_exporter.add_field_output("Element Type")
field_exporter.add_field_output("Position")
Note that to actually save the fields a call to save() is required:
The fields are saved in VisualizationOutput/ directory in the current working
directory.
They can be opened using ParaView with
Example¶
import mufem
sim = mufem.Simulation.New(
name="My Case", mesh_path="data/mufem.mesh", print_only_warnings=True,
)
refinement_model = mufem.RefinementModel()
sim.get_model_manager().add_model(refinement_model)
field_exporter = sim.get_field_exporter()
field_exporter.add_field_output("Cell Volume")
field_exporter.add_field_output("Element Type")
field_exporter.add_field_output("Position")
field_exporter.save()
With ParaView we can further post-process the data.

The image above shows the Cell Volume field visualized in ParaView. It highlights the distribution of cell sizes in the mesh, which can help identify regions of refinement or poor quality. Note that the cell volume is cell-wise constant.

The image above shows the Position field visualized in ParaView, specifically the x-component. This field is not cell-wise constant thus we can see the variation of the x coordinate across a cell.