Debian Codegraph @

python/demo/undocumented/parallel-refinement/demo_parallel-refinement.py

raw
1 # Copyright (C) 2013 Chris N. Richardson
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: 2013-04-26
19 # Last changed: 2013-04-26
20
21 from dolfin import *
22
23 # Create mesh
24 mesh = UnitSquareMesh(20, 20)
25
26 # Create MeshFunction to hold cell process rank
27 processes = MeshFunction('size_t', mesh, mesh.topology().dim(), MPI.rank(mesh.mpi_comm()))
28
29 # Output cell distribution to VTK file
30 file = File("processes.pvd")
31 file << processes
32
33 # Mark all cells on process 0 for refinement
34 marker = MeshFunction('bool', mesh, mesh.topology().dim(), (MPI.rank(mesh.mpi_comm()) == 0))
35
36 # Refine mesh, but keep all news cells on parent process
37 mesh0 = refine(mesh, marker, False)
38
39 # Create MeshFunction to hold cell process rank for refined mesh
40 processes1 = MeshFunction('size_t', mesh0, mesh0.topology().dim(), MPI.rank(mesh.mpi_comm()))
41 file << processes1
42
43 # Refine mesh, but this time repartition the mesh after refinement
44 mesh1 = refine(mesh, marker, True)
45
46 # Create MeshFunction to hold cell process rank for refined mesh
47 processes2 = MeshFunction('size_t', mesh1, mesh1.topology().dim(), MPI.rank(mesh.mpi_comm()))
48 file << processes2