Sierra Toolkit Version of the Day
Gmesh_STKmesh_Fixture.cpp
00001 #include "Gmesh_STKmesh_Fixture.hpp"
00002 
00003 #include <stk_mesh/base/Part.hpp>
00004 
00005 #include <stk_mesh/base/MetaData.hpp>
00006 
00007 #include <stk_io/IossBridge.hpp>
00008 
00009 #include <generated/Iogn_DatabaseIO.h>
00010 #include <generated/Iogn_GeneratedMesh.h>
00011 
00012 #include <init/Ionit_Initializer.h>
00013 
00014 #include <Shards_BasicTopologies.hpp>
00015 
00016 #include <stdexcept>
00017 #include <sstream>
00018 
00019 using namespace stk::io::util;
00020 
00021 static const size_t spatial_dimension = 3;
00022 
00024 Gmesh_STKmesh_Fixture::Gmesh_STKmesh_Fixture(stk::ParallelMachine comm,
00025                                              const std::string& gmesh_spec)
00027   : 
00028     m_meta_data(spatial_dimension),
00029     m_bulk_data(m_meta_data.get_meta_data(m_meta_data), comm),
00030     m_num_x(0),
00031     m_num_y(0),
00032     m_num_z(0)
00033 {
00034   // Initialize IO system.  Registers all element types and storage
00035   // types and the exodusII default database type.
00036   Ioss::Init::Initializer init_db;
00037 
00038   stk::io::util::MeshData mesh_data;
00039   stk::io::util::create_input_mesh("generated", gmesh_spec,
00040                                    ".", comm,
00041                                    m_meta_data,
00042                                    m_mesh_data,
00043                                    false);
00044 
00045   const Iogn::DatabaseIO* database =
00046     dynamic_cast<const Iogn::DatabaseIO*>(m_mesh_data.m_region->get_database());
00047 
00048   // compute m_num_{x|y|z}
00049   m_num_x = database->get_generated_mesh()->get_num_x();
00050   m_num_y = database->get_generated_mesh()->get_num_y();
00051   m_num_z = database->get_generated_mesh()->get_num_z();
00052 
00053   // get face parts names; need to convert these to strings
00054   const std::vector<std::string> sideset_names = database->get_sideset_names();
00055 
00056   for (std::vector<std::string>::const_iterator itr = sideset_names.begin();
00057        itr != sideset_names.end(); ++itr) {
00058     m_sideset_names.push_back(*itr);
00059     m_sideset_parts.push_back(m_meta_data.get_part(*itr));
00060   }
00061 }
00062 
00064 void Gmesh_STKmesh_Fixture::commit()
00066 {
00067   m_meta_data.commit();
00068 
00069   stk::io::util::populate_bulk_data(m_bulk_data, m_mesh_data, "generated");
00070 }
00071 
00073 size_t Gmesh_STKmesh_Fixture::getSurfElemCount(size_t surf_id) const
00075 {
00076   if (Iogn::GeneratedMesh::PZ < surf_id) {
00077     throw std::runtime_error("Invalid surface id");
00078   }
00079 
00080   switch( surf_id )
00081   {
00082     case Iogn::GeneratedMesh::MX:
00083     case Iogn::GeneratedMesh::PX:
00084       return m_num_y*m_num_z;
00085       break;
00086     case Iogn::GeneratedMesh::MY:
00087     case Iogn::GeneratedMesh::PY:
00088       return m_num_x*m_num_z;
00089       break;
00090     case Iogn::GeneratedMesh::MZ:
00091     case Iogn::GeneratedMesh::PZ:
00092       return m_num_x*m_num_y;
00093       break;
00094   }
00095   return 0;
00096 }
00097 
00099 std::pair<int, double>
00100 Gmesh_STKmesh_Fixture::getSurfCoordInfo(size_t surf_id) const
00102 {
00103   if (Iogn::GeneratedMesh::PZ < surf_id) {
00104     throw std::runtime_error("Invalid surface id");
00105   }
00106 
00107   switch( surf_id )
00108   {
00109     case Iogn::GeneratedMesh::MX:
00110       return std::make_pair<int, double>(0, 0.0);
00111       break;
00112     case Iogn::GeneratedMesh::PX:
00113       return std::make_pair<int, double>(0, (double)m_num_x);
00114       break;
00115     case Iogn::GeneratedMesh::MY:
00116       return std::make_pair<int, double>(1, 0.0);
00117       break;
00118     case Iogn::GeneratedMesh::PY:
00119       return std::make_pair<int, double>(1, (double)m_num_y);
00120       break;
00121     case Iogn::GeneratedMesh::MZ:
00122       return std::make_pair<int, double>(2, 0.0);
00123       break;
00124     case Iogn::GeneratedMesh::PZ:
00125       return std::make_pair<int, double>(2, (double)m_num_z);
00126       break;
00127   }
00128 
00129   return std::make_pair<int, double>(-1, -1.0);
00130 }
00131 
00133 size_t Gmesh_STKmesh_Fixture::getSideCount() const
00135 {
00136   return 2 * (m_num_x*m_num_y + m_num_x*m_num_z + m_num_y*m_num_z);
00137 }
00138 
00140 size_t Gmesh_STKmesh_Fixture::getElemCount() const
00142 {
00143   return m_num_x * m_num_y * m_num_z;
00144 }
00145 
00147 size_t Gmesh_STKmesh_Fixture::getNodeCount() const
00149 {
00150   return (m_num_x+1)*(m_num_y+1)*(m_num_z+1);
00151 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends