Commit c4a889e6 authored by Christian Godenschwager's avatar Christian Godenschwager
Browse files

Let Layout determine padding

parent f4b47d49
......@@ -61,7 +61,8 @@ struct LayoutAoS
{
constexpr LayoutAoS() = delete;
constexpr uint_t alignment() { return uint_t(1); }
constexpr static uint_t alignment() { return uint_t(1); }
constexpr static uint_t numFluidCellsToAllocate( const uint_t numFluidCellsRequired ) { return numFluidCellsRequired; }
constexpr static Index_T getPDFIdx( const uint_t idx, const uint_t f, const uint_t /*N*/ ) { return numeric_cast<Index_T>( idx * Stencil::Size + f ); }
constexpr static Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d, const uint_t /*N*/ )
......@@ -82,11 +83,19 @@ struct LayoutAoS
template< typename Stencil, typename Index_T = walberla::uint32_t, uint_t ALIGNMENT = 64 >
struct LayoutSoA
{
static_assert( ( ( ALIGNMENT & ( ALIGNMENT - uint_t( 1 ) ) ) == 0 ) && ( ALIGNMENT >= uint_t(1) ), "The alignment for the list layout has to a power of two!" );
static_assert( ( ( ALIGNMENT & ( ALIGNMENT - uint_t( 1 ) ) ) == 0 ) && ( ALIGNMENT >= uint_t(1) ), "The alignment for the SoA list layout has to a power of two!" );
constexpr LayoutSoA() = delete;
constexpr static uint_t alignment() { return ALIGNMENT; }
constexpr static uint_t numFluidCellsToAllocate( const uint_t numFluidCellsRequired )
{
uint_t alignedStepSize = std::max( uint_t(1), alignment() / sizeof( real_t ) );
if( ( numFluidCellsRequired % alignedStepSize ) == 0 )
return numFluidCellsRequired;
else
return ( numFluidCellsRequired / alignedStepSize + uint_t(1) ) * alignedStepSize;
}
constexpr static Index_T getPDFIdx( const uint_t idx, const uint_t f, const uint_t N ) { return numeric_cast<Index_T>( f * N + idx ); }
constexpr static Index_T getPullIdxIdx( const uint_t idx, const stencil::Direction d, const uint_t N )
......@@ -145,10 +154,10 @@ public:
return it->second;
}
const Cell & getCell( const uint_t idx ) const
const Cell & getCell( const uint_t cellIdx ) const
{
WALBERLA_ASSERT_LESS( idx, idxToCell_.size() );
return idxToCell_[ idx ];
WALBERLA_ASSERT_LESS( cellIdx, idxToCell_.size() );
return idxToCell_[ cellIdx ];
}
const std::vector<Cell> & getFluidCells() const { return idxToCell_; }
......@@ -262,20 +271,16 @@ void List<LatticeModel_T, Layout_T, Index_T>::init( const std::vector<Cell> & fl
{
uint_t idx = 0;
cellToIdx_.reserve( fluidCells.size() );
for( auto it = fluidCells.begin(); it != fluidCells.end(); ++it, ++idx )
for( const Cell & cell : fluidCells )
{
cellToIdx_.push_back( std::make_pair( *it, idx ) );
cellToIdx_.push_back( std::make_pair( cell, idx++ ) );
}
std::sort( cellToIdx_.begin(), cellToIdx_.end(), CellToIdxOrdering() );
}
// Allocate Fluid PDFs
uint_t alignedStepSize = std::max( uint_t(1), Layout_T::alignment() / sizeof( real_t ) );
if( ( fluidCells.size() % alignedStepSize ) == 0 )
numFluidCellsPadded_ = fluidCells.size();
else
numFluidCellsPadded_ = ( fluidCells.size() / alignedStepSize + uint_t(1) ) * alignedStepSize; // add padding to pdfs in order to ensure alignment for the first value of every pdf-direction
numFluidCellsPadded_ = Layout::numFluidCellsToAllocate( fluidCells.size() );
WALBERLA_CHECK_LESS( Stencil::Size * numFluidCellsPadded_, numeric_cast<size_t>( std::numeric_limits<Index_T>::max() ),
"The number of PDFs you want to initialize the PDFs list with is beyond the capacity of Index_T (a.k.a. "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment