Skip to content
Snippets Groups Projects
Commit b58393a9 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed NetgenWriter

parent 389c0037
No related branches found
No related tags found
No related merge requests found
...@@ -16,69 +16,55 @@ ...@@ -16,69 +16,55 @@
#pragma once #pragma once
#include <fstream> #include <ostream>
#include <istream>
#include <sstream>
#include <iomanip> #include <iomanip>
#include <TNL/String.h> #include <TNL/String.h>
namespace TNL { namespace TNL {
namespace Meshes { namespace Meshes {
namespace Writers {
class MeshWriterNetgen template< typename Mesh >
class NetgenWriter
{ {
public: using GlobalIndexType = typename Mesh::GlobalIndexType;
using PointType = typename Mesh::PointType;
using Cell = typename Mesh::Cell;
static constexpr int meshDimension = Mesh::getMeshDimension();
template< typename MeshType > public:
static bool writeMesh( const String& fileName, static void writeMesh( const Mesh& mesh, std::ostream& str )
MeshType& mesh,
bool verbose )
{ {
std::fstream outputFile; str << std::setprecision( 6 );
outputFile.open( fileName.getString(), std::ios::out ); str << std::fixed;
if( ! outputFile )
{
std::cerr << "I am not able to open the output file " << fileName << "." << std::endl;
return false;
}
outputFile << std::setprecision( 6 );
outputFile << std::fixed;
const int meshDimension = MeshType::meshDimension; const GlobalIndexType numberOfVertices = mesh.template getEntitiesCount< typename Mesh::Vertex >();
typedef typename MeshType::template EntitiesTraits< 0 >::GlobalIndexType VerticesIndexType; str << numberOfVertices << std::endl;
typedef typename MeshType::PointType PointType; for( GlobalIndexType i = 0; i < numberOfVertices; i++ )
const VerticesIndexType numberOfVertices = mesh.getVerticesCount();
outputFile << numberOfVertices << std::endl;
for( VerticesIndexType i = 0; i < numberOfVertices; i++ )
{ {
const PointType& point = mesh.getVertex( i ).getPoint(); const PointType& point = mesh.template getEntity< typename Mesh::Vertex >( i ).getPoint();
outputFile << " "; str << " ";
for( int d = 0; d < meshDimension; d++ ) for( int d = 0; d < meshDimension; d++ )
outputFile << " " << point[ d ]; str << " " << point[ d ];
outputFile << std::endl; str << std::endl;
} }
typedef typename MeshType::template EntitiesTraits< meshDimension >::GlobalIndexType CellIndexType; const GlobalIndexType numberOfCells = mesh.template getEntitiesCount< typename Mesh::Cell >();
typedef typename MeshType::template EntitiesTraits< meshDimension >::Type CellType; str << numberOfCells << std::endl;
typedef typename CellType::LocalIndexType LocalIndexType; for( GlobalIndexType cellIdx = 0; cellIdx < numberOfCells; cellIdx++ )
const CellIndexType numberOfCells = mesh.template getEntitiesCount< meshDimension >();
outputFile << numberOfCells << std::endl;
for( CellIndexType cellIdx = 0; cellIdx < numberOfCells; cellIdx++ )
{ {
const CellType& cell = mesh.template getEntity< meshDimension >( cellIdx ); const Cell& cell = mesh.template getEntity< typename Mesh::Cell >( cellIdx );
outputFile << " 1"; str << " 1";
for( LocalIndexType cellVertexIdx = 0; for( int cellVertexIdx = 0;
cellVertexIdx < meshDimension + 1; cellVertexIdx < meshDimension + 1;
cellVertexIdx++ ) cellVertexIdx++ )
outputFile << " " << cell.getVertexIndex( cellVertexIdx ); str << " " << cell.getVertexIndex( cellVertexIdx );
outputFile << std::endl; str << "\n";
} }
return true;
} }
}; };
} // namespace Writers
} // namespace Meshes } // namespace Meshes
} // namespace TNL } // namespace TNL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment