Sierra Toolkit  Version of the Day
io_generated.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <string>
10 #include <iostream>
11 
12 #include <boost/program_options.hpp>
13 #include <boost/program_options/cmdline.hpp>
14 
15 #include <stk_util/parallel/Parallel.hpp>
16 #include <stk_util/parallel/BroadcastArg.hpp>
17 #include <stk_util/environment/ProgramOptions.hpp>
18 #include <stk_util/use_cases/UseCaseEnvironment.hpp>
19 
20 #include <stk_mesh/base/MetaData.hpp>
21 #include <stk_mesh/base/BulkData.hpp>
22 #include <stk_mesh/base/Entity.hpp>
23 #include <stk_mesh/base/Comm.hpp>
24 #include <stk_mesh/base/GetBuckets.hpp>
25 #include <stk_mesh/base/FieldData.hpp>
26 
27 #include <stk_mesh/fem/FEMMetaData.hpp>
28 #include <stk_mesh/fem/CoordinateSystems.hpp>
29 
30 #include <stk_io/IossBridge.hpp>
31 #include <stk_io/MeshReadWriteUtils.hpp>
32 
33 #include <init/Ionit_Initializer.h>
34 #include <Ioss_SubSystem.h>
35 
36 namespace {
37  void driver(stk_classic::ParallelMachine comm,
38  size_t dimension,
39  const std::string &working_directory,
40  const std::string &filename,
41  const std::string &type,
42  const std::string &decomp_method,
43  int compression_level,
44  bool compression_shuffle,
45  int db_integer_size);
46 }
47 
48 namespace bopt = boost::program_options;
49 
50 int main(int argc, char** argv)
51 {
52  std::string working_directory = "";
53  std::string decomp_method = "";
54  std::string mesh = "";
55  std::string type = "exodusii";
56  size_t spatial_dimension = 3;
57  int compression_level = 0;
58  bool compression_shuffle = false;
59  int db_integer_size = 4;
60 
61 
62  //----------------------------------
63  // Process the broadcast command line arguments
64  bopt::options_description desc("options");
65 
66  // NOTE: Options --directory --output-log --runtest are handled/defined in UseCaseEnvironment
67  desc.add_options()
68  ("directory,d", bopt::value<std::string>(&working_directory),
69  "working directory with trailing '/'" )
70  ("decomposition,D", bopt::value<std::string>(&decomp_method),
71  "decomposition method" )
72  ("mesh", bopt::value<std::string>(&mesh),
73  "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'" )
74  ("dimension", bopt::value<size_t>(&spatial_dimension), "problem spatial dimension" )
75  ("compression_level", bopt::value<int>(&compression_level), "compression level [1..9] to use" )
76  ("shuffle", bopt::value<bool>(&compression_shuffle), "use shuffle filter prior to compressing data" )
77  ("db_integer_size", bopt::value<int>(&db_integer_size), "use 4 or 8-byte integers on output database" );
78 
79 
81 
82  use_case::UseCaseEnvironment use_case_environment(&argc, &argv);
83 
84  if (mesh.empty()) {
85  std::cerr << "\nERROR: The --mesh option is required\n";
86  std::cerr << "\nApplication " << desc << "\n";
87  std::exit(EXIT_FAILURE);
88  }
89 
90  type = "exodusii";
91  if (strncasecmp("gen:", mesh.c_str(), 4) == 0) {
92  mesh = mesh.substr(4, mesh.size());
93  type = "generated";
94  }
95  if (strncasecmp("dof:", mesh.c_str(), 4) == 0) {
96  mesh = mesh.substr(4, mesh.size());
97  type = "dof";
98  }
99  driver(use_case_environment.m_comm, spatial_dimension,
100  working_directory, mesh, type, decomp_method,
101  compression_level, compression_shuffle, db_integer_size);
102 
103  return 0;
104 }
105 
106 namespace {
107  void driver(stk_classic::ParallelMachine comm,
108  size_t spatial_dimension,
109  const std::string &working_directory,
110  const std::string &filename,
111  const std::string &type,
112  const std::string &decomp_method,
113  int compression_level,
114  bool compression_shuffle,
115  int db_integer_size)
116  {
117 
118  // Initialize IO system. Registers all element types and storage
119  // types and the exodusII default database type.
120  Ioss::Init::Initializer init_db;
121 
122  stk_classic::mesh::fem::FEMMetaData fem_meta_data( spatial_dimension );
123  stk_classic::mesh::MetaData &meta_data = fem_meta_data.get_meta_data( fem_meta_data );
124  stk_classic::io::MeshData mesh_data;
125 
126  bool use_netcdf4 = false;
127  if (!decomp_method.empty()) {
128  mesh_data.m_property_manager.add(Ioss::Property("DECOMPOSITION_METHOD", decomp_method));
129  }
130 
131  if (compression_level > 0) {
132  mesh_data.m_property_manager.add(Ioss::Property("COMPRESSION_LEVEL", compression_level));
133  use_netcdf4 = true;
134  }
135  if (compression_shuffle) {
136  mesh_data.m_property_manager.add(Ioss::Property("COMPRESSION_SHUFFLE", 1));
137  use_netcdf4 = true;
138  }
139  if (use_netcdf4) {
140  mesh_data.m_property_manager.add(Ioss::Property("FILE_TYPE", "netcdf4"));
141  }
142  if (db_integer_size == 8) {
143  mesh_data.m_property_manager.add(Ioss::Property("INTEGER_SIZE_DB", db_integer_size));
144  }
145 
146  std::string file = working_directory;
147  file += filename;
148  stk_classic::io::create_input_mesh(type, file, comm, fem_meta_data, mesh_data);
149  stk_classic::io::define_input_fields(mesh_data, fem_meta_data);
150 
151  fem_meta_data.commit();
152  stk_classic::mesh::BulkData bulk_data(meta_data , comm);
153  stk_classic::io::populate_bulk_data(bulk_data, mesh_data);
154 
155  //------------------------------------------------------------------
156  // Create output mesh... ("generated_mesh.out") ("exodus_mesh.out")
157  std::string output_filename = working_directory + type + "_mesh.out";
158  stk_classic::io::create_output_mesh(output_filename, comm, bulk_data, mesh_data);
159  stk_classic::io::define_output_fields(mesh_data, fem_meta_data);
160 
161  // Determine number of timesteps on input database...
162  int timestep_count = mesh_data.m_input_region->get_property("state_count").get_int();
163  for (int step=1; step <= timestep_count; step++) {
164  double time = mesh_data.m_input_region->get_state_time(step);
165  stk_classic::io::process_input_request(mesh_data, bulk_data, step);
166  stk_classic::io::process_output_request(mesh_data, bulk_data, time);
167  }
168  }
169 }
void process_input_request(MeshData &mesh_data, stk_classic::mesh::BulkData &bulk, double time)
FEMMetaData is a class that implements a Finite Element Method skin on top of the Sierra Tool Kit Met...
Definition: FEMMetaData.hpp:54
The manager of an integrated collection of parts and fields.
Definition: MetaData.hpp:56
void create_output_mesh(const std::string &filename, stk_classic::ParallelMachine comm, stk_classic::mesh::BulkData &bulk_data, MeshData &mesh_data, bool lower_case_variable_names)
const std::string working_directory()
Function working_directory returns the current working directory of this application execution...
Definition: Env.cpp:252
void populate_bulk_data(stk_classic::mesh::BulkData &bulk_data, MeshData &mesh_data)
void define_input_fields(MeshData &mesh_data, stk_classic::mesh::fem::FEMMetaData &fem_meta)
boost::program_options::options_description & get_options_description()
Function get_options_description is a singleton used to store the command line option descriptions fo...
void define_output_fields(const MeshData &mesh_data, const stk_classic::mesh::fem::FEMMetaData &fem_meta, bool add_all_fields)
Manager for an integrated collection of entities, entity relations, and buckets of field data...
Definition: BulkData.hpp:49
void create_input_mesh(const std::string &mesh_type, const std::string &mesh_filename, stk_classic::ParallelMachine comm, stk_classic::mesh::fem::FEMMetaData &fem_meta, stk_classic::io::MeshData &mesh_data, bool lower_case_variable_names)
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32
int process_output_request(MeshData &mesh_data, stk_classic::mesh::BulkData &bulk, double time, const std::set< const stk_classic::mesh::Part *> &exclude)