Sierra Toolkit  Version of the Day
Gmesh_STKmesh_Fixture.cpp
1 #include "Gmesh_STKmesh_Fixture.hpp"
2 
3 #include <stk_mesh/base/Part.hpp>
4 
5 #include <stk_mesh/base/MetaData.hpp>
6 
7 #include <stk_io/IossBridge.hpp>
8 
9 #include <generated/Iogn_DatabaseIO.h>
10 #include <generated/Iogn_GeneratedMesh.h>
11 
12 #include <init/Ionit_Initializer.h>
13 #include <Ioss_Region.h>
14 
15 #include <Shards_BasicTopologies.hpp>
16 
17 #include <stdexcept>
18 #include <sstream>
19 
20 using namespace stk_classic::io::util;
21 
22 static const size_t spatial_dimension = 3;
23 
26  const std::string& gmesh_spec)
28  :
29  m_meta_data(spatial_dimension),
30  m_bulk_data(m_meta_data.get_meta_data(m_meta_data), comm),
31  m_num_x(0),
32  m_num_y(0),
33  m_num_z(0)
34 {
35  // Initialize IO system. Registers all element types and storage
36  // types and the exodusII default database type.
37  Ioss::Init::Initializer init_db;
38 
39  stk_classic::io::MeshData mesh_data;
40  stk_classic::io::create_input_mesh("generated", gmesh_spec, comm,
41  m_meta_data, m_mesh_data);
42 
43  const Iogn::DatabaseIO* database =
44  dynamic_cast<const Iogn::DatabaseIO*>(m_mesh_data.m_input_region->get_database());
45 
46  // compute m_num_{x|y|z}
47  m_num_x = database->get_generated_mesh()->get_num_x();
48  m_num_y = database->get_generated_mesh()->get_num_y();
49  m_num_z = database->get_generated_mesh()->get_num_z();
50 
51  // get face parts names; need to convert these to strings
52  const std::vector<std::string> sideset_names = database->get_sideset_names();
53 
54  for (std::vector<std::string>::const_iterator itr = sideset_names.begin();
55  itr != sideset_names.end(); ++itr) {
56  m_sideset_names.push_back(*itr);
57  m_sideset_parts.push_back(m_meta_data.get_part(*itr));
58  }
59 }
60 
64 {
65  m_meta_data.commit();
66 
67  stk_classic::io::populate_bulk_data(m_bulk_data, m_mesh_data);
68 }
69 
71 size_t Gmesh_STKmesh_Fixture::getSurfElemCount(size_t surf_id) const
73 {
74  if (Iogn::GeneratedMesh::PZ < surf_id) {
75  throw std::runtime_error("Invalid surface id");
76  }
77 
78  switch( surf_id )
79  {
80  case Iogn::GeneratedMesh::MX:
81  case Iogn::GeneratedMesh::PX:
82  return m_num_y*m_num_z;
83  break;
84  case Iogn::GeneratedMesh::MY:
85  case Iogn::GeneratedMesh::PY:
86  return m_num_x*m_num_z;
87  break;
88  case Iogn::GeneratedMesh::MZ:
89  case Iogn::GeneratedMesh::PZ:
90  return m_num_x*m_num_y;
91  break;
92  }
93  return 0;
94 }
95 
97 std::pair<int, double>
100 {
101  if (Iogn::GeneratedMesh::PZ < surf_id) {
102  throw std::runtime_error("Invalid surface id");
103  }
104 
105  switch( surf_id )
106  {
107  case Iogn::GeneratedMesh::MX:
108  return std::make_pair<int, double>(0, 0.0);
109  break;
110  case Iogn::GeneratedMesh::PX:
111  return std::make_pair<int, double>(0, (double)m_num_x);
112  break;
113  case Iogn::GeneratedMesh::MY:
114  return std::make_pair<int, double>(1, 0.0);
115  break;
116  case Iogn::GeneratedMesh::PY:
117  return std::make_pair<int, double>(1, (double)m_num_y);
118  break;
119  case Iogn::GeneratedMesh::MZ:
120  return std::make_pair<int, double>(2, 0.0);
121  break;
122  case Iogn::GeneratedMesh::PZ:
123  return std::make_pair<int, double>(2, (double)m_num_z);
124  break;
125  }
126 
127  return std::make_pair<int, double>(-1, -1.0);
128 }
129 
133 {
134  return 2 * (m_num_x*m_num_y + m_num_x*m_num_z + m_num_y*m_num_z);
135 }
136 
140 {
141  return m_num_x * m_num_y * m_num_z;
142 }
143 
147 {
148  return (m_num_x+1)*(m_num_y+1)*(m_num_z+1);
149 }
std::pair< int, double > getSurfCoordInfo(size_t surf_id) const
void populate_bulk_data(stk_classic::mesh::BulkData &bulk_data, MeshData &mesh_data)
Gmesh_STKmesh_Fixture(stk_classic::ParallelMachine comm, const std::string &gmesh_spec)
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)
void commit()
Commit the part and field declarations so that the meta data manager can be used to create mesh bulk ...
Part * get_part(const std::string &p_name, const char *required_by=NULL) const
Get an existing part by its application-defined text name.
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32