Weird error when differentiating TrialFunction

More
4 years 4 months ago #2944 by Bittermandeln
The relevant code-snippets I use is

def normal_grad(f,n):
return f.Diff(x)*n[0] + f.Diff(y)*n[1]

Vh = H1(mesh, order=order, dirichlet=[1,2,3,4],flags={"dgjumps": True})
v = Vh.TestFunction()

nF = specialcf.normal(2)

vn = normal_grad(v,n)
vno = normal_grad(v.Other(),nF)

vnno = normal_grad(vno,nF)
vnn = normal_grad(vn,nF)



and I get error


NgException Traceback (most recent call last)
<ipython-input-197-5729456d113a> in <module>
179 jump_u_2 = normal_grad(un,nF) - normal_grad(uno,nF)
180 vnno = normal_grad(vno,nF)
--> 181 vnn = normal_grad(vn,nF)
182 jump_v_2 = vnn-vnno
183

<ipython-input-191-e5403275507c> in normal_grad(f, n)
1 def normal_grad(f,n):
----> 2 return f.Diff(x)*n[0] + f.Diff(y)*n[1]
3

NgException: Deriv not implemented for CF N5ngfem23NormCoefficientFunctionE

Has anyone stumbled upon this error before? I find it weird since I can do the same thing for a TestFunction, and it works. I am trying to implement higher order directional derivatives.

Best regards,

Henrik
More
4 years 4 months ago #2945 by mneunteufel
Hi Henrik,

I needed to change "vn = normal_grad(v,n)" to "vn = normal_grad(v,nF)" to get your code-snippet running, but I did not get any further error. Do you have the latest NGSolve version?

To compute the normal derivative of a H1 test/trial function u you have to write
Code:
grad(u)*n
as Diff(x) is used for differentiating CoefficientFunctions depending explicitly on x. Using u.Diff(x) returns 0.

Best
Michael
More
4 years 4 months ago #2946 by Bittermandeln
Thank you so much! Did not spot that error. That solved it.
More
4 years 4 months ago #2960 by schruste
Small addition:
With the above correction you will only get first (or with "hesse") second order normal derivatives.
In ngsxfem we have a DifferentialOperator "dn" for higher order normal derivatives implemented with limited scope of application. However, perhaps you want to have a look at the "dnjump" use case in the example
github.com/ngsxfem/ngsxfem/blob/release/.../fictdom_ghostpen.py

Best,
Christoph
More
4 years 4 months ago #2965 by Bittermandeln
Thank you very much Christoph!

Henrik
Time to create page: 0.115 seconds