Add option to not throw error when coefficient is not found

Issue #96 new
Prof Garth Wells created an issue

It can be convenient to attach all coefficients to all forms, in which case the DOLFIN wrapper shouldn't throw an error. A scenario is the $\theta$ method for time stepping. It $\theta$ is the in the UFL file, the coefficients attached to the bilinear and linear for can change depending on the value of $\theta$ (due to UFL optimising away zero), which is tedious to modify code for.

Comments (7)

  1. Martin Sandve Alnæs

    In the C++ layer? The difficulty is that the a.f = f; notation is only possible for a fixed set of names. Adding a class to collect sets of named objects could solve that and additionally remove the need to repeat a.f=f; L.f=f; etc.

    Functions functions;
    functions.add("f", f);
    ...
    BilinearForm a(V, V, functions);
    LinearForm L(V, functions);
    
  2. Prof Garth Wells reporter

    The relevant code is in the C++ wrappers for DOLFIN that FFC generates. In addition to what you sketched above, we also have

    BilinearForm a(V, V);
    auto f = std::make_shared<Constant>(1.0); 
    a.set_coefficient("f", f);
    

    I use this form as it accepts shared pointers (a.f only takes a reference to f.)

  3. Martin Sandve Alnæs

    Ok, so just adding a.set_coefficients(functions); and adding the Functions (FunctionSet?) class (doesn't need to be generated) is one fairly simple way to go.

  4. Prof Garth Wells reporter

    Much simpler; a.set_coefficients already exists in the wrappers. Just need an extra argument to disable the error.

  5. Log in to comment