Sierra Toolkit  Version of the Day
SelectorFixture.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 <sstream>
11 #include <stk_mesh/fixtures/SelectorFixture.hpp>
12 
13 namespace stk_classic {
14 namespace mesh {
15 namespace fixtures {
16 
17 SelectorFixture::~SelectorFixture() {}
18 
19 SelectorFixture::SelectorFixture()
20  : m_meta_data( std::vector<std::string>(1, std::string("MyEntityRank")) )
21  , m_bulk_data( m_meta_data , MPI_COMM_WORLD )
22  , m_partA( m_meta_data.declare_part( "PartA" , 0 ) )
23  , m_partB( m_meta_data.declare_part( "PartB" , 0 ) )
24  , m_partC( m_meta_data.declare_part( "PartC" , 0 ) )
25  , m_partD( m_meta_data.declare_part( "PartD" , 0 ) )
26  , m_entity1( NULL )
27  , m_entity2( NULL )
28  , m_entity3( NULL )
29  , m_entity4( NULL )
30  , m_entity5( NULL )
31  , m_fieldA(m_meta_data.declare_field<stk_classic::mesh::Field<double> >("FieldA"))
32  , m_fieldABC(m_meta_data.declare_field<stk_classic::mesh::Field<double> >("FieldABC"))
33 {
34  stk_classic::mesh::EntityRank ent_rank = 0;
35 
36  stk_classic::mesh::put_field(m_fieldA, ent_rank, m_partA);
37 
38  stk_classic::mesh::put_field(m_fieldABC, ent_rank, m_partA);
39  stk_classic::mesh::put_field(m_fieldABC, ent_rank, m_partB);
40  stk_classic::mesh::put_field(m_fieldABC, ent_rank, m_partC);
41 }
42 
43 void SelectorFixture::generate_mesh()
44 {
45  const unsigned entity_count = 5 ;
46 
47  stk_classic::mesh::EntityRank ent_type = 0; // rank
48 
49  // Create Entities and assign to parts:
50  stk_classic::mesh::EntityId ent_id =
51  1 + entity_count * m_bulk_data.parallel_rank(); // Unique ID
52 
53  std::vector<stk_classic::mesh::Part*> partMembership;
54 
55  // Entity1 is contained in PartA
56  partMembership.clear();
57  partMembership.push_back( & m_partA );
58  m_entity1 = & m_bulk_data.declare_entity(ent_type, ent_id, partMembership);
59  ++ent_id;
60 
61  // Entity2 is contained in PartA and PartB
62  partMembership.clear();
63  partMembership.push_back( & m_partA );
64  partMembership.push_back( & m_partB );
65  m_entity2 = & m_bulk_data.declare_entity(ent_type, ent_id, partMembership);
66  ++ent_id;
67 
68  // Entity3 is contained in PartB and PartC
69  partMembership.clear();
70  partMembership.push_back( & m_partB );
71  partMembership.push_back( & m_partC );
72  m_entity3 = & m_bulk_data.declare_entity(ent_type, ent_id, partMembership);
73  ++ent_id;
74 
75  // Entity4 is contained in PartC
76  partMembership.clear();
77  partMembership.push_back( & m_partC );
78  m_entity4 = & m_bulk_data.declare_entity(ent_type, ent_id, partMembership);
79  ++ent_id;
80 
81  // Entity5 is not contained in any Part
82  partMembership.clear();
83  m_entity5 = & m_bulk_data.declare_entity(ent_type, ent_id, partMembership);
84 }
85 
86 //--------------------------------------------------------------------------
87 
88 VariableSelectorFixture::~VariableSelectorFixture() {}
89 
90 VariableSelectorFixture::VariableSelectorFixture(int NumParts)
91  : m_MetaData( std::vector<std::string>(1, std::string("MyEntityRank")) )
92  , m_BulkData( m_MetaData , MPI_COMM_WORLD )
93  , m_declared_part_vector()
94 {
95  // Create Parts and commit:
96  std::string myPartName;
97  stk_classic::mesh::EntityRank myRank = 0;
98 
99  std::string partName = "Part_";
100  for (int part_i=0 ; part_i<NumParts; ++part_i) {
101  std::ostringstream localPartName(partName);
102  localPartName << part_i;
103  stk_classic::mesh::Part * part =
104  & m_MetaData.declare_part(localPartName.str(),myRank);
105  m_declared_part_vector.push_back( part );
106  }
107 
108  m_MetaData.commit();
109 
110  // Create Entities and assign to parts:
111 
112  m_BulkData.modification_begin();
113 
114  stk_classic::mesh::EntityRank ent_type = 0; // rank
115  stk_classic::mesh::EntityId ent_id =
116  1 + NumParts * m_BulkData.parallel_rank(); // Unique ID
117 
118  for (int part_i = 0 ; part_i < NumParts ; ++part_i) {
119  std::vector<stk_classic::mesh::Part*> partMembership;
120  partMembership.push_back(m_declared_part_vector[part_i]);
122  & m_BulkData.declare_entity(ent_type, ent_id, partMembership);
123  m_entities.push_back( e );
124  ++ent_id;
125  }
126 
127  m_BulkData.modification_end();
128 }
129 
130 } // fixtures
131 } // mesh
132 } // stk
field_type & put_field(field_type &field, EntityRank entity_rank, const Part &part, const void *init_value=NULL)
Declare a field to exist for a given entity type and Part.
An application-defined subset of a problem domain.
Definition: Part.hpp:49
basic_string< char > string
string / wstring
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
Definition: Entity.hpp:120
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.