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

Shape mismatch in numerical flux DG

0 votes

I am trying to implement a DG solver for the linear scalar wave equation from the book of Warburton and Hesthaven (Nodal Discontinuous Galerkin Methods, p20).

So the 1D equation is
$$
\frac{\partial u}{\partial t} + a \frac{\partial u}{\partial x} = 0
$$

The proposed numerical flux is
$$
\left(au\right)^* = \left\{\left\{au\right\}\right\} + \left|a\right|\frac{1-\alpha}{2}\left[u\right], \qquad 0 \leq \alpha \leq 1
$$

But when I try to implement this, I get a shape mismatch in my numerical flux.

# Define fluxes on interior and exterior facets
uhat = avg(uold) + a*(1.-alpha)/2.0*jump(uold, n)
uhatbnd = uold + a*(1.-alpha)/2.0*uold*n

Does anyone know what's wrong and how to fix it?

My code:

from dolfin import *

# constants
a     = 2.0*DOLFIN_PI
lmbda = 0.5*a
l     = a/lmbda
omega = -a*a/lmbda

# prepare a mesh
mesh = IntervalMesh(50, 0.0, a)

# Define function spaces
DGorder = 1
V = FunctionSpace(mesh, "DG", DGorder)
U = FunctionSpace(mesh, "DG", DGorder)

# Set initial values
uinit = Expression("0")
u0 = interpolate(uinit, U)

#Set boundary conditions
ubdr = Expression("sin(l*x[0]-omega*t)", l=l, omega=omega, t=0.0)
Port = CompiledSubDomain("x[0] == 0.0")
End  = CompiledSubDomain("x[0] == a", a = a)

bdr = [DirichletBC(V, ubdr, Port)]#, DirichletBC(V, uinit, End)]

# Define test and trial functions
v = TestFunction(V)
u = TrialFunction(U)

# Set time stepping parameters
t  = 0
dt = 0.01
T  = DOLFIN_PI

# Define normals
n = FacetNormal(mesh)

# Set penalty parameter
alpha = 1.

# Central differences for time and spatial discretisation
udot = (u-u0)/dt
uold = (u+u0)*0.5

# Define fluxes on interior and exterior facets
uhat = avg(uold) + a*(1.-alpha)/2.0*jump(uold, n)
uhatbnd = uold + a*(1.-alpha)/2.0*uold*n

# Define variational formulation
F = (udot*v - a*(uold*v.dx(0)))*dx \
    - a*inner(uhat, jump(v,n))*dS \
    - a*inner(uhatbnd, v*n)*ds

a, L = lhs(F), rhs(F)

# Prepare solution
u = Function(U)
plot(u0)

# the acutal timestepping
while t < T:
    solve(a == L, u, bdr)
    u0.assign(u)
    t += dt
    plot(u0)
asked Dec 5, 2013 by stevenvdk FEniCS User (1,590 points)
edited Dec 5, 2013 by stevenvdk

1 Answer

+2 votes
 
Best answer

Hi, you get the shape mismatch error because in many places you are trying to add vectors and scalars. In this line

uhatbnd = uold + a*(1.-alpha)/2.0*uold*n

uold is a scalar but the other term is a vector due to uold*n. In the expression for uhat, there is again a scalar avg(uold) and a vector jump(uold, n). Also, the two expressions in F that include inner are vectors whereas the first term is scalar. If you need scalar valued jump use

jump(uold)
answered Dec 5, 2013 by MiroK FEniCS Expert (80,920 points)
selected Dec 6, 2013 by stevenvdk
...