Hi James
here are a couple of comments which might help you:
- You can move
Code:
bl.Assemble()
c.Update()
outside of the time-stepping loop (but inside the TaskManager), as the matrix does not change over time. At the moment this is quite a lot of redundant computational effort.
- Doing
Code:
soln.Set(0, definedon=mesh.Boundaries("left|right"))
is unnecessary (if you zero out the Griduction at initialisation
Code:
soln = GridFunction(fes)
soln.vec[:] = 0.0
) as Dirchlet DOFs remain unchanged when solving the system.
- To copy the data from one GridFunction to another GridFunction (of the same space) I recommend doing
Code:
soln_prev.vec.data = soln.vec
. As far as I understand, GridFunction.Set is designed to interpolate a CoefficientFunction into the discrete function, see the
documentation
.
Now to the explicit Euler part. At the moment you are missing the explicit evaluation of the diffusion operator. This could be done for example by doing
Code:
l += -dt * InnerProduct(grad(soln_prev), grad(v)) * dx
BUT: Explicit methods are only stable for very small time-steps. So a direct comparison might not be possible, since the explicit Euler might not be stable for you chosen time-steps. For example you might see that the solution looks good for a few time steps and then explodes.
Best wishes,
Henry