# Copyright (C) 2007 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/>.
#
# Specification of a system F(u, v) = 0 and extraction of
# the bilinear and linear forms a and L for the left- and
# right-hand sides:
#
#   F(u, v) = a(u, v) - L(v) = 0
#
# The example below demonstrates the specification of the
# linear system for a cG(1)/Crank-Nicholson time step for
# the heat equation.
#
# The below formulation is equivalent to writing
#
#  a = u*v*dx + 0.5*k*inner(grad(u), grad(v))*dx
#  L = u0*v*dx - 0.5*k*inner(grad(u0), grad(v))*dx
#
# but instead of manually shuffling terms not including
# the unknown u to the right-hand side, all terms may
# be listed on one line and left- and right-hand sides
# extracted by lhs() and rhs().
#
# Compile this form with FFC: ffc Equation.ufl

element = FiniteElement("Lagrange", triangle, 1)

k = 0.1

u = TrialFunction(element)
v = TestFunction(element)
u0 = Coefficient(element)

eq = (u - u0)*v*dx + k*inner(grad(0.5*(u0 + u)), grad(v))*dx

a = lhs(eq)
L = rhs(eq)
