Sierra Toolkit Version of the Day
SelectorFixture.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 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 <sstream>
00011 #include <stk_mesh/fixtures/SelectorFixture.hpp>
00012 
00013 namespace stk {
00014 namespace mesh {
00015 namespace fixtures {
00016 
00017   SelectorFixture::~SelectorFixture() {}
00018 
00019   SelectorFixture::SelectorFixture()
00020     : m_MetaData( std::vector<std::string>(1, std::string("MyEntityRank")) )
00021     , m_BulkData( m_MetaData , MPI_COMM_WORLD )
00022     , m_partA( m_MetaData.declare_part( "PartA" , 0 ) )
00023     , m_partB( m_MetaData.declare_part( "PartB" , 0 ) )
00024     , m_partC( m_MetaData.declare_part( "PartC" , 0 ) )
00025     , m_partD( m_MetaData.declare_part( "PartD" , 0 ) )
00026     , m_entity1( NULL )
00027     , m_entity2( NULL )
00028     , m_entity3( NULL )
00029     , m_entity4( NULL )
00030     , m_entity5( NULL )
00031   {
00032     m_MetaData.commit();
00033 
00034     m_BulkData.modification_begin();
00035 
00036     const unsigned entity_count = 5 ;
00037 
00038     stk::mesh::EntityRank ent_type = 0; // rank
00039 
00040     // Create Entities and assign to parts:
00041     stk::mesh::EntityId ent_id =
00042       1 + entity_count * m_BulkData.parallel_rank(); // Unique ID
00043 
00044     std::vector<stk::mesh::Part*> partMembership;
00045 
00046     // Entity1 is contained in PartA
00047     partMembership.clear();
00048     partMembership.push_back( & m_partA );
00049     m_entity1 = & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
00050     ++ent_id;
00051 
00052     // Entity2 is contained in PartA and PartB
00053     partMembership.clear();
00054     partMembership.push_back( & m_partA );
00055     partMembership.push_back( & m_partB );
00056     m_entity2 = & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
00057     ++ent_id;
00058 
00059     // Entity3 is contained in PartB and PartC
00060     partMembership.clear();
00061     partMembership.push_back( & m_partB );
00062     partMembership.push_back( & m_partC );
00063     m_entity3 = & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
00064     ++ent_id;
00065 
00066     // Entity4 is contained in PartC
00067     partMembership.clear();
00068     partMembership.push_back( & m_partC );
00069     m_entity4 = & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
00070     ++ent_id;
00071 
00072     // Entity5 is not contained in any Part
00073     partMembership.clear();
00074     m_entity5 = & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
00075 
00076     m_BulkData.modification_end();
00077   }
00078 
00079   //--------------------------------------------------------------------------
00080 
00081   VariableSelectorFixture::~VariableSelectorFixture() {}
00082 
00083   VariableSelectorFixture::VariableSelectorFixture(int NumParts)
00084     : m_MetaData( std::vector<std::string>(1, std::string("MyEntityRank")) )
00085     , m_BulkData( m_MetaData , MPI_COMM_WORLD )
00086     , m_declared_part_vector()
00087   {
00088     // Create Parts and commit:
00089     std::string myPartName;
00090     stk::mesh::EntityRank myRank = 0;
00091 
00092     std::string partName = "Part_";
00093     for (int part_i=0 ; part_i<NumParts; ++part_i) {
00094       std::ostringstream localPartName(partName);
00095       localPartName << part_i;
00096       stk::mesh::Part * part =
00097         & m_MetaData.declare_part(localPartName.str(),myRank);
00098       m_declared_part_vector.push_back( part );
00099     }
00100 
00101     m_MetaData.commit();
00102 
00103     // Create Entities and assign to parts:
00104 
00105     m_BulkData.modification_begin();
00106 
00107     stk::mesh::EntityRank ent_type = 0; // rank
00108     stk::mesh::EntityId ent_id =
00109       1 + NumParts * m_BulkData.parallel_rank(); // Unique ID
00110 
00111     for (int part_i = 0 ; part_i < NumParts ; ++part_i) {
00112       std::vector<stk::mesh::Part*> partMembership;
00113       partMembership.push_back(m_declared_part_vector[part_i]);
00114       stk::mesh::Entity * e =
00115         & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
00116       m_entities.push_back( e );
00117       ++ent_id;
00118     }
00119 
00120     m_BulkData.modification_end();
00121   }
00122 
00123 } // fixtures
00124 } // mesh
00125 } // stk
00126 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends