Sierra Toolkit  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UnitTestChangeEntityId.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 #include <stdexcept>
9 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
10 #include <stk_mesh/fixtures/HexFixture.hpp>
11 #include <stk_mesh/base/FieldData.hpp>
12 
13 #include <boost/foreach.hpp>
14 
15 
16 STKUNIT_UNIT_TEST( UnitTestChangeEntityId, change_id )
17 {
18  using namespace stk_classic::mesh;
19 
20  const unsigned NX = 50;
21  const unsigned NY = 50;
22  const unsigned NZ = 50;
23  const unsigned num_elems = NX * NY * NZ;
24 
25  fixtures::HexFixture hf(MPI_COMM_WORLD,NX,NY,NZ);
26 
27  Field<int> & simple_nodal_field = hf.m_fem_meta.declare_field<Field<int> >("simple_nodal_field");
28 
29  put_field( simple_nodal_field,
30  fem::FEMMetaData::NODE_RANK,
31  hf.m_hex_part);
32 
33 
34  //create nodal field on hex topo
35 
36  hf.m_fem_meta.commit();
37 
38  hf.generate_mesh();
39 
40  stk_classic::mesh::BulkData & mesh = hf.m_bulk_data;
41 
42  mesh.modification_begin();
43 
44  const BucketVector & nodes = mesh.buckets(fem::FEMMetaData::NODE_RANK);
45 
46  BOOST_FOREACH(Bucket * b, nodes) {
47  BucketArray< Field<int> > nodal_field(simple_nodal_field,*b);
48  for (int i =0; i<nodal_field.size(); ++i) {
49  nodal_field[i] = 1;
50  }
51  }
52 
53 
54  const BucketVector & elems = mesh.buckets(hf.m_fem_meta.element_rank());
55 
56  std::vector<EntityId> old_ids;
57  old_ids.reserve(num_elems);
58  BOOST_FOREACH(Bucket * b, elems) {
59  for (size_t i =0; i<b->size(); ++i) {
60  Entity & e = (*b)[i];
61  old_ids.push_back(e.identifier());
62  mesh.change_entity_id( e.identifier()+num_elems, e);
63  }
64  }
65 
66  mesh.modification_end();
67 
68  mesh.modification_begin();
69  mesh.modification_end();
70 
71  std::vector<EntityId> new_ids_minus_num_elems;
72  new_ids_minus_num_elems.reserve(num_elems);
73  BOOST_FOREACH(Bucket * b, elems) {
74  for (size_t i =0; i<b->size(); ++i) {
75  Entity & e = (*b)[i];
76  new_ids_minus_num_elems.push_back(e.identifier()-num_elems);
77  }
78  }
79 
80  STKUNIT_EXPECT_TRUE(old_ids == new_ids_minus_num_elems);
81 
82  BOOST_FOREACH(Bucket * b, nodes) {
83  BucketArray< Field<int> > nodal_field(simple_nodal_field,*b);
84  for (int i =0; i<nodal_field.size(); ++i) {
85  STKUNIT_EXPECT_TRUE( nodal_field[i] == 1);
86  }
87  }
88 
89 }
90 
EntityId identifier() const
Identifier for this entity which is globally unique for a given entity type.
Definition: Entity.hpp:133
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.
Field with defined data type and multi-dimensions (if any)
Definition: Field.hpp:118
bool modification_begin()
Begin a modification phase during which the mesh bulk data could become parallel inconsistent. This is a parallel synchronous call. The first time this method is called the mesh meta data is verified to be committed and parallel consistent. An exception is thrown if this verification fails.
Definition: BulkData.cpp:172
size_t size() const
Number of entities associated with this bucket.
Definition: Bucket.hpp:119
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
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94
Field data Array for a given array field and bucket
Definition: FieldData.hpp:65