Rapid integration on finite elements

Asked by James Avery

Dear all,

I need to evaluate inner products between many finite element
functions rapidly. Let's write

  f(x) = \sum_i a_i \phi_i(x)
  g(x) = \sum_i b_i \phi_i(x)

We now want to quickly compute the L2-inner product \int dx f(x) g(x).

With Deal.II, I would compute the exact L2-inner product by a sparse
vector-matrix-vector scalar product of the coefficient vectors with
the mass matrix (or overlap matrix):

 \int dx f(x) g(x) = \sum_{i,j} a_i b_j \int dx \phi_i(x) \phi_j(x)
                   = a^T M b

Due to the sparsity of M, this is an O(Ndof)-operation. However, when
doing the same using Dolfin (C++), this is an incredibly slow
operation that seems to scale as O(n^2), i.e. as a dense matrix-vector
product. This becomes unusable even for moderate sized finite element
meshes. I cannot access the sparsity pattern of a matrix, so I also
dont't see how to implement the operation myself.

I get the feeling that this is not the "blessed" way to go about this
with FEniCS/Dolfin, and would appreciate your input on this: How does
one compute L1 (\int dx f(x)) and L2 (\int dx f(x) g(x)) integrals for
finite element functions when using Dolfin - efficiently and
accurately?

Thanks very, very much in advance for your help!

Best regards,
James

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

On 01/08/11 14:55, James Avery wrote:
> New question #166656 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/166656
>
> Dear all,
>
> I need to evaluate inner products between many finite element
> functions rapidly. Let's write
>
> f(x) = \sum_i a_i \phi_i(x)
> g(x) = \sum_i b_i \phi_i(x)
>
> We now want to quickly compute the L2-inner product \int dx f(x) g(x).
>
> With Deal.II, I would compute the exact L2-inner product by a sparse
> vector-matrix-vector scalar product of the coefficient vectors with
> the mass matrix (or overlap matrix):
>
> \int dx f(x) g(x) = \sum_{i,j} a_i b_j \int dx \phi_i(x) \phi_j(x)
> = a^T M b
>
> Due to the sparsity of M, this is an O(Ndof)-operation. However, when
> doing the same using Dolfin (C++), this is an incredibly slow
> operation that seems to scale as O(n^2), i.e. as a dense matrix-vector
> product. This becomes unusable even for moderate sized finite element
> meshes. I cannot access the sparsity pattern of a matrix, so I also
> dont't see how to implement the operation myself.
>
> I get the feeling that this is not the "blessed" way to go about this
> with FEniCS/Dolfin, and would appreciate your input on this: How does
> one compute L1 (\int dx f(x)) and L2 (\int dx f(x) g(x)) integrals for
> finite element functions when using Dolfin - efficiently and
> accurately?
>

From Python, for L2 do

   M = f*g*dx
   x = assemble(M)
   print "L2 inner product:", x

For the L1 norm (code untested),

   M = abs(f)*dx
   x = assemble(M)
   print "L1 norm:", x

You can also do

   x = assemble(f*g*dx)

etc.

Garth

> Thanks very, very much in advance for your help!
>
> Best regards,
> James
>

Revision history for this message
James Avery (avery-diku) said :
#2

Thanks very much!

Now, from C++: Would I have to define and compile a bilinear form with UFL/FFC first, or is that not necessary? Also, in this case, I'm assembling a scalar rather than a matrix: how does that work?

Thanks very much for your help!

Revision history for this message
Best Garth Wells (garth-wells) said :
#3

On 02/08/11 21:11, James Avery wrote:
> Question #166656 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/166656
>
> James Avery posted a new comment:
> Thanks very much!
>
> Now, from C++: Would I have to define and compile a bilinear form with
> UFL/FFC first, or is that not necessary?

You need to define a functional (M = . . . ) in UFL and compile it with
FFC. See the demo

   demo/undocumented/lift-drag

> Also, in this case, I'm
> assembling a scalar rather than a matrix: how does that work?
>

Nothing fancy. It just evaluates the inner product on each cell and sums
them up.

Garth

> Thanks very much for your help!
>

Revision history for this message
James Avery (avery-diku) said :
#4

Thanks Garth Wells, that solved my question.

Revision history for this message
James Avery (avery-diku) said :
#5

Thanks very much, Garth. That did the trick!