This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

integration over domain for computed solutions

+1 vote

Hi all,
I run poisson problem with different boundary conditions so I got different solutions at the end let's say 2 different solutions u1 and u2. Now, the problem is to compute this:
Integral / domain ( u1 * u2 ) dOmega.

Anyone know how to do this, please ?
Thanks in advance

asked Nov 29, 2013 by zineroi FEniCS Novice (170 points)

1 Answer

+1 vote
 
Best answer

Hi, you need

integral = assemble(u1*u2*dx)
answered Nov 29, 2013 by MiroK FEniCS Expert (80,920 points)
selected Nov 30, 2013 by Jan Blechta

thanks for the answer,
but could you tell me how to do it with C++ and what to put inside the UFL file ?

Thanks in advance

Hi, in Cpp you can have a form file like this

# cg.ufl                                                                         
element = FiniteElement("CG", triangle, 1)                                       

u1 = Coefficient(element)                                                        
u2 = Coefficient(element)                                                        

form1 = u1*u2*dx                                                                 
forms = [form1]  

and then the cpp code is

#include <dolfin.h>                                                              
#include "cg.h"                                                                  

using namespace dolfin;                                                          

int main()                                                                       
{                                                                                
  UnitSquareMesh mesh(2, 2);                                                     

  Constant u1(10);                                                               
  Constant u2(10);                                                               

  cg::Form_form1 form1(mesh, u1, u2);                                            

  std::cout << assemble(form1) << std::endl;                                     

  return 0;                                                                      
}    

You might also want to take a look at this demo.

thanks man,
your idea works great, it's a bit difficult to use FEniCS with C++ with so little documentation about the library and especially for beginners like me.
thank you again

...