- Thank you received: 0
Weird error when differentiating TrialFunction
- Bittermandeln
- Topic Author
- Offline
- Junior Member
Less
More
4 years 4 months ago #2944
by Bittermandeln
Weird error when differentiating TrialFunction was created 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
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
- mneunteufel
- Offline
- Premium Member
Less
More
- Thank you received: 59
4 years 4 months ago #2945
by mneunteufel
Replied by mneunteufel on topic Weird error when differentiating TrialFunction
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
as Diff(x) is used for differentiating CoefficientFunctions depending explicitly on x. Using u.Diff(x) returns 0.
Best
Michael
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
Best
Michael
- Bittermandeln
- Topic Author
- Offline
- Junior Member
Less
More
- Thank you received: 0
4 years 4 months ago #2946
by Bittermandeln
Replied by Bittermandeln on topic Weird error when differentiating TrialFunction
Thank you so much! Did not spot that error. That solved it.
4 years 4 months ago #2960
by schruste
Replied by schruste on topic Weird error when differentiating TrialFunction
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
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
- Bittermandeln
- Topic Author
- Offline
- Junior Member
Less
More
- Thank you received: 0
4 years 4 months ago #2965
by Bittermandeln
Replied by Bittermandeln on topic Weird error when differentiating TrialFunction
Thank you very much Christoph!
Henrik
Henrik
Time to create page: 0.115 seconds