Visualization

To visualize a field represented by a coefficient function, we can use the 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 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.

field_exporter.save()

The fields are saved in VisualizationOutput/ directory in the current working directory. They can be opened using ParaView with

paraview VisualizationOutput/Output.vtpc.series

Example

import mufem

sim = mufem.Simulation.New("My Case", f"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()
paraview VisualizationOutput/Output.vtpc.series

With ParaView we can further post-process the data.

ParaView Cell Volume

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.

ParaView Position X

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 a cell.