Debian Codegraph @

test/unit/cpp/io/XMLMeshData.cpp

raw
1 // Copyright (C) 2013 Garth N. Wells
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 #include <dolfin.h>
19 #include <catch.hpp>
20
21 using namespace dolfin;
22
23 namespace
24 {
25 void xml_mesh_data()
26 {
27 // XML mesh output is not supported in parallel. Add test for
28 // parallel with HDF5 when ready.
29 if (dolfin::MPI::size(MPI_COMM_WORLD) == 1)
30 {
31 const std::size_t value = 10;
32 {
33 UnitSquareMesh mesh(2, 2);
34
35 // Create some mesh data
36 std::vector<std::size_t>& data0 = mesh.data().create_array("v", 0);
37 data0.resize(mesh.num_entities(0), value);
38
39 mesh.init(1);
40 std::vector<std::size_t>& data1 = mesh.data().create_array("e", 1);
41 data1.resize(mesh.num_entities(1), value);
42
43 std::vector<std::size_t>& data2 = mesh.data().create_array("c", 2);
44 data2.resize(mesh.num_entities(2), value);
45
46 File file("mesh_data.xml");
47 file << mesh;
48 }
49
50 {
51 // Read mesh from file
52 Mesh mesh("mesh_data.xml");
53
54 // Access mesh data and check
55 const std::vector<std::size_t>& data0 = mesh.data().array("v", 0);
56 CHECK(data0.size() == mesh.num_entities(0));
57 CHECK(data0[2] == value);
58 const std::vector<std::size_t>& data1 = mesh.data().array("e", 1);
59 CHECK(data1.size() == mesh.num_entities(1));
60 CHECK(data1[2] == value);
61 const std::vector<std::size_t>& data2 = mesh.data().array("c", 2);
62 CHECK(data2.size() == mesh.num_entities(2));
63 CHECK(data2[2] == value);
64 }
65 }
66 }
67 }
68
69 //-----------------------------------------------------------------------------
70 TEST_CASE("Test XML mesh data", "[xml_mesh_data]")
71 {
72 CHECK_NOTHROW(xml_mesh_data());
73 }