Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestGetBuckets.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include "stk_unit_test_utils/stk_mesh_fixtures/SelectorFixture.hpp" // for SelectorFixture
36 #include <algorithm> // for sort
37 #include <gtest/gtest.h> // for AssertHelper, ASSERT_FALSE, etc
38 #include <stk_mesh/base/Bucket.hpp> // for Bucket
39 #include <stk_mesh/base/BulkData.hpp> // for BulkData
40 #include <stk_mesh/base/MetaData.hpp> // for MetaData
41 #include <stk_unit_test_utils/BulkDataTester.hpp>
42 #include <vector> // for vector
43 namespace stk { namespace mesh { class Part; } }
44 namespace stk { namespace mesh { class Selector; } }
45 namespace stk { namespace mesh { struct Entity; } }
46
47 namespace {
48
49 using stk::mesh::Bucket;
50 using stk::mesh::Part;
51 using stk::mesh::Selector;
52 using stk::mesh::BulkData;
53 using stk::mesh::Entity;
54
55 // Just make copies so we don't have to worry about constness
56 template <class T>
57 void sort_and_compare_eq(std::vector<T*> results,
58 std::vector<T*> expected_results)
59 {
60 std::sort(expected_results.begin(), expected_results.end());
61 std::sort(results.begin(), results.end());
62 ASSERT_EQ(results.size(), expected_results.size());
63 for (unsigned i = 0; i < results.size(); ++i) {
64 ASSERT_TRUE(results[i] == expected_results[i]);
65 }
66 }
67
68 TEST( UnitTestGetBuckets, ExampleFixture )
69 {
70 // Using the SelectorFixture, test for correct bucket membership and
71 // correct results from get_buckets.
72
73 // Generate mesh
74
75 stk::mesh::fixtures::SelectorFixture fix ;
76 fix.m_meta_data.commit();
77
78 fix.m_bulk_data.modification_begin();
79 fix.generate_mesh();
80 ASSERT_TRUE(fix.m_bulk_data.modification_end());
81 const stk::mesh::BulkData& mesh = fix.m_bulk_data;
82
83 // Check bucket membership correctness
84
85 {
86 const Bucket & bucket = mesh.bucket(fix.m_entity1);
87 ASSERT_TRUE( bucket.member( fix.m_partA ) );
88 ASSERT_FALSE( bucket.member( fix.m_partB ) );
89 ASSERT_FALSE( bucket.member( fix.m_partC ) );
90 ASSERT_FALSE( bucket.member( fix.m_partD ) );
91 }
92
93 {
94 const Bucket & bucket = mesh.bucket(fix.m_entity2);
95 ASSERT_TRUE( bucket.member( fix.m_partA ) );
96 ASSERT_TRUE( bucket.member( fix.m_partB ) );
97 ASSERT_FALSE( bucket.member( fix.m_partC ) );
98 ASSERT_FALSE( bucket.member( fix.m_partD ) );
99 }
100
101 {
102 const Bucket & bucket = mesh.bucket(fix.m_entity3);
103 ASSERT_FALSE( bucket.member( fix.m_partA ) );
104 ASSERT_TRUE( bucket.member( fix.m_partB ) );
105 ASSERT_TRUE( bucket.member( fix.m_partC ) );
106 ASSERT_FALSE( bucket.member( fix.m_partD ) );
107 }
108
109 {
110 const Bucket & bucket = mesh.bucket(fix.m_entity4);
111 ASSERT_FALSE( bucket.member( fix.m_partA ) );
112 ASSERT_FALSE( bucket.member( fix.m_partB ) );
113 ASSERT_TRUE( bucket.member( fix.m_partC ) );
114 ASSERT_FALSE( bucket.member( fix.m_partD ) );
115 }
116
117 {
118 const Bucket & bucket = mesh.bucket(fix.m_entity5);
119 ASSERT_FALSE( bucket.member( fix.m_partA ) );
120 ASSERT_FALSE( bucket.member( fix.m_partB ) );
121 ASSERT_FALSE( bucket.member( fix.m_partC ) );
122 ASSERT_FALSE( bucket.member( fix.m_partD ) );
123 }
124
125 }
126
127 } // empty namespace