How to compute the gradient of a bilinear form in C++?

14 months ago by
Hi all,

I need to compute the gradient of a bilinear form.

A little bit of theory, in order to make you understand better.
Given a bilinear form, continuous and coercive on a Hilbert space H:

 $a:HxH\rightarrow R$a:HxHR 

The  Gateaux derivative of this (in a "point" u) is a linear functional defined on H such that:
 $L\psi=a\left(u,\psi\right)\forall\psi\in H$Lψ=a(u,ψ)ψH 

By the Riesz's theorem, there exists a representative of H, say J, called "the gradient of a(.,.)" such that:

 $\left(J,\psi\right)_H=a\left(u,\psi\right)\forall\psi\in H$(J,ψ)H=a(u,ψ)ψH 

Where (.,.)H is the inner product (L2 in our case) in H.

Now, when everything is discretized using FEniCS, this representative should be a dofin::Function Jh such that:


where Jhi is the ith coefficient of Jh relative to the basis function phii of the discretized space, and "a" our dolfin::Form.

Now, my question is: how do I compute this quantity? I tried to use the "NonlinearVariationalProblem.h" header, but it does not seem to have the tools we need. Also I tried some tool to extract all the basis function and compute that quantity "by hand", but I can't accomplish this task.

Thanks for your time.

2 Answers

14 months ago by
This should work

u = Function(V)
v = TestFunction(V)
# Define a = a(u,v)
J = assemble(a)​

Thank you.
I am coding in C++. Should this be included in the .ufl file?
written 14 months ago by Francesco Clerici 
14 months ago by
I don't know if this is the only way, but see the following for my solution (answer at bottom) to computing the gradient of an arbitrary scalar function in Fenics (in C++).

Please login to add an answer/comment or follow this question.

Similar posts:
Search »