Sometimes it is convenient to export results that were obtained with NGSolve to third party visualization tools (for rendering/videos etc.). A simple way to do this is the export to the VTK format (ascii) that is provided from NGS-py.
Given a mesh (2D or 3D) and a list of CoefficientFunctions and a list of labels (strings) you can create such on object with
# VTKOutput object
vtk = VTKOutput(ma=mesh,
names = ["density","velocity"],
# Exporting the results:
Here the Coefficients in the coefs-list can be scalar- and vector-valued. You can also pass empty lists in case only the geometry should be drawn.
The output only stores piecewise linear information. In order to get a higher resolution of higher order functions you can use the subdivision option. Coefficients are drawn as continuous functions (piecewise linear on the subtriangulation) within elements (currently only simplices are supported) but can be discontinuous across element interfaces.
To actually apply the export you have to call the Do() method of the VTKOuput object which will export the data to the filename with the prefix provided. The Do() method can be called several times (useful for changing data in time-dependent simulations). Each time an index will be increased and added as a suffix to the filename it exports to.
Attached you can find a simple example which visualizes all basis function of an H(div)-conforming FESpace and puts them into a sequence. This sequence can be visualized from external software, for instance Paraview (a screenshot is also attached).
Uploaded Thursday, 05 January 2017 by Christoph Lehrenfeld