Sierra Toolkit Version of the Day
UnitTestInducedPart.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010, 2011 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #include <stdexcept>
00011 
00012 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00013 
00014 #include <stk_util/parallel/Parallel.hpp>
00015 
00016 #include <stk_mesh/base/BulkData.hpp>
00017 
00018 #include <stk_mesh/fem/FEMMetaData.hpp>
00019 
00020 using stk::mesh::Part;
00021 using stk::mesh::fem::FEMMetaData;
00022 using stk::mesh::BulkData;
00023 using stk::mesh::Entity;
00024 
00025 namespace {
00026 
00027 bool has_part(const Entity& entity, const Part& part)
00028 {
00029   return entity.bucket().member(part);
00030 }
00031 
00032 // Set up a very simple mesh with one element, one side, one node:
00033 // rels: E->(S1,S2)->N
00034 // parts: E in element_rank_part, unranked_part
00035 //        S1, S2 in side_rank_part
00036 //        element_ranked_part subset of unranked_superset_part
00037 // modification cycle is left uncompleted
00038 #define SETUP_MESH()                            \
00039   stk::ParallelMachine pm = MPI_COMM_SELF;              \
00040                                                   \
00041   const unsigned spatial_dim = 2;                                       \
00042                                                                         \
00043   std::vector<std::string> entity_rank_names = stk::mesh::fem::entity_rank_names(spatial_dim); \
00044   FEMMetaData meta_data(spatial_dim, entity_rank_names);                \
00045   Part& unranked_part = meta_data.declare_part("unranked_part");        \
00046   Part& element_rank_part = meta_data.declare_part("element_rank_part", meta_data.element_rank()); \
00047   Part& element_rank_superset_part = meta_data.declare_part("element_rank_superset_part", meta_data.element_rank()); \
00048   Part& side_rank_part = meta_data.declare_part("side_rank_part", meta_data.side_rank()); \
00049   Part& unranked_superset_part = meta_data.declare_part("unranked_superset_part"); \
00050   meta_data.declare_part_subset(unranked_superset_part, element_rank_part); \
00051   meta_data.declare_part_subset(element_rank_superset_part, element_rank_part); \
00052                                                                         \
00053   meta_data.commit();                                                   \
00054   BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm);             \
00055                                                                         \
00056   mesh.modification_begin();                                            \
00057                                                                         \
00058   stk::mesh::PartVector parts;                                          \
00059   parts.push_back(&unranked_part);                                       \
00060   parts.push_back(&element_rank_part);                                   \
00061   Entity& elem = mesh.declare_entity(meta_data.element_rank(), 1 /*id*/, parts); \
00062                                                                         \
00063   parts.clear();                                                        \
00064   parts.push_back(&side_rank_part);                                      \
00065   Entity& side1 = mesh.declare_entity(meta_data.side_rank(), 1 /*id*/, parts); \
00066   Entity& side2 = mesh.declare_entity(meta_data.side_rank(), 2 /*id*/, parts); \
00067                                                                         \
00068   parts.clear();                                                        \
00069   Entity& node = mesh.declare_entity(meta_data.node_rank(), 1 /*id*/, parts); \
00070                                                                         \
00071   mesh.declare_relation(elem, side1,  0 /*rel id*/);                    \
00072   mesh.declare_relation(elem, side2,  1 /*rel id*/);                    \
00073   mesh.declare_relation(side1, node,  0 /*rel id*/);                    \
00074   mesh.declare_relation(side2, node,  0 /*rel id*/);
00075 
00076 STKUNIT_UNIT_TEST ( UnitTestInducedPart , verifyBasicInducedPart )
00077 {
00078   SETUP_MESH();
00079 
00080   // Check that directly-induced parts are induced upon relation creation
00081   // before modification end.
00082   STKUNIT_EXPECT_TRUE(has_part(node, side_rank_part));
00083   STKUNIT_EXPECT_TRUE(has_part(side1, element_rank_part));
00084   STKUNIT_EXPECT_TRUE(has_part(side2, element_rank_part));
00085 
00086   mesh.modification_end();
00087 
00088   // Modification-end should not have changed induced parts
00089   STKUNIT_EXPECT_TRUE(has_part(node, side_rank_part));
00090   STKUNIT_EXPECT_TRUE(has_part(side1, element_rank_part));
00091   STKUNIT_EXPECT_TRUE(has_part(side2, element_rank_part));
00092 }
00093 
00094 STKUNIT_UNIT_TEST ( UnitTestInducedPart , verifyNotTransitiveInducedPart )
00095 {
00096   SETUP_MESH();
00097 
00098   // Node should not have picked-up the element_rank_part indirectly through
00099   // it's relation to the sides because induced-parts are not supposed to be
00100   // transitive according to the STK_Mesh domain design.
00101   // TODO: Are we sure we don't want induced parts to be transitive??
00102   STKUNIT_EXPECT_TRUE(!has_part(node, element_rank_part));
00103 }
00104 
00105 STKUNIT_UNIT_TEST ( UnitTestInducedPart, verifyInducedPartCorrectnessWhenRelationsRemoved )
00106 {
00107   SETUP_MESH();
00108 
00109   // Destroy one relation from element to a side, confirm that the side that lost
00110   // the relation no longer has the element part.
00111   mesh.destroy_relation(elem, side1, 0 /*rel id*/);
00112   STKUNIT_EXPECT_TRUE(!has_part(side1, element_rank_part));
00113 
00114   // Destroy one of the relations from side to node. Confirm that node still has
00115   // side part due to its remaining relation.
00116   mesh.destroy_relation(side1, node, 0 /*rel id*/);
00117   STKUNIT_EXPECT_TRUE(has_part(node, side_rank_part));
00118 
00119   // Destroy the other relations from side to node. Confirm that node no longer
00120   // has any induced parts.
00121   mesh.destroy_relation(side2, node, 0 /*rel id*/);
00122   STKUNIT_EXPECT_TRUE(!has_part(node, side_rank_part));
00123 }
00124 
00125 STKUNIT_UNIT_TEST ( UnitTestInducedPart , verifySupersetsOfInducedPart )
00126 {
00127   SETUP_MESH();
00128 
00129   // Check for superset/subset consistency in induced parts. If an entity is
00130   // induced into a part, it should also be induced into the supersets of
00131   // that part even if the superset parts are unranked.
00132   STKUNIT_EXPECT_TRUE(has_part(side1, element_rank_superset_part));
00133   STKUNIT_EXPECT_TRUE(has_part(side1, unranked_superset_part));
00134 }
00135 
00136 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines