示例#1
0
void
NetgenMeshReader::readElements( UnsMesh& mesh )
//******************************************************************************
//  Read element connectivity
//! \param[in] mesh Unstructured mesh object
//! \author J. Bakosi
//******************************************************************************
{
  int nel;

  // Read in number of tetrahedra
  m_inFile >> nel;
  if (!m_inFile.eof()) {
    ErrChk( nel > 0, "Number of tetrahedra (volume elements) must be greater "
                     "than zero in file " + m_filename );
    std::string s;
    getline( m_inFile, s );  // finish reading the last line

    // Read in tetrahedra element tags and connectivity
    for (int i=0; i<nel; ++i) {
      int tag;
      std::array< std::size_t, 4 > n;
      // tag n[1-4]
      m_inFile >> tag >> n[3] >> n[0] >> n[1] >> n[2];
      mesh.tettag().push_back( { tag } );
      mesh.tetinpoel().push_back( n[0] );
      mesh.tetinpoel().push_back( n[1] );
      mesh.tetinpoel().push_back( n[2] );
      mesh.tetinpoel().push_back( n[3] );
    }

    // Shift node IDs to start from zero
    shiftToZero( mesh.tetinpoel() );
  }
示例#2
0
void
NetgenMeshReader::readNodes( UnsMesh& mesh )
//******************************************************************************
//  Read nodes
//! \param[in] mesh Unstructured mesh object
//! \author J. Bakosi
//******************************************************************************
{
  int nnode;
  m_inFile >> nnode;
  ErrChk( nnode > 0,
          "Number of nodes must be greater than zero in file " + m_filename  );

  // Read in node coordinates: x-coord y-coord z-coord
  for (int i=0; i<nnode; ++i) {
    tk::real x, y, z;
    m_inFile >> x >> y >> z;
    mesh.x().push_back( x );
    mesh.y().push_back( y );
    mesh.z().push_back( z );
  }

  std::string s;
  getline( m_inFile, s );  // finish reading the last line
}
示例#3
0
void
GmshMeshWriter::writeElements( const UnsMesh& mesh )
//******************************************************************************
//  Write "$Elements--$EndElements" section
//! \param[in] mesh Unstructured mesh object
//! \author J. Bakosi
//******************************************************************************
{
  m_outFile << "$Elements" << std::endl;

  // Write out number of elements
  m_outFile << mesh.lininpoel().size()/2 +
               mesh.triinpoel().size()/3 +
               mesh.tetinpoel().size()/4
            << std::endl;

  // Write out line element ids, tags, and connectivity (node list)
  writeElemBlock( 2, GmshElemType::LIN, mesh.lintag(), mesh.lininpoel() );

  // Write out triangle element ids, tags, and connectivity (node list)
  writeElemBlock( 3, GmshElemType::TRI, mesh.tritag(), mesh.triinpoel() );

  // Write out terahedron element ids, tags, and connectivity (node list)
  writeElemBlock( 4, GmshElemType::TET, mesh.tettag(), mesh.tetinpoel() );

  if (isBinary()) m_outFile << std::endl;
  m_outFile << "$EndElements" << std::endl;
}
示例#4
0
void
HyperMeshReader::readNodes( const std::string& filename, UnsMesh& mesh ) const
// *****************************************************************************
//  Read nodes
//! \param[in] filename Filename to read nodes from
//! \param[in] mesh Unstructured mesh object to put nodes coordinates
//! \note We throw away the node ID, which means the nodes must be in order.
//! \author J. Bakosi
// *****************************************************************************
{
  // Read in node coordinates: x-coord y-coord z-coord
  for (auto& line : tk::Reader(filename).lines()) {
    std::stringstream ss(line);
    int id;
    tk::real x, y, z;
    ss >> id >> x >> y >> z;
    mesh.x().push_back( x );
    mesh.y().push_back( y );
    mesh.z().push_back( z );
  }
}
示例#5
0
void
HyperMeshReader::readElements( const std::string& filename, UnsMesh& mesh )
const
// *****************************************************************************
//  Read element connectivity
//! \param[in] filename Filename to read nodes from
//! \param[in] mesh Unstructured mesh object to put element connectivity
//! \note We throw away the element ID.
//! \author J. Bakosi
// *****************************************************************************
{
  for (auto& line : tk::Reader(filename).lines()) {
    std::stringstream ss(line);
    int id;
    std::array< std::size_t, 4 > n;
    ss >> id >> n[0] >> n[1] >> n[2] >> n[3];
    mesh.tetinpoel().push_back( n[0] );
    mesh.tetinpoel().push_back( n[1] );
    mesh.tetinpoel().push_back( n[2] );
    mesh.tetinpoel().push_back( n[3] );
  }
}
示例#6
0
std::vector< std::pair< std::string, tk::real > >
writeUnsMesh( const tk::Print& print,
              const std::string& filename,
              UnsMesh& mesh,
              bool reorder )
// *****************************************************************************
//  Write unstructured mesh to file
//! \param[in] print Pretty printer
//! \param[in] filename Filename to write mesh to
//! \param[in] mesh Unstructured mesh object to write from
//! \param[in] reorder Whether to also reorder mesh nodes
//! \return Vector of time stamps consisting of a timer label (a string), and a
//!   time state (a tk::real in seconds) measuring the renumber and the mesh
//!   write time
//! \author J. Bakosi
// *****************************************************************************
{
  std::vector< std::pair< std::string, tk::real > > times;

  tk::Timer t;

  if (reorder) {
    print.diagstart( "Reordering mesh nodes ..." );

    auto& inpoel = mesh.tetinpoel();
    const auto psup = tk::genPsup( inpoel, 4, tk::genEsup( inpoel, 4 ) );
    std::vector< std::size_t > map, invmap;
    std::tie( map, invmap ) = tk::renumber( psup );
    tk::remap( inpoel, map );

    print.diagend( "done" );
    times.emplace_back( "Renumber mesh", t.dsec() );
    t.zero();
  }

  print.diagstart( "Writing mesh to file ..." );

  const auto meshtype = pickOutput( filename );

  if (meshtype == MeshWriter::GMSH)
    GmshMeshWriter( filename ).writeMesh( mesh );
  else if (meshtype == MeshWriter::NETGEN)
    NetgenMeshWriter( filename ).writeMesh( mesh );
  else if (meshtype== MeshWriter::EXODUSII)
    ExodusIIMeshWriter( filename, ExoWriter::CREATE ).writeMesh( mesh );

  print.diagend( "done" );
  times.emplace_back( "Write mesh to file", t.dsec() );

  return times;
}
示例#7
0
void
GmshMeshWriter::writeNodes( const UnsMesh& mesh )
//******************************************************************************
//  Write "$Nodes--$EndNodes" section
//! \param[in] mesh Unstructured mesh object
//! \author J. Bakosi
//******************************************************************************
{
  m_outFile << "$Nodes" << std::endl;

  // Write out number of nodes
  m_outFile << mesh.nnode() << std::endl;

  // Write node ids and coordinates: node-number x-coord y-coord z-coord
  if (isASCII()) {
    for (std::size_t i=0; i<mesh.nnode(); ++i) {
      m_outFile << i+1 << " " << std::setprecision(16)
                << mesh.x()[i] << " "
                << mesh.y()[i] << " "
                << mesh.z()[i] << std::endl;
    }
  } else {
    for (std::size_t i=0; i<mesh.nnode(); ++i) {
      // gmsh likes one-based node ids
      int I = static_cast< int >( i+1 );
      m_outFile.write(
        reinterpret_cast<const char*>(&I), sizeof(int) );
      m_outFile.write(
        reinterpret_cast<const char*>(&mesh.x()[i]), sizeof(double) );
      m_outFile.write(
        reinterpret_cast<const char*>(&mesh.y()[i]), sizeof(double) );
      m_outFile.write(
        reinterpret_cast<const char*>(&mesh.z()[i]), sizeof(double) );
    }
    m_outFile << std::endl;
  }

  m_outFile << "$EndNodes" << std::endl;
}