- Thank you received: 0
Is there a diff operator for partial derivatives
4 years 9 months ago #2366
by gflower
Is there a diff operator for partial derivatives was created 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
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
- mneunteufel
- Offline
- Premium Member
Less
More
- Thank you received: 59
4 years 9 months ago #2367
by mneunteufel
Replied by mneunteufel on topic Is there a diff operator for partial derivatives
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
Best,
Michael
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
3 years 9 months ago - 3 years 9 months ago #3523
by Subway
Replied by Subway on topic Is there a diff operator for partial derivatives
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!
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 9 months ago by Subway. Reason: Just figured it out!
- mneunteufel
- Offline
- Premium Member
Less
More
- Thank you received: 59
3 years 9 months ago #3524
by mneunteufel
Replied by mneunteufel on topic Is there a diff operator for partial derivatives
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.:
Using Grad gives always the Jacobian, grad gives, depending on the finite element space, the Jacobian or the transpose of the Jacobian.
Best,
Michael
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
Time to create page: 0.120 seconds