This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to use RKSolver

0 votes

I have been trying to use the RKSolver on the heat equation, but no matter what I do I can't get the time dependence to work. For the following heat equation I get a constant 0 solution, although we should see it increase over time.

dt = 0.01 
viz = None

mesh = UnitSquareMesh(30, 30)
W = FunctionSpace(mesh, 'CG', 1)

u = Function(W)
v = TestFunction(W)

time = 0.
f = Expression('2 * pi * pi * sin(pi * x[0]) * sin(pi * x[1]) * sin(pi*time)', time=time)
r = -(inner(grad(u), grad(v)) - f * v) * dx

bcs = DirichletBC(W, Constant(0.), 'on_boundary')
scheme = RK4(r, u, time, [bcs])
solver = RKSolver(scheme)

next_dt = dt
while float(scheme.t())<T:

    solver.step(next_dt)
    next_dt = min(T-float(scheme.t()), dt)

    if viz is None:
        viz = plot(u)
    else:
        viz.plot(u)
asked Jun 8, 2016 by erichlf FEniCS Novice (190 points)
...