|
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 <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_classic::ParallelMachine comm, 00038 size_t dimension, 00039 const std::string &working_directory, 00040 const std::string &filename, 00041 const std::string &type, 00042 const std::string &decomp_method, 00043 int compression_level, 00044 bool compression_shuffle, 00045 int db_integer_size); 00046 } 00047 00048 namespace bopt = boost::program_options; 00049 00050 int main(int argc, char** argv) 00051 { 00052 std::string working_directory = ""; 00053 std::string decomp_method = ""; 00054 std::string mesh = ""; 00055 std::string type = "exodusii"; 00056 size_t spatial_dimension = 3; 00057 int compression_level = 0; 00058 bool compression_shuffle = false; 00059 int db_integer_size = 4; 00060 00061 00062 //---------------------------------- 00063 // Process the broadcast command line arguments 00064 bopt::options_description desc("options"); 00065 00066 // NOTE: Options --directory --output-log --runtest are handled/defined in UseCaseEnvironment 00067 desc.add_options() 00068 ("directory,d", bopt::value<std::string>(&working_directory), 00069 "working directory with trailing '/'" ) 00070 ("decomposition,D", bopt::value<std::string>(&decomp_method), 00071 "decomposition method" ) 00072 ("mesh", bopt::value<std::string>(&mesh), 00073 "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'" ) 00074 ("dimension", bopt::value<size_t>(&spatial_dimension), "problem spatial dimension" ) 00075 ("compression_level", bopt::value<int>(&compression_level), "compression level [1..9] to use" ) 00076 ("shuffle", bopt::value<bool>(&compression_shuffle), "use shuffle filter prior to compressing data" ) 00077 ("db_integer_size", bopt::value<int>(&db_integer_size), "use 4 or 8-byte integers on output database" ); 00078 00079 00080 stk_classic::get_options_description().add(desc); 00081 00082 use_case::UseCaseEnvironment use_case_environment(&argc, &argv); 00083 00084 if (mesh.empty()) { 00085 std::cerr << "\nERROR: The --mesh option is required\n"; 00086 std::cerr << "\nApplication " << desc << "\n"; 00087 std::exit(EXIT_FAILURE); 00088 } 00089 00090 type = "exodusii"; 00091 if (strncasecmp("gen:", mesh.c_str(), 4) == 0) { 00092 mesh = mesh.substr(4, mesh.size()); 00093 type = "generated"; 00094 } 00095 if (strncasecmp("dof:", mesh.c_str(), 4) == 0) { 00096 mesh = mesh.substr(4, mesh.size()); 00097 type = "dof"; 00098 } 00099 driver(use_case_environment.m_comm, spatial_dimension, 00100 working_directory, mesh, type, decomp_method, 00101 compression_level, compression_shuffle, db_integer_size); 00102 00103 return 0; 00104 } 00105 00106 namespace { 00107 void driver(stk_classic::ParallelMachine comm, 00108 size_t spatial_dimension, 00109 const std::string &working_directory, 00110 const std::string &filename, 00111 const std::string &type, 00112 const std::string &decomp_method, 00113 int compression_level, 00114 bool compression_shuffle, 00115 int db_integer_size) 00116 { 00117 00118 // Initialize IO system. Registers all element types and storage 00119 // types and the exodusII default database type. 00120 Ioss::Init::Initializer init_db; 00121 00122 stk_classic::mesh::fem::FEMMetaData fem_meta_data( spatial_dimension ); 00123 stk_classic::mesh::MetaData &meta_data = fem_meta_data.get_meta_data( fem_meta_data ); 00124 stk_classic::io::MeshData mesh_data; 00125 00126 bool use_netcdf4 = false; 00127 if (!decomp_method.empty()) { 00128 mesh_data.m_property_manager.add(Ioss::Property("DECOMPOSITION_METHOD", decomp_method)); 00129 } 00130 00131 if (compression_level > 0) { 00132 mesh_data.m_property_manager.add(Ioss::Property("COMPRESSION_LEVEL", compression_level)); 00133 use_netcdf4 = true; 00134 } 00135 if (compression_shuffle) { 00136 mesh_data.m_property_manager.add(Ioss::Property("COMPRESSION_SHUFFLE", 1)); 00137 use_netcdf4 = true; 00138 } 00139 if (use_netcdf4) { 00140 mesh_data.m_property_manager.add(Ioss::Property("FILE_TYPE", "netcdf4")); 00141 } 00142 if (db_integer_size == 8) { 00143 mesh_data.m_property_manager.add(Ioss::Property("INTEGER_SIZE_DB", db_integer_size)); 00144 } 00145 00146 std::string file = working_directory; 00147 file += filename; 00148 stk_classic::io::create_input_mesh(type, file, comm, fem_meta_data, mesh_data); 00149 stk_classic::io::define_input_fields(mesh_data, fem_meta_data); 00150 00151 fem_meta_data.commit(); 00152 stk_classic::mesh::BulkData bulk_data(meta_data , comm); 00153 stk_classic::io::populate_bulk_data(bulk_data, mesh_data); 00154 00155 //------------------------------------------------------------------ 00156 // Create output mesh... ("generated_mesh.out") ("exodus_mesh.out") 00157 std::string output_filename = working_directory + type + "_mesh.out"; 00158 stk_classic::io::create_output_mesh(output_filename, comm, bulk_data, mesh_data); 00159 stk_classic::io::define_output_fields(mesh_data, fem_meta_data); 00160 00161 // Determine number of timesteps on input database... 00162 int timestep_count = mesh_data.m_input_region->get_property("state_count").get_int(); 00163 for (int step=1; step <= timestep_count; step++) { 00164 double time = mesh_data.m_input_region->get_state_time(step); 00165 stk_classic::io::process_input_request(mesh_data, bulk_data, step); 00166 stk_classic::io::process_output_request(mesh_data, bulk_data, time); 00167 } 00168 } 00169 }