Debian Codegraph @

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