Debian Codegraph @

demo/undocumented/conditional/cpp/Conditional.ufl

raw
1 # Copyright (C) 2010 Kristian B. Oelgaard
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 where spatial coordinates are used to define the source
20 # term. However, the source term is only active in a part of the domain and
21 # a Conditional is used to handle this.
22 #
23 # Compile this form with FFC: ffc -l dolfin Conditional.ufl
24
25 from ufl_legacy import (dx, FiniteElement,
26 conditional, ge, le, SpatialCoordinate,
27 grad, inner,
28 triangle, TestFunction, TrialFunction)
29
30 element = FiniteElement("Lagrange", triangle, 2)
31
32 u = TrialFunction(element)
33 v = TestFunction(element)
34
35 x = SpatialCoordinate(triangle)
36 c0 = conditional(le( (x[0]-0.33)**2 + (x[1]-0.67)**2, 0.015), -1.0, 5.0)
37 c = conditional( le( (x[0]-0.33)**2 + (x[1]-0.67)**2, 0.025), c0, 0.0 )
38
39 t0 = conditional(ge( x[0], 0.55), -1.0, 0.0)
40 t1 = conditional(le( x[0], 0.95), t0, 0.0)
41 t2 = conditional(ge( x[1], 0.05), t1, 0.0)
42 t3 = conditional(le( x[1], 0.45), t2, 0.0)
43 t = conditional(ge( x[1] - x[0] - 0.05 + 0.55, 0.0), t3, 0.0)
44
45 f = c + t
46
47 a = inner(grad(u), grad(v))*dx
48 L = f*v*dx
49