integrating functional in C++ (Cahn-Hilliard equation)

Asked by Payman Tohidifar

Hello,

I need to compute the integral of functional u over a domain. I used assemble(u*dx) in python and it worked pretty well. However, I don't know how to employ assemble function in C++ specially in Cahn-Hilliard problem (C++ Demo) to integrate functional since u is a pointer. I would appreciate if you could help me out.

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Blechta
Solved:
Last query:
Last reply:
Revision history for this message
Jan Blechta (blechta) said :
#1

You need to define this 0-form (rank 0 because it has no trial nor test functions and is scalar) in UFL file and compile with ffc -ldolfin. Then in your C++ code you assign your computed u to this form and assemble. Not tested.

Jan

Revision history for this message
Payman Tohidifar (payman-che) said :
#2

Thanks Jan for your response. But I don't think if I get your comment very
well. Would you please give me a short example? . I'd really appreciate it.

Payman

Revision history for this message
Best Jan Blechta (blechta) said :
#3

form.ufl:
_______________________________________
elem = FiniteElement("CG", triangle, 1) # or whatever element you need
u = Coefficient(elem)
M = u*dx()
________________________________________

cpp:
_______________________
#include "form.h"
...
Mesh mesh;
Function u(V);
...
form::Functional F(mesh);
F.u = u;
double f = assemble(F);
...
_______________________

Not tested. Just try it with some mesh and u.

Revision history for this message
Payman Tohidifar (payman-che) said :
#4

Thanks a lot Jan. It worked pretty well for me.

Payman

Revision history for this message
Payman Tohidifar (payman-che) said :
#5

Thanks Jan Blechta, that solved my question.