Hi,
I'm trying to implement periodic boundary conditions using dG (fenics version 1.6.0), but information does not appear to be transmitted across the boundary. The code below solves the advection equation with an upwinding flux. When the function space is changed from DG to CG the periodic boundary works as it should. Does anyone know why this is, and/or how to resolve this issue?
This question was asked a couple of years ago here, and the answer was there was not support at the time to do this, fingers crossed this has changed!
Thank you for your help,
James
from dolfin import *
mesh = UnitIntervalMesh(256)
c0=Expression('exp(-pow((x[0]-0.5),2)/0.025)')
class PeriodicBoundary(SubDomain):
def inside(self, x, on_boundary):
return bool(x[0] < DOLFIN_EPS and x[0] > -DOLFIN_EPS and on_boundary)
def map(self, x, y):
y[0] = x[0] - 1.0
V = FunctionSpace(mesh, 'DG', 1, constrained_domain=PeriodicBoundary())
c=TrialFunction(V)
v=TestFunction(V)
n = FacetNormal(mesh)
a_K = - v*c.dx(0)*dx + jump(c, n[0]) *v('-')*dS
a_M = c*v*dx
M=assemble(a_M)
K=assemble(a_K)
c=Function(V)
c_1=interpolate(c0,V)
c.assign(c_1)
k=[]
for i in range(4):
k.append(Function(V))
T = 4
t = 0
dt =0.001
while t<=T:
b1=K*c.vector()
solve(M,k[0].vector(),b1)
b2=K*(c.vector()+0.5*dt*k[0].vector())
solve(M,k[1].vector(),b2)
b3=K*(c.vector()+0.5*dt*k[1].vector())
solve(M,k[2].vector(),b3)
b4=K*(c.vector()+dt*k[2].vector())
solve(M,k[3].vector(),b4)
c.vector()[:]= c.vector()+dt*(k[0].vector()+ 2 * k[1].vector() + 2 * k[2].vector() +k[3].vector())/6.0
t += dt
plot(c,rescale=False)