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

Evaluating integrals on domain

0 votes

I have a solution generated in fenics to a variant of stokes flow, giving me u and P as usual.

I need to evaluate integrals on the domain that look like

v^i = \integral_Y u^i dy

I can find the area of the domain using the usual

area = assemble(Constant(1.0)*dx(mesh))

I assume using a similar expression I can find the integral for v.

Naively I tried

v[1] = assemble(Dx(u,0)*dx(mesh))

Which returned that I can only integrate scalar expressions, is there a projection required here?

asked May 23, 2016 by varnis FEniCS Novice (390 points)

Hi, can you clarify what you want to achieve? It seems you want 3 numbers(assuming your are in 3d) which are the volume integrals of the vector field, $v_i = \int_{\Omega} u_i dx$ where $u=(u_0, u_1, u_2)$. Is that it?

Thanks for the reply, that is indeed what I am trying to find. In my case I'm actually in 2d, but yes, I need the two numbers for further calculations.

1 Answer

0 votes
 
Best answer

Hi, consider

from dolfin import *

mesh = UnitSquareMesh(10, 10)
V = VectorFunctionSpace(mesh, 'CG', 2)
v = interpolate(Expression(('x[0]', '-x[1]'), degree=1), V)

print [assemble(v[i]*dx) for i in range(2)]  # volume integral of each component of vector
print [[assemble(Dx(v[i], j)*dx) for j in range(2)] for i in range(2)]
answered May 24, 2016 by MiroK FEniCS Expert (80,920 points)
selected May 24, 2016 by varnis
...