Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestSoloIdGeneration.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 <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc
36 #include <stddef.h> // for size_t
37 #include <vector> // for vector, operator==
38 #include "mpi.h" // for MPI_COMM_WORLD, etc
39 #include "stk_mesh/base/Types.hpp" // for EntityId, PartVector, etc
40 #include "stk_mesh/baseImpl/SoloSideIdGenerator.hpp"
41
42 class SoloSideIdGeneratorTester : public stk::mesh::impl::SoloSideIdGenerator
43 {
44 public:
45 SoloSideIdGeneratorTester(int numProcsArg, int proc, uint64_t maxSideId)
46 : SoloSideIdGenerator(numProcsArg, proc, maxSideId)
47 {}
48
49 stk::mesh::EntityId test_get_solo_side_id_using_formula(unsigned elementId, unsigned sideOrdinal)
50 {
51 return get_solo_side_id_using_formula(elementId, sideOrdinal);
52 }
53 };
54
55 TEST( SoloSideIdGenerator, get_solo_side_id_using_formula )
56 {
57 const int numProcs = 1;
58 const int myProcId = 0;
59 const uint64_t maxSideId = 100;
60 SoloSideIdGeneratorTester soloSideIdGenerator(numProcs, myProcId, maxSideId);
61
62 const unsigned maxPseudoElement = soloSideIdGenerator.max_pseudo_element();
63 EXPECT_EQ(17u, soloSideIdGenerator.test_get_solo_side_id_using_formula(1, 6));
64 EXPECT_EQ(18u, soloSideIdGenerator.test_get_solo_side_id_using_formula(1, 7));
65 EXPECT_EQ(19u, soloSideIdGenerator.test_get_solo_side_id_using_formula(1, 8));
66 EXPECT_EQ(20u, soloSideIdGenerator.test_get_solo_side_id_using_formula(1, 9));
67 EXPECT_EQ(27u, soloSideIdGenerator.test_get_solo_side_id_using_formula(2, 6));
68 EXPECT_NO_THROW(soloSideIdGenerator.test_get_solo_side_id_using_formula(maxPseudoElement, 9));
69 EXPECT_THROW( soloSideIdGenerator.test_get_solo_side_id_using_formula(maxPseudoElement+1, 6), std::exception);
70 }
71
72 TEST( SoloSideIdGenerator, get_solo_side_id )
73 {
74 const int numProcs = 1;
75 const int myProcId = 0;
76 const uint64_t maxSideId = 100;
77 SoloSideIdGeneratorTester soloSideIdGenerator(numProcs, myProcId, maxSideId);
78
79 EXPECT_EQ(17u, soloSideIdGenerator.get_solo_side_id());
80 EXPECT_EQ(18u, soloSideIdGenerator.get_solo_side_id());
81 EXPECT_EQ(19u, soloSideIdGenerator.get_solo_side_id());
82 EXPECT_EQ(20u, soloSideIdGenerator.get_solo_side_id());
83 EXPECT_EQ(27u, soloSideIdGenerator.get_solo_side_id());
84 }
85
86 TEST( SoloSideIdGenerator, test_id_space_per_proc )
87 {
88 int myProcId = -1;
89 int numProcs = -1;
90 MPI_Comm_rank(MPI_COMM_WORLD, &myProcId);
91 MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
92
93 const uint64_t maxSideId = 1000000;
94 SoloSideIdGeneratorTester soloSideIdGenerator(numProcs, myProcId, maxSideId);
95 uint64_t maxPseudoElement = soloSideIdGenerator.max_pseudo_element();
96
97 for(size_t elementIndex = myProcId+1; elementIndex <= maxPseudoElement; elementIndex+=numProcs)
98 {
99 for(size_t ordinal = 6; ordinal < 10; ordinal++)
100 {
101 EXPECT_EQ(soloSideIdGenerator.get_solo_side_id(), soloSideIdGenerator.test_get_solo_side_id_using_formula(elementIndex, ordinal));
102 }
103 }
104
105 EXPECT_THROW(soloSideIdGenerator.get_solo_side_id(), std::exception);
106 }