From 0f49d396f900313b798054c7c200b983fcd6d8c3 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Thu, 13 Mar 2014 22:34:42 +0100 Subject: [PATCH] Debuging tnlMesh. --- src/core/CMakeLists.txt | 1 + src/core/arrays/tnlArrayOperations.h | 1 + src/core/tnlDynamicTypeTag.h | 28 +++++++ src/implementation/core/arrays/tnlArrayIO.h | 82 +++++++++++++++++++ .../core/arrays/tnlArray_impl.h | 6 +- src/mesh/layers/tnlMeshStorageLayer.h | 8 +- .../layers/tnlMeshSuperentityStorageLayer.h | 9 +- src/mesh/tnlMeshEntity.h | 12 +-- tests/unit-tests/mesh/tnlMeshTester.h | 3 +- tools/src/tnl-view.cpp | 8 +- 10 files changed, 137 insertions(+), 21 deletions(-) create mode 100644 src/core/tnlDynamicTypeTag.h create mode 100644 src/implementation/core/arrays/tnlArrayIO.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a4ef603257..2ca4ddd90d 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -8,6 +8,7 @@ set (headers tnlAssert.h tnlCuda.h tnlDataElement.h tnlDevice.h + tnlDynamicTypeTag.h tnlFeature.h tnlFile.h tnlFlopsCounter.h diff --git a/src/core/arrays/tnlArrayOperations.h b/src/core/arrays/tnlArrayOperations.h index 02cb11b32a..73246999dc 100644 --- a/src/core/arrays/tnlArrayOperations.h +++ b/src/core/arrays/tnlArrayOperations.h @@ -69,6 +69,7 @@ class tnlArrayOperations< tnlHost > static bool compareMemory( const Element1* destination, const Element2* source, const Index size ); + }; template<> diff --git a/src/core/tnlDynamicTypeTag.h b/src/core/tnlDynamicTypeTag.h new file mode 100644 index 0000000000..9c2b6c551a --- /dev/null +++ b/src/core/tnlDynamicTypeTag.h @@ -0,0 +1,28 @@ +/*************************************************************************** + tnlDynamicTypeTag.h - description + ------------------- + begin : Mar 13, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef TNLDYNAMICTYPETAG_H_ +#define TNLDYNAMICTYPETAG_H_ + +template< typename Element > +struct tnlDynamicTypeTag +{ + enum { value = false }; +}; + + +#endif /* TNLDYNAMICTYPETAG_H_ */ diff --git a/src/implementation/core/arrays/tnlArrayIO.h b/src/implementation/core/arrays/tnlArrayIO.h new file mode 100644 index 0000000000..a66be243ed --- /dev/null +++ b/src/implementation/core/arrays/tnlArrayIO.h @@ -0,0 +1,82 @@ +/*************************************************************************** + tnlArrayIO.h - description + ------------------- + begin : Mar 13, 2014 + copyright : (C) 2014 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef TNLARRAYIO_H_ +#define TNLARRAYIO_H_ + +#include<core/tnlDynamicTypeTag.h> +#include<core/tnlFile.h> + +template< typename Element, + typename Device, + typename Index, + bool DynamicType = tnlDynamicTypeTag< Element >::value > +class tnlArrayIO +{}; + +template< typename Element, + typename Device, + typename Index > +class tnlArrayIO< Element, Device, Index, true > +{ + public: + + static bool save( tnlFile& file, + const Element* data, + const Index elements ) + { + for( Index i = 0; i < elements; i++ ) + if( ! data[ i ].save( file ) ) + return false; + return true; + } + + static bool load( tnlFile& file, + Element* data, + const Index elements ) + { + for( Index i = 0; i < elements; i++ ) + if( ! data[ i ].load( file ) ) + return false; + return true; + } +}; + +template< typename Element + typename Device, + typename Index > +class tnlArrayIO< Element, Device, Index, false > +{ + public: + + static bool save( tnlFile& file, + const Element* data, + const Index elements ) + { + return file.write< Element, Device, Index >( data, elements ); + } + + static bool load( tnlFile& file, + Element* data, + const Index elements ) + { + return file.read< Element, Device, Index >( data, elements ); + } + +}; + +#endif /* TNLARRAYIO_H_ */ diff --git a/src/implementation/core/arrays/tnlArray_impl.h b/src/implementation/core/arrays/tnlArray_impl.h index 3f20f9c846..c41235097a 100644 --- a/src/implementation/core/arrays/tnlArray_impl.h +++ b/src/implementation/core/arrays/tnlArray_impl.h @@ -24,6 +24,7 @@ #include <core/mfuncs.h> #include <core/param-types.h> #include <core/arrays/tnlArrayOperations.h> +#include <implementation/core/arrays/tnlArrayIO.h> using namespace std; @@ -332,7 +333,7 @@ bool tnlArray< Element, Device, Index > :: save( tnlFile& file ) const if( ! file. write( &this -> size ) ) return false; #endif - if( this -> size != 0 && ! file. write< Element, Device, Index >( this -> data, this -> size ) ) + if( this -> size != 0 && ! tnlArrayIO< Element, Device, Index >::save( file, this -> data, this -> size ) ) { cerr << "I was not able to save " << this->getType() << " " << this -> getName() @@ -365,7 +366,7 @@ bool tnlArray< Element, Device, Index > :: load( tnlFile& file ) if( _size ) { setSize( _size ); - if( ! file. read< Element, Device, Index >( this -> data, this -> size ) ) + if( ! tnlArrayIO< Element, Device, Index >::load( file, this -> data, this -> size ) ) { cerr << "I was not able to load " << this->getType() << " " << this -> getName() @@ -392,7 +393,6 @@ bool tnlArray< Element, Device, Index > :: load( const tnlString& fileName ) return tnlObject :: load( fileName ); } - template< typename Element, typename Device, typename Index > diff --git a/src/mesh/layers/tnlMeshStorageLayer.h b/src/mesh/layers/tnlMeshStorageLayer.h index 129257c386..c2474b0c2e 100644 --- a/src/mesh/layers/tnlMeshStorageLayer.h +++ b/src/mesh/layers/tnlMeshStorageLayer.h @@ -124,7 +124,7 @@ class tnlMeshStorageLayer< ConfigTag, bool save( tnlFile& file ) const { if( ! BaseType::save( file ) || - ! this->entities.save( file ) ) + ! this->entities.saveRecursively( file ) ) return false; return true; } @@ -133,7 +133,7 @@ class tnlMeshStorageLayer< ConfigTag, { cout << "Loading mesh layer with dimensions " << DimensionsTraits::value << endl; if( ! BaseType::load( file ) || - ! this->entities.load( file ) ) + ! this->entities.loadRecursively( file ) ) return false; this->sharedEntities.bind( this->entities ); return true; @@ -278,14 +278,14 @@ class tnlMeshStorageLayer< ConfigTag, bool save( tnlFile& file ) const { - if( ! this->vertices.save( file ) ) + if( ! this->vertices.saveRecursively( file ) ) return false; return true; } bool load( tnlFile& file ) { - if( ! this->vertices.load( file ) ) + if( ! this->vertices.loadRecursively( file ) ) return false; this->sharedVertices.bind( this->vertices ); return true; diff --git a/src/mesh/layers/tnlMeshSuperentityStorageLayer.h b/src/mesh/layers/tnlMeshSuperentityStorageLayer.h index ba81c87459..7eb7feff7a 100644 --- a/src/mesh/layers/tnlMeshSuperentityStorageLayer.h +++ b/src/mesh/layers/tnlMeshSuperentityStorageLayer.h @@ -85,7 +85,9 @@ class tnlMeshSuperentityStorageLayer< ConfigTag, ~tnlMeshSuperentityStorageLayer() { - cout << " Destroying " << this->superentitiesIndices.getSize() << " superentities with "<< DimensionsTraits::value << " dimensions." << endl; + cerr << " Destroying " << this->superentitiesIndices.getSize() << " superentities with "<< DimensionsTraits::value << " dimensions." << endl; + cerr << " this->superentitiesIndices.getName() = " << this->superentitiesIndices.getName() << endl; + cerr << " this->sharedSuperentitiesIndices.getName() = " << this->sharedSuperentitiesIndices.getName() << endl; } tnlMeshSuperentityStorageLayer& operator = ( const tnlMeshSuperentityStorageLayer& layer ) @@ -146,9 +148,10 @@ class tnlMeshSuperentityStorageLayer< ConfigTag, bool load( tnlFile& file ) { - if( ! BaseType::load( file ) || - ! this->superentitiesIndices.load( file ) ) + if( ! BaseType::load( file ) ) //|| + //! this->superentitiesIndices.load( file ) ) return false; + cerr << "Loaded superentities " << this->superentitiesIndices.getName() << endl; return true; } diff --git a/src/mesh/tnlMeshEntity.h b/src/mesh/tnlMeshEntity.h index 0c5f9529df..aedba5ce32 100644 --- a/src/mesh/tnlMeshEntity.h +++ b/src/mesh/tnlMeshEntity.h @@ -64,9 +64,9 @@ class tnlMeshEntity bool load( tnlFile& file ) const { - if( ! tnlMeshSubentityStorageLayers< ConfigTag, EntityTag >::load( file ) || - ! tnlMeshSuperentityStorageLayers< ConfigTag, EntityTag >::load( file ) ) - return false; + //if( ! tnlMeshSubentityStorageLayers< ConfigTag, EntityTag >::load( file ) || + // ! tnlMeshSuperentityStorageLayers< ConfigTag, EntityTag >::load( file ) ) + // return false; return true; } @@ -332,9 +332,9 @@ class tnlMeshEntity< ConfigTag, tnlMeshVertexTag > bool load( tnlFile& file ) const { - if( ! tnlMeshSuperentityStorageLayers< ConfigTag, tnlMeshVertexTag >::load( file ) || - ! point.load( file ) ) - return false; + //if( ! tnlMeshSuperentityStorageLayers< ConfigTag, tnlMeshVertexTag >::load( file ) || + // ! point.load( file ) ) + // return false; return true; } diff --git a/tests/unit-tests/mesh/tnlMeshTester.h b/tests/unit-tests/mesh/tnlMeshTester.h index 18df7a2518..ed9d145360 100644 --- a/tests/unit-tests/mesh/tnlMeshTester.h +++ b/tests/unit-tests/mesh/tnlMeshTester.h @@ -128,7 +128,7 @@ class tnlMeshTester : public CppUnit :: TestCase point0 edge2 point1 */ - tnlMesh< TestTriangleMeshConfig > mesh2, mesh; + tnlMesh< TestTriangleMeshConfig > mesh, mesh2; mesh.setName( "mesh" ); mesh.setNumberOfVertices( 4 ); mesh.setVertex( 0, PointType( 0.0, 0.0 ) ); @@ -156,6 +156,7 @@ class tnlMeshTester : public CppUnit :: TestCase CPPUNIT_ASSERT( mesh2.load( "mesh.tnl" ) ); mesh2.setName( "mesh2" ); + mesh2.print( cout ); //cout << "===================== Mesh2 =========================" << endl; //mesh2.print( cout ); //cout << "=====================================================" << endl; diff --git a/tools/src/tnl-view.cpp b/tools/src/tnl-view.cpp index 81bf602c8e..e4bb459317 100644 --- a/tools/src/tnl-view.cpp +++ b/tools/src/tnl-view.cpp @@ -27,10 +27,10 @@ #include <mesh/tnlLinearGridGeometry.h> // TODO: Remove -#include <mesh/tnlMesh.h> +/*#include <mesh/tnlMesh.h> #include <mesh/tnlMeshWriterNetgen.h> #include <mesh/config/tnlMeshConfigBase.h> -#include <mesh/topologies/tnlMeshTriangleTag.h> +#include <mesh/topologies/tnlMeshTriangleTag.h>*/ #include "tnlConfig.h" const char configFile[] = TNL_CONFIG_DIRECTORY "tnl-view.cfg.desc"; @@ -125,7 +125,7 @@ int main( int argc, char* argv[] ) } if( parsedMeshType[ 0 ] == "tnlMesh" ) { - tnlString meshFile = parameters. GetParameter< tnlString >( "mesh" ); + /*tnlString meshFile = parameters. GetParameter< tnlString >( "mesh" ); struct MeshConfig : public tnlMeshConfigBase< 2 > { typedef tnlMeshTriangleTag CellTag; @@ -134,7 +134,7 @@ int main( int argc, char* argv[] ) if( ! mesh.load( meshFile ) ) return EXIT_FAILURE; if( ! tnlMeshWriterNetgen::writeMesh( "tnl-mesh.ng", mesh, true ) ) - return EXIT_FAILURE; + return EXIT_FAILURE;*/ } return EXIT_FAILURE; } -- GitLab