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