Skip to content
Snippets Groups Projects
Commit 9e1288a7 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing the mesh reader.

parent 1b7a5bbc
No related branches found
No related tags found
No related merge requests found
......@@ -66,12 +66,12 @@ class tnlMeshStorageLayer< ConfigTag,
using BaseType::setEntity;
using BaseType::getEntity;
bool setNumberOfEntities( const GlobalIndexType size )
bool setNumberOfEntities( DimensionsTraits, const GlobalIndexType size )
{
return this->entities.setSize( size );
}
GlobalIndexType getNumberOfEntities() const
GlobalIndexType getNumberOfEntities( DimensionsTraits ) const
{
return this->entities.getSize();
}
......@@ -86,13 +86,13 @@ class tnlMeshStorageLayer< ConfigTag,
EntityType& getEntity( DimensionsTraits,
const GlobalIndexType entityIndex )
{
return this->entities.getElement( entityIndex );
return this->entities[ entityIndex ];
}
const EntityType& getEntity( DimensionsTraits,
const GlobalIndexType entityIndex ) const
{
return this->entities.getElement( entityIndex );
return this->entities[ entityIndex ];
}
private:
......@@ -153,44 +153,36 @@ class tnlMeshStorageLayer< ConfigTag,
}
void setPoint( const GlobalIndexType vertexIndex,
const PointType& point ) const
void setVertex( const GlobalIndexType vertexIndex,
const PointType& point ) const
{
this->vertices.getElement( vertexIndex ).setPoint( point );
}
PointType& getPoint( const GlobalIndexType vertexIndex )
{
return this->vertices.getElement( vertexIndex ).getPoint();
}
const PointType& getPoint( const GlobalIndexType vertexIndex ) const
{
return this->vertices.getElement( vertexIndex ).getPoint();
}
/****
* This is only for the completeness and compatibility
* with higher dimensions entities storage layers.
*/
bool setNumberOfEntities( const GlobalIndexType size )
bool setNumberOfEntities( DimensionsTraits,
const GlobalIndexType size )
{
return this->vertices.setSize( size );
}
GlobalIndexType getNumberOfEntities() const
GlobalIndexType getNumberOfEntities( DimensionsTraits ) const
{
return this->vertices.getSize();
}
void setEntity( const GlobalIndexType entityIndex,
void setEntity( DimensionsTraits,
const GlobalIndexType entityIndex,
const VertexType& entity ) const
{
this->vertices.setElement( entityIndex, entity );
}
const VertexType& getEntity( const GlobalIndexType entityIndex ) const
const VertexType& getEntity( DimensionsTraits,
const GlobalIndexType entityIndex ) const
{
return this->vertices.getElement( entityIndex );
}
......
......@@ -90,8 +90,6 @@ class tnlMesh : public tnlMeshStorageLayers< ConfigTag >
using BaseType::getNumberOfVertices;
using BaseType::setVertex;
using BaseType::getVertex;
using BaseType::setPoint;
using BaseType::getPoint;
void load(const char *filename);
......
......@@ -22,11 +22,14 @@
#include <istream>
#include <sstream>
using namespace std;
class tnlMeshReaderNetgen
{
public:
static int detectDimensions( const tnlString& fileName )
static bool detectDimensions( const tnlString& fileName,
int& dimensions )
{
fstream inputFile( fileName.getString() );
if( ! inputFile )
......@@ -34,15 +37,125 @@ class tnlMeshReaderNetgen
cerr << "I am not able to open the file " << fileName << "." << endl;
return false;
}
string line;
istringstream iss;
/****
* Skip whitespaces
*/
inputFile >> ws;
std::string line;
int count;
std::istringstream iss;
/****
* Skip number of vertices
*/
if( ! inputFile )
return false;
getline( inputFile, line );
/****
* Read the first vertex and compute number of components
*/
if( ! inputFile )
return false;
getline( inputFile, line );
iss.str( line );
dimensions = -1;
while( iss )
{
double aux;
iss >> aux;
dimensions++;
}
return true;
}
static bool readMesh( const tnlString& fileName )
template< typename MeshType >
static bool readMesh( const tnlString& fileName,
MeshType& mesh,
bool verbose )
{
typedef typename MeshType::PointType PointType;
const int dimensions = PointType::size;
fstream inputFile( fileName.getString() );
if( ! inputFile )
{
cerr << "I am not able to open the file " << fileName << "." << endl;
return false;
}
string line;
istringstream iss;
/****
* Skip white spaces
*/
inputFile >> ws;
/****
* Read the number of vertices
*/
if( ! inputFile )
return false;
getline( inputFile, line );
iss.str( line );
typedef typename MeshType::template EntitiesTraits< 0 >::GlobalIndexType VertexIndexType;
VertexIndexType numberOfVertices;
iss >> numberOfVertices;
if( verbose )
cout << numberOfVertices << " vertices expected ... " << endl;
if( ! mesh.setNumberOfVertices( numberOfVertices ) )
{
cerr << "I am not able to allocate enough memory for " << numberOfVertices << " vertices." << endl;
return false;
}
for( VertexIndexType i = 0; i < numberOfVertices; i++ )
{
getline( inputFile, line );
iss.clear();
iss.str( line );
PointType p;
for( int d = 0; d < dimensions; d++ )
iss >> p[ d ];
mesh.setVertex( i, p );
}
/****
* Skip white spaces
*/
inputFile >> ws;
/****
* Read number of cells
*/
typedef typename MeshType::template EntitiesTraits< dimensions >::GlobalIndexType CellIndexType;
if( ! inputFile )
return false;
getline( inputFile, line );
iss.str( line );
CellIndexType numberOfCells;
iss >> numberOfCells;
if( verbose )
cout << numberOfCells << " cells expected ... " << endl;
if( ! mesh.template setNumberOfEntities< dimensions >( numberOfCells ) )
{
cerr << "I am not able to allocate enough memory for " << numberOfCells << " cells." << endl;
return false;
}
for( CellIndexType i = 0; i < numberOfCells; i++ )
{
getline( inputFile, line );
iss.clear();
iss.str( line );
for( int cellVertex = 0; cellVertex < dimensions + 1; cellVertex++ )
{
VertexIndexType vertexIdx;
iss >> vertexIdx;
mesh.template getEntity< dimensions >( i ).setVertexIndex( cellVertex, vertexIdx );
}
}
}
protected:
......
......@@ -44,7 +44,7 @@ class tnlMeshEntitiesTraits
typedef tnlStorageTraits< storageEnabled > EntityStorageTag;
typedef tnlArray< Type, tnlHost, GlobalIndexType > ContainerType;
typedef tnlArray< Type, tnlHost, GlobalIndexType > ContainerType;
//typedef IndexedSet< Type, GlobalIndexType, Key > UniqueContainerType;
typedef tnlConstSharedArray< Type, tnlHost, GlobalIndexType > SharedArrayType;
......
......@@ -102,10 +102,10 @@ class tnlMeshTester : public CppUnit :: TestCase
tnlMesh< TestTriangleMeshConfig > mesh;
mesh.setNumberOfVertices( 4 );
mesh.setPoint( 0, PointType( 0.0, 0.0 ) );
mesh.setPoint( 1, PointType( 1.0, 0.0 ) );
mesh.setPoint( 2, PointType( 0.0, 1.0 ) );
mesh.setPoint( 3, PointType( 1.0, 1.0 ) );
mesh.setVertex( 0, PointType( 0.0, 0.0 ) );
mesh.setVertex( 1, PointType( 1.0, 0.0 ) );
mesh.setVertex( 2, PointType( 0.0, 1.0 ) );
mesh.setVertex( 3, PointType( 1.0, 1.0 ) );
/* tnlStaticArray< 4, VertexMeshEntityType > vertexEntities;
vertexEntities[ 0 ].setPoint( point0 );
......
......@@ -20,8 +20,31 @@
#include <config/tnlParameterContainer.h>
#include <mesh/tnlMeshReaderNetgen.h>
#include <mesh/config/tnlMeshConfigBase.h>
#include <mesh/topologies/tnlMeshTriangleTag.h>
#include <mesh/tnlMesh.h>
#include <core/mfilename.h>
template< int Dimensions >
bool readMeshWithDimensions( const tnlParameterContainer& parameters )
{
const tnlString& inputFileName = parameters.GetParameter< tnlString >( "input-file" );
const tnlString fileExt = getFileExtension( inputFileName );
if( Dimensions == 2 )
{
struct MeshConfig : public tnlMeshConfigBase< 2 >
{
typedef tnlMeshTriangleTag CellTag;
};
tnlMesh< MeshConfig > mesh;
if( fileExt == "ng" &&
! tnlMeshReaderNetgen::readMesh<>( inputFileName, mesh, true ) )
return false;
}
return true;
}
bool readMesh( const tnlParameterContainer& parameters )
{
const tnlString& inputFileName = parameters.GetParameter< tnlString >( "input-file" );
......@@ -29,10 +52,13 @@ bool readMesh( const tnlParameterContainer& parameters )
if( fileExt == "ng" )
{
int dimensions;
if( ! tnlMeshReaderNetgen::detectDimensions( inputFileName ) )
if( ! tnlMeshReaderNetgen::detectDimensions( inputFileName, dimensions ) )
return false;
if( dimensions == 2 &&
! readMeshWithDimensions< 2 >( parameters ) )
return false;
cout << "dimensions = " << dimensions << endl;
if( ! tnlMeshReaderNetgen::readMesh( inputFileName ) )
if( dimensions == 3 &&
! readMeshWithDimensions< 3 >( parameters ) )
return false;
}
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment