From 11c39a5333c8f8a55e54ff5a746848ec54bfc0ca Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Mon, 28 Jul 2014 20:07:41 +0200 Subject: [PATCH] Implementing the grid unit tests. --- src/implementation/mesh/tnlGrid2D_impl.h | 27 ++- src/implementation/mesh/tnlGrid3D_impl.h | 59 +++--- tests/unit-tests/mesh/tnlGridTester.h | 236 +++++++++++++++++++++++ 3 files changed, 278 insertions(+), 44 deletions(-) diff --git a/src/implementation/mesh/tnlGrid2D_impl.h b/src/implementation/mesh/tnlGrid2D_impl.h index 13d10a520b..28fd0d7668 100644 --- a/src/implementation/mesh/tnlGrid2D_impl.h +++ b/src/implementation/mesh/tnlGrid2D_impl.h @@ -192,31 +192,28 @@ __device__ __host__ #endif Index tnlGrid< 2, Real, Device, Index >::getFaceIndex( const CoordinatesType& faceCoordinates ) const { - tnlStaticAssert( nx >= 0 && ny >= 0 && nx + ny = 1, "Wrong template parameters nx or ny." ); + tnlStaticAssert( nx >= 0 && ny >= 0 && nx + ny == 1, "Wrong template parameters nx or ny." ); if( nx ) { - tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions.x() + 1, + tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x() + 1, cerr << "faceCoordinates.x() = " << faceCoordinates.x() << " this->getDimensions().x() + 1 = " << this->getDimensions().x() + 1 << " this->getName() = " << this->getName(); ); - tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions.y(), + tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y(), cerr << "faceCoordinates.y() = " << faceCoordinates.y() << " this->getDimensions().y() = " << this->getDimensions().y() << " this->getName() = " << this->getName(); ); return faceCoordinates.y() * ( this->getDimensions().x() + 1 ) + faceCoordinates.x(); } - if( ny ) - { - tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions.x(), - cerr << "faceCoordinates.x() = " << faceCoordinates.x() - << " this->getDimensions().x() = " << this->getDimensions().x() - << " this->getName() = " << this->getName(); ); - tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions.y() + 1, - cerr << "faceCoordinates.y() = " << faceCoordinates.y() - << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 - << " this->getName() = " << this->getName(); ); - return this->numberOfNxFaces + faceCoordinates.y() * this->getDimensions().x() + faceCoordinates.x(); - } + tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x(), + cerr << "faceCoordinates.x() = " << faceCoordinates.x() + << " this->getDimensions().x() = " << this->getDimensions().x() + << " this->getName() = " << this->getName(); ); + tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y() + 1, + cerr << "faceCoordinates.y() = " << faceCoordinates.y() + << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 + << " this->getName() = " << this->getName(); ); + return this->numberOfNxFaces + faceCoordinates.y() * this->getDimensions().x() + faceCoordinates.x(); } template< typename Real, diff --git a/src/implementation/mesh/tnlGrid3D_impl.h b/src/implementation/mesh/tnlGrid3D_impl.h index 175061f32f..e773aad74a 100644 --- a/src/implementation/mesh/tnlGrid3D_impl.h +++ b/src/implementation/mesh/tnlGrid3D_impl.h @@ -83,6 +83,7 @@ void tnlGrid< 3, Real, Device, Index > :: setDimensions( const Index xSize, cons this->numberOfDxEdges = xSize * ( ySize + 1 ) * ( zSize + 1 ); this->numberOfDyEdges = ( xSize + 1 ) * ySize * ( zSize + 1 ); this->numberOfDzEdges = ( xSize + 1 ) * ( ySize + 1 ) * zSize; + this->numberOfDxAndDyEdges = this->numberOfDxEdges + this->numberOfDyEdges; this->numberOfEdges = this->numberOfDxEdges + this->numberOfDyEdges + this->numberOfDzEdges; @@ -213,56 +214,56 @@ __device__ __host__ #endif Index tnlGrid< 3, Real, Device, Index >::getFaceIndex( const CoordinatesType& faceCoordinates ) const { - tnlStaticAssert( nx >= 0 && ny >= 0 && && nz >= 0 && nx + ny + nz = 1, "Wrong template parameters nx or ny or nz." ); + tnlStaticAssert( nx >= 0 && ny >= 0 && nz >= 0 && nx + ny + nz == 1, "Wrong template parameters nx or ny or nz." ); if( nx ) { - tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions.x() + 1, + tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x() + 1, cerr << "faceCoordinates.x() = " << faceCoordinates.x() << " this->getDimensions().x() + 1 = " << this->getDimensions().x() + 1 << " this->getName() = " << this->getName(); ); - tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions.y(), + tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y(), cerr << "faceCoordinates.y() = " << faceCoordinates.y() << " this->getDimensions().y() = " << this->getDimensions().y() << " this->getName() = " << this->getName(); ); - tnlAssert( faceCoordinates.z() >= 0 && faceCoordinates.z() < this->getDimensions.z(), + tnlAssert( faceCoordinates.z() >= 0 && faceCoordinates.z() < this->getDimensions().z(), cerr << "faceCoordinates.z() = " << faceCoordinates.z() << " this->getDimensions().z() = " << this->getDimensions().z() << " this->getName() = " << this->getName(); ); - return ( faceCoordinates.z() * this->getDimensions.y() + faceCoordinates.y() ) * ( this->getDimensions().x() + 1 ) + faceCoordinates.x(); + return ( faceCoordinates.z() * this->getDimensions().y() + faceCoordinates.y() ) * ( this->getDimensions().x() + 1 ) + faceCoordinates.x(); } if( ny ) { - tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions.x(), + tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x(), cerr << "faceCoordinates.x() = " << faceCoordinates.x() << " this->getDimensions().x() = " << this->getDimensions().x() << " this->getName() = " << this->getName(); ); - tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions.y() + 1, + tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y() + 1, cerr << "faceCoordinates.y() = " << faceCoordinates.y() << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 - << " this->getName() = " << this->getName(); ) - tnlAssert( faceCoordinates.z() >= 0 && faceCoordinates.z() < this->getDimensions.z(), + << " this->getName() = " << this->getName(); ); + tnlAssert( faceCoordinates.z() >= 0 && faceCoordinates.z() < this->getDimensions().z(), cerr << "faceCoordinates.z() = " << faceCoordinates.z() << " this->getDimensions().z() = " << this->getDimensions().z() << " this->getName() = " << this->getName(); ); - return this->numberOfNxFaces + ( faceCoordinates.z() * ( this->getDimensions().y + 1 ) + faceCoordinates.y() ) * this->getDimensions().x() + faceCoordinates.x(); + return this->numberOfNxFaces + ( faceCoordinates.z() * ( this->getDimensions().y() + 1 ) + faceCoordinates.y() ) * this->getDimensions().x() + faceCoordinates.x(); } if( nz ) { - tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions.x(), + tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x(), cerr << "faceCoordinates.x() = " << faceCoordinates.x() << " this->getDimensions().x() = " << this->getDimensions().x() << " this->getName() = " << this->getName(); ); - tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions.y(), + tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y(), cerr << "faceCoordinates.y() = " << faceCoordinates.y() << " this->getDimensions().y()= " << this->getDimensions().y() - << " this->getName() = " << this->getName(); ) - tnlAssert( faceCoordinates.z() >= 0 && faceCoordinates.z() < this->getDimensions.z() + 1, + << " this->getName() = " << this->getName(); ); + tnlAssert( faceCoordinates.z() >= 0 && faceCoordinates.z() < this->getDimensions().z() + 1, cerr << "faceCoordinates.z() = " << faceCoordinates.z() << " this->getDimensions().z() + 1 = " << this->getDimensions().z() + 1 << " this->getName() = " << this->getName(); ); - return this->numberOfNxAndNyFaces + ( faceCoordinates.z() * this->getDimensions().y + faceCoordinates.y() ) * this->getDimensions().x() + faceCoordinates.x(); + return this->numberOfNxAndNyFaces + ( faceCoordinates.z() * this->getDimensions().y() + faceCoordinates.y() ) * this->getDimensions().x() + faceCoordinates.x(); } } @@ -318,56 +319,56 @@ __device__ __host__ #endif Index tnlGrid< 3, Real, Device, Index > :: getEdgeIndex( const CoordinatesType& edgeCoordinates ) const { - tnlStaticAssert( dx >= 0 && dy >= 0 && dz >= 0 && dx + dy + dz = 1, "Wrong template parameters dx or dy or dz."); + tnlStaticAssert( dx >= 0 && dy >= 0 && dz >= 0 && dx + dy + dz == 1, "Wrong template parameters dx or dy or dz."); if( dx ) { - tnlAssert( edgeCoordinates.x() >= 0 && edgeCoordinates.x() < this->getDimensions.x(), + tnlAssert( edgeCoordinates.x() >= 0 && edgeCoordinates.x() < this->getDimensions().x(), cerr << "edgeCoordinates.x() = " << edgeCoordinates.x() << " this->getDimensions().x() = " << this->getDimensions().x() << " this->getName() = " << this->getName(); ); - tnlAssert( edgeCoordinates.y() >= 0 && edgeCoordinates.y() < this->getDimensions.y() + 1, + tnlAssert( edgeCoordinates.y() >= 0 && edgeCoordinates.y() < this->getDimensions().y() + 1, cerr << "edgeCoordinates.y() = " << edgeCoordinates.y() << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 << " this->getName() = " << this->getName(); ); - tnlAssert( edgeCoordinates.z() >= 0 && edgeCoordinates.z() < this->getDimensions.z() + 1, + tnlAssert( edgeCoordinates.z() >= 0 && edgeCoordinates.z() < this->getDimensions().z() + 1, cerr << "edgeCoordinates.z() = " << edgeCoordinates.z() << " this->getDimensions().z() + 1 = " << this->getDimensions().z() + 1 << " this->getName() = " << this->getName(); ); - return ( edgeCoordinates.z() * ( this->getDimensions.y() + 1 ) + edgeCoordinates.y() ) * this->getDimensions().x() + edgeCoordinates.x(); + return ( edgeCoordinates.z() * ( this->getDimensions().y() + 1 ) + edgeCoordinates.y() ) * this->getDimensions().x() + edgeCoordinates.x(); } if( dy ) { - tnlAssert( edgeCoordinates.x() >= 0 && edgeCoordinates.x() < this->getDimensions.x() + 1, + tnlAssert( edgeCoordinates.x() >= 0 && edgeCoordinates.x() < this->getDimensions().x() + 1, cerr << "edgeCoordinates.x() = " << edgeCoordinates.x() << " this->getDimensions().x() + 1 = " << this->getDimensions().x() + 1 << " this->getName() = " << this->getName(); ); - tnlAssert( edgeCoordinates.y() >= 0 && edgeCoordinates.y() < this->getDimensions.y(), + tnlAssert( edgeCoordinates.y() >= 0 && edgeCoordinates.y() < this->getDimensions().y(), cerr << "edgeCoordinates.y() = " << edgeCoordinates.y() << " this->getDimensions().y() = " << this->getDimensions().y() << " this->getName() = " << this->getName(); ); - tnlAssert( edgeCoordinates.z() >= 0 && edgeCoordinates.z() < this->getDimensions.z() + 1, + tnlAssert( edgeCoordinates.z() >= 0 && edgeCoordinates.z() < this->getDimensions().z() + 1, cerr << "edgeCoordinates.z() = " << edgeCoordinates.z() << " this->getDimensions().z() + 1 = " << this->getDimensions().z() + 1 << " this->getName() = " << this->getName(); ); - return this->numberOfDxEdges + ( edgeCoordinates.z() * this->getDimensions().y + edgeCoordinates.y() ) * ( this->getDimensions().x() + 1 ) + edgeCoordinates.x(); + return this->numberOfDxEdges + ( edgeCoordinates.z() * this->getDimensions().y() + edgeCoordinates.y() ) * ( this->getDimensions().x() + 1 ) + edgeCoordinates.x(); } if( dz ) { - tnlAssert( edgeCoordinates.x() >= 0 && edgeCoordinates.x() < this->getDimensions.x() + 1, + tnlAssert( edgeCoordinates.x() >= 0 && edgeCoordinates.x() < this->getDimensions().x() + 1, cerr << "edgeCoordinates.x() = " << edgeCoordinates.x() << " this->getDimensions().x() = " << this->getDimensions().x() << " this->getName() = " << this->getName(); ); - tnlAssert( edgeCoordinates.y() >= 0 && edgeCoordinates.y() < this->getDimensions.y() + 1, + tnlAssert( edgeCoordinates.y() >= 0 && edgeCoordinates.y() < this->getDimensions().y() + 1, cerr << "edgeCoordinates.y() = " << edgeCoordinates.y() << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 << " this->getName() = " << this->getName(); ); - tnlAssert( edgeCoordinates.z() >= 0 && edgeCoordinates.z() < this->getDimensions.z(), + tnlAssert( edgeCoordinates.z() >= 0 && edgeCoordinates.z() < this->getDimensions().z(), cerr << "edgeCoordinates.z() = " << edgeCoordinates.z() << " this->getDimensions().z() = " << this->getDimensions().z() << " this->getName() = " << this->getName(); ); - return this->numberOfDxAndDyEdges + ( edgeCoordinates.z() * ( this->getDimensions().y + 1 ) + edgeCoordinates.y() ) * ( this->getDimensions().x() + 1 ) + edgeCoordinates.x(); + return this->numberOfDxAndDyEdges + ( edgeCoordinates.z() * ( this->getDimensions().y() + 1 ) + edgeCoordinates.y() ) * ( this->getDimensions().x() + 1 ) + edgeCoordinates.x(); } } @@ -394,7 +395,7 @@ tnlGrid< 3, Real, Device, Index > :: getEdgeCoordinates( const Index edgeIndex, ( edgeIndex / this->getDimensions().x() ) % aux, edgeIndex / ( this->getDimensions().x() * aux ) ); } - if( edgeIndex < this->numberOfNxAndNyFaces ) + if( edgeIndex < this->numberOfDxAndDyEdges ) { dx = 0; dy = 1; diff --git a/tests/unit-tests/mesh/tnlGridTester.h b/tests/unit-tests/mesh/tnlGridTester.h index 570442813f..e28b7e0dc4 100644 --- a/tests/unit-tests/mesh/tnlGridTester.h +++ b/tests/unit-tests/mesh/tnlGridTester.h @@ -117,13 +117,91 @@ class tnlGridTester< 2, RealType, Device, IndexType >: public CppUnit :: TestCas CppUnit :: TestResult result; suiteOfTests -> addTest( new TestCallerType( "setDomainTest", &TesterType::setDomainTest ) ); + suiteOfTests -> addTest( new TestCallerType( "cellIndexingTest", &TesterType::cellIndexingTest ) ); + suiteOfTests -> addTest( new TestCallerType( "faceIndexingTest", &TesterType::faceIndexingTest ) ); + suiteOfTests -> addTest( new TestCallerType( "vertexIndexingTest", &TesterType::vertexIndexingTest ) ); + return suiteOfTests; } void setDomainTest() { + GridType grid; + grid.setDomain( VertexType( 0.0, 0.0 ), VertexType( 1.0, 1.0 ) ); + grid.setDimensions( 10, 20 ); + + CPPUNIT_ASSERT( grid.getCellProportions().x() == 0.1 ); + CPPUNIT_ASSERT( grid.getCellProportions().y() == 0.05 ); + } + + void cellIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + GridType grid; + grid.setDimensions( xSize, ySize ); + for( IndexType j = 0; j < ySize; j++ ) + for( IndexType i = 0; i < xSize; i++ ) + { + CoordinatesType cellCoordinates( i, j ); + const IndexType cellIndex = grid.getCellIndex( cellCoordinates ); + CPPUNIT_ASSERT( cellIndex >= 0 ); + CPPUNIT_ASSERT( cellIndex < grid.getNumberOfCells() ); + CPPUNIT_ASSERT( grid.getCellCoordinates( cellIndex ) == cellCoordinates ); + } + } + + void faceIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + GridType grid; + grid.setDimensions( xSize, ySize ); + + int nx, ny; + for( IndexType j = 0; j < ySize; j++ ) + for( IndexType i = 0; i < xSize + 1; i++ ) + { + CoordinatesType faceCoordinates( i, j ); + const IndexType faceIndex = grid.template getFaceIndex< 1, 0 >( faceCoordinates ); + CPPUNIT_ASSERT( faceIndex >= 0 ); + CPPUNIT_ASSERT( faceIndex < grid.getNumberOfFaces() ); + CPPUNIT_ASSERT( grid.getFaceCoordinates( faceIndex, nx, ny ) == faceCoordinates ); + CPPUNIT_ASSERT( nx == 1 ); + CPPUNIT_ASSERT( ny == 0 ); + } + + for( IndexType j = 0; j < ySize + 1; j++ ) + for( IndexType i = 0; i < xSize; i++ ) + { + CoordinatesType faceCoordinates( i, j ); + const IndexType faceIndex = grid.template getFaceIndex< 0, 1 >( faceCoordinates ); + CPPUNIT_ASSERT( faceIndex >= 0 ); + CPPUNIT_ASSERT( faceIndex < grid.getNumberOfFaces() ); + CPPUNIT_ASSERT( grid.getFaceCoordinates( faceIndex, nx, ny ) == faceCoordinates ); + CPPUNIT_ASSERT( nx == 0 ); + CPPUNIT_ASSERT( ny == 1 ); + } } + + void vertexIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + GridType grid; + grid.setDimensions( xSize, ySize ); + for( IndexType j = 0; j < ySize + 1; j++ ) + for( IndexType i = 0; i < xSize + 1; i++ ) + { + CoordinatesType vertexCoordinates( i, j ); + const IndexType vertexIndex = grid.getVertexIndex( vertexCoordinates ); + CPPUNIT_ASSERT( vertexIndex >= 0 ); + CPPUNIT_ASSERT( vertexIndex < grid.getNumberOfVertices() ); + CPPUNIT_ASSERT( grid.getVertexCoordinates( vertexIndex ) == vertexCoordinates ); + } + } + }; template< typename RealType, typename Device, typename IndexType > @@ -148,13 +226,171 @@ class tnlGridTester< 3, RealType, Device, IndexType >: public CppUnit :: TestCas CppUnit :: TestResult result; suiteOfTests -> addTest( new TestCallerType( "setDomainTest", &TesterType::setDomainTest ) ); + suiteOfTests -> addTest( new TestCallerType( "cellIndexingTest", &TesterType::cellIndexingTest ) ); + suiteOfTests -> addTest( new TestCallerType( "faceIndexingTest", &TesterType::faceIndexingTest ) ); + suiteOfTests -> addTest( new TestCallerType( "edgeIndexingTest", &TesterType::edgeIndexingTest ) ); + suiteOfTests -> addTest( new TestCallerType( "vertexIndexingTest", &TesterType::vertexIndexingTest ) ); + return suiteOfTests; } void setDomainTest() { + GridType grid; + grid.setDomain( VertexType( 0.0, 0.0, 0.0 ), VertexType( 1.0, 1.0, 1.0 ) ); + grid.setDimensions( 10, 20, 40 ); + + CPPUNIT_ASSERT( grid.getCellProportions().x() == 0.1 ); + CPPUNIT_ASSERT( grid.getCellProportions().y() == 0.05 ); + CPPUNIT_ASSERT( grid.getCellProportions().z() == 0.025 ); + } + + void cellIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + const IndexType zSize( 19 ); + GridType grid; + grid.setDimensions( xSize, ySize, zSize ); + for( IndexType k = 0; k < zSize; k++ ) + for( IndexType j = 0; j < ySize; j++ ) + for( IndexType i = 0; i < xSize; i++ ) + { + CoordinatesType cellCoordinates( i, j, k ); + const IndexType cellIndex = grid.getCellIndex( cellCoordinates ); + CPPUNIT_ASSERT( cellIndex >= 0 ); + CPPUNIT_ASSERT( cellIndex < grid.getNumberOfCells() ); + CPPUNIT_ASSERT( grid.getCellCoordinates( cellIndex ) == cellCoordinates ); + } + } + + void faceIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + const IndexType zSize( 19 ); + GridType grid; + grid.setDimensions( xSize, ySize, zSize ); + + int nx, ny, nz; + for( IndexType k = 0; k < zSize; k++ ) + for( IndexType j = 0; j < ySize; j++ ) + for( IndexType i = 0; i < xSize + 1; i++ ) + { + CoordinatesType faceCoordinates( i, j, k ); + const IndexType faceIndex = grid.template getFaceIndex< 1, 0, 0 >( faceCoordinates ); + CPPUNIT_ASSERT( faceIndex >= 0 ); + CPPUNIT_ASSERT( faceIndex < grid.getNumberOfFaces() ); + CPPUNIT_ASSERT( grid.getFaceCoordinates( faceIndex, nx, ny, nz ) == faceCoordinates ); + CPPUNIT_ASSERT( nx == 1 ); + CPPUNIT_ASSERT( ny == 0 ); + CPPUNIT_ASSERT( nz == 0 ); + } + + for( IndexType k = 0; k < zSize; k++ ) + for( IndexType j = 0; j < ySize + 1; j++ ) + for( IndexType i = 0; i < xSize; i++ ) + { + CoordinatesType faceCoordinates( i, j, k ); + const IndexType faceIndex = grid.template getFaceIndex< 0, 1, 0 >( faceCoordinates ); + CPPUNIT_ASSERT( faceIndex >= 0 ); + CPPUNIT_ASSERT( faceIndex < grid.getNumberOfFaces() ); + CPPUNIT_ASSERT( grid.getFaceCoordinates( faceIndex, nx, ny, nz ) == faceCoordinates ); + CPPUNIT_ASSERT( nx == 0 ); + CPPUNIT_ASSERT( ny == 1 ); + CPPUNIT_ASSERT( nz == 0 ); + } + + for( IndexType k = 0; k < zSize + 1; k++ ) + for( IndexType j = 0; j < ySize; j++ ) + for( IndexType i = 0; i < xSize; i++ ) + { + CoordinatesType faceCoordinates( i, j, k ); + const IndexType faceIndex = grid.template getFaceIndex< 0, 0, 1 >( faceCoordinates ); + CPPUNIT_ASSERT( faceIndex >= 0 ); + CPPUNIT_ASSERT( faceIndex < grid.getNumberOfFaces() ); + CPPUNIT_ASSERT( grid.getFaceCoordinates( faceIndex, nx, ny, nz ) == faceCoordinates ); + CPPUNIT_ASSERT( nx == 0 ); + CPPUNIT_ASSERT( ny == 0 ); + CPPUNIT_ASSERT( nz == 1 ); + } + + } + + void edgeIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + const IndexType zSize( 19 ); + GridType grid; + grid.setDimensions( xSize, ySize, zSize ); + + int dx, dy, dz; + for( IndexType k = 0; k < zSize + 1; k++ ) + for( IndexType j = 0; j < ySize + 1; j++ ) + for( IndexType i = 0; i < xSize; i++ ) + { + CoordinatesType edgeCoordinates( i, j, k ); + const IndexType edgeIndex = grid.template getEdgeIndex< 1, 0, 0 >( edgeCoordinates ); + CPPUNIT_ASSERT( edgeIndex >= 0 ); + CPPUNIT_ASSERT( edgeIndex < grid.getNumberOfEdges() ); + CPPUNIT_ASSERT( grid.getEdgeCoordinates( edgeIndex, dx, dy, dz ) == edgeCoordinates ); + CPPUNIT_ASSERT( dx == 1 ); + CPPUNIT_ASSERT( dy == 0 ); + CPPUNIT_ASSERT( dz == 0 ); + } + + for( IndexType k = 0; k < zSize + 1; k++ ) + for( IndexType j = 0; j < ySize; j++ ) + for( IndexType i = 0; i < xSize + 1; i++ ) + { + CoordinatesType edgeCoordinates( i, j, k ); + const IndexType edgeIndex = grid.template getEdgeIndex< 0, 1, 0 >( edgeCoordinates ); + CPPUNIT_ASSERT( edgeIndex >= 0 ); + CPPUNIT_ASSERT( edgeIndex < grid.getNumberOfEdges() ); + CPPUNIT_ASSERT( grid.getEdgeCoordinates( edgeIndex, dx, dy, dz ) == edgeCoordinates ); + CPPUNIT_ASSERT( dx == 0 ); + CPPUNIT_ASSERT( dy == 1 ); + CPPUNIT_ASSERT( dz == 0 ); + } + + for( IndexType k = 0; k < zSize; k++ ) + for( IndexType j = 0; j < ySize + 1; j++ ) + for( IndexType i = 0; i < xSize + 1; i++ ) + { + CoordinatesType edgeCoordinates( i, j, k ); + const IndexType edgeIndex = grid.template getEdgeIndex< 0, 0, 1 >( edgeCoordinates ); + CPPUNIT_ASSERT( edgeIndex >= 0 ); + CPPUNIT_ASSERT( edgeIndex < grid.getNumberOfEdges() ); + CPPUNIT_ASSERT( grid.getEdgeCoordinates( edgeIndex, dx, dy, dz ) == edgeCoordinates ); + CPPUNIT_ASSERT( dx == 0 ); + CPPUNIT_ASSERT( dy == 0 ); + CPPUNIT_ASSERT( dz == 1 ); + } + + } + void vertexIndexingTest() + { + const IndexType xSize( 13 ); + const IndexType ySize( 17 ); + const IndexType zSize( 19 ); + GridType grid; + grid.setDimensions( xSize, ySize, zSize ); + for( IndexType k = 0; k < zSize + 1; k++ ) + for( IndexType j = 0; j < ySize + 1; j++ ) + for( IndexType i = 0; i < xSize + 1; i++ ) + { + CoordinatesType vertexCoordinates( i, j, k ); + const IndexType vertexIndex = grid.getVertexIndex( vertexCoordinates ); + CPPUNIT_ASSERT( vertexIndex >= 0 ); + CPPUNIT_ASSERT( vertexIndex < grid.getNumberOfVertices() ); + CPPUNIT_ASSERT( grid.getVertexCoordinates( vertexIndex ) == vertexCoordinates ); + } } + + + }; -- GitLab