Debian Codegraph @

python/demo/undocumented/refinement/demo_refinement.py

raw
1 "This demo illustrates mesh refinement."
2
3 # Copyright (C) 2007-2009 Anders Logg
4 #
5 # This file is part of DOLFIN.
6 #
7 # DOLFIN is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # DOLFIN is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
19 #
20 # First added: 2007-06-01
21 # Last changed: 2012-11-12
22
23
24 from dolfin import *
25 import matplotlib.pyplot as plt
26
27
28 # Create mesh of unit square
29 mesh = UnitSquareMesh(8, 8)
30 plt.figure(1)
31 plot(mesh)
32
33 info(mesh)
34 print()
35
36 # Uniform refinement
37 mesh = refine(mesh)
38 plt.figure(2)
39 plot(mesh)
40
41 info(mesh)
42 print()
43
44 # Uniform refinement
45 mesh = refine(mesh)
46 plt.figure(3)
47 plot(mesh)
48
49 info(mesh)
50 print()
51
52 # Refine mesh close to x = (0.5, 0.5)
53 p = Point(0.5, 0.5)
54 for i in range(5):
55
56 print("marking for refinement")
57
58 # Mark cells for refinement
59 cell_markers = MeshFunction("bool", mesh, mesh.topology().dim())
60 for c in cells(mesh):
61 if c.midpoint().distance(p) < 0.1:
62 cell_markers[c] = True
63 else:
64 cell_markers[c] = False
65
66 # Refine mesh
67 mesh = refine(mesh, cell_markers)
68
69 # Plot mesh
70 plt.figure()
71 plot(mesh)
72
73 plt.show()