Debian Codegraph @

test/unit/cpp/mesh/MeshFunction.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 // Unit tests for MeshFunction
19
20 #include <dolfin.h>
21 #include <catch.hpp>
22
23 using namespace dolfin;
24
25 TEST_CASE("MeshFunctions")
26 {
27 SECTION("Test create from domains")
28 {
29 // Create mesh
30 std::shared_ptr<Mesh> mesh(new UnitSquareMesh(3, 3));
31 dolfin_assert(mesh);
32
33 const std::size_t D = mesh->topology().dim();
34
35 // Test setting all values
36 for (std::size_t d = 0; d <= D; ++d)
37 {
38 // Create MeshDomains object
39 MeshDomains mesh_domains;
40 mesh_domains.init(D);
41
42 mesh->init(d);
43
44 // Build mesh domain
45 std::map<std::size_t, std::size_t>& domain = mesh_domains.markers(d);
46 for (std::size_t i = 0; i < mesh->num_entities(d); ++i)
47 domain.insert(std::make_pair(i, i));
48
49 // Create MeshFunction and test values
50 MeshFunction<std::size_t> mf(mesh, d, mesh_domains);
51 for (std::size_t i = 0; i < mf.size(); ++i)
52 CHECK(mf[i] == i);
53 }
54
55 // Test setting some values only
56 for (std::size_t d = 0; d <= D; ++d)
57 {
58 // Create MeshDomains object
59 MeshDomains mesh_domains;
60 mesh_domains.init(D);
61
62 mesh->init(d);
63
64 // Build mesh domain
65 std::map<std::size_t, std::size_t>& domain = mesh_domains.markers(d);
66 const std::size_t num_entities = mesh->num_entities(d);
67 for (std::size_t i = num_entities/2; i < num_entities; ++i)
68 domain.insert(std::make_pair(i, i));
69
70 // Create MeshFunction and test values
71 MeshFunction<std::size_t> mf(mesh, d, mesh_domains);
72 for (std::size_t i = 0; i < num_entities/2; ++i)
73 CHECK(mf[i] == std::numeric_limits<std::size_t>::max());
74 for (std::size_t i = num_entities/2; i < mf.size(); ++i)
75 CHECK(mf[i] == i);
76 }
77 }
78 }