Python 'assemble' function is missing an argument for nonlinear problems

Issue #145 resolved
Prof Garth Wells created an issue

The Python assembler has the signature

def assemble(form,
             tensor=None,
             mesh=None,
             coefficients=None,
             function_spaces=None,
             cell_domains=None,
             exterior_facet_domains=None,
             interior_facet_domains=None,
             reset_sparsity=True,
             add_values=False,
             finalize_tensor=True,
             keep_diagonal=False,
             backend=None,
             form_compiler_parameters=None,
             bcs=None,
             symmetric_mod=None):

which is missing an argument to pass a vector x as is required inside a Newton loop.

Options are:

  1. Add an extra argument, as with assemble_system; or
  2. Remove the bc argument and let users apply the bcs (is there are compelling JIT-related issue why bcs should be applied inside assemble?

Comments (13)

  1. Johan Hake

    It looks like the bcs and symmetric_mode areleft over from the work of Joacim Haga wrt symmetric assemble. The commit message of 6c62604fed8b5274d7b5a2d1b7a683a2ffe54bb4 says that one can do:

    A, An = symmetric_assemble(a, bcs=bc)
    b = assemble(L, bcs=bc, symmetric_mod=An)
    solve(A, x, b)
    

    With symetric_assemble out of the code we should be able to just remove this.

    It makes sense to have x0 in the assemble_system function but I am not sure it makes sense to introduce that to assemble as it only (more or less) mirrors the C++ version, which lacks functionality to pass an additional vector.

  2. Prof Garth Wells reporter

    @johanhake Sounds good - let's remove bcs, and symmetric flagsfrom assemble, and add x0 to system_assembler.

  3. Johan Hake

    @garth.wells ok, will do. As this might potentially break some user code I suggest we add a deprecation message for the bcs arg.

    Btw x0 is already present in assemble_system.

  4. Johan Hake

    There should not be any point to do that as the Assembler::assemble, which the python assemble use does not provide any interface for the x0 argument. bcs is now just used for convenience.

  5. Prof Garth Wells reporter

    But if we let the Python assemble interface apply bcs, we should probably pass in x0 too.

  6. Johan Hake

    Not sure how that could be done? Assembler::assemble does (naturally) not support x0 and that is what the python assemble use. When bcs we introduced it was used to assemble symmetric rhs together with the symmetric_mod argument, which was used to pass a Matrix (not a flag), see syntax above.

    Now bcs can only be used as convenience. In my view there are no compelling reasons why that should be provided, as it diverge the C++ and Python interface. But some users might rely on it in their code so therefore I suggest we keep it with a deprecation message. There is no demo or test using it.

  7. Log in to comment