Hi guys,

I know ngsolve is capable of doing p-refienement, but I am wondering whether it can be done via the python interface easily… (say, solve the laplace equation on a fixed mesh with p-refinement)… hp-refinement would be even better…
I didn’t see any variable-degree tutorials in python.


Hi Guosheng,

yes, we can, but the syntax is not yet converged and thus you don’t find a documentation. I shortly describe the concepts:

All finite element spaces in NGSolve can handle variable and also anisotropic polynomial orders.

Now the default.
future: only active when you set the flag:
H1 ( … , order_policy = ORDER_POLICY.VARIABLE), otherwise we do some fixed-order optimisations.

You can give orders to mesh-nodes (e.g. edge number 7 set or order 5):
fes.SetOrder (NodeId(EDGE,7), 5)

After setting the orders, some tables must be recalculated via

How you distribute the orders is your job. Either via error estimators, or on refinement level, distant to corners …

Hope this helps,

Sounds good!
I don’t have any specific problem in mind for p-refinement yet, but it is very nice to know about this! :>

Hi Joachim,

I tried your suggestion on using
SetOrder and UpdateDofTables
for the finite elements, but it failed to work.

Here in the attachement is a modification of your adaptive.py demo code, where I only changed the h-refinement line 103
to p-refinement line 104
I tried to use “V.UpdateDofTables()” afterwards, but it gives me an error message…
‘ngsolve.comp.H1’ object has no attribute ‘UpdateDofTables’


Attachment: p_adaptive.py

Hi Guosheng,

here is now a working mini-example. It needs the fixes I commited just now.

You have to set the order for the element-interior, as well as on the edges. By now only the H1 supports variable order from Python, the other spaces may come soon.

I have to warn you again, these things are very experimental and may change anytime.

Best, Joachim

Attachment: poisson_p.py

Hi Joachim,

Great! It works nicely now.
It would be even better if you could help to support the variable order L2 space. :slight_smile:
I am trying to see whether p-adaptivity would be a good choice for time domain wave propagation in the DG context…