Sierra Toolkit  Version of the Day
UnitTestInducedPart.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 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_util/parallel/Parallel.hpp>
15 
16 #include <stk_mesh/base/BulkData.hpp>
17 
18 #include <stk_mesh/fem/FEMMetaData.hpp>
19 
24 
25 namespace {
26 
27 bool has_part(const Entity& entity, const Part& part)
28 {
29  return entity.bucket().member(part);
30 }
31 
32 // Set up a very simple mesh with one element, one side, one node:
33 // rels: E->(S1,S2)->N
34 // parts: E in element_rank_part, unranked_part
35 // S1, S2 in side_rank_part
36 // element_ranked_part subset of unranked_superset_part
37 // modification cycle is left uncompleted
38 #define SETUP_MESH() \
39  stk_classic::ParallelMachine pm = MPI_COMM_SELF; \
40  \
41  const unsigned spatial_dim = 2; \
42  \
43  std::vector<std::string> entity_rank_names = stk_classic::mesh::fem::entity_rank_names(spatial_dim); \
44  FEMMetaData meta_data(spatial_dim, entity_rank_names); \
45  Part& unranked_part = meta_data.declare_part("unranked_part"); \
46  Part& element_rank_part = meta_data.declare_part("element_rank_part", meta_data.element_rank()); \
47  Part& element_rank_superset_part = meta_data.declare_part("element_rank_superset_part", meta_data.element_rank()); \
48  Part& side_rank_part = meta_data.declare_part("side_rank_part", meta_data.side_rank()); \
49  Part& unranked_superset_part = meta_data.declare_part("unranked_superset_part"); \
50  meta_data.declare_part_subset(unranked_superset_part, element_rank_part); \
51  meta_data.declare_part_subset(element_rank_superset_part, element_rank_part); \
52  \
53  meta_data.commit(); \
54  BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm); \
55  \
56  mesh.modification_begin(); \
57  \
58  stk_classic::mesh::PartVector parts; \
59  parts.push_back(&unranked_part); \
60  parts.push_back(&element_rank_part); \
61  Entity& elem = mesh.declare_entity(meta_data.element_rank(), 1 /*id*/, parts); \
62  \
63  parts.clear(); \
64  parts.push_back(&side_rank_part); \
65  Entity& side1 = mesh.declare_entity(meta_data.side_rank(), 1 /*id*/, parts); \
66  Entity& side2 = mesh.declare_entity(meta_data.side_rank(), 2 /*id*/, parts); \
67  \
68  parts.clear(); \
69  Entity& node = mesh.declare_entity(meta_data.node_rank(), 1 /*id*/, parts); \
70  \
71  mesh.declare_relation(elem, side1, 0 /*rel id*/); \
72  mesh.declare_relation(elem, side2, 1 /*rel id*/); \
73  mesh.declare_relation(side1, node, 0 /*rel id*/); \
74  mesh.declare_relation(side2, node, 0 /*rel id*/);
75 
76 STKUNIT_UNIT_TEST ( UnitTestInducedPart , verifyBasicInducedPart )
77 {
78  SETUP_MESH();
79 
80  // Check that directly-induced parts are induced upon relation creation
81  // before modification end.
82  STKUNIT_EXPECT_TRUE(has_part(node, side_rank_part));
83  STKUNIT_EXPECT_TRUE(has_part(side1, element_rank_part));
84  STKUNIT_EXPECT_TRUE(has_part(side2, element_rank_part));
85 
86  mesh.modification_end();
87 
88  // Modification-end should not have changed induced parts
89  STKUNIT_EXPECT_TRUE(has_part(node, side_rank_part));
90  STKUNIT_EXPECT_TRUE(has_part(side1, element_rank_part));
91  STKUNIT_EXPECT_TRUE(has_part(side2, element_rank_part));
92 }
93 
94 STKUNIT_UNIT_TEST ( UnitTestInducedPart , verifyNotTransitiveInducedPart )
95 {
96  SETUP_MESH();
97 
98  // Node should not have picked-up the element_rank_part indirectly through
99  // it's relation to the sides because induced-parts are not supposed to be
100  // transitive according to the STK_Mesh domain design.
101  // TODO: Are we sure we don't want induced parts to be transitive??
102  STKUNIT_EXPECT_TRUE(!has_part(node, element_rank_part));
103 }
104 
105 STKUNIT_UNIT_TEST ( UnitTestInducedPart, verifyInducedPartCorrectnessWhenRelationsRemoved )
106 {
107  SETUP_MESH();
108 
109  // Destroy one relation from element to a side, confirm that the side that lost
110  // the relation no longer has the element part.
111  mesh.destroy_relation(elem, side1, 0 /*rel id*/);
112  STKUNIT_EXPECT_TRUE(!has_part(side1, element_rank_part));
113 
114  // Destroy one of the relations from side to node. Confirm that node still has
115  // side part due to its remaining relation.
116  mesh.destroy_relation(side1, node, 0 /*rel id*/);
117  STKUNIT_EXPECT_TRUE(has_part(node, side_rank_part));
118 
119  // Destroy the other relations from side to node. Confirm that node no longer
120  // has any induced parts.
121  mesh.destroy_relation(side2, node, 0 /*rel id*/);
122  STKUNIT_EXPECT_TRUE(!has_part(node, side_rank_part));
123 }
124 
125 STKUNIT_UNIT_TEST ( UnitTestInducedPart , verifySupersetsOfInducedPart )
126 {
127  SETUP_MESH();
128 
129  // Check for superset/subset consistency in induced parts. If an entity is
130  // induced into a part, it should also be induced into the supersets of
131  // that part even if the superset parts are unranked.
132  STKUNIT_EXPECT_TRUE(has_part(side1, element_rank_superset_part));
133  STKUNIT_EXPECT_TRUE(has_part(side1, unranked_superset_part));
134 }
135 
136 }
FEMMetaData is a class that implements a Finite Element Method skin on top of the Sierra Tool Kit Met...
Definition: FEMMetaData.hpp:54
Bucket & bucket() const
The bucket which holds this mesh entity&#39;s field data.
Definition: Entity.hpp:141
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
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
bool member(const Part &) const
Bucket is a subset of the given part.
Definition: Bucket.cpp:60