Debian Codegraph @

python/demo/documented/subdomains/demo_subdomains.py

raw
1 """This demo program demonstrates how to mark sub domains of a mesh
2 and store the sub domain markers as a mesh function to a DOLFIN XML
3 file.
4
5 The sub domain markers produced by this demo program are the ones used
6 for the Stokes demo programs.
7 """
8
9 # Copyright (C) 2007 Kristian B. Oelgaard
10 #
11 # This file is part of DOLFIN.
12 #
13 # DOLFIN is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
17 #
18 # DOLFIN is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License for more details.
22 #
23 # You should have received a copy of the GNU Lesser General Public License
24 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
25 #
26 # Modified by Anders Logg, 2008.
27 #
28 # First added: 2007-11-15
29 # Last changed: 2011-01-25
30 # Begin demo
31
32 from dolfin import *
33
34 set_log_level(1)
35
36 # Sub domain for no-slip (mark whole boundary, inflow and outflow will overwrite)
37 class Noslip(SubDomain):
38 def inside(self, x, on_boundary):
39 return on_boundary
40
41 # Sub domain for inflow (right)
42 class Inflow(SubDomain):
43 def inside(self, x, on_boundary):
44 return x[0] > 1.0 - DOLFIN_EPS and on_boundary
45
46 # Sub domain for outflow (left)
47 class Outflow(SubDomain):
48 def inside(self, x, on_boundary):
49 return x[0] < DOLFIN_EPS and on_boundary
50
51 # Read mesh
52 mesh = Mesh("../dolfin_fine.xml.gz")
53
54 # Create mesh functions over the cell facets
55 sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
56 sub_domains_bool = MeshFunction("bool", mesh, mesh.topology().dim() - 1)
57 sub_domains_double = MeshFunction("double", mesh, mesh.topology().dim() - 1)
58
59 # Mark all facets as sub domain 3
60 sub_domains.set_all(3)
61 sub_domains_bool.set_all(False)
62 sub_domains_double.set_all(0.3)
63
64 # Mark no-slip facets as sub domain 0, 0.0
65 noslip = Noslip()
66 noslip.mark(sub_domains, 0)
67 noslip.mark(sub_domains_double, 0.0)
68
69 # Mark inflow as sub domain 1, 01
70 inflow = Inflow()
71 inflow.mark(sub_domains, 1)
72 inflow.mark(sub_domains_double, 0.1)
73
74 # Mark outflow as sub domain 2, 0.2, True
75 outflow = Outflow()
76 outflow.mark(sub_domains, 2)
77 outflow.mark(sub_domains_double, 0.2)
78 outflow.mark(sub_domains_bool, True)
79
80 # Save sub domains to file
81 file = File("subdomains.xml")
82 file << sub_domains
83
84 # FIXME: Not implemented
85 #file_bool = File("subdomains_bool.xml")
86 #file_bool << sub_domains_bool
87
88 file_double = File("subdomains_double.xml")
89 file_double << sub_domains_double
90
91 # Save sub domains to VTK files
92 file = File("subdomains.pvd")
93 file << sub_domains
94
95 file = File("subdomains_double.pvd")
96 file << sub_domains_double