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

Periodic boundary conditions for dG

+1 vote

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)
asked Nov 24, 2015 by james3547 FEniCS Novice (140 points)

1 Answer

0 votes

I think you should use your form K instead of M when you solve your problem if you want to use DG elements.

answered Nov 27, 2015 by str FEniCS User (1,600 points)

Hi all,

I too am having the same issue and the fix suggested does not seem to work. In all my attempts the solution fails to wrap itself around to the other side.

Has anyone got a script for solving a 1D advection problem using DG and periodic BCs? I am wondering whether the combination of DG and periodic BCs is not available in fenics? Any help much appreciated.

Cheers

...