Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

how to pythonize a NumProc? My-Little-Ngsolve question

More
7 years 4 days ago #17 by Guosheng Fu
Hello,

I have trouble using NumProc in python.
More specifically, in the file myAssembling.cpp, we use
static RegisterNumProc<...> ..("myassemble")
Then, the pde file recognize myassemble as a numproc, and we can call it using the command
numproc myassemble np1

The question is how to call this NumProc in python. It seems I need to register this numproc in python to use it... Is this related to "pythonize the code"?

I dig a bit into the source code but find nothing.... What I noticed is that the names created in RegisterFESpace can be used in <FESpace>, the names created in RegisterBilinearFormIntegrator can be used in <BFI>, similar for <LFI>, and the name created in RegisterPreconditioner can be used in <Preconditioner>. So, naively, I thought the name created by RegisterNumProc shall be used in <NumProc>, but this is not the case...

Best,
Guosheng
More
7 years 1 day ago #18 by joachim
Hi Guosheng,

short answer: The Pythonic way is not using NumProcs anymore. Whatever you do in the NumProc::Do() working function, you can do in a Python function. The old PDE class contains a list of NumProcs, which are processed in order. This is not needed anymore, since the program-flow is now steered from Python. As you mentioned myassemble, this can be done perfectly from Python.
It makes sense to register FESpaces from C++ and access them in Python. Here a lot of functionality is programmed in C++, and there is a small common interface. The same holds for preconditioners.
Specific LinearForm/BilinearForm-integrators from C++ should not be needed anymore, one should be able to define the form using SymbolicBFI/SymbolicLFI.

Of course, it will be important also in future to export C++ functions to Python, to perform some specific functionality more efficient and in parallel. Here you have to Python-wrap some functions (or also classes).

Practically, for the transition time from old PDE-style to new Python-style, we also wrapped NumProcs to Python, such that existing NumProcs could be used. See the example of the "BVP" numproc (file solve/bvp.cpp). Here we exported a creator-function (line 789) to create a NumProcBVP from Python.

See also mylittlengsolve/python/myngspy.cpp showing how to write extensions in extra shared libraries (comment: I just updated from boost::python to pybind11, needs some more testing).

Hope this explains the ideas, if there are particular questions left, let us know.

Best, Joachim
The following user(s) said Thank You: Guosheng Fu
Time to create page: 0.134 seconds