Debian Codegraph @

demo/CustomIntegral.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-03
20 #
21 # This demo illustrates the use of custom integrals.
22 #
23 # Compile this form with FFC: ffc CustomIntegral.ufl
24
25 # Define element
26 element = FiniteElement("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 # Bilinear form
52 a = dot(grad(u), grad(v))*dx \
53 - dot(avg(grad(u)), jump(v, n))*di \
54 - dot(avg(grad(v)), jump(u, n))*di \
55 + alpha/h*jump(u)*jump(v)*di \
56 + dot(jump(grad(u)), jump(grad(v)))*do
57
58 # Linear form
59 L = f*v*dx