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 }
00043 
00044 namespace bopt = boost::program_options;
00045 
00046 int main(int argc, char** argv)
00047 {
00048   std::string working_directory = "";
00049   std::string mesh = "";
00050   std::string type = "exodusii";
00051   size_t spatial_dimension = 3;
00052 
00053 
00054   //----------------------------------
00055   // Process the broadcast command line arguments
00056   bopt::options_description desc("options");
00057 
00058   // NOTE: Options --directory --output-log --runtest are handled/defined in UseCaseEnvironment
00059   desc.add_options()
00060     ("directory,d",   bopt::value<std::string>(&working_directory),
00061      "working directory with trailing '/'" )
00062     ("mesh",          bopt::value<std::string>(&mesh),
00063      "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'" )
00064     ("dimension", bopt::value<size_t>(&spatial_dimension), "problem spatial dimension" );
00065 
00066   stk::get_options_description().add(desc);
00067 
00068   use_case::UseCaseEnvironment use_case_environment(&argc, &argv);
00069 
00070   if (mesh.empty()) {
00071     std::cerr << "\nERROR: The --mesh option is required\n";
00072     std::cerr << "\nApplication " << desc << "\n";
00073     std::exit(EXIT_FAILURE);
00074   }
00075 
00076   type = "exodusii";
00077   if (strncasecmp("gen:", mesh.c_str(), 4) == 0) {
00078     mesh = mesh.substr(4, mesh.size());
00079     type = "generated";
00080   }
00081   driver(use_case_environment.m_comm, spatial_dimension,
00082    working_directory, mesh, type);
00083 
00084   return 0;
00085 }
00086 
00087 namespace {
00088   void driver(stk::ParallelMachine  comm,
00089               size_t spatial_dimension,
00090         const std::string &working_directory,
00091         const std::string &filename,
00092         const std::string &type)
00093   {
00094 
00095     // Initialize IO system.  Registers all element types and storage
00096     // types and the exodusII default database type.
00097     Ioss::Init::Initializer init_db;
00098 
00099     stk::mesh::fem::FEMMetaData fem_meta_data( spatial_dimension );
00100     stk::mesh::MetaData &meta_data = fem_meta_data.get_meta_data( fem_meta_data );
00101     stk::io::MeshData mesh_data;
00102 
00103     std::string file = working_directory;
00104     file += filename;
00105     stk::io::create_input_mesh(type, file, comm, fem_meta_data, mesh_data);
00106 
00107     fem_meta_data.commit();
00108     stk::mesh::BulkData bulk_data(meta_data , comm);
00109     stk::io::populate_bulk_data(bulk_data, mesh_data);
00110 
00111     //------------------------------------------------------------------
00112     // Create output mesh...  ("generated_mesh.out") ("exodus_mesh.out")
00113     std::string output_filename = working_directory + type + "_mesh.out";
00114     stk::io::create_output_mesh(output_filename, comm, bulk_data, mesh_data);
00115   }
00116 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends