Skip to content

Add VTK links to Python bindings

Dave Moxey requested to merge dmoxey/nektar:feature/python-vtk into master

Issue/feature addressed

This branch adds VTK support to the Python bindings, which necessitates adjustment of FieldUtils modules. A Filter wrapper is also added as a method to demonstrate and test the additions.

Proposed solution

Following from !1343 (merged), a function GetVtkGrid has been added to the Python wrapper for Module. This then allows the VTK grid to be returned when the module object is a OutputVtk module. An exception is thrown if either not compiled for VTK or the module is not an instance of OutputVtk.

Implementation

For the VTK output:

  • A prohibitWrite option has been added to the OutputModule class. This indicates that files should not be written out, but that any processing up to the point of writing should be done. This is done so that Python modules can control when output occurs when calling the Run function after a module.
  • The ConvertCommandLine function, used in several places in the Python wrappers, has been refactored into a helper CppCommandLine class. This also ensures memory cleanup is done from the C pointers for argv.
  • A VTK_PYTHON_CONVERSION macro has been adapted from the VTK documentation to enable the wrapping of vtk objects within boost.python. This is defined in the VtkWrapper.hpp file.
  • The Field class has a new function SetupFromExpList which facilitates easier construction of Field objects programatically from both Python and C++.

For Filters:

  • Filter wrapper has been added in a way such that filters can be defined in Python as a subclass, and registered with the C++ factory. This follows the same approach used in NekMesh and FieldUtils.
  • Minimal wrappers have been added for EquationSystem, since this is passed as a weak_ptr to the Filter constructor.
  • To get weak_ptr to work with boost.python, a block of code has been added in NekPyConfig.hpp: this adjusts the mechanism which uses shared_ptr<void> with customer deleter, since this doesn't then allow for conversion from weak_ptr.
  • A FilterPython has been added which serves as a way to usefully use the Filter wrappers. This is documented in the user guide.

Tests

  • Unit tests have been added for the new Filter wrappers.
  • A FilterPython test has been added to ADRSolver, which uses the FieldUtils wrapper and the Filter wrapper to write VTK files as checkpoints.
  • A demo for reading a mesh and creating an image using the VTK Python bindings has been included.

Notes

Checklist

  • Functions and classes, or changes to them, are documented.
  • User guide/documentation is updated.
  • Changelog is updated.
  • Suitable tests added for new functionality.
  • Contributed code is correctly formatted. (See the contributing guidelines).
  • License added to any new files.
  • No extraneous files have been added (e.g. compiler output or test data files).

Warning

On the 19.07 the code formatting (code style) was standardised using clang-format, over the whole Nektar++ code. This means changes in your branch will conflict with formatting changes on the master branch. To resolve these conflicts , see #295 (closed)

Edited by Dave Moxey

Merge request reports