diff --git a/src/TNL/Meshes/MeshBuilder.h b/src/TNL/Meshes/MeshBuilder.h index 0513e1a3f8986d0deaa3706bc94257204a1ba76b..a32a7883eedbe79e38bf0e2fb4ac3962395b6d30 100644 --- a/src/TNL/Meshes/MeshBuilder.h +++ b/src/TNL/Meshes/MeshBuilder.h @@ -86,22 +86,33 @@ class MeshBuilder bool validate() const { - if( !allPointsSet() ) + if( ! allPointsSet() ) { std::cerr << "Mesh builder error: Not all points were set." << std::endl; return false; } + std::unordered_set< GlobalIndexType > assignedPoints; for( GlobalIndexType i = 0; i < getCellsCount(); i++ ) { auto cornerIds = this->cellSeeds[ i ].getCornerIds(); for( LocalIndexType j = 0; j < cornerIds.getSize(); j++ ) + { + assignedPoints.insert( cornerIds[ j ] ); if( cornerIds[ j ] < 0 || getPointsCount() <= cornerIds[ j ] ) { std::cerr << "Cell seed " << i << " is referencing unavailable point " << cornerIds[ j ] << std::endl; return false; } + } } + + if( (GlobalIndexType) assignedPoints.size() != this->getPointsCount() ) + { + std::cerr << "Mesh builder error: Some points were not used for cells." << std::endl; + return false; + } + return true; } @@ -109,7 +120,7 @@ class MeshBuilder bool allPointsSet() const { for( GlobalIndexType i = 0; i < this->points.getSize(); i++ ) - if (! this->pointsSet[ i ] ) + if( ! this->pointsSet[ i ] ) return false; return true; } diff --git a/src/TNL/Meshes/MeshDetails/initializer/MeshEntityInitializer.h b/src/TNL/Meshes/MeshDetails/initializer/MeshEntityInitializer.h index d04969604a7941e2b02319c546126ddd842a32a2..e7c31ac5c321cbde179c1333f398ebc5bd6661ec 100644 --- a/src/TNL/Meshes/MeshDetails/initializer/MeshEntityInitializer.h +++ b/src/TNL/Meshes/MeshDetails/initializer/MeshEntityInitializer.h @@ -161,14 +161,14 @@ protected: static void initSubentities( EntityType& entity, GlobalIndexType entityIndex, const SeedType& entitySeed, InitializerType& meshInitializer ) { - //cout << " Initiating subentities with " << DimensionTag::value << " dimensions ... " << std::endl; + //std::cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; auto subentitySeeds = SubentitySeedsCreatorType::create( entitySeed ); IdArrayType& subentityIdsArray = InitializerType::template subentityIdsArray< DimensionTag >( entity ); for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ ) { - //cout << " Adding subentity " << subentityIdsArray[ i ] << std::endl; subentityIdsArray[ i ] = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] ); + //std::cout << " Adding subentity " << subentityIdsArray[ i ] << std::endl; meshInitializer. template getSuperentityInitializer< DimensionTag >(). addSuperentity( EntityDimensionTag(), subentityIdsArray[ i ], entityIndex ); @@ -220,18 +220,18 @@ protected: static void initSubentities( EntityType& entity, GlobalIndexType entityIndex, const SeedType& entitySeed, InitializerType& meshInitializer ) { - //cout << " Initiating subentities with " << DimensionTag::value << " dimensions ... " << std::endl; + //std::cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; auto subentitySeeds = SubentitySeedsCreatorType::create( entitySeed ); IdArrayType& subentityIdsArray = InitializerType::template subentityIdsArray< DimensionTag >( entity ); OrientationArrayType &subentityOrientationsArray = InitializerType::template subentityOrientationsArray< DimensionTag >( entity ); for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ ) { - //cout << " Adding subentity " << subentityIdsArray[ i ] << std::endl; GlobalIndexType subentityIndex = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] ); subentityIdsArray[ i ] = subentityIndex; - subentityOrientationsArray[ i ] = meshInitializer.template getReferenceOrientation< DimensionTag >( subentityIndex ).createOrientation( subentitySeeds[ i ] ); - //cout << " Subentity orientation = " << subentityOrientationsArray[ i ].getSubvertexPermutation() << std::endl; + //std::cout << " Adding subentity " << subentityIdsArray[ i ] << std::endl; + subentityOrientationsArray[ i ] = meshInitializer.template getReferenceOrientation< DimensionsTag >( subentityIndex ).createOrientation( subentitySeeds[ i ] ); + //std::cout << " Subentity orientation = " << subentityOrientationsArray[ i ].getSubvertexPermutation() << std::endl; meshInitializer. template getSuperentityInitializer< DimensionTag >(). addSuperentity( EntityDimensionTag(), subentityIdsArray[ i ], entityIndex ); @@ -283,16 +283,16 @@ protected: static void initSubentities( EntityType& entity, GlobalIndexType entityIndex, const SeedType& entitySeed, InitializerType& meshInitializer ) { - //cout << " Initiating subentities with " << DimensionTag::value << " dimensions ... " << std::endl; + //std::cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; auto subentitySeeds = SubentitySeedsCreatorType::create( entitySeed ); IdArrayType& subentityIdsArray = InitializerType::template subentityIdsArray< DimensionTag >( entity ); OrientationArrayType &subentityOrientationsArray = InitializerType::template subentityOrientationsArray< DimensionTag >( entity ); for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++ ) { - //cout << " Adding subentity " << subentityIdsArray[ i ] << std::endl; subentityIdsArray[ i ] = meshInitializer.findEntitySeedIndex( subentitySeeds[ i ] ); - subentityOrientationsArray[ i ] = meshInitializer.template getReferenceOrientation< DimensionTag >( subentitySeeds[ i ] ).createOrientation( subentitySeeds[ i ] ); + //std::cout << " Adding subentity " << subentityIdsArray[ i ] << std::endl; + subentityOrientationsArray[ i ] = meshInitializer.template getReferenceOrientation< DimensionsTag >( subentitySeeds[ i ] ).createOrientation( subentitySeeds[ i ] ); } BaseType::initSubentities( entity, entityIndex, entitySeed, meshInitializer ); @@ -336,7 +336,7 @@ protected: static void initSubentities( EntityType& entity, GlobalIndexType entityIndex, const SeedType& entitySeed, InitializerType& meshInitializer ) { - //cout << " Initiating subentities with " << DimensionTag::value << " dimensions ... " << std::endl; + //std::cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; auto subentitySeeds = SubentitySeedsCreatorType::create( entitySeed ); IdArrayType& subentityIdsArray = InitializerType::template subentityIdsArray< DimensionTag >( entity ); @@ -384,7 +384,7 @@ protected: static void initSubentities( EntityType& entity, GlobalIndexType entityIndex, const SeedType& entitySeed, InitializerType& meshInitializer ) { - //cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; + //std::cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; auto subentitySeeds = SubentitySeedsCreatorType::create( entitySeed ); IdArrayType& subentityIdsArray = InitializerType::template subentityIdsArray< DimensionsTag >( entity ); for( LocalIndexType i = 0; i < subentitySeeds.getSize(); i++) @@ -442,7 +442,7 @@ protected: static void initSubentities( EntityType& entity, GlobalIndexType entityIndex, const SeedType& entitySeed, InitializerType& meshInitializer ) { - //cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; + //std::cout << " Initiating subentities with " << DimensionsTag::value << " dimensions ... " << std::endl; const IdArrayType &subentityIdsArray = InitializerType::template subentityIdsArray< DimensionsTag >(entity); for( LocalIndexType i = 0; i < subentityIdsArray.getSize(); i++ ) meshInitializer.template getSuperentityInitializer< DimensionsTag >().addSuperentity( EntityDimensionsTag(), subentityIdsArray[ i ], entityIndex); diff --git a/src/UnitTests/Meshes/MeshTest.h b/src/UnitTests/Meshes/MeshTest.h index 002bb3b73ceae3d22317cef909e4320bbf58f2ff..6e1da8ab3671701f0afd95d6b9558d3b07b27dbc 100644 --- a/src/UnitTests/Meshes/MeshTest.h +++ b/src/UnitTests/Meshes/MeshTest.h @@ -381,10 +381,11 @@ TEST( MeshTest, RegularMeshOfTrianglesTest ) for( IndexType j = 0; j < ySize; j++ ) for( IndexType i = 0; i < xSize; i++ ) { - IndexType vertex0 = j * xSize + i; - IndexType vertex1 = j * xSize + i + 1; - IndexType vertex2 = ( j + 1 ) * xSize + i; - IndexType vertex3 = ( j + 1 ) * xSize + i + 1; + const IndexType vertex0 = j * ( xSize + 1 ) + i; + const IndexType vertex1 = j * ( xSize + 1 ) + i + 1; + const IndexType vertex2 = ( j + 1 ) * ( xSize + 1 ) + i; + const IndexType vertex3 = ( j + 1 ) * ( xSize + 1 ) + i + 1; + meshBuilder.getCellSeed( cellIdx ).setCornerId( 0, vertex0 ); meshBuilder.getCellSeed( cellIdx ).setCornerId( 1, vertex1 ); meshBuilder.getCellSeed( cellIdx++ ).setCornerId( 2, vertex2 ); @@ -436,10 +437,11 @@ TEST( MeshTest, RegularMeshOfQuadrilateralsTest ) for( IndexType j = 0; j < ySize; j++ ) for( IndexType i = 0; i < xSize; i++ ) { - IndexType vertex0 = j * xSize + i; - IndexType vertex1 = j * xSize + i + 1; - IndexType vertex2 = ( j + 1 ) * xSize + i; - IndexType vertex3 = ( j + 1 ) * xSize + i + 1; + const IndexType vertex0 = j * ( xSize + 1 ) + i; + const IndexType vertex1 = j * ( xSize + 1 ) + i + 1; + const IndexType vertex2 = ( j + 1 ) * ( xSize + 1 ) + i; + const IndexType vertex3 = ( j + 1 ) * ( xSize + 1 ) + i + 1; + meshBuilder.getCellSeed( cellIdx ).setCornerId( 0, vertex0 ); meshBuilder.getCellSeed( cellIdx ).setCornerId( 1, vertex1 ); meshBuilder.getCellSeed( cellIdx ).setCornerId( 2, vertex2 ); @@ -494,14 +496,14 @@ TEST( MeshTest, RegularMeshOfHexahedronsTest ) for( IndexType j = 0; j < ySize; j++ ) for( IndexType i = 0; i < xSize; i++ ) { - IndexType vertex0 = k * xSize * ySize + j * xSize + i; - IndexType vertex1 = k * xSize * ySize + j * xSize + i + 1; - IndexType vertex2 = k * xSize * ySize + ( j + 1 ) * xSize + i; - IndexType vertex3 = k * xSize * ySize + ( j + 1 ) * xSize + i + 1; - IndexType vertex4 = ( k + 1 ) * xSize * ySize + j * xSize + i; - IndexType vertex5 = ( k + 1 ) * xSize * ySize + j * xSize + i + 1; - IndexType vertex6 = ( k + 1 ) * xSize * ySize + ( j + 1 ) * xSize + i; - IndexType vertex7 = ( k + 1 ) * xSize * ySize + ( j + 1 ) * xSize + i + 1; + const IndexType vertex0 = k * ( xSize + 1 ) * ( ySize + 1 ) + j * ( xSize + 1 ) + i; + const IndexType vertex1 = k * ( xSize + 1 ) * ( ySize + 1 ) + j * ( xSize + 1 ) + i + 1; + const IndexType vertex2 = k * ( xSize + 1 ) * ( ySize + 1 ) + ( j + 1 ) * ( xSize + 1 ) + i; + const IndexType vertex3 = k * ( xSize + 1 ) * ( ySize + 1 ) + ( j + 1 ) * ( xSize + 1 ) + i + 1; + const IndexType vertex4 = ( k + 1 ) * ( xSize + 1 ) * ( ySize + 1 ) + j * ( xSize + 1 ) + i; + const IndexType vertex5 = ( k + 1 ) * ( xSize + 1 ) * ( ySize + 1 ) + j * ( xSize + 1 ) + i + 1; + const IndexType vertex6 = ( k + 1 ) * ( xSize + 1 ) * ( ySize + 1 ) + ( j + 1 ) * ( xSize + 1 ) + i; + const IndexType vertex7 = ( k + 1 ) * ( xSize + 1 ) * ( ySize + 1 ) + ( j + 1 ) * ( xSize + 1 ) + i + 1; meshBuilder.getCellSeed( cellIdx ).setCornerId( 0, vertex0 ); meshBuilder.getCellSeed( cellIdx ).setCornerId( 1, vertex1 );