Debian Codegraph @

python/demo/undocumented/overlapping-regions/demo_overlapping-regions.py

raw
1 # Copyright (C) 2011-2013 Marie E. Rognes, Martin S. Alnaes
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 # First added: 2011-11-09
19 # Last changed: 2013-01-29
20
21 # Begin demo
22
23 #
24 # NB! This demo is work in progress and will be updated as we get further in the multidomain features implementation.
25 #
26 from dolfin import *
27 import matplotlib.pyplot as plt
28
29
30 class Left(SubDomain):
31 def inside(self, x, on_boundary):
32 return (x[0] <= 0.25+DOLFIN_EPS)
33
34 class Mid(SubDomain):
35 def inside(self, x, on_boundary):
36 return (x[0] >= 0.375-DOLFIN_EPS) and (x[0] <= 0.625+DOLFIN_EPS)
37
38 class Right(SubDomain):
39 def inside(self, x, on_boundary):
40 return (x[0] >= 0.75-DOLFIN_EPS)
41
42 # Define mesh and subdomains
43 mesh = UnitSquareMesh(64, 64)
44 domains = MeshFunction("size_t", mesh, mesh.topology().dim())
45 domains.set_all(0)
46 Left().mark(domains, 1)
47 Mid().mark(domains, 2)
48 Right().mark(domains, 3)
49
50 # Define input data
51 alpha = Constant(1e-3)
52 f = Constant(3.0)
53 g = Constant(5.0)
54
55 # Define function space and basis functions
56 V = FunctionSpace(mesh, "CG", 2)
57 u = TrialFunction(V)
58 v = TestFunction(V)
59
60 # Define regions as tuples of subdomain labels
61 DL, DM, DR = (1,2), (2,), (2,3) # ***
62
63 # Define new measures associated with the interior domains
64 dx = Measure('dx', domain=mesh, subdomain_data=domains)
65
66 # Make forms for equation
67 a = u*v*dx() + alpha*dot(grad(u), grad(v))*dx() # ***
68 L = f*v*dx(DR) + g*v*dx(DL) - (f+g)/2*v*dx(DM) # ***
69
70 # Solve problem
71 u = Function(V)
72 solve(a == L, u)
73
74 # Plot solution and gradient
75 plt.figure()
76 plot(domains, title='domains')
77 plt.figure()
78 plot(u, title="u")
79 plt.show()