Debian Codegraph @

demo/undocumented/refinement/cpp/main.cpp

raw
1 // Copyright (C) 2006-2011 Anders Logg
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 // Modified by Johan Hoffman, 2006.
19 //
20 // First added: 2006-10-26
21 // Last changed: 2012-11-12
22
23 #include <dolfin.h>
24
25 using namespace dolfin;
26
27 int main()
28 {
29 File file("mesh.pvd");
30
31 // Create mesh of unit square
32 auto mesh = std::make_shared<Mesh>(UnitSquareMesh(5, 5));
33
34 file << *mesh;
35
36 // Uniform refinement
37 mesh = std::make_shared<Mesh>(refine(*mesh));
38 file << *mesh;
39
40 // Refine mesh close to x = (0.5, 0.5)
41 Point p(0.5, 0.5);
42 for (unsigned int i = 0; i < 5; i++)
43 {
44 // Mark cells for refinement
45 MeshFunction<bool> cell_markers(mesh, mesh->topology().dim(), false);
46 for (CellIterator c(*mesh); !c.end(); ++c)
47 {
48 if (c->midpoint().distance(p) < 0.1)
49 cell_markers[*c] = true;
50 }
51
52 // Refine mesh
53 mesh = std::make_shared<Mesh>(refine(*mesh, cell_markers));
54
55 file << *mesh;
56 }
57
58 return 0;
59 }