# Copyright (C) 2006-2007 Kristian B. Oelgaard and Anders Logg # # This file is part of DOLFIN. # # DOLFIN 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. # # DOLFIN 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 DOLFIN. If not, see . # # The bilinear form a(u, v) and linear form L(v) for # Poisson's equation in a discontinuous Galerkin (DG) # formulation. # # Compile this form with FFC: ffc -l dolfin Poisson.ufl from ufl_legacy import (CellDiameter, Coefficient, dS, ds, dx, FiniteElement, avg, dot, FacetNormal, grad, jump, triangle, TestFunction, TrialFunction) # Elements element = FiniteElement("Discontinuous Lagrange", triangle, 1) # Trial and test functions u = TrialFunction(element) v = TestFunction(element) # Source term, Dirichlet term, Neumann term f = Coefficient(element) u0 = Coefficient(element) g = Coefficient(element) # Normal component, cell size and right-hand side h = CellDiameter(triangle) h_avg = (h('+') + h('-'))/2 n = FacetNormal(triangle) # Parameters alpha = 4.0 gamma = 8.0 # Bilinear form a = dot(grad(v), grad(u))*dx \ - dot(avg(grad(v)), jump(u, n))*dS \ - dot(jump(v, n), avg(grad(u)))*dS \ + alpha/h_avg*dot(jump(v, n), jump(u, n))*dS \ - dot(grad(v), u*n)*ds(1) \ - dot(v*n, grad(u))*ds(1) \ + (gamma/h)*v*u*ds(1) # Linear form L = v*f*dx - u0*dot(grad(v), n)*ds(1) + (gamma/h)*u0*v*ds(1) + g*v*ds(2)