### multi-stage solver not working properly

171
views
0
6 months ago by

Hi I got into troubles using the multistage schemes and solvers when trying to just implement a simple diffusion equation with a delta function in the center. I used the usual way following the tutorial in heat equation and it agrees well with the analytical solution. However, when I am trying to use the multistage scheme already integrated in FEniCS, it did not work.

I use quite small time-step to ensure stability. But no matter what scheme I use, it just quickly dies out to 0, which is not what is predicted to be like. Following is my code, could anybody comment on this issue though?

import numpy as np
import matplotlib.pyplot as plt
from fenics import *

class Delta(Expression):
def __init__(self, eps, x0, **kwargs):
self.eps = eps
self.x0  = x0
def eval(self, values, x):
eps = self.eps
x0  = self.x0
values[0] = 0.0
if near(x[0], x0, eps):
values[0] = .5/eps/1.50

T = 1e-4
num_steps = 5     # number of time steps
dt = T / num_steps # time step size
D  = 1.0

# Create mesh and define function space
nx = 100
delta_x = 1.0/nx
mesh = UnitIntervalMesh(nx)
V = FunctionSpace(mesh, 'CG', 1)
# initial conditions
u0 = Delta(1e-2, 0.5, degree=1)

# Define variational problem
u = Function(V)
v = TestFunction(V)

t = Constant(0.0)
w = interpolate(u0, V)

scheme = RK4(F, w, t)
solver = RKSolver(scheme)

while float(scheme.t()) < T:
solver.step(dt)
plot(w)

Community: FEniCS Project
A late reply: For some reasons you code worked fine for me (with FEniCS 2017.2) and the solutions look good, also for larger time intervals.
(I guess you already solved the problem somehow, anyway, thanks for your post! It was the first example of RKSolve I found :)
written 3 months ago by Steffen