I am new to FEniCS and I am trying to solve a type of inviscid Burgers equation with periodic boundary conditions on the unit interval. The code I have written does not throw any errors, but the resulting functions that I plotted did not have periodic boundary conditions.
I have supplied my code below. I have installed FEniCS 2018.1.0 from Anaconda.
I have added a print statement to the map function and noticed that it doesn’t execute.
Am I doing something wrong?
from fenics import *
import matplotlib.pyplot as plt
t0 = 0
num_elements = 300
p_lbd = 2
dt = 0.001
# define periodic boundary
class PeriodicBoundary(SubDomain):
def inside(self, x, on_boundary):
return bool(x[0] < DOLFIN_EPS or x[0] > 1 - DOLFIN_EPS and on_boundary)
def map(self, x, y):
y[0] = x[0] - 1
print(x)
mesh = UnitIntervalMesh(num_elements)
V = FunctionSpace(mesh, 'P', 1, constrained_domain=PeriodicBoundary())
u = Function(V)
v = TestFunction(V)
u0 = Expression("p_lbd + sin(DOLFIN_PI*(2*x[0]))", p_lbd=p_lbd, element=V.ufl_element())
u0 = project(u0, V)
# implicit euler formulation
F = u*v*dx + dt*inner(grad(u),grad(v))*u*dx + dt*0.01*inner(grad(u), grad(v))*dx - u0*v*dx
T = 0.1
t = dt
# steps
while t <= T:
solve(F == 0, u)
t += dt
u0.assign(u)
plot(u)
plt.show()