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 }
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; }
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 ); } }