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