To preface, I’m very new to Fenics (& finite elements) so I appreciate any help or pointers I can get. I’m working on solving Burgers Equation, but I’m running into some issues achieving convergence.
This is the problem I’m working on:
u_t + uu_x - (0.01/\pi)u_{xx}= 0
u(0, x)=-sin(\pi x)
u(t,-1)=u(t,1)=0
where x \in [-1,1] and t \in [0,1].
I’ve defined the variational formulation as follows:
F = [\frac{u-u_n}{dt}\cdot v + u\nabla u \cdot v - \frac{1}{100\pi}\nabla u\nabla v]dx
I’ve messed with the parameters for a while now, but is there anyway I could better define the variational formulation? I’ve messed around with the number of mesh points and the number of time steps without too much luck. I’ve also tried using a few different solvers instead of the default NewtonSolver as well, but not much luck there either.
Here’s a working example of what I have so far:
from fenics import *
import matplotlib.pyplot as plt
%matplotlib notebook
nx = 100
x0, xf = (-1.0, 1.0)
T = 1.0
nSteps = 1000
dt = T/nSteps
order = 2
mesh = IntervalMesh(nx, x0, xf)
V = FunctionSpace(mesh, "CG", order)
# boundary conditions
def left(x, on_boundary):
return on_boundary and near(x[0], x0)
def right(x, on_boundary):
return on_boundary and near(x[0], xf)
bc_l = DirichletBC(V, Constant(0), left)
bc_r = DirichletBC(V, Constant(0), right)
bcs = [bc_l, bc_r]
# initial conditions
u_0 = Expression('-sin(pi*x[0])', degree=1)
u_n = interpolate(u_0, V)
# define variational problem
u = Function(V)
v = TestFunction(V)
u_x = u.dx(0)
DT = Constant(dt)
alpha = Constant(1/(100*pi))
f = Expression("0.0", degree=0)
F = (dot(u - u_n, v)/DT
+ dot(u*u_x, v)
- alpha*dot(grad(u), grad(v))
- dot(f, v))*dx
t = 0
for n in range(nSteps):
# update time
t += dt
# solve variational problem
solve(F == 0, u, bcs)
# update previous solution
u_n.assign(u)
This seems like a pretty simple problem to solve, so I think I must be setting it up incorrectly somehow. Thanks for the help.