Creating User Interface for NGSolve using PyQt5

More
4 years 3 months ago #3030 by Luma
Hello NGSolve users,

i am currently trying to write a user interface for one of my NGSolve simulations using PyQt5.
In the attached MWE, the user interface is used to read in a parameter and execute the poisson.py script using the provided parameter via pressing a 'start script' button.
The computed result should then be shown in the Netgen Window, such that one can quickly adjust the parameter and view the effect on the result.
This is where things don't work out yet. The Netgen window is opened and updated only after the GUI window is closed, despite Draw() is called in the successfully executed script.
If a Netgen window is already open, the window is frozen until the UI is terminated.

On top of that, i would like to embed or dock the Netgen window into the PyQt UI, such that the user only has one window to focus on.

Hope that someone with a little bit of experience in PyQt5 and NGSolve can help me out here :)


Kind regards and thanks in advance
Lukas
Attachments:
More
4 years 3 months ago #3034 by christopher
Hi Lukas,
Have you had a look at the pyside2/pyqt5 project ngsgui?
github.com/NGSolve/ngsgui
I think it is basically what you are looking for. It provides entry points for extension and you can add arbitrary functionality to the gui in your extension.
Best
Christopher
The following user(s) said Thank You: Luma
More
4 years 3 months ago - 4 years 3 months ago #3039 by Luma
Hello Christopher,

thanks for your response! Looks exactly like what I'm looking for.
Unfortunately I am not very experienced in managing Ubuntu packages and run into some trouble installing it.
NgsGui works on an older version of ipykernel, but I'd like to use Spyder IDE, which requires the latest version of ipykernel . Through the installation i thus get the error message that : 'ngsgui 0.1.11 requires ipykernel<5, but you'll have ipykernel 5.3.4 which is incompatible'.
Can you tell me how to resolve this?
Running the demo programs Spyder encounters an unknown internal error.

kind regards
Lukas
Last edit: 4 years 3 months ago by Luma.
More
4 years 3 months ago - 4 years 3 months ago #3040 by christopher
If I'm correct the ipykernel<5 is because of this

github.com/ipython/ipykernel/issues/358

which seems to be fixed in ipykernel 5.3.2:
github.com/ipython/ipykernel/pull/523

Since 5.3.4 is the current version, we can replace this requirement with a recent one I think.
I'll update the setup.py and release a new version to pip

Thanks for reporting.
Best
Christopher
Last edit: 4 years 3 months ago by christopher.
More
4 years 3 months ago - 4 years 3 months ago #3049 by Luma
Hello Christopher,

thanks for the fix! It works fine now, except for some smaller issues:
When the ngsgui window starts, the first solution drawn is always corrupted. It shows some weird clipping error:




When i play around with the lighting and clipping settings, it dissappears after a while most times...

I would also like to set the min and max value of the drawn function programatically, is this possible?

In the meantime i tried to find a workaround for the GUI using the VTK output of ngsolve. The field is written as .vtk file via vtk = VTKOutput(..) and calling vtk.Do(). It is then read back in to a PyQt vtk object and integrated in the display:



I attached the example code. In my opinion, this looks really nice and is very convenient for the user. Unfortunately, the vtk output file gets very large, when a more complex mesh is used, and the writing/reading takes a long time. If one could skip that step by converting the NGSolve vtk-object to a PyQt vtk-object this may work much faster.
Maybe someone with a little experince knows if and how this is possible. :)
Last edit: 4 years 3 months ago by Luma. Reason: Attachements wont upload
More
4 years 3 months ago #3050 by christopher
Can you send the script creating the clipping error?
Going via vtk is an option, but the ngsolve vtk object doesn't have anything to do with the python vtk objects provided by pyqt... To bypass the writing you would have to extract the required information manually from the ngsolve objects (for example as numpy arrays) and put it into pyqt... Which is some work I guess and needs some understanding of vtk and ngsolve.
Time to create page: 0.130 seconds