Sierra Toolkit  Version of the Day
UnitTestPartRepository.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 
10 #include <stdexcept>
11 
12 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
13 
14 #include <stk_mesh/baseImpl/PartRepository.hpp>
15 
16 #include <stk_mesh/base/MetaData.hpp>
17 
18 #include <stk_mesh/fem/FEMMetaData.hpp>
19 #include <stk_mesh/fem/FEMHelpers.hpp>
20 
24 using stk_classic::mesh::impl::PartRepository;
25 
26 class UnitTestPartRepository
27 {
28 public:
29  UnitTestPartRepository();
30  ~UnitTestPartRepository() {}
31 
32  const int spatial_dimension;
33  MetaData meta;
34  stk_classic::mesh::impl::PartRepository partRepo;
35  stk_classic::mesh::impl::PartRepository partRepo_1;
36  stk_classic::mesh::impl::PartRepository partRepo_2;
37 
38  stk_classic::mesh::Part * universal_part;
39  stk_classic::mesh::Part * part_A;
40  stk_classic::mesh::Part * part_B;
41  stk_classic::mesh::Part * part_C;
42  stk_classic::mesh::Part * part_D;
43  stk_classic::mesh::Part * part_1_A;
44  stk_classic::mesh::Part * part_1_B;
45  stk_classic::mesh::Part * part_2_A;
46  std::vector<stk_classic::mesh::Part *> intersection;
48  const CellTopologyData * singleton;
49 };
50 
51 UnitTestPartRepository::UnitTestPartRepository()
52  : spatial_dimension(3)
53  , meta( stk_classic::mesh::fem::entity_rank_names(spatial_dimension) )
54  , partRepo( &meta )
55  , partRepo_1( &meta )
56  , partRepo_2( &meta )
57  , universal_part( partRepo.universal_part() )
58  , part_A ( partRepo.declare_part("A",0) )
59  , part_B ( partRepo.declare_part("B",0) )
60  , part_C ( partRepo.declare_part("C",0) )
61  , part_D ( partRepo.declare_part("D",1) )
62  , part_1_A ( partRepo_1.declare_part("A",0) )
63  , part_1_B ( partRepo_1.declare_part("B",0) )
64  , part_2_A ( partRepo_2.declare_part("A",0) )
65  , intersection ( )
66  , relation ( )
67  , singleton ( NULL )
68 {
69  meta.commit();
70 }
71 
72 namespace {
73 
74 STKUNIT_UNIT_TEST( UnitTestPartRepository, construct )
75 {
76  UnitTestPartRepository upr;
77  STKUNIT_EXPECT_TRUE( upr.universal_part != NULL );
78 }
79 
80 STKUNIT_UNIT_TEST( UnitTestPartRepository, universal_in_subset )
81 {
82  UnitTestPartRepository upr;
83  STKUNIT_ASSERT_THROW(
84  upr.partRepo.declare_subset(*upr.part_A,*upr.universal_part),
85  std::runtime_error
86  );
87 }
88 
89 STKUNIT_UNIT_TEST( UnitTestPartRepository, subset_equal_superset )
90 {
91  UnitTestPartRepository upr;
92  STKUNIT_ASSERT_THROW(
93  upr.partRepo.declare_subset(*upr.part_A,*upr.part_A),
94  std::runtime_error
95  );
96 }
97 
98 STKUNIT_UNIT_TEST( UnitTestPartRepository, universal_in_intersection )
99 {
100  UnitTestPartRepository upr;
101  upr.intersection.push_back(upr.universal_part);
102  STKUNIT_ASSERT_THROW(
103  upr.partRepo.declare_part(upr.intersection),
104  std::runtime_error
105  );
106  upr.intersection.push_back(upr.part_A);
107  STKUNIT_ASSERT_THROW(
108  upr.partRepo.declare_part(upr.intersection),
109  std::runtime_error
110  );
111 }
112 
113 STKUNIT_UNIT_TEST( UnitTestPartRepository, circular_subset )
114 {
115  UnitTestPartRepository upr;
116  upr.partRepo.declare_subset(*upr.part_A,*upr.part_B);
117  upr.partRepo.declare_subset(*upr.part_B,*upr.part_C);
118  STKUNIT_ASSERT_THROW(
119  upr.partRepo.declare_subset(*upr.part_C,*upr.part_A),
120  std::runtime_error
121  );
122 }
123 
124 STKUNIT_UNIT_TEST( UnitTestPartRepository, inconsistent_rank_subset )
125 {
126  UnitTestPartRepository upr;
127  // lower rank cannot contain higher rank:
128  STKUNIT_ASSERT_THROW(
129  upr.partRepo.declare_subset(*upr.part_A,*upr.part_D),
130  std::runtime_error
131  );
132  // higher rank can contain lower rank:
133  STKUNIT_ASSERT_NO_THROW(
134  upr.partRepo.declare_subset(*upr.part_D,*upr.part_A)
135  );
136 }
137 
138 STKUNIT_UNIT_TEST( UnitTestPartRepository, two_part_repositories )
139 {
140  UnitTestPartRepository upr;
141  // subset/superset parts must come from same part repository
142  STKUNIT_ASSERT_THROW(
143  upr.partRepo_1.declare_subset(*upr.part_1_A,*upr.part_2_A),
144  std::runtime_error
145  );
146 
147  // intersection contains parts from another part repository
148  {
149  upr.intersection.push_back(upr.part_1_A);
150  upr.intersection.push_back(upr.part_1_B);
151  STKUNIT_ASSERT_THROW(
152  upr.partRepo_2.declare_part( upr.intersection ),
153  std::runtime_error
154  );
155  }
156  // intersection contains parts from multiple part repositories
157  {
158  upr.intersection.push_back(upr.part_1_A);
159  upr.intersection.push_back(upr.part_2_A);
160  STKUNIT_ASSERT_THROW(
161  upr.partRepo_1.declare_part( upr.intersection ),
162  std::runtime_error
163  );
164  }
165 }
166 
167 STKUNIT_UNIT_TEST( UnitTestPartRepository, invalid_relation )
168 {
169  UnitTestPartRepository upr;
170  upr.relation.m_root = upr.part_B;
171  upr.relation.m_target = upr.part_A;
172  STKUNIT_ASSERT_THROW(
173  upr.partRepo.declare_part_relation( *upr.part_A, upr.relation, *upr.part_B ),
174  std::runtime_error
175  );
176 }
177 
178 //Test covers declare_attribute_no_delete in PartRepository.hpp and PartImpl.hpp
179 STKUNIT_UNIT_TEST( UnitTestPartRepository, declare_attribute_no_delete )
180 {
181  UnitTestPartRepository upr;
182  upr.partRepo.declare_attribute_no_delete(*upr.part_A, upr.singleton);
183 
184 }
185 
186 }
The manager of an integrated collection of parts and fields.
Definition: MetaData.hpp:56
An application-defined subset of a problem domain.
Definition: Part.hpp:49
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
Part & declare_part(FEMMetaData &meta_data, const std::string &name)
Declare a part with a given cell topology. This is just a convenient function that wraps FEMMetaData&#39;...
Definition: FEMHelpers.hpp:93
Sierra Toolkit.
A defined entity-relationship between parts. An internal class that should never need to be directly...