Local assembly of forms for a posteriori error analysis

Asked by Rodolphe Prignitz

Hello,

I would like to do some a posteriori error analysis. I'm aware that dolfin has built in methods, but as I do some research in this field, I have to assemble the local terms by myself.

An error estimator consists usually of local terms of the form ||r||_T or ||r||_{\partial T}, where r is a finite element function, T a mesh object of CoDim 0 and partial T its border (CoDim 1). As far as I read the documentation the only way to do that now, is to define subdomains and assemble the forms on them. This approach is rather inefficient, as I have to call the assembly routine for every cell in my mesh.

Is there any other way to do this?

From https://answers.launchpad.net/dolfin/+question/186702 I understood that there is a local assembly routine in the C++ library, but I really prefer to use the python interface, which is really great!

Thanks in advance,
Rodolphe

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Martin Sandve Alnæs
Solved:
Last query:
Last reply:
Revision history for this message
Best Martin Sandve Alnæs (martinal) said :
#1

If I understand you correctly you want to assemble the scalar value of
the functional ||r|| over each T? Just multiply it by a DG0 test
function and the assembled vector will contain the functional value
for each cell.

V0 = FunctionSpace(mesh, "DG", 0)
v = TestFunction(V0)
L = inner(r,r)*v*dx

Note that there is some adaptivity functionality already, check out
the dolfin demos.

Martin

On 30 October 2012 09:51, Rodolphe Prignitz
<email address hidden> wrote:
> New question #212729 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/212729
>
> Hello,
>
> I would like to do some a posteriori error analysis. I'm aware that dolfin has built in methods, but as I do some research in this field, I have to assemble the local terms by myself.
>
> An error estimator consists usually of local terms of the form ||r||_T or ||r||_{\partial T}, where r is a finite element function, T a mesh object of CoDim 0 and partial T its border (CoDim 1). As far as I read the documentation the only way to do that now, is to define subdomains and assemble the forms on them. This approach is rather inefficient, as I have to call the assembly routine for every cell in my mesh.
>
> Is there any other way to do this?
>
> >From https://answers.launchpad.net/dolfin/+question/186702 I understood that there is a local assembly routine in the C++ library, but I really prefer to use the python interface, which is really great!
>
> Thanks in advance,
> Rodolphe
>
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Martin Eigel (meigel) said :
#2

I'd like to add to the initial question that often the local domains are patches (e.g. the union of all cells sharing a vertex) rather than single cells. In that case, the DG approach does not work and instead one would need an efficient way to just assemble and solve local problems on a specific set of cells. I had the impression that dolfin currently is not well suited for this kind of calculation which is required for classical implicit error estimators and also for the very efficient recent equilibration error estimators. For the latter, one would determine equilibrated fluxes in an appropriate space (e.g. H(div)) on the patches.

Cheers, Martin

Revision history for this message
Martin Eigel (meigel) said :
#3

For the intention of the TO, the following questions might prove helpful
https://answers.launchpad.net/dolfin/+question/203757
https://answers.launchpad.net/dolfin/+question/177108

Revision history for this message
Rodolphe Prignitz (prignitz) said :
#4

Thanks Martin Sandve Alnæs, that solved my question.

Revision history for this message
Rodolphe Prignitz (prignitz) said :
#5

Rerering to Martin Eigels first answer (Post #2) I would also like to see support of patch-wise assembly in dolfin. In some variants of the Dual Weighted Residual error estimator it is also needed to perform patch-wise interpolations of the discrete solution to compute an dual solution which is not an element of the primal solution space.

Revision history for this message
Rodolphe Prignitz (prignitz) said :
#6

Thank you Martin for the follow ups. They helped a lot.

Revision history for this message
Marie Rognes (meg-simula) said :
#7

Let me just comment that although dolfin does not have a native patch-wise assembler,
the necessary information should be there via the ufl-ffc-ufc toolchain. The patch-wise
assembly could be accomplished by writing your own assembler which iterates
over patches, computes contributes from each cell/facet and adds to a suitable matrix/vector/tensor.

For computing a dual solution of higher-order than the primal solution space,
I would recommend taking a look at the Extrapolation class. This provides functionality for computing an extrapolated
solution based on least-squares curve fitting. This is what we use as the default approach
for computing an improved dual solution for the automated dual-weighted-residual error estimates.

Revision history for this message
Anders Logg (logg) said :
#8

On Wed, Oct 31, 2012 at 08:50:57AM -0000, Marie Rognes wrote:
> Question #212729 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/212729
>
> Marie Rognes posted a new comment:
> Let me just comment that although dolfin does not have a native
> patch-wise assembler, the necessary information should be there via
> the ufl-ffc-ufc toolchain. The patch-wise assembly could be
> accomplished by writing your own assembler which iterates over
> patches, computes contributes from each cell/facet and adds to a
> suitable matrix/vector/tensor.

Good answer. Often our response to a user wanting to do something
slightly more complex than just standard assembly, is it can't be
done, but in fact most things can be done. It's just that we don't
have a function for it. The entire interface of FEniCS (in particular
DOLFIN) has been designed to be easy to work with, which means that
the implementation of the assembler in DOLFIN itself is pretty
short. So take a look at Assembler.cpp, implement your own iteration
over cells, iterate over neighbors etc to solve the local problems.

--
Anders

> For computing a dual solution of higher-order than the primal
> solution space, I would recommend taking a look at the Extrapolation
> class. This provides functionality for computing an extrapolated
> solution based on least-squares curve fitting. This is what we use
> as the default approach for computing an improved dual solution for
> the automated dual-weighted-residual error estimates.
>

Revision history for this message
Thomas Fraunholz (sleater) said :
#9

I've written a small example how swig can be used for communication between python and cpp (especially with dolfin). Perhaps this is useful to someone. If there are any questions please contact me.

http://scwww.math.uni-augsburg.de/~tommy/python_dolfin_swig_demo.tar.gz

Revision history for this message
Johan Hake (johan-hake) said :
#10

Also have a look at compile_extension_module to do it JIT within a
Python sesion. Try:

  from dolfin import *
  mesh = UnitSquare(4, 4)
  V = FunctionSpace(mesh, "Lagrange", 1)
  u = interpolate(Constant(1.0), V)
  code = """
  void set_to_zero(boost::shared_ptr<dolfin::GenericVector> x) {
   x->zero();
  }
  """
  compiled_module = compile_extension_module(code)
  compiled_module.set_to_zero(u.vector())
  plot(u)
  interactive()

Johan

On 11/05/2012 08:51 AM, Thomas Fraunholz wrote:
> Question #212729 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/212729
>
> Thomas Fraunholz posted a new comment:
> I've written a small example how swig can be used for communication
> between python and cpp (especially with dolfin). Perhaps this is useful
> to someone. If there are any questions please contact me.
>
> http://scwww.math.uni-augsburg.de/~tommy/python_dolfin_swig_demo.tar.gz
>

Revision history for this message
Thomas Fraunholz (sleater) said :
#11

That's nice! A lot easier...

Revision history for this message
Johan Hake (johan-hake) said :
#12

On 11/05/2012 10:25 PM, Thomas Fraunholz wrote:
> Question #212729 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/212729
>
> Thomas Fraunholz posted a new comment:
> That's nice! A lot easier...

:)

FYI: compiled_expressions and compiled_subdomains all uses this interface.

Johan