Unexpected behaviour of Bilinearform (is this a bug?)

Hello everybody,

I found a weird behaviour of the bilinearform. When setting up my bilinearform it makes a measurable difference if I spilt the terms in multiple lines. For my understanding the bilinearforms defined by:

blf_one_line += (u * v + v * InnerProduct(flow, grad(u)) ) * dx


blf_two_line += u * v * dx
blf_two_line += v * InnerProduct(flow, grad(u)) * dx

should give the same (in machine accuracy) results. But the matrix entries (measured in the 2-norm) differ even more than the mesh size.

The error vanishes when the flow field is constant.

Do I overlook something or is this a bug?

I’ve added an MWE to test the error.

Thanks for your help and kind regards,

MWE_lines_in_blf.py (1.1 KB)

This is due to how ngsolve does automatic selection of integration rules:

The rule in general is that integration of bf integrators is 2*order_space. If trial or test function is only used with a derivative and derivative + element allows it, it is reduced by one order.

In your case this means that the second line in the 2 line version reduced integration order by 1. But you have flow as a p1 function so it actually integrates 1 order to little to integrate exact. The upper one has u also without gradient so it does exact integration of your form.

You can add

blf_two_line += v * InnerProduct(flow, grad(u)) * dx(bonus_intorder=1)

to fix this problem

Thank you for the fast and really helpful reply! This works.

Best whishes!