Debian Codegraph @

demo/undocumented/parallel-refinement/cpp/main.cpp

raw
1 // Copyright (C) 2013 Chris 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 #include <dolfin.h>
22
23 using namespace dolfin;
24
25 int main()
26 {
27 // Create mesh
28 auto mesh = std::make_shared<UnitSquareMesh>(20, 20);
29
30 // Create MeshFunction to hold cell process rank
31 MeshFunction<std::size_t>
32 processes0(mesh, mesh->topology().dim(), dolfin::MPI::rank(mesh->mpi_comm()));
33
34 // Output cell distribution to VTK file
35 File file("processes.pvd");
36 file << processes0;
37
38 // Mark all cells on process 0 for refinement
39 const MeshFunction<bool>
40 marker(mesh, mesh->topology().dim(), (dolfin::MPI::rank(mesh->mpi_comm()) == 0));
41
42 // Refine mesh, but keep all new cells on parent process
43 auto mesh0 = std::make_shared<Mesh>(refine(*mesh, marker, false));
44
45 // Create MeshFunction to hold cell process rank
46 const MeshFunction<std::size_t>
47 processes1(mesh0, mesh->topology().dim(), dolfin::MPI::rank(mesh->mpi_comm()));
48 file << processes1;
49
50 // Refine mesh, but this time repartition the mesh after refinement
51 auto mesh1 = std::make_shared<Mesh>(refine(*mesh, marker, false));
52
53 // Create MeshFunction to hold cell process rank
54 MeshFunction<std::size_t>
55 processes2(mesh1, mesh->topology().dim(), dolfin::MPI::rank(mesh->mpi_comm()));
56 file << processes2;
57
58 return 0;
59 }