Sierra Toolkit Version of the Day
io_generated.cpp
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 <string>
00010 #include <iostream>
00011 
00012 #include <boost/program_options.hpp>
00013 #include <boost/program_options/cmdline.hpp>
00014 
00015 #include <stk_util/parallel/Parallel.hpp>
00016 #include <stk_util/parallel/BroadcastArg.hpp>
00017 #include <stk_util/environment/ProgramOptions.hpp>
00018 #include <stk_util/use_cases/UseCaseEnvironment.hpp>
00019 
00020 #include <stk_mesh/base/MetaData.hpp>
00021 #include <stk_mesh/base/BulkData.hpp>
00022 #include <stk_mesh/base/Entity.hpp>
00023 #include <stk_mesh/base/Comm.hpp>
00024 #include <stk_mesh/base/GetBuckets.hpp>
00025 #include <stk_mesh/base/FieldData.hpp>
00026 
00027 #include <stk_mesh/fem/FEMMetaData.hpp>
00028 #include <stk_mesh/fem/CoordinateSystems.hpp>
00029 
00030 #include <stk_io/IossBridge.hpp>
00031 #include <stk_io/MeshReadWriteUtils.hpp>
00032 
00033 #include <init/Ionit_Initializer.h>
00034 #include <Ioss_SubSystem.h>
00035 
00036 namespace {
00037   void driver(stk::ParallelMachine  comm,
00038               size_t dimension,
00039         const std::string &working_directory,
00040         const std::string &filename,
00041         const std::string &type,
00042         int  compression_level,
00043         bool compression_shuffle,
00044         int  db_integer_size);
00045 }
00046 
00047 namespace bopt = boost::program_options;
00048 
00049 int main(int argc, char** argv)
00050 {
00051   std::string working_directory = "";
00052   std::string mesh = "";
00053   std::string type = "exodusii";
00054   size_t spatial_dimension = 3;
00055   int compression_level = 0;
00056   bool compression_shuffle = false;
00057   int db_integer_size = 4;
00058 
00059 
00060   //----------------------------------
00061   // Process the broadcast command line arguments
00062   bopt::options_description desc("options");
00063 
00064   // NOTE: Options --directory --output-log --runtest are handled/defined in UseCaseEnvironment
00065   desc.add_options()
00066     ("directory,d",   bopt::value<std::string>(&working_directory),
00067      "working directory with trailing '/'" )
00068     ("mesh",          bopt::value<std::string>(&mesh),
00069      "mesh file. Use name of form 'gen:NxMxL' to internally generate a hex mesh of size N by M by L intervals. See GeneratedMesh documentation for more options. Can also specify a filename. The generated mesh will be output to the file 'generated_mesh.out'" )
00070     ("dimension", bopt::value<size_t>(&spatial_dimension), "problem spatial dimension" )
00071     ("compression_level", bopt::value<int>(&compression_level), "compression level [1..9] to use" )
00072     ("shuffle", bopt::value<bool>(&compression_shuffle), "use shuffle filter prior to compressing data" )
00073     ("db_integer_size", bopt::value<int>(&db_integer_size), "use 4 or 8-byte integers on output database" );
00074     
00075 
00076   stk::get_options_description().add(desc);
00077 
00078   use_case::UseCaseEnvironment use_case_environment(&argc, &argv);
00079 
00080   if (mesh.empty()) {
00081     std::cerr << "\nERROR: The --mesh option is required\n";
00082     std::cerr << "\nApplication " << desc << "\n";
00083     std::exit(EXIT_FAILURE);
00084   }
00085 
00086   type = "exodusii";
00087   if (strncasecmp("gen:", mesh.c_str(), 4) == 0) {
00088     mesh = mesh.substr(4, mesh.size());
00089     type = "generated";
00090   }
00091   driver(use_case_environment.m_comm, spatial_dimension,
00092    working_directory, mesh, type,
00093    compression_level, compression_shuffle, db_integer_size);
00094 
00095   return 0;
00096 }
00097 
00098 namespace {
00099   void driver(stk::ParallelMachine  comm,
00100               size_t spatial_dimension,
00101         const std::string &working_directory,
00102         const std::string &filename,
00103         const std::string &type,
00104         int  compression_level,
00105         bool compression_shuffle,
00106         int  db_integer_size)
00107   {
00108 
00109     // Initialize IO system.  Registers all element types and storage
00110     // types and the exodusII default database type.
00111     Ioss::Init::Initializer init_db;
00112 
00113     stk::mesh::fem::FEMMetaData fem_meta_data( spatial_dimension );
00114     stk::mesh::MetaData &meta_data = fem_meta_data.get_meta_data( fem_meta_data );
00115     stk::io::MeshData mesh_data;
00116 
00117     bool use_netcdf4 = false;
00118     if (compression_level > 0) {
00119       mesh_data.m_property_manager.add(Ioss::Property("COMPRESSION_LEVEL", compression_level));
00120       use_netcdf4 = true;
00121     }
00122     if (compression_shuffle) {
00123       mesh_data.m_property_manager.add(Ioss::Property("COMPRESSION_SHUFFLE", 1));
00124       use_netcdf4 = true;
00125     }
00126     if (use_netcdf4) {
00127       mesh_data.m_property_manager.add(Ioss::Property("FILE_TYPE", "netcdf4"));
00128     }
00129     if (db_integer_size == 8) {
00130       mesh_data.m_property_manager.add(Ioss::Property("INTEGER_SIZE_DB", db_integer_size));
00131     }
00132       
00133     std::string file = working_directory;
00134     file += filename;
00135     stk::io::create_input_mesh(type, file, comm, fem_meta_data, mesh_data);
00136     stk::io::define_input_fields(mesh_data, fem_meta_data);
00137 
00138     fem_meta_data.commit();
00139     stk::mesh::BulkData bulk_data(meta_data , comm);
00140     stk::io::populate_bulk_data(bulk_data, mesh_data);
00141 
00142     //------------------------------------------------------------------
00143     // Create output mesh...  ("generated_mesh.out") ("exodus_mesh.out")
00144     std::string output_filename = working_directory + type + "_mesh.out";
00145     stk::io::create_output_mesh(output_filename, comm, bulk_data, mesh_data);
00146     stk::io::define_output_fields(mesh_data, fem_meta_data);
00147 
00148     // Determine number of timesteps on input database...
00149     int timestep_count = mesh_data.m_input_region->get_property("state_count").get_int();
00150     for (int step=1; step <= timestep_count; step++) {
00151       double time = mesh_data.m_input_region->get_state_time(step);
00152       stk::io::process_input_request(mesh_data, bulk_data, step);
00153       stk::io::process_output_request(mesh_data, bulk_data, time);
00154     }
00155   }
00156 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends