ffc team mailing list archive
-
ffc team
-
Mailing list archive
-
Message #00271
Re: Changed storage of constants from reference to copy in forms. This is [...]
On Sun, Sep 11, 2005 at 07:49:35AM -0500, Anders Logg wrote:
> The reason it's a reference is that in a time-stepping loop, you want
> to be able to give the time step k or time t as an argument to the
> form and have it automatically get updated as you change k and t.
>
> Maybe one should require that one uses references for the constants,
> that is, the constant must exist in a variable outside of the form, in
> the same way as a Function must exist outside of the form?
>
> /Anders
>
Ah right, I'll change it back.
I think the only reason it's a problem is because basic types are
usually passed as copies, not references, and it's very common to
construct them on the stack. Maybe it's enough to just make a class
Constant? Then people would treat it just as a Function, and it could
also be generalized to being tensor-valued etc.
I don't think we can keep it this way. As soon as you construct a form
in a separate function from where you use it, you will run into this
issue. Consider:
LinearForm* L;
init()
{
real c = 13.7;
L = new LinearForm(c)
}
solve()
{
L.assemble(); // Here L->c0 is undefined
}
If it wasn't for valgrind telling me exactly what the problem was, I
would have spent a long time scratching my head on this.
Johan
Follow ups
References