### Preassemble Norm

64

views

0

Hi,

I am implementing tim stepping and thus need to call dolfin.norm quite often.

cProfile tells me that the call to norm makes around 25% of my preprocess, solve, postprocess cycle of my time stepping.

Most of the call seems to be to dolfin.fem.assemble ( dolfin.fem._create_dolfin_form).

Can I prevent /reduce this assembling step?

Best Regards,

Moritz

I am implementing tim stepping and thus need to call dolfin.norm quite often.

cProfile tells me that the call to norm makes around 25% of my preprocess, solve, postprocess cycle of my time stepping.

Most of the call seems to be to dolfin.fem.assemble ( dolfin.fem._create_dolfin_form).

Can I prevent /reduce this assembling step?

Best Regards,

Moritz

Community: FEniCS Project

### 1 Answer

3

You can either use norm on the vector instead of the function if the difference between l2 and L2 is not important to you. Otherwise, you can create an ufl expression for the norm

`(u1 - u2)**2*dx`

or whatever and then set `form = dolfin.Form(ufl_expression)`

which pre-compiles the form. Now you can call `assemble(form)`

whenever you need to compute the norm. This avoids compilation time, but assembly will of course need to be done every time if you want the "real" norm (the integral formulation). The linear algebra vector version, calling `f.vector().norm('l2')`

, should always be faster
Please login to add an answer/comment or follow this question.