# Copyright (C) 2009 Kristian B. Oelgaard, Garth N. Wells and Anders Logg
#
# This file is part of FFC.
#
# FFC is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FFC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with FFC. If not, see <http://www.gnu.org/licenses/>.
#
# First added:  2009-06-26
# Last changed: 2011-03-08
#
# The bilinear form a(u, v) and linear form L(v) for
# Biharmonic equation in a discontinuous Galerkin (DG)
# formulation.
#
# Compile this form with FFC: ffc -l dolfin Biharmonic.ufl

# Elements
element = FiniteElement("Lagrange", triangle, 2)

# Trial and test functions
u = TrialFunction(element)
v = TestFunction(element)

# Facet normal, mesh size and right-hand side
n = FacetNormal(triangle)
h = 2.0*Circumradius(triangle)
f = Coefficient(element)

# Compute average of mesh size
h_avg = (h('+') + h('-'))/2.0

# Parameters
alpha = Coefficient(FiniteElement("Real", triangle, 0))

# Bilinear form
a = inner(div(grad(u)), div(grad(v)))*dx \
  - inner(jump(grad(u), n), avg(div(grad(v))))*dS \
  - inner(avg(div(grad(u))), jump(grad(v), n))*dS \
  + alpha/h_avg*inner(jump(grad(u),n), jump(grad(v),n))*dS

# Linear form
L = f*v*dx
