Skip to content

provide 'dune.fem.assemble'

Andreas Dedner requested to merge feature/assembleFunction into master

this function takes a form and returns depending on its arity a value, a functional, a matrix Also added a space.zero attribute that (on demand) generates a zero discrete function. So one can write

op(space.zero,b)
b *= -1

to get the right hand side.

A linear problem can now be assembled using:

   A = dune.fem.assemble(u*v*dx)
   b = dune.fem.assemble(f*v*dx)
   x = solve(A,b)

It is also possible to pass in an equation and get both matrix and rhs

    A,b = dune.fem.assemble(u*v*dx == f*v*dx)

or for the same result

    A,b = dune.fem.assemble((u-f)*v*dx == 0)

Note: I'm not quite sure how Dirichlet constraints are included in this concept - how do the others do that, does somebody know? I've added the following option

   A = dune.fem.assemble( [u*v*dx, dbc] )
   b = dune.fem.assemble( [f*v*dx, dbc] )
   x = solve(A,b)

or of course

   A,b = dune.fem.assemble( [(u-f)*v*dx, dbc] )
   x = solve(A,b)

I guess one could have dbc.apply(A) and dbc.apply(b) but that is really inefficient especially if one has multiple DirichletBC classes.

Note: one issue with this function could be efficiency if used wrongly (#saveusersfromthemslves). But that is perhaps not an issue since for example non-linear operators can't be linearized this way so no one would implement a Newton method using assemble in each iteration.

Note: the assembly of a functional is quite inefficient at the moment since the implementation uses a Galerkin operator to compute this requiring the setup of a bilinear form etc. A better implementation can be added at some other time.

Note: the integrate (arity zero) version only works with dx (not tested) would be nice to include ds etc. Also it requires to pass in a gridView since that can be not be extracted from the form (if no GridFunction is included). This is because we can not initialize a SpatialCoordinate with a GridView) or provide this information some other way to the form.

Edited by Andreas Dedner

Merge request reports