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

Fixed MeshEntityTest and MultimapTest

parent 25599f7f
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,9 @@ class TestTetrahedronMeshConfig : public MeshConfigBase< MeshTetrahedronTopology
}
};
template< typename MeshConfig, typename EntityTopology, int Dimensions >
using StorageNetwork = typename MeshSuperentityTraits< MeshConfig, EntityTopology, Dimensions >::StorageNetworkType;
// stupid wrapper around MeshEntity to expose protected members needed for tests
template< typename MeshConfig, typename EntityTopology >
class TestMeshEntity
......@@ -58,11 +61,18 @@ class TestMeshEntity
public:
template< int Subdimensions >
void setSubentityIndex( const typename BaseType::LocalIndexType localIndex,
const typename BaseType::GlobalIndexType globalIndex )
void setSubentityIndex( const typename BaseType::LocalIndexType& localIndex,
const typename BaseType::GlobalIndexType& globalIndex )
{
BaseType::template setSubentityIndex< Subdimensions >( localIndex, globalIndex );
}
template< int Superdimensions >
void setSuperentityIndex( const typename BaseType::LocalIndexType& localIndex,
const typename BaseType::GlobalIndexType& globalIndex )
{
BaseType::template setSuperentityIndex< Superdimensions >( localIndex, globalIndex );
}
};
using RealType = double;
......@@ -428,38 +438,60 @@ TEST( MeshEntityTest, TwoTrianglesMeshEntityTest )
ASSERT_TRUE( triangleEntities[ 1 ].template getSubentityIndex< 1 >( 1 ) == 3 );
ASSERT_TRUE( triangleEntities[ 1 ].template getSubentityIndex< 1 >( 2 ) == 4 );
// vertexEntities[ 0 ].template setNumberOfSuperentities< 1 >( 2 );
// vertexEntities[ 0 ].template setSuperentityIndex< 1 >( 0, 2 );
// vertexEntities[ 0 ].template setSuperentityIndex< 1 >( 1, 1 );
// vertexEntities[ 1 ].template setNumberOfSuperentities< 1 >( 3 );
// vertexEntities[ 1 ].template setSuperentityIndex< 1 >( 0, 0 );
// vertexEntities[ 1 ].template setSuperentityIndex< 1 >( 1, 2 );
// vertexEntities[ 1 ].template setSuperentityIndex< 1 >( 2, 4 );
/*
* Tests for the superentities layer.
*/
StorageNetwork< TestTriangleMeshConfig, MeshVertexTopology, 1 > vertexEdgeSuperentities;
vertexEdgeSuperentities.setRanges( 4, 3 );
vertexEdgeSuperentities.allocate( 3 );
vertexEntities[ 0 ].template bindSuperentitiesStorageNetwork< 1 >( vertexEdgeSuperentities.getValues( 0 ) );
vertexEntities[ 0 ].template setNumberOfSuperentities< 1 >( 2 );
vertexEntities[ 0 ].template setSuperentityIndex< 1 >( 0, 2 );
vertexEntities[ 0 ].template setSuperentityIndex< 1 >( 1, 1 );
ASSERT_EQ( vertexEntities[ 0 ].template getNumberOfSuperentities< 1 >(), 2 );
ASSERT_EQ( vertexEntities[ 0 ].template getSuperentityIndex< 1 >( 0 ), 2 );
ASSERT_EQ( vertexEntities[ 0 ].template getSuperentityIndex< 1 >( 1 ), 1 );
vertexEntities[ 1 ].template bindSuperentitiesStorageNetwork< 1 >( vertexEdgeSuperentities.getValues( 1 ) );
vertexEntities[ 1 ].template setNumberOfSuperentities< 1 >( 3 );
vertexEntities[ 1 ].template setSuperentityIndex< 1 >( 0, 0 );
vertexEntities[ 1 ].template setSuperentityIndex< 1 >( 1, 2 );
vertexEntities[ 1 ].template setSuperentityIndex< 1 >( 2, 4 );
ASSERT_EQ( vertexEntities[ 1 ].template getNumberOfSuperentities< 1 >(), 3 );
ASSERT_EQ( vertexEntities[ 1 ].template getSuperentityIndex< 1 >( 0 ), 0 );
ASSERT_EQ( vertexEntities[ 1 ].template getSuperentityIndex< 1 >( 1 ), 2 );
ASSERT_EQ( vertexEntities[ 1 ].template getSuperentityIndex< 1 >( 2 ), 4 );
StorageNetwork< TestTriangleMeshConfig, MeshVertexTopology, 2 > vertexCellSuperentities;
vertexCellSuperentities.setRanges( 4, 2 );
vertexCellSuperentities.allocate( 2 );
// vertexEntities[ 1 ].template setNumberOfSuperentities< 2 >( 2 );
// vertexEntities[ 1 ].template setSuperentityIndex< 2 >( 0, 0 );
// vertexEntities[ 1 ].template setSuperentityIndex< 2 >( 1, 1 );
vertexEntities[ 1 ].template bindSuperentitiesStorageNetwork< 2 >( vertexCellSuperentities.getValues( 1 ) );
vertexEntities[ 1 ].template setNumberOfSuperentities< 2 >( 2 );
vertexEntities[ 1 ].template setSuperentityIndex< 2 >( 0, 0 );
vertexEntities[ 1 ].template setSuperentityIndex< 2 >( 1, 1 );
// ASSERT_TRUE( vertexEntities[ 0 ].template getNumberOfSuperentities< 1 >() == 2 );
// ASSERT_TRUE( vertexEntities[ 0 ].template getSuperentityIndex< 1 >( 0 ) == 2 );
// ASSERT_TRUE( vertexEntities[ 0 ].template getSuperentityIndex< 1 >( 1 ) == 1 );
ASSERT_EQ( vertexEntities[ 1 ].template getNumberOfSuperentities< 2 >(), 2 );
ASSERT_EQ( vertexEntities[ 1 ].template getSuperentityIndex< 2 >( 0 ), 0 );
ASSERT_EQ( vertexEntities[ 1 ].template getSuperentityIndex< 2 >( 1 ), 1 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getNumberOfSuperentities< 1 >() == 3 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getSuperentityIndex< 1 >( 0 ) == 0 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getSuperentityIndex< 1 >( 1 ) == 2 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getSuperentityIndex< 1 >( 2 ) == 4 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getNumberOfSuperentities< 2 >() == 2 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getSuperentityIndex< 2 >( 0 ) == 0 );
// ASSERT_TRUE( vertexEntities[ 1 ].template getSuperentityIndex< 2 >( 1 ) == 1 );
StorageNetwork< TestTriangleMeshConfig, MeshEdgeTopology, 2 > edgeCellSuperentities;
edgeCellSuperentities.setRanges( 5, 2 );
edgeCellSuperentities.allocate( 2 );
// edgeEntities[ 0 ].template setNumberOfSuperentities< 2 >( 2 );
// edgeEntities[ 0 ].template setSuperentityIndex< 2 >( 0, 0 );
// edgeEntities[ 0 ].template setSuperentityIndex< 2 >( 1, 1 );
edgeEntities[ 0 ].template bindSuperentitiesStorageNetwork< 2 >( edgeCellSuperentities.getValues( 0 ) );
edgeEntities[ 0 ].template setNumberOfSuperentities< 2 >( 2 );
edgeEntities[ 0 ].template setSuperentityIndex< 2 >( 0, 0 );
edgeEntities[ 0 ].template setSuperentityIndex< 2 >( 1, 1 );
// ASSERT_TRUE( edgeEntities[ 0 ].template getNumberOfSuperentities< 2 >() == 2 );
// ASSERT_TRUE( edgeEntities[ 0 ].template getSuperentityIndex< 2 >( 0 ) == 0 );
ASSERT_EQ( edgeEntities[ 0 ].template getNumberOfSuperentities< 2 >(), 2 );
ASSERT_EQ( edgeEntities[ 0 ].template getSuperentityIndex< 2 >( 0 ), 0 );
}
#endif
......@@ -20,6 +20,49 @@ TEST( MultimapTest, TestTypedefs )
ASSERT_TRUE( same_localindex );
}
TEST( MultimapTest, TestSettingSizes )
{
using MultimapType = TNL::EllpackIndexMultimap< IndexType, Device, LocalIndexType >;
IndexType inputs = 10;
LocalIndexType valuesRange = 4;
LocalIndexType valuesGlobalMax = 3;
LocalIndexType valuesLocalMax = 2;
MultimapType map;
map.setRanges( inputs, valuesRange );
ASSERT_EQ( map.getKeysRange(), inputs );
ASSERT_EQ( map.getValuesRange(), valuesRange );
typename MultimapType::ValuesAllocationVectorType allocationRanges;
ASSERT_TRUE( allocationRanges.setSize( inputs ) );
allocationRanges.setValue( valuesGlobalMax );
ASSERT_TRUE( map.allocate( allocationRanges ) );
for( IndexType i = 0; i < inputs; i++ ) {
auto values = map.getValues( i );
const auto constValues = ( (const MultimapType) map ).getValues( i );
ASSERT_TRUE( values.setSize( valuesLocalMax ) );
ASSERT_EQ( values.getSize(), valuesLocalMax );
ASSERT_EQ( constValues.getSize(), valuesLocalMax );
// setting wrong local sizes should not be allowed
ASSERT_FALSE( values.setSize( valuesGlobalMax + 1 ) );
ASSERT_EQ( values.getSize(), valuesLocalMax );
ASSERT_EQ( constValues.getSize(), valuesLocalMax );
}
for( IndexType i = 0; i < inputs; i++ ) {
auto values = map.getValues( i );
const auto constValues = ( (const MultimapType) map ).getValues( i );
ASSERT_TRUE( values.setSize( valuesGlobalMax ) );
ASSERT_EQ( values.getSize(), valuesGlobalMax );
ASSERT_EQ( constValues.getSize(), valuesGlobalMax );
}
}
TEST( MultimapTest, TestSettingValues )
{
using MultimapType = TNL::EllpackIndexMultimap< IndexType, Device, LocalIndexType >;
......@@ -42,13 +85,15 @@ TEST( MultimapTest, TestSettingValues )
auto values = map.getValues( i );
const auto constValues = ( (const MultimapType) map ).getValues( i );
ASSERT_TRUE( values.setSize( allocatedValues ) );
for( LocalIndexType o = 0; o < allocatedValues; o++ )
values.setOutput( o, i + o );
values.setValue( o, i + o );
for( LocalIndexType o = 0; o < allocatedValues; o++ ) {
ASSERT_EQ( values.getOutput( o ), i + o );
ASSERT_EQ( values.getValue( o ), i + o );
ASSERT_EQ( values[ o ], i + o );
ASSERT_EQ( constValues.getOutput( o ), i + o );
ASSERT_EQ( constValues.getValue( o ), i + o );
ASSERT_EQ( constValues[ o ], i + o );
}
......@@ -56,9 +101,9 @@ TEST( MultimapTest, TestSettingValues )
values[ o ] = i * o;
for( LocalIndexType o = 0; o < allocatedValues; o++ ) {
ASSERT_EQ( values.getOutput( o ), i * o );
ASSERT_EQ( values.getValue( o ), i * o );
ASSERT_EQ( values[ o ], i * o );
ASSERT_EQ( constValues.getOutput( o ), i * o );
ASSERT_EQ( constValues.getValue( o ), i * o );
ASSERT_EQ( constValues[ o ], i * o );
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment