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.

Is there a diff operator for partial derivatives

More
4 years 2 months ago #2366 by gflower
Hi,
I'm a little new to NGSolve and was looking for an operator for a simple partial derivative to solve a problem with a Bilinear form that might look like this:

[tex]\int_\Omega\frac{\partial v(x,y)}{\partial x}\frac{\partial u(x,y)}{\partial x}\mathrm{d}x\mathrm{d}y[/tex]

I found that coefficient functions have a partial derivative method called diff(), I was hoping there would be somthing similar for test and trial functions that might look something like this:

a = BilinearForm(fes)
a+=(diff(u,x)*diff(v,x))*dx

Does such an function exist in NGSolve (obviously the above doesn't work)? Sorry if I simply haven't read the documentation well enough
More
4 years 2 months ago #2367 by mneunteufel
Hi gflower,

you can get access to the i-th partial derivative by taking the i-th entry of the full gradient.

For a scalar u and v your example would be
Code:
a = BilinearForm(fes) a+= grad(u)[0]*grad(v)[0]*dx

Best,
Michael
The following user(s) said Thank You: gflower
More
3 years 2 months ago - 3 years 2 months ago #3523 by Subway
Hi mneunteufel,

Thanks for your post. What if u and v are not scalars? In other words, if u is a vector, can we get one component of u first, then take the gradient, then pick the i th component? Thanks in advance!
Last edit: 3 years 2 months ago by Subway. Reason: Just figured it out!
More
3 years 2 months ago #3524 by mneunteufel
Hi Subway,

for vector-valued functions you can compute the Jacobian matrix and then choose the j-th partial derivative of the i-th component of the vector. E.g.:
Code:
fes = HCurl(mesh, order=2) u,v = fes.TnT() a = BilinearForm(fes) a += Grad(u)[0,1]*Grad(v)[0,1]*dx #dx_2u_1*dx_2v_1

Using Grad gives always the Jacobian, grad gives, depending on the finite element space, the Jacobian or the transpose of the Jacobian.

Best,
Michael
More
3 years 2 months ago #3530 by Subway
Hi Michael,

That makes sense. Thanks a lot for your help!
Time to create page: 0.142 seconds