|
Sierra Toolkit
Version of the Day
|
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 #include <sstream> 00010 #include <stdexcept> 00011 #include <iostream> 00012 00013 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 00014 00015 #include <stk_util/parallel/Parallel.hpp> 00016 00017 #include <stk_mesh/base/BulkData.hpp> 00018 #include <stk_mesh/base/Field.hpp> 00019 #include <stk_mesh/base/FieldData.hpp> 00020 #include <stk_mesh/base/Comm.hpp> 00021 #include <stk_mesh/base/EntityComm.hpp> 00022 00023 #include <stk_mesh/fem/FEMMetaData.hpp> 00024 #include <stk_mesh/fem/CoordinateSystems.hpp> 00025 00026 using stk_classic::mesh::Entity; 00027 using stk_classic::mesh::EntityRank; 00028 using stk_classic::mesh::Part; 00029 using stk_classic::mesh::Field; 00030 using stk_classic::mesh::BulkData; 00031 using stk_classic::mesh::EntityId; 00032 using stk_classic::mesh::fem::FEMMetaData; 00033 00034 namespace { 00035 00036 const EntityRank NODE_RANK = FEMMetaData::NODE_RANK; 00037 00038 STKUNIT_UNIT_TEST(UnitTestFieldDataInitVal, test_scalar_field) 00039 { 00040 // Test that if an initial-value is set on a scalar field, that value is 00041 // present the first time field-data is referenced for that field. 00042 // 00043 00044 stk_classic::ParallelMachine pm = MPI_COMM_WORLD; 00045 MPI_Barrier( MPI_COMM_WORLD ); 00046 00047 // Set up meta and bulk data 00048 const unsigned spatial_dim = 2; 00049 FEMMetaData meta_data(spatial_dim); 00050 00051 const unsigned num_states = 1; 00052 Field<double>& dfield = meta_data.declare_field<Field<double> >("double_scalar", num_states); 00053 00054 const double initial_value = 99.9; 00055 00056 stk_classic::mesh::put_field(dfield, NODE_RANK, meta_data.universal_part(), &initial_value); 00057 00058 meta_data.commit(); 00059 00060 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm); 00061 unsigned p_rank = mesh.parallel_rank(); 00062 00063 // Begin modification cycle so we can create stuff 00064 mesh.modification_begin(); 00065 00066 // Node will be automatically added to the universal part 00067 stk_classic::mesh::PartVector empty_parts; 00068 00069 EntityId node_id = p_rank+1; 00070 // Create node 00071 Entity & node = mesh.declare_entity(NODE_RANK, node_id, empty_parts); 00072 00073 mesh.modification_end(); 00074 00075 //now insist that data for dfield on node is equal to the initial-value specified above: 00076 00077 double* data_ptr = stk_classic::mesh::field_data( dfield, node); 00078 00079 STKUNIT_ASSERT_EQUAL( *data_ptr, initial_value ); 00080 } 00081 00082 STKUNIT_UNIT_TEST(UnitTestFieldDataInitVal, test_vector_field) 00083 { 00084 // Test that if an initial-value is set on a vector field, that value is 00085 // present the first time field-data is referenced for that field. 00086 // 00087 00088 typedef stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian2d> VectorField; 00089 00090 stk_classic::ParallelMachine pm = MPI_COMM_WORLD; 00091 MPI_Barrier( MPI_COMM_WORLD ); 00092 00093 // Set up meta and bulk data 00094 const unsigned spatial_dim = 2; 00095 FEMMetaData meta_data(spatial_dim); 00096 00097 const unsigned num_states = 1; 00098 VectorField& vfield = meta_data.declare_field<VectorField>("double_vector", num_states); 00099 00100 const double initial_value[stk_classic::mesh::Cartesian2d::Size] = { 50.0, 99.0 }; 00101 00102 stk_classic::mesh::put_field(vfield, NODE_RANK, meta_data.universal_part(), stk_classic::mesh::Cartesian2d::Size, initial_value); 00103 00104 meta_data.commit(); 00105 00106 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm); 00107 unsigned p_rank = mesh.parallel_rank(); 00108 00109 // Begin modification cycle so we can create stuff 00110 mesh.modification_begin(); 00111 00112 // Node will be automatically added to the universal part 00113 stk_classic::mesh::PartVector empty_parts; 00114 00115 EntityId node_id = p_rank+1; 00116 // Create node 00117 Entity & node = mesh.declare_entity(NODE_RANK, node_id, empty_parts); 00118 00119 mesh.modification_end(); 00120 00121 //now insist that data for vfield on node is equal to the initial-value specified above: 00122 00123 double* data_ptr = stk_classic::mesh::field_data( vfield, node); 00124 00125 STKUNIT_ASSERT_EQUAL( data_ptr[0], initial_value[0] ); 00126 STKUNIT_ASSERT_EQUAL( data_ptr[1], initial_value[1] ); 00127 } 00128 00129 STKUNIT_UNIT_TEST(UnitTestFieldDataInitVal, test_vector_field_move_bucket) 00130 { 00131 // Test that if an initial-value is set on a vector field, that value is 00132 // present the first time field-data is referenced for that field, and 00133 // that the value is present for a node that is moved from a bucket without 00134 // the field to a new bucket that does have the field. 00135 // 00136 00137 typedef stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian2d> VectorField; 00138 00139 stk_classic::ParallelMachine pm = MPI_COMM_WORLD; 00140 MPI_Barrier( MPI_COMM_WORLD ); 00141 00142 // Set up meta and bulk data 00143 const unsigned spatial_dim = 2; 00144 FEMMetaData meta_data(spatial_dim); 00145 00146 const unsigned num_states = 1; 00147 VectorField& vfield = meta_data.declare_field<VectorField>("double_vector", num_states); 00148 00149 const double initial_value[stk_classic::mesh::Cartesian2d::Size] = { 50.0, 99.0 }; 00150 00151 Part& node_part = meta_data.declare_part<shards::Node>("node_part"); 00152 00153 stk_classic::mesh::put_field(vfield, NODE_RANK, node_part, stk_classic::mesh::Cartesian2d::Size, initial_value); 00154 00155 meta_data.commit(); 00156 00157 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm); 00158 unsigned p_rank = mesh.parallel_rank(); 00159 00160 // Begin modification cycle so we can create stuff 00161 mesh.modification_begin(); 00162 00163 // Node will be automatically added to the universal part 00164 stk_classic::mesh::PartVector empty_parts; 00165 00166 EntityId node_id = p_rank+1; 00167 // Create node 00168 Entity & node = mesh.declare_entity(NODE_RANK, node_id, empty_parts); 00169 00170 stk_classic::mesh::Bucket& old_bucket = node.bucket(); 00171 00172 //Now move the node to the "node_part": 00173 stk_classic::mesh::PartVector node_part_vec; 00174 node_part_vec.push_back(&node_part); 00175 mesh.change_entity_parts(node, node_part_vec); 00176 00177 mesh.modification_end(); 00178 00179 //Insist that the node is now in a different bucket: 00180 stk_classic::mesh::Bucket& new_bucket = node.bucket(); 00181 STKUNIT_ASSERT_NE(&old_bucket, &new_bucket); 00182 00183 //now insist that data for vfield on node is equal to the initial-value specified above: 00184 00185 double* data_ptr = stk_classic::mesh::field_data( vfield, node); 00186 00187 STKUNIT_ASSERT_EQUAL( data_ptr[0], initial_value[0] ); 00188 STKUNIT_ASSERT_EQUAL( data_ptr[1], initial_value[1] ); 00189 } 00190 00191 STKUNIT_UNIT_TEST(UnitTestFieldDataInitVal, test_multi_state_vector_field) 00192 { 00193 // Test that if an initial-value is set on a multi-state vector field, that value is 00194 // present the first time field-data is referenced for that field. 00195 // 00196 00197 typedef stk_classic::mesh::Field<double,stk_classic::mesh::Cartesian2d> VectorField; 00198 00199 stk_classic::ParallelMachine pm = MPI_COMM_WORLD; 00200 MPI_Barrier( MPI_COMM_WORLD ); 00201 00202 // Set up meta and bulk data 00203 const unsigned spatial_dim = 2; 00204 FEMMetaData meta_data(spatial_dim); 00205 00206 const unsigned num_states = 2; 00207 VectorField& vfield = meta_data.declare_field<VectorField>("double_vector", num_states); 00208 00209 const double initial_value[stk_classic::mesh::Cartesian2d::Size] = { 50.0, 99.0 }; 00210 00211 stk_classic::mesh::put_field(vfield, NODE_RANK, meta_data.universal_part(), stk_classic::mesh::Cartesian2d::Size, initial_value); 00212 00213 meta_data.commit(); 00214 00215 BulkData mesh(FEMMetaData::get_meta_data(meta_data), pm); 00216 unsigned p_rank = mesh.parallel_rank(); 00217 00218 // Begin modification cycle so we can create stuff 00219 mesh.modification_begin(); 00220 00221 // Node will be automatically added to the universal part 00222 stk_classic::mesh::PartVector empty_parts; 00223 00224 EntityId node_id = p_rank+1; 00225 // Create node 00226 Entity & node = mesh.declare_entity(NODE_RANK, node_id, empty_parts); 00227 00228 mesh.modification_end(); 00229 00230 //now insist that data for vfield on node is equal to the initial-value specified above: 00231 00232 STKUNIT_ASSERT_EQUAL( vfield.number_of_states(), num_states); 00233 00234 VectorField& vfield_new = vfield.field_of_state(stk_classic::mesh::StateNew); 00235 VectorField& vfield_old = vfield.field_of_state(stk_classic::mesh::StateOld); 00236 00237 double* data_ptr_new = stk_classic::mesh::field_data( vfield_new, node); 00238 double* data_ptr_old = stk_classic::mesh::field_data( vfield_old, node); 00239 00240 STKUNIT_ASSERT_EQUAL( data_ptr_new[0], initial_value[0] ); 00241 STKUNIT_ASSERT_EQUAL( data_ptr_new[1], initial_value[1] ); 00242 00243 STKUNIT_ASSERT_EQUAL( data_ptr_old[0], initial_value[0] ); 00244 STKUNIT_ASSERT_EQUAL( data_ptr_old[1], initial_value[1] ); 00245 } 00246 00247 }