Div of a Curl

Hi,

I’ve been enjoying the updated iTutorials very much!

I noticed a small issue with the new HCurlDiv iTutorial, though…

It tries to compute the div of the curl of a grid function l in block 12, and fails like this:


Exception Traceback (most recent call last)
in ()
----> 1 div(uc)

~/ngsuite/ngsolve-install/lib/python3/dist-packages/ngsolve/utils.py in div(func)
84 if add:
85 return add
—> 86 raise Exception(“cannot form div”)
87
88

Exception: cannot form div

Just to see what would happen, I changed a line in utils.py (as below) and restarted the Jupyter kernel.

[code]def div(func):

if func.derivname == “div”:

if func.derivname in ["div", "curl"]:
    return func.Deriv()
add = func.Operator("div")
if add:
    return add
raise Exception("cannot form div")

[/code]

It seemed to work:

div(uc)
<ngsolve.comp.CoefficientFunction at 0x7fd22cce68e0>

Best,
Dow

Hi, that line was there to show that you cannot form the div of a function in HCurl (because its not implemented either as the default operator or as an additional operator). So it raises an exception.
The function .Deriv() returns the default derivative for the finite element space the Testfunction/Trialfunction/Gridfunction is defined on. We give a function from HCurl, so

if func.derivname in ["div", "curl"]:

returns true and with

return func.Deriv()

you return the curl of the function not the div…

Best
Christopher

Hi Christopher,

Thanks for clearing up my misunderstanding on this!

Best,
Dow

Hi dow!

Note however that the piecewise grad operator is exported for H(curl) function. By this you could for example implement (just for fun :D…) an H(curl) conforming dg vector laplce problem.

Thus you can easily implement the pice-wise div operator on your own.

Best, Philip

PS: I think grad(u) is actually the transpose…