Debian Codegraph @

demo/undocumented/mesh-quality/cpp/main.cpp

raw
1 // Copyright (C) 2013 Jan Blechta
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-11-20
19 // Last changed:
20 //
21 // This demo illustrates basic inspection of mesh quality.
22
23 #include <dolfin.h>
24
25 using namespace dolfin;
26
27 int main()
28 {
29 // The output needs to be deterministic so that it can be piped to python
30 parameters["std_out_all_processes"] = false;
31
32 // Read mesh from file
33 Mesh mesh("../dolfin_fine.xml.gz");
34
35 // Print minimal and maximal radius ratio
36 const std::pair<double, double> qminmax
37 = MeshQuality::radius_ratio_min_max(mesh);
38 if (dolfin::MPI::rank(mesh.mpi_comm()) == 0)
39 {
40 std::cout << "# Minimal radius ratio: " << qminmax.first << std::endl;
41 std::cout << "# Maximal radius ratio: " << qminmax.second << std::endl;
42 std::cout << std::endl;
43 }
44
45 // Print matplotlib code for generation of histogram
46 const std::string hist = MeshQuality::radius_ratio_matplotlib_histogram(mesh);
47 if (dolfin::MPI::rank(mesh.mpi_comm()) == 0)
48 {
49 std::cout << "# Execute following commands in python" << std::endl;
50 std::cout << "# to get histogram of radius ratios:" << std::endl;
51 std::cout << std::endl;
52 std::cout << "# ------------------------------------" << std::endl;
53 std::cout << "# ------------------------------------" << std::endl;
54 std::cout << hist << std::endl;
55 std::cout << "# ------------------------------------" << std::endl;
56 std::cout << "# ------------------------------------" << std::endl;
57 std::cout << "# or pass output of this program" << std::endl;
58 std::cout << "# to python, i.e.:" << std::endl;
59 std::cout << "# $> ./demo_mesh-quality | python" << std::endl;
60 }
61
62 // Write out mesh to XDMF.
63 XDMFFile("mesh.xdmf").write(mesh);
64
65 return 0;
66 }