Glad you found the problem :)

Redefining the form can be a bad idea, since low-level C code will be generated for each new form (this is disastrous if you're in the "small mesh, lots of timesteps" regime!)

A better way is to use Constant.  For example,

Q = Constant(0.0)
a = Q*....*dx
t = 0.0
while t < T - 0.5*dt:
    Q.assign(A*sin(2*pi*F*t))
    ...
    t += dt

On 1 October 2015 at 14:17, Anna Kalogirou <a.kalogirou@leeds.ac.uk> wrote:
I was just ready to send you a code when I realised what the problem was.

When I define Q as a scalar expression, updating it after every time
step does not update the expression in the weak form (I define a and L
outside the time loop and then just call the solver at every time step).
Defining the expression by

Q_expr = Expression("A*sin(2*pi*F*t)", t=t, A=A, F=F)
Q.interpolate(Q_expr)

and updating it by Q_expr.t = t works though.

Therefore I had to re-define the linear and bilinear parts of the weak
form inside the time loop for the first approach to work.


On 30/09/15 15:58, Lawrence Mitchell wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 30/09/15 15:51, Anna Kalogirou wrote:
>> Yes, I double - and triple - checked and I believe I am doing the
>> same thing in both approaches. I don't understand then why the
>> results are different.
> Hmph, can you show us some breaking code?
>
> Lawrence
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
>
> iQEcBAEBAgAGBQJWC/imAAoJECOc1kQ8PEYvalEH/2z+lJMa3od/bKUbcbW73imx
> i3In1Wg9ZKVGeZG8VmVlcnirkr38EgzIi5ZoRZVtGQ6tmWsXTCwojfqsaLUv5k+b
> fWma1V9FWp8Vk6XSo8eqR+5oV0CBH0KRZtN8sZdGGqBm2QY5PBrQSyYcy5XHunIm
> h/mc7tT8oLRQKaPwYxuDt8WBtzc+BdNZPexLbGEa921qE1ms/SemDk85GbOQ5oqr
> oqvqfxpyrzwMBlPjz7GLN697u7r15e+qwGFni0Z6x3YsaBUF1OKXq7k0FvT5ObeI
> t30lYnhlxxKbbZQh1NI7goAZ7RUEd5RgAge2wUXN3V8EDyKVqzooRso1GGKGAwg=
> =jk88
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> firedrake mailing list
> firedrake@imperial.ac.uk
> https://mailman.ic.ac.uk/mailman/listinfo/firedrake

--

  Dr Anna Kalogirou
  Research Fellow
  School of Mathematics
  University of Leeds

  http://www1.maths.leeds.ac.uk/~matak/


_______________________________________________
firedrake mailing list
firedrake@imperial.ac.uk
https://mailman.ic.ac.uk/mailman/listinfo/firedrake