Debian Codegraph @

demo/undocumented/dg-poisson/cpp/Poisson.ufl

raw
1 # Copyright (C) 2006-2007 Kristian B. Oelgaard and Anders Logg
2 #
3 # This file is part of DOLFIN.
4 #
5 # DOLFIN is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # DOLFIN is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # The bilinear form a(u, v) and linear form L(v) for
19 # Poisson's equation in a discontinuous Galerkin (DG)
20 # formulation.
21 #
22 # Compile this form with FFC: ffc -l dolfin Poisson.ufl
23
24 from ufl_legacy import (CellDiameter, Coefficient, dS, ds, dx, FiniteElement,
25 avg, dot, FacetNormal, grad, jump,
26 triangle, TestFunction, TrialFunction)
27
28 # Elements
29 element = FiniteElement("Discontinuous Lagrange", triangle, 1)
30
31 # Trial and test functions
32 u = TrialFunction(element)
33 v = TestFunction(element)
34
35 # Source term, Dirichlet term, Neumann term
36 f = Coefficient(element)
37 u0 = Coefficient(element)
38 g = Coefficient(element)
39
40 # Normal component, cell size and right-hand side
41 h = CellDiameter(triangle)
42 h_avg = (h('+') + h('-'))/2
43 n = FacetNormal(triangle)
44
45 # Parameters
46 alpha = 4.0
47 gamma = 8.0
48
49 # Bilinear form
50 a = dot(grad(v), grad(u))*dx \
51 - dot(avg(grad(v)), jump(u, n))*dS \
52 - dot(jump(v, n), avg(grad(u)))*dS \
53 + alpha/h_avg*dot(jump(v, n), jump(u, n))*dS \
54 - dot(grad(v), u*n)*ds(1) \
55 - dot(v*n, grad(u))*ds(1) \
56 + (gamma/h)*v*u*ds(1)
57
58 # Linear form
59 L = v*f*dx - u0*dot(grad(v), n)*ds(1) + (gamma/h)*u0*v*ds(1) + g*v*ds(2)