|
Sierra Toolkit
Version of the Day
|
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 #include <stdexcept> 00009 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 00010 #include <stk_mesh/fixtures/HexFixture.hpp> 00011 #include <stk_mesh/base/FieldData.hpp> 00012 00013 #include <boost/foreach.hpp> 00014 00015 00016 STKUNIT_UNIT_TEST( UnitTestChangeEntityId, change_id ) 00017 { 00018 using namespace stk_classic::mesh; 00019 00020 const unsigned NX = 50; 00021 const unsigned NY = 50; 00022 const unsigned NZ = 50; 00023 const unsigned num_elems = NX * NY * NZ; 00024 00025 fixtures::HexFixture hf(MPI_COMM_WORLD,NX,NY,NZ); 00026 00027 Field<int> & simple_nodal_field = hf.m_fem_meta.declare_field<Field<int> >("simple_nodal_field"); 00028 00029 put_field( simple_nodal_field, 00030 fem::FEMMetaData::NODE_RANK, 00031 hf.m_hex_part); 00032 00033 00034 //create nodal field on hex topo 00035 00036 hf.m_fem_meta.commit(); 00037 00038 hf.generate_mesh(); 00039 00040 stk_classic::mesh::BulkData & mesh = hf.m_bulk_data; 00041 00042 mesh.modification_begin(); 00043 00044 const BucketVector & nodes = mesh.buckets(fem::FEMMetaData::NODE_RANK); 00045 00046 BOOST_FOREACH(Bucket * b, nodes) { 00047 BucketArray< Field<int> > nodal_field(simple_nodal_field,*b); 00048 for (int i =0; i<nodal_field.size(); ++i) { 00049 nodal_field[i] = 1; 00050 } 00051 } 00052 00053 00054 const BucketVector & elems = mesh.buckets(hf.m_fem_meta.element_rank()); 00055 00056 std::vector<EntityId> old_ids; 00057 old_ids.reserve(num_elems); 00058 BOOST_FOREACH(Bucket * b, elems) { 00059 for (size_t i =0; i<b->size(); ++i) { 00060 Entity & e = (*b)[i]; 00061 old_ids.push_back(e.identifier()); 00062 mesh.change_entity_id( e.identifier()+num_elems, e); 00063 } 00064 } 00065 00066 mesh.modification_end(); 00067 00068 mesh.modification_begin(); 00069 mesh.modification_end(); 00070 00071 std::vector<EntityId> new_ids_minus_num_elems; 00072 new_ids_minus_num_elems.reserve(num_elems); 00073 BOOST_FOREACH(Bucket * b, elems) { 00074 for (size_t i =0; i<b->size(); ++i) { 00075 Entity & e = (*b)[i]; 00076 new_ids_minus_num_elems.push_back(e.identifier()-num_elems); 00077 } 00078 } 00079 00080 STKUNIT_EXPECT_TRUE(old_ids == new_ids_minus_num_elems); 00081 00082 BOOST_FOREACH(Bucket * b, nodes) { 00083 BucketArray< Field<int> > nodal_field(simple_nodal_field,*b); 00084 for (int i =0; i<nodal_field.size(); ++i) { 00085 STKUNIT_EXPECT_TRUE( nodal_field[i] == 1); 00086 } 00087 } 00088 00089 } 00090