Debian Codegraph @

demo/Equation.ufl

raw
1 # Copyright (C) 2007 Anders Logg
2 #
3 # This file is part of FFC.
4 #
5 # FFC 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 # FFC 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 FFC. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Specification of a system F(u, v) = 0 and extraction of
19 # the bilinear and linear forms a and L for the left- and
20 # right-hand sides:
21 #
22 # F(u, v) = a(u, v) - L(v) = 0
23 #
24 # The example below demonstrates the specification of the
25 # linear system for a cG(1)/Crank-Nicholson time step for
26 # the heat equation.
27 #
28 # The below formulation is equivalent to writing
29 #
30 # a = u*v*dx + 0.5*k*inner(grad(u), grad(v))*dx
31 # L = u0*v*dx - 0.5*k*inner(grad(u0), grad(v))*dx
32 #
33 # but instead of manually shuffling terms not including
34 # the unknown u to the right-hand side, all terms may
35 # be listed on one line and left- and right-hand sides
36 # extracted by lhs() and rhs().
37 #
38 # Compile this form with FFC: ffc Equation.ufl
39
40 element = FiniteElement("Lagrange", triangle, 1)
41
42 k = 0.1
43
44 u = TrialFunction(element)
45 v = TestFunction(element)
46 u0 = Coefficient(element)
47
48 eq = (u - u0)*v*dx + k*inner(grad(0.5*(u0 + u)), grad(v))*dx
49
50 a = lhs(eq)
51 L = rhs(eq)