Debian Codegraph @

demo/CustomMixedIntegral.ufl

raw
1 # Copyright (C) 2014 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 # First added: 2014-06-10
19 # Last changed: 2014-06-17
20 #
21 # This demo illustrates the use of custom integrals with mixed elements.
22 #
23 # Compile this form with FFC: ffc CustomMixedIntegral.ufl
24
25 # Define element
26 P2 = VectorElement("Lagrange", triangle, 2)
27 P1 = FiniteElement("Lagrange", triangle, 1)
28 TH = P2 * P1
29
30 # Define trial and test functions and right-hand side
31 (u, p) = TrialFunctions(TH)
32 (v, q) = TestFunctions(TH)
33 f = Coefficient(P2)
34
35 # Define facet normal and mesh size
36 n = FacetNormal(triangle)
37 h = 2.0*Circumradius(triangle)
38 h = (h('+') + h('-')) / 2
39
40 # Define custom measures (FIXME: prettify this)
41 dc0 = dc(0, metadata={"num_cells": 1})
42 dc1 = dc(1, metadata={"num_cells": 2})
43 dc2 = dc(2, metadata={"num_cells": 2})
44
45 # Define measures for integration
46 dx = dx + dc0 # domain integral
47 di = dc1 # interface integral
48 do = dc2 # overlap integral
49
50 # Parameters
51 alpha = 4.0
52
53 def tensor_jump(v, n):
54 return outer(v('+'), n('+')) + outer(v('-'), n('-'))
55
56 def a_h(v, w):
57 return inner(grad(v), grad(w))*dx \
58 - inner(avg(grad(v)), tensor_jump(w, n))*di \
59 - inner(avg(grad(w)), tensor_jump(v, n))*di
60
61 def b_h(v, q):
62 return -div(v)*q*dx + jump(v, n)*avg(q)*di
63
64 def s_h(v, w):
65 return inner(jump(grad(v)), jump(grad(w)))*do
66
67 # Bilinear form
68 a = a_h(u, v) + b_h(v, p) + b_h(u, q) + s_h(u, v)
69
70 # Linear form
71 L = dot(f, v)*dx