From 091c56e18b8e56d3258e85e7285831849c1d07fc Mon Sep 17 00:00:00 2001 From: Christoph Rettinger <christoph.rettinger@fau.de> Date: Mon, 7 May 2018 16:26:03 +0200 Subject: [PATCH] [API] changed return type to std array for improved usability --- src/blockforest/BlockNeighborhoodSection.h | 21 +++++++--------- .../loadbalancing/DynamicDiffusive.h | 24 +++++++++---------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/blockforest/BlockNeighborhoodSection.h b/src/blockforest/BlockNeighborhoodSection.h index f39b5d1f2..161e2f2e4 100644 --- a/src/blockforest/BlockNeighborhoodSection.h +++ b/src/blockforest/BlockNeighborhoodSection.h @@ -25,7 +25,7 @@ #include "core/debug/Debug.h" #include "stencil/Directions.h" - +#include <array> namespace walberla { namespace blockforest { @@ -94,31 +94,28 @@ inline uint_t getBlockMaxNeighborhoodSectionSize( const uint_t sectionIndex ) -inline const uint_t * getFaceNeighborhoodSectionIndices() +inline const std::array<uint_t, 6> & getFaceNeighborhoodSectionIndices() { - static const uint_t faces[] = { uint_t(4), uint_t(10), uint_t(12), uint_t(13), uint_t(15), uint_t(21) }; + static std::array<uint_t, 6> faces{ { uint_t(4), uint_t(10), uint_t(12), uint_t(13), uint_t(15), uint_t(21) } }; return faces; } - -inline const uint_t * getEdgeNeighborhoodSectionIndices() +inline const std::array<uint_t,12> & getEdgeNeighborhoodSectionIndices() { - static const uint_t edges[] = { uint_t( 1), uint_t( 3), uint_t( 5), uint_t( 7), uint_t( 9), uint_t(11), - uint_t(14), uint_t(16), uint_t(18), uint_t(20), uint_t(22), uint_t(24) }; + static std::array<uint_t,12> edges{{ uint_t( 1), uint_t( 3), uint_t( 5), uint_t( 7), uint_t( 9), uint_t(11), + uint_t(14), uint_t(16), uint_t(18), uint_t(20), uint_t(22), uint_t(24) }}; return edges; } - -inline const uint_t * getCornerNeighborhoodSectionIndices() +inline const std::array<uint_t, 8> & getCornerNeighborhoodSectionIndices() { - static const uint_t corners[] = { uint_t( 0), uint_t( 2), uint_t( 6), uint_t( 8), - uint_t(17), uint_t(19), uint_t(23), uint_t(25) }; + static std::array<uint_t, 8> corners {{ uint_t( 0), uint_t( 2), uint_t( 6), uint_t( 8), + uint_t(17), uint_t(19), uint_t(23), uint_t(25) }}; return corners; } - } // namespace blockforest } // namespace walberla diff --git a/src/blockforest/loadbalancing/DynamicDiffusive.h b/src/blockforest/loadbalancing/DynamicDiffusive.h index b914bda50..d9037070b 100644 --- a/src/blockforest/loadbalancing/DynamicDiffusive.h +++ b/src/blockforest/loadbalancing/DynamicDiffusive.h @@ -409,8 +409,8 @@ bool DynamicDiffusionBalance< PhantomData_T >::operator()( std::vector< std::pai const uint_t level = levelwise_ ? block->getLevel() : uint_t(0); if( level == l && targetProcess[i].second == blockforest.getProcess() ) { - const uint_t * faces = blockforest::getFaceNeighborhoodSectionIndices(); - for( uint_t j = uint_t(0); j != uint_t(6); ++j ) + auto faces = blockforest::getFaceNeighborhoodSectionIndices(); + for( uint_t j = uint_t(0); j != faces.size(); ++j ) { const uint_t sectionIndex = faces[j]; const uint_t sectionSize = block->getNeighborhoodSectionSize( sectionIndex ); @@ -427,8 +427,8 @@ bool DynamicDiffusionBalance< PhantomData_T >::operator()( std::vector< std::pai } } } - const uint_t * edges = blockforest::getEdgeNeighborhoodSectionIndices(); - for( uint_t j = uint_t(0); j != uint_t(12); ++j ) + auto edges = blockforest::getEdgeNeighborhoodSectionIndices(); + for( uint_t j = uint_t(0); j != edges.size(); ++j ) { const uint_t sectionIndex = edges[j]; const uint_t sectionSize = block->getNeighborhoodSectionSize( sectionIndex ); @@ -445,8 +445,8 @@ bool DynamicDiffusionBalance< PhantomData_T >::operator()( std::vector< std::pai } } } - const uint_t * corners = blockforest::getCornerNeighborhoodSectionIndices(); - for( uint_t j = uint_t(0); j != uint_t(8); ++j ) + auto corners = blockforest::getCornerNeighborhoodSectionIndices(); + for( uint_t j = uint_t(0); j != corners.size(); ++j ) { const uint_t sectionIndex = corners[j]; const uint_t sectionSize = block->getNeighborhoodSectionSize( sectionIndex ); @@ -655,8 +655,8 @@ bool DynamicDiffusionBalance< PhantomData_T >::operator()( std::vector< std::pai { if( regardConnectivity_ && iteration < disregardConnectivityStart_ ) { - const uint_t * faces = blockforest::getFaceNeighborhoodSectionIndices(); - for( uint_t j = uint_t(0); j != uint_t(6); ++j ) + auto faces = blockforest::getFaceNeighborhoodSectionIndices(); + for( uint_t j = uint_t(0); j != faces.size(); ++j ) { const uint_t sectionIndex = faces[j]; const uint_t sectionSize = block->getNeighborhoodSectionSize( sectionIndex ); @@ -675,8 +675,8 @@ bool DynamicDiffusionBalance< PhantomData_T >::operator()( std::vector< std::pai } } } - const uint_t * edges = blockforest::getEdgeNeighborhoodSectionIndices(); - for( uint_t j = uint_t(0); j != uint_t(12); ++j ) + auto edges = blockforest::getEdgeNeighborhoodSectionIndices(); + for( uint_t j = uint_t(0); j != edges.size(); ++j ) { const uint_t sectionIndex = edges[j]; const uint_t sectionSize = block->getNeighborhoodSectionSize( sectionIndex ); @@ -695,8 +695,8 @@ bool DynamicDiffusionBalance< PhantomData_T >::operator()( std::vector< std::pai } } } - const uint_t * corners = blockforest::getCornerNeighborhoodSectionIndices(); - for( uint_t j = uint_t(0); j != uint_t(8); ++j ) + auto corners = blockforest::getCornerNeighborhoodSectionIndices(); + for( uint_t j = uint_t(0); j != corners.size(); ++j ) { const uint_t sectionIndex = corners[j]; const uint_t sectionSize = block->getNeighborhoodSectionSize( sectionIndex ); -- GitLab