Hi Corbin, On Wed, 25 Nov 2020 at 00:05, Bruno Turcksin <[email protected]> wrote:
> deal.II has some limited support for python mainly for mesh manipulation. > We have some python notebooks here > <https://github.com/dealii/dealii/blob/master/contrib/python-bindings/notebooks/index.ipynb>. > I think what you want to do is similar to the step-62 notebook. Right now, > the only way to interact with numpy is to print the data to a file and then > load it (see here > <https://dealii.org/current/doxygen/deal.II/classLinearAlgebra_1_1Vector.html#a2fadcc595d3e7e9ba44de8c85fd7595c> > and here > <https://dealii.org/current/doxygen/deal.II/classSparseMatrix.html#a3141075e3ad6362fce005d2f1c8da699>). > If you want to manipulate the mesh directly in python, you need > boost.python and you need to configure deal.II with > -DDEAL_II_COMPONENT_PYTHON_BINDING=ON. It's sometimes a little bit tricky > to enable the python binding so don't hesitate to ask any question on the > mailing list if you need help. > > On Tuesday, November 24, 2020 at 12:16:18 AM UTC-5 [email protected] > wrote: > >> >> - what is the best practice for exporting deal.ii solution data in a >> way that Python / numpy can interact with it? >> >> Depending on what you want from the data, another option might be to export the data as .vtu (*not* .vtk) and read it with VTKPython. For example, you can use VTKPython to grid it, and then work with the gridded data with numpy. If I/O turns out to be a bottleneck, you could also consider writing the data as HDF5 https://www.dealii.org/current/doxygen/deal.II/namespaceHDF5.html and then accessing the HDF5 file from Python (using h5py, for example). I haven't used deal.II's HDF5 export but HDF5 can sometimes vastly improve I/O performance compared to text files or even other binary formats (e.g., with blosc compression). > >> - Is there a good way for external software to 'hook' into the >> deal.ii pipeline? Something like: >> - initialize a triangulation / grid >> - run the solver >> - make a call like: new_data = external_software(deal_ii_output, >> grid) >> - reinitialize the grid based on new_data >> - loop >> >> Have you used Cython at all? https://cython.org/ It is my favorite way to use C and C++ libraries from Python (compared to binding generators, or writing extensions by hand, or cffi). It provides a very natural way to transfer data to and from C or C++ library code using typed numpy arrays. It can take some patience to get what you want from the documentation, but if you are already used to Python and have some familiarity with C and C++ it makes it very easy to migrate code between C / C++ and Python. So, for example, you can prototype in Python and gradually shift functionality over to C or C++. What I have found easiest is to put the heavy-lifting code in a static C++ library, building from the (awesome) deal.II tutorials and documentation, and then wrap that C++ library into a loadable Python extension module using Cython. Then you can pass arguments from Python to your solver using the extension module. In my experience, the trickiest part of this is not Cython per se, but getting testing and continuous integration working with the mix of languages: C++, Cython, Python, and your build system (CMake?) mini-language. If you choose this route, another option for controlling your solver from Python (possibly with less pain / dependencies than Boost.Python?) might be pybind11 (disclaimer: haven't tried it myself). Best Alex -- The deal.II project is located at http://www.dealii.org/ For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/CAM8c7P0XKZ_N0Zycu5ko_29TvBQ%2BR-wXcUj5GL5tuphXbYV2fA%40mail.gmail.com.
