Sierra Toolkit Version of the Day
UnitTestIOFixture.cpp
00001 #include <stk_io/util/IO_Fixture.hpp>
00002 
00003 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00004 #include <stk_mesh/base/GetEntities.hpp>
00005 #include <stk_mesh/base/BulkData.hpp>
00006 
00007 #include <string>
00008 #include <stdlib.h>
00009 
00010 namespace {
00011 
00012 void activate_entities(stk::io::util::IO_Fixture &fixture,
00013                        stk::mesh::Part &active_part)
00014 {
00015   // Seed generator so multiple calls produce same result
00016   srand(999999u);
00017   stk::mesh::fem::FEMMetaData & meta = fixture.meta_data();
00018   stk::mesh::BulkData &bulk = fixture.bulk_data();
00019 
00020   stk::mesh::EntityRank elem_rank = meta.element_rank();
00021 
00022   stk::mesh::PartVector add_parts(1, &active_part);
00023 
00024   bulk.modification_begin();
00025   const stk::mesh::PartVector & all_parts = meta.get_parts();
00026   for ( stk::mesh::PartVector::const_iterator
00027           ip = all_parts.begin(); ip != all_parts.end(); ++ip ) {
00028 
00029     stk::mesh::Part * const part = *ip;
00030     if (stk::io::is_part_io_part(*part) && part->primary_entity_rank() == elem_rank) {
00031       // Get all entities (elements) on this part...
00032       std::vector<stk::mesh::Entity*> entities;
00033       stk::mesh::Selector select = meta.locally_owned_part() & *part;
00034       stk::mesh::get_selected_entities(select, bulk.buckets(elem_rank), entities);
00035       for (size_t i=0; i < entities.size(); i++) {
00036         if (rand() > (RAND_MAX/4)*3)
00037           bulk.change_entity_parts(*entities[i], add_parts);
00038       }
00039     }
00040   }
00041   bulk.modification_end();
00042 }
00043 
00044 }
00045 
00046 STKUNIT_UNIT_TEST( IOFixture, iofixture )
00047 {
00048   // A simple test for reading and writing an exodus file using the IOFixture.
00049 
00050   stk::ParallelMachine pm = MPI_COMM_WORLD;
00051 
00052   stk::io::util::IO_Fixture fixture(pm);
00053 
00054   std::string input_base_filename = "unit_test.g";
00055 
00056   // Initialize meta data from exodus file
00057   fixture.initialize_meta_data( input_base_filename, "exodusii" );
00058 
00059   stk::mesh::fem::FEMMetaData & meta_data = fixture.meta_data();
00060 
00061   // Commit meta_data
00062   meta_data.commit();
00063 
00064   // bulk_data initialize (from exodus file)
00065   fixture.initialize_bulk_data();
00066 
00067   // exodus file creation
00068   std::string output_base_filename = "unit_test_output.e";
00069   fixture.create_output_mesh( output_base_filename, "exodusii" );
00070 
00071   // process output
00072   const double time_step = 0;
00073   fixture.add_timestep_to_output_mesh( time_step );
00074 
00075   // Since correctness can only be established by running SEACAS tools, correctness
00076   // checking is left to the test XML.
00077 }
00078 
00079 STKUNIT_UNIT_TEST( IOFixture, active_only )
00080 {
00081   // A simple test for reading and writing an exodus file using the IOFixture.
00082 
00083   stk::ParallelMachine pm = MPI_COMM_WORLD;
00084   stk::io::util::IO_Fixture fixture(pm);
00085 
00086   std::string input_base_filename = "unit_test.g";
00087 
00088   // Initialize meta data from exodus file
00089   fixture.initialize_meta_data( input_base_filename, "exodusii" );
00090   stk::mesh::fem::FEMMetaData & meta_data = fixture.meta_data();
00091 
00092   // Add an "active" part...
00093   stk::mesh::Part &active = meta_data.declare_part("active", meta_data.element_rank());
00094   meta_data.commit();
00095 
00096   // bulk_data initialize (from exodus file)
00097   fixture.initialize_bulk_data();
00098 
00099   // Put some entities into the "active" part...
00100   // This will be used to test the I/O filtering via a selector...
00101   activate_entities(fixture, active);
00102 
00103   // Set the output filter on the mesh_data...
00104   stk::mesh::Selector active_selector(active);
00105   fixture.mesh_data().m_anded_selector = &active_selector;
00106 
00107   // exodus file creation
00108   std::string output_base_filename = "unit_test_output_filtered.e";
00109   fixture.create_output_mesh( output_base_filename, "exodusii" );
00110 
00111   // process output
00112   const double time_step = 0;
00113   fixture.add_timestep_to_output_mesh( time_step );
00114 
00115 
00116   // Since correctness can only be established by running SEACAS tools, correctness
00117   // checking is left to the test XML.
00118 }
00119 
00120 STKUNIT_UNIT_TEST( IOFixture, active_and_all )
00121 {
00122   // A simple test for reading and writing two exodus files using the IOFixture.
00123   stk::ParallelMachine pm = MPI_COMM_WORLD;
00124   stk::io::util::IO_Fixture fixture(pm);
00125 
00126   std::string input_base_filename = "unit_test.g";
00127 
00128   // Initialize meta data from exodus file
00129   fixture.initialize_meta_data( input_base_filename, "exodusii" );
00130   stk::mesh::fem::FEMMetaData & meta_data = fixture.meta_data();
00131 
00132   // Add an "active" part...
00133   stk::mesh::Part &active = meta_data.declare_part("active", meta_data.element_rank());
00134   meta_data.commit();
00135 
00136   // bulk_data initialize (from exodus file)
00137   fixture.initialize_bulk_data();
00138 
00139   // Put some entities into the "active" part...
00140   // This will be used to test the I/O filtering via a selector...
00141   activate_entities(fixture, active);
00142 
00143   // Set the output filter on the mesh_data...
00144   stk::mesh::Selector active_selector(active);
00145   fixture.mesh_data().m_anded_selector = &active_selector;
00146 
00147   // exodus file creation
00148   std::string filtered_output_base_filename = "unit_test_output_first_of_two.e";
00149   fixture.create_output_mesh( filtered_output_base_filename, "exodusii" );
00150 
00151   // process output
00152   double time_step = 0;
00153   fixture.add_timestep_to_output_mesh( time_step );
00154 
00155 
00156   Teuchos::RCP<Ioss::Region> active_output_ioss_region = fixture.output_ioss_region();
00157 
00158   // Set the output filter on the mesh_data...
00159   stk::mesh::Selector universal_selector(meta_data.universal_part());
00160   fixture.mesh_data().m_anded_selector = &universal_selector;
00161 
00162   // exodus file creation
00163   std::string unfiltered_output_base_filename = "unit_test_output_second_of_two.e";
00164   fixture.create_output_mesh( unfiltered_output_base_filename, "exodusii" );
00165   fixture.add_timestep_to_output_mesh( time_step );
00166 
00167   Teuchos::RCP<Ioss::Region> universal_output_ioss_region = fixture.output_ioss_region();
00168 
00169   ++time_step;
00170 
00171   fixture.output_ioss_region(active_output_ioss_region);
00172   fixture.mesh_data().m_anded_selector = &active_selector;
00173   fixture.add_timestep_to_output_mesh( time_step );
00174 
00175   fixture.output_ioss_region(universal_output_ioss_region);
00176   fixture.mesh_data().m_anded_selector = &universal_selector;
00177   fixture.add_timestep_to_output_mesh( time_step );
00178 
00179   ++time_step;
00180 
00181   fixture.output_ioss_region(active_output_ioss_region);
00182   fixture.mesh_data().m_anded_selector = &active_selector;
00183   fixture.add_timestep_to_output_mesh( time_step );
00184 
00185   fixture.output_ioss_region(universal_output_ioss_region);
00186   fixture.mesh_data().m_anded_selector = &universal_selector;
00187   fixture.add_timestep_to_output_mesh( time_step );
00188   // Since correctness can only be established by running SEACAS tools, correctness
00189   // checking is left to the test XML.
00190 }
00191 
00192 STKUNIT_UNIT_TEST( IOFixture, large_mesh_test )
00193 {
00194   // A simple test for reading and writing two exodus files using the IOFixture.
00195   stk::ParallelMachine pm = MPI_COMM_WORLD;
00196   stk::io::util::IO_Fixture fixture(pm);
00197 
00198   std::string input_base_filename = "1mCube_20x20x20.g";
00199 
00200   // Initialize meta data from exodus file
00201   fixture.initialize_meta_data( input_base_filename, "exodusii" );
00202   stk::mesh::fem::FEMMetaData & meta_data = fixture.meta_data();
00203 
00204   // Commit
00205   meta_data.commit();
00206 
00207   // bulk_data initialize (from exodus file)
00208   fixture.initialize_bulk_data();
00209   stk::mesh::BulkData &bulk_data = fixture.bulk_data();
00210 
00211   const std::vector< stk::mesh::Bucket * > & element_buckets
00212     = bulk_data.buckets( meta_data.element_rank());
00213 
00214   // iterate elements and check num nodal relations
00215   for ( std::vector<stk::mesh::Bucket*>::const_iterator ib = element_buckets.begin() ;
00216         ib != element_buckets.end() ; ++ib ) {
00217     stk::mesh::Bucket & b = **ib ;
00218     const int length   = b.size();
00219     for ( int k = 0 ; k < length ; ++k ) {
00220       // get element
00221       stk::mesh::Entity &elem = b[k];
00222       stk::mesh::PairIterRelation elem_node_rels = elem.relations(stk::mesh::fem::FEMMetaData::NODE_RANK);
00223       STKUNIT_EXPECT_EQ( 8u, elem_node_rels.size());
00224     }
00225   }
00226 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends