| 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 <stddef.h> // for NULL |
| 36 |
#include <stdexcept> // for runtime_error |
| 37 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData |
| 38 |
#include <stk_mesh/baseImpl/PartRepository.hpp> // for PartRepository |
| 39 |
#include <gtest/gtest.h> |
| 40 |
#include "stk_mesh/base/Types.hpp" // for PartVector |
| 41 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 42 |
namespace stk { namespace mesh { class BulkData; } } |
| 43 |
namespace stk { namespace mesh { class Part; } } |
| 44 |
|
| 45 |
using stk::mesh::MetaData; |
| 46 |
using stk::mesh::BulkData; |
| 47 |
using stk::mesh::Part; |
| 48 |
using stk::mesh::impl::PartRepository; |
| 49 |
|
| 50 |
class UnitTestPartRepository |
| 51 |
{ |
| 52 |
public: |
| 53 |
UnitTestPartRepository(); |
| 54 |
~UnitTestPartRepository() {} |
| 55 |
|
| 56 |
const int spatial_dimension; |
| 57 |
MetaData meta; |
| 58 |
stk::mesh::impl::PartRepository partRepo; |
| 59 |
stk::mesh::impl::PartRepository partRepo_1; |
| 60 |
stk::mesh::impl::PartRepository partRepo_2; |
| 61 |
|
| 62 |
stk::mesh::Part * universal_part; |
| 63 |
stk::mesh::Part * part_A; |
| 64 |
stk::mesh::Part * part_B; |
| 65 |
stk::mesh::Part * part_C; |
| 66 |
stk::mesh::Part * part_D; |
| 67 |
stk::mesh::Part * part_1_A; |
| 68 |
stk::mesh::Part * part_1_B; |
| 69 |
stk::mesh::Part * part_2_A; |
| 70 |
const stk::topology * singleton; |
| 71 |
}; |
| 72 |
|
| 73 |
UnitTestPartRepository::UnitTestPartRepository() |
| 74 |
: spatial_dimension(3), |
| 75 |
meta(spatial_dimension), |
| 76 |
partRepo(&meta), |
| 77 |
partRepo_1(&meta), |
| 78 |
partRepo_2(&meta), |
| 79 |
universal_part(partRepo.universal_part()), |
| 80 |
part_A (partRepo.declare_part("A",stk::topology::NODE_RANK) ), |
| 81 |
part_B (partRepo.declare_part("B",stk::topology::NODE_RANK) ), |
| 82 |
part_C (partRepo.declare_part("C",stk::topology::NODE_RANK) ), |
| 83 |
part_D (partRepo.declare_part("D",stk::topology::EDGE_RANK) ), |
| 84 |
part_1_A (partRepo_1.declare_part("A",stk::topology::NODE_RANK) ), |
| 85 |
part_1_B (partRepo_1.declare_part("B",stk::topology::NODE_RANK) ), |
| 86 |
part_2_A (partRepo_2.declare_part("A",stk::topology::NODE_RANK) ), |
| 87 |
singleton(nullptr) |
| 88 |
{ |
| 89 |
meta.commit(); |
| 90 |
} |
| 91 |
|
| 92 |
namespace { |
| 93 |
|
| 94 |
TEST( UnitTestPartRepository, construct ) |
| 95 |
{ |
| 96 |
UnitTestPartRepository upr; |
| 97 |
EXPECT_TRUE( upr.universal_part != NULL ); |
| 98 |
} |
| 99 |
|
| 100 |
TEST( UnitTestPartRepository, universal_in_subset ) |
| 101 |
{ |
| 102 |
UnitTestPartRepository upr; |
| 103 |
ASSERT_THROW( |
| 104 |
upr.partRepo.declare_subset(*upr.part_A,*upr.universal_part), |
| 105 |
std::runtime_error |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
TEST( UnitTestPartRepository, subset_equal_superset ) |
| 110 |
{ |
| 111 |
UnitTestPartRepository upr; |
| 112 |
ASSERT_THROW( |
| 113 |
upr.partRepo.declare_subset(*upr.part_A,*upr.part_A), |
| 114 |
std::runtime_error |
| 115 |
); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
TEST( UnitTestPartRepository, circular_subset ) |
| 120 |
{ |
| 121 |
UnitTestPartRepository upr; |
| 122 |
upr.partRepo.declare_subset(*upr.part_A,*upr.part_B); |
| 123 |
upr.partRepo.declare_subset(*upr.part_B,*upr.part_C); |
| 124 |
ASSERT_THROW( |
| 125 |
upr.partRepo.declare_subset(*upr.part_C,*upr.part_A), |
| 126 |
std::runtime_error |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
TEST( UnitTestPartRepository, inconsistent_rank_subset ) |
| 131 |
{ |
| 132 |
UnitTestPartRepository upr; |
| 133 |
// lower rank cannot contain higher rank: |
| 134 |
ASSERT_THROW( |
| 135 |
upr.partRepo.declare_subset(*upr.part_A,*upr.part_D), |
| 136 |
std::runtime_error |
| 137 |
); |
| 138 |
// higher rank can contain lower rank: |
| 139 |
ASSERT_NO_THROW( |
| 140 |
upr.partRepo.declare_subset(*upr.part_D,*upr.part_A) |
| 141 |
); |
| 142 |
} |
| 143 |
|
| 144 |
TEST( UnitTestPartRepository, two_part_repositories ) |
| 145 |
{ |
| 146 |
UnitTestPartRepository upr; |
| 147 |
// subset/superset parts must come from same part repository |
| 148 |
ASSERT_THROW( |
| 149 |
upr.partRepo_1.declare_subset(*upr.part_1_A,*upr.part_2_A), |
| 150 |
std::runtime_error |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
//Test covers declare_attribute_no_delete in PartRepository.hpp and PartImpl.hpp |
| 155 |
TEST( UnitTestPartRepository, declare_attribute_no_delete ) |
| 156 |
{ |
| 157 |
UnitTestPartRepository upr; |
| 158 |
upr.partRepo.declare_attribute_no_delete(*upr.part_A, upr.singleton); |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
TEST( UnitTestPartRepository, get_all_parts ) |
| 163 |
{ |
| 164 |
UnitTestPartRepository upr; |
| 165 |
const stk::mesh::PartVector & pv = upr.partRepo.get_all_parts(); |
| 166 |
ASSERT_EQ( pv.size(), 5u ); |
| 167 |
} |
| 168 |
|
| 169 |
TEST( UnitTestPartRepository, get_mesh_parts ) |
| 170 |
{ |
| 171 |
UnitTestPartRepository upr; |
| 172 |
stk::mesh::PartVector mpv = upr.partRepo.get_mesh_parts(); |
| 173 |
ASSERT_EQ( mpv.size(), 4u ); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
} |