Commit 27f71c7d authored by Markus Holzer's avatar Markus Holzer
Browse files

Adapted python coupling

parent 8f75e1ba
......@@ -37,20 +37,14 @@ using namespace walberla;
#define FIELD_TYPES \
Field<walberla::real_t,1>,\
Field<walberla::real_t,2>,\
Field<walberla::real_t,3>,\
Field<walberla::real_t,9>,\
Field<walberla::real_t,15>,\
Field<walberla::real_t,19>,\
Field<walberla::real_t,27>,\
Field<walberla::int8_t,1>,\
Field<walberla::int64_t,1>,\
Field<walberla::int64_t,2>,\
Field<walberla::int64_t,3>,\
Field<walberla::uint8_t,1>,\
Field<walberla::uint16_t,1>,\
Field<walberla::uint32_t,1>
Field<walberla::real_t>,\
Field<walberla::int8_t>,\
Field<walberla::int16_t>,\
Field<walberla::int32_t>,\
Field<walberla::int64_t>,\
Field<walberla::uint8_t>,\
Field<walberla::uint16_t>,\
Field<walberla::uint32_t>
#define GPU_FIELD_TYPES \
GPUField<real_t>,\
......
......@@ -75,13 +75,13 @@ namespace cuda {
template<typename T, uint_t fs>
void fieldCpy( cuda::GPUField<T> & dst, const field::Field<T,fs> & src );
template<typename T>
void fieldCpy( cuda::GPUField<T> & dst, const field::Field<T> & src );
template<typename T, uint_t fs>
void fieldCpy( field::Field<T,fs> & dst, const cuda::GPUField<T> & src );
template<typename T>
void fieldCpy( field::Field<T> & dst, const cuda::GPUField<T> & src );
......@@ -95,15 +95,15 @@ namespace cuda {
template<typename T, uint_t fs>
void fieldCpy( cuda::GPUField<T> & dst, const field::Field<T,fs> & src )
template<typename T>
void fieldCpy( cuda::GPUField<T> & dst, const field::Field<T> & src )
{
cudaMemcpy3DParms p;
memset( &p, 0, sizeof(p) );
if ( dst.layout() != src.layout() ) {
WALBERLA_ABORT( "Cannot copy fields with different layout" );
WALBERLA_ABORT( "Cannot copy fields with different layout" )
}
bool canCopy = ( src.layout() == fzyx &&
......@@ -119,7 +119,7 @@ namespace cuda {
dst.fSize() == src.fSize() );
if ( !canCopy ) {
WALBERLA_ABORT("Field have to have the same size ");
WALBERLA_ABORT("Field have to have the same size ")
}
if ( dst.layout() == fzyx )
......@@ -147,19 +147,19 @@ namespace cuda {
p.dstPtr = dst.pitchedPtr();
p.kind = cudaMemcpyHostToDevice;
WALBERLA_CUDA_CHECK( cudaMemcpy3D( &p ) );
WALBERLA_CUDA_CHECK( cudaMemcpy3D( &p ) )
}
template<typename T, uint_t fs>
void fieldCpy( field::Field<T,fs> & dst, const cuda::GPUField<T> & src )
template<typename T>
void fieldCpy( field::Field<T> & dst, const cuda::GPUField<T> & src )
{
cudaMemcpy3DParms p;
memset( &p, 0, sizeof(p) );
if ( dst.layout() != src.layout() ) {
WALBERLA_ABORT( "Cannot copy fields with different layout" );
WALBERLA_ABORT( "Cannot copy fields with different layout" )
}
bool canCopy = ( src.layout() == fzyx &&
......@@ -175,7 +175,7 @@ namespace cuda {
dst.fSize() == src.fSize() );
if ( !canCopy ) {
WALBERLA_ABORT("Field have to have the same size ");
WALBERLA_ABORT("Field have to have the same size ")
}
if ( dst.layout() == fzyx )
......@@ -203,7 +203,7 @@ namespace cuda {
p.srcPtr = src.pitchedPtr();
p.kind = cudaMemcpyDeviceToHost;
WALBERLA_CUDA_CHECK( cudaMemcpy3D( &p ) );
WALBERLA_CUDA_CHECK( cudaMemcpy3D( &p ) )
}
......
......@@ -319,7 +319,8 @@ namespace field {
{
WALBERLA_ASSERT_NULLPTR( values_ )
WALBERLA_ASSERT_NULLPTR( valuesWithOffset_ )
WALBERLA_ASSERT(_fSize > 0, "fSize()=0 means: empty field")
// TODO: Do we want this check? Compare for example FieldGatherTest line 64, would fail with this check.
// WALBERLA_ASSERT(_fSize > 0, "fSize()=0 means: empty field")
// Automatically select allocator if none was given
if ( alloc == 0 )
......
......@@ -59,6 +59,11 @@ namespace field {
boundingBox = blocks->getDomainCellBB();
}
// TODO: is there a better way to get the fSize from the BlockForest?
// Maybe implement something like: uint_t fSize = block->template getFSize<Field_T> (fieldID)?
IBlock * firstBlock = & ( * blocks->begin() );
const uint_t fSize = firstBlock->template getData<Field_T>( fieldID )->fSize();
// -- Packing --
mpi::SendBuffer sendBuffer;
for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt )
......@@ -83,7 +88,7 @@ namespace field {
// layouts on different blocks
blocks->transformGlobalToBlockLocalCellInterval( intersection, block );
for( auto it = field->beginSliceXYZ(intersection); it != field->end(); ++it )
for( uint_t f = 0; f < Field_T::F_SIZE; ++f )
for( uint_t f = 0; f < fSize; ++f )
sendBuffer << it.getF(f);
}
......@@ -97,7 +102,7 @@ namespace field {
// -- Unpacking --
if ( recvBuffer.size() > 0 )
{
gatheredField.resize( boundingBox.size(0), boundingBox.size(1), boundingBox.size(2) );
gatheredField.resize( boundingBox.size(0), boundingBox.size(1), boundingBox.size(2), fSize );
while ( ! recvBuffer.isEmpty() )
{
......@@ -105,7 +110,7 @@ namespace field {
recvBuffer >> targetInterval;
for( auto it = gatheredField.beginSliceXYZ(targetInterval); it != gatheredField.end(); ++it )
for( uint_t f = 0; f < Field_T::F_SIZE; ++f )
for( uint_t f = 0; f < fSize; ++f )
recvBuffer >> it.getF(f);
}
}
......
......@@ -47,22 +47,20 @@ class StencilRestrictedPackInfo : public walberla::communication::UniformPackInf
{
public:
StencilRestrictedPackInfo( const BlockDataID & fieldId ) : fieldId_( fieldId ) {}
virtual ~StencilRestrictedPackInfo() {}
~StencilRestrictedPackInfo() override = default;
bool constantDataExchange() const { return true; }
bool threadsafeReceiving() const { return true; }
bool constantDataExchange() const override { return true; }
bool threadsafeReceiving() const override { return true; }
void unpackData( IBlock * receiver, stencil::Direction dir, mpi::RecvBuffer & buffer );
void unpackData( IBlock * receiver, stencil::Direction dir, mpi::RecvBuffer & buffer ) override;
void communicateLocal( const IBlock * sender, IBlock * receiver, stencil::Direction dir );
void communicateLocal( const IBlock * sender, IBlock * receiver, stencil::Direction dir ) override;
protected:
void packDataImpl( const IBlock * sender, stencil::Direction dir, mpi::SendBuffer & outBuffer ) const;
void packDataImpl( const IBlock * sender, stencil::Direction dir, mpi::SendBuffer & outBuffer ) const override;
const BlockDataID fieldId_;
static_assert(GhostLayerField_T::F_SIZE == Stencil_T::Size, "Size of stencil and f size of field have to be equal");
};
......@@ -73,8 +71,9 @@ void StencilRestrictedPackInfo<GhostLayerField_T, Stencil>::unpackData( IBlock *
return;
GhostLayerField_T * pdfField = receiver->getData< GhostLayerField_T >( fieldId_ );
WALBERLA_ASSERT_NOT_NULLPTR( pdfField );
WALBERLA_ASSERT_EQUAL( pdfField->nrOfGhostLayers(), 1 );
WALBERLA_ASSERT_NOT_NULLPTR( pdfField )
WALBERLA_ASSERT_EQUAL( pdfField->nrOfGhostLayers(), 1 )
WALBERLA_ASSERT(Stencil::Size == pdfField->fSize(), "Size of stencil and f size of field have to be equal")
stencil::Direction packerDirection = stencil::inverseDir[dir];
......@@ -94,7 +93,11 @@ void StencilRestrictedPackInfo<GhostLayerField_T, Stencil>::communicateLocal( co
const GhostLayerField_T * sf = sender ->getData< GhostLayerField_T >( fieldId_ );
GhostLayerField_T * rf = receiver->getData< GhostLayerField_T >( fieldId_ );
WALBERLA_ASSERT_EQUAL( sf->xyzSize(), rf->xyzSize() );
WALBERLA_ASSERT_EQUAL( sf->xyzSize(), rf->xyzSize() )
WALBERLA_ASSERT(Stencil::Size == sf->fSize(), "Size of stencil and f size of field have to be equal")
WALBERLA_ASSERT(Stencil::Size == rf->fSize(), "Size of stencil and f size of field have to be equal")
typename GhostLayerField_T::const_iterator srcIter = sf->beginSliceBeforeGhostLayerXYZ(dir);
typename GhostLayerField_T::iterator dstIter = rf->beginGhostLayerOnlyXYZ(stencil::inverseDir[dir]);
......@@ -107,8 +110,8 @@ void StencilRestrictedPackInfo<GhostLayerField_T, Stencil>::communicateLocal( co
++srcIter;
++dstIter;
}
WALBERLA_ASSERT( srcIter == sf->end() );
WALBERLA_ASSERT( dstIter == rf->end() );
WALBERLA_ASSERT( srcIter == sf->end() )
WALBERLA_ASSERT( dstIter == rf->end() )
}
......@@ -120,8 +123,9 @@ void StencilRestrictedPackInfo<GhostLayerField_T, Stencil>::packDataImpl( const
return;
const GhostLayerField_T * pdfField = sender->getData< GhostLayerField_T >( fieldId_ );
WALBERLA_ASSERT_NOT_NULLPTR( pdfField );
WALBERLA_ASSERT_EQUAL( pdfField->nrOfGhostLayers(), 1 );
WALBERLA_ASSERT_NOT_NULLPTR( pdfField )
WALBERLA_ASSERT_EQUAL( pdfField->nrOfGhostLayers(), 1 )
WALBERLA_ASSERT(Stencil::Size == pdfField->fSize(), "Size of stencil and f size of field have to be equal")
for( auto i = pdfField->beginSliceBeforeGhostLayerXYZ(dir); i != pdfField->end(); ++i )
for(uint_t f = 0; f < Stencil::d_per_d_length[dir]; ++f)
......
......@@ -31,21 +31,21 @@ namespace field {
template< typename FlagField_T, typename T >
class FlagFieldMapping : public vtk::BlockCellDataWriter<T,1>
class FlagFieldMapping : public vtk::BlockCellDataWriter<T>
{
private:
typedef typename FlagField_T::flag_t flag_t;
public:
FlagFieldMapping( const ConstBlockDataID flagId, const std::string& id ) :
vtk::BlockCellDataWriter<T,1>( id ), flagId_( flagId ), flagField_( NULL ) {}
vtk::BlockCellDataWriter<T>( id, 1 ), flagId_( flagId ), flagField_( NULL ) {}
FlagFieldMapping( const ConstBlockDataID flagId, const std::string& id, const std::map< FlagUID, T > mapping ) :
vtk::BlockCellDataWriter<T,1>( id ), flagId_( flagId ), flagField_( NULL ), mapping_( mapping ) {}
vtk::BlockCellDataWriter<T>( id, 1 ), flagId_( flagId ), flagField_( NULL ), mapping_( mapping ) {}
void addMapping( const FlagUID& flag, const T& value )
{
WALBERLA_ASSERT( mapping_.find( flag ) == mapping_.end() );
WALBERLA_ASSERT( mapping_.find( flag ) == mapping_.end() )
mapping_[ flag ] = value;
}
......@@ -53,7 +53,7 @@ protected:
void configure()
{
WALBERLA_ASSERT_NOT_NULLPTR( this->block_ );
WALBERLA_ASSERT_NOT_NULLPTR( this->block_ )
flagField_ = this->block_->template getData< FlagField_T >( flagId_ );
for( auto mapping = mapping_.begin(); mapping != mapping_.end(); ++mapping )
......@@ -66,7 +66,7 @@ protected:
T evaluate( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const cell_idx_t /*f*/ )
{
WALBERLA_ASSERT_NOT_NULLPTR( flagField_ );
WALBERLA_ASSERT_NOT_NULLPTR( flagField_ )
T result = 0;
for( auto mapping = flagMap_.begin(); mapping != flagMap_.end(); ++mapping )
if( flagField_->isFlagSet( x, y, z, mapping->first ) )
......@@ -84,24 +84,24 @@ protected:
template<typename FieldType, typename TargetType=uint8_t>
class BinarizationFieldWriter : public vtk::BlockCellDataWriter<TargetType,1>
class BinarizationFieldWriter : public vtk::BlockCellDataWriter<TargetType>
{
typedef typename FieldType::value_type SrcType;
public:
BinarizationFieldWriter( const ConstBlockDataID fieldID, const std::string& id, SrcType mask) :
vtk::BlockCellDataWriter<TargetType,1>( id ), fieldID_( fieldID ), field_( NULL ), mask_( mask ) {}
vtk::BlockCellDataWriter<TargetType>( id, 1 ), fieldID_( fieldID ), field_( NULL ), mask_( mask ) {}
protected:
void configure() {
WALBERLA_ASSERT_NOT_NULLPTR( this->block_ );
WALBERLA_ASSERT_NOT_NULLPTR( this->block_ )
field_ = this->block_->template getData< FieldType >( fieldID_ );
}
TargetType evaluate( const cell_idx_t x, const cell_idx_t y, const cell_idx_t z, const cell_idx_t /*f*/ )
{
WALBERLA_ASSERT_NOT_NULLPTR( field_ );
WALBERLA_ASSERT_NOT_NULLPTR( field_ )
if (field_->get(x,y,z) & mask_) {
return TargetType(1);
} else {
......
......@@ -58,59 +58,22 @@ namespace py = pybind11;
//===================================================================================================================
template< typename FieldType >
typename std::enable_if<FieldType::F_SIZE == 27, py::object>::type
createStencilRestrictedPackInfoObject( BlockDataID bdId )
py::object createStencilRestrictedPackInfoObject( BlockDataID bdId, const uint_t fSize )
{
typedef GhostLayerField<typename FieldType::value_type, 27> GlField_T;
typedef GhostLayerField<typename FieldType::value_type> GlField_T;
using field::communication::StencilRestrictedPackInfo;
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q27> >( bdId) );
}
template< typename FieldType >
typename std::enable_if<FieldType::F_SIZE == 19, py::object>::type
createStencilRestrictedPackInfoObject( BlockDataID bdId )
{
typedef GhostLayerField<typename FieldType::value_type, 19> GlField_T;
using field::communication::StencilRestrictedPackInfo;
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q19> >( bdId) );
}
template< typename FieldType >
typename std::enable_if<FieldType::F_SIZE == 15, py::object>::type
createStencilRestrictedPackInfoObject( BlockDataID bdId )
{
typedef GhostLayerField<typename FieldType::value_type, 15> GlField_T;
using field::communication::StencilRestrictedPackInfo;
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q15> >( bdId) );
}
template< typename FieldType >
typename std::enable_if<FieldType::F_SIZE == 7, py::object>::type
createStencilRestrictedPackInfoObject( BlockDataID bdId )
{
typedef GhostLayerField<typename FieldType::value_type, 7> GlField_T;
using field::communication::StencilRestrictedPackInfo;
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q7> >( bdId) );
}
template< typename FieldType >
typename std::enable_if<FieldType::F_SIZE == 9, py::object>::type
createStencilRestrictedPackInfoObject( BlockDataID bdId )
{
typedef GhostLayerField<typename FieldType::value_type, 9> GlField_T;
using field::communication::StencilRestrictedPackInfo;
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D2Q9> >( bdId) );
}
template< typename FieldType >
typename std::enable_if<!(FieldType::F_SIZE == 9 ||
FieldType::F_SIZE == 7 ||
FieldType::F_SIZE == 15 ||
FieldType::F_SIZE == 19 ||
FieldType::F_SIZE == 27), py::object>::type
createStencilRestrictedPackInfoObject( BlockDataID )
{
throw py::value_error("This works only for fields with fSize in 7, 9, 15, 19 or 27");
if (fSize == 27)
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q27> >( bdId) );
else if (fSize == 19)
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q19> >( bdId) );
else if (fSize == 15)
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q15> >( bdId) );
else if (fSize == 9)
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D2Q9> >( bdId) );
else if (fSize == 7)
return py::cast( make_shared< StencilRestrictedPackInfo<GlField_T, stencil::D3Q7> >( bdId) );
else
throw py::value_error("This works only for fields with fSize in 7, 9, 15, 19 or 27");
}
class StencilRestrictedPackInfoExporter
......@@ -124,12 +87,18 @@ class StencilRestrictedPackInfoExporter
void operator() ( python_coupling::NonCopyableWrap<FieldType> )
{
typedef typename FieldType::value_type T;
const uint_t F_SIZE = FieldType::F_SIZE;
typedef GhostLayerField<T, F_SIZE> GlField_T;
typedef GhostLayerField<T> GlField_T;
IBlock * firstBlock = & ( * blocks_->begin() );
if( firstBlock->isDataClassOrSubclassOf<FieldType>(fieldId_) )
{
resultStencilRestrictedPackInfo_ = createStencilRestrictedPackInfoObject<GlField_T>(fieldId_);
// TODO: is there a better way to get the fSize from the BlockForest?
// Maybe implement something like: uint_t fSize = block->template getFSize<Field_T> (fieldID)?
const uint_t fSize = firstBlock->getData< FieldType >(fieldId_)->fSize();
if (!(fSize == 7 || fSize == 9 || fSize == 15 || fSize == 19 || fSize == 27))
{
throw py::value_error("This works only for fields with fSize in 7, 9, 15, 19 or 27");
}
resultStencilRestrictedPackInfo_ = createStencilRestrictedPackInfoObject<GlField_T>(fieldId_, fSize);
}
}
py::object getResultStencilRestrictedPackInfo()
......@@ -151,7 +120,7 @@ static py::object StencilRestrictedPackInfoWrapper(const shared_ptr<StructuredBl
if ( blocks->begin() == blocks->end() ) {
// if no blocks are on this field an arbitrary PackInfo can be returned
return py::cast( make_shared< field::communication::StencilRestrictedPackInfo<GhostLayerField<real_t, 9>, stencil::D2Q9> >( fieldID ) );
return py::cast( make_shared< field::communication::StencilRestrictedPackInfo<GhostLayerField<real_t>, stencil::D2Q9> >( fieldID ) );
}
StencilRestrictedPackInfoExporter exporter(blocks, fieldID);
......@@ -181,8 +150,7 @@ class PackInfoExporter
void operator() ( python_coupling::NonCopyableWrap<FieldType> )
{
typedef typename FieldType::value_type T;
const uint_t F_SIZE = FieldType::F_SIZE;
typedef GhostLayerField<T, F_SIZE> GlField_T;
typedef GhostLayerField<T> GlField_T;
IBlock * firstBlock = & ( * blocks_->begin() );
if( firstBlock->isDataClassOrSubclassOf<FieldType>(fieldId_) )
{
......@@ -217,7 +185,7 @@ static py::object PackInfoWrapper(const shared_ptr<StructuredBlockForest> & bloc
if ( blocks->begin() == blocks->end() ) {
// if no blocks are on this field an arbitrary PackInfo can be returned
return py::cast( make_shared< field::communication::PackInfo<GhostLayerField<real_t,1>> >( fieldID, numberOfGhostLayers ) );
return py::cast( make_shared< field::communication::PackInfo<GhostLayerField<real_t>> >( fieldID, numberOfGhostLayers ) );
}
PackInfoExporter exporter(blocks, fieldID, numberOfGhostLayers);
......@@ -247,8 +215,7 @@ class UniformMPIDatatypeInfoExporter
void operator() ( python_coupling::NonCopyableWrap<FieldType> )
{
typedef typename FieldType::value_type T;
const uint_t F_SIZE = FieldType::F_SIZE;
typedef GhostLayerField<T, F_SIZE> GlField_T;
typedef GhostLayerField<T> GlField_T;
IBlock * firstBlock = & ( * blocks_->begin() );
if( firstBlock->isDataClassOrSubclassOf<FieldType>(fieldId_) )
{
......@@ -280,7 +247,7 @@ static py::object UniformMPIDatatypeInfoWrapper(const shared_ptr<StructuredBlock
if ( blocks->begin() == blocks->end() ) {
// if no blocks are on this field an arbitrary PackInfo can be returned
return py::cast( make_shared< field::communication::UniformMPIDatatypeInfo<GhostLayerField<real_t,1>> >( fieldID, numberOfGhostLayers ) );
return py::cast( make_shared< field::communication::UniformMPIDatatypeInfo<GhostLayerField<real_t>> >( fieldID, numberOfGhostLayers ) );
}
UniformMPIDatatypeInfoExporter exporter(blocks, fieldID, numberOfGhostLayers);
......@@ -304,25 +271,25 @@ void exportStencilRestrictedPackInfo(py::module_& m)
{
using field::communication::StencilRestrictedPackInfo;
{
typedef StencilRestrictedPackInfo< GhostLayerField< T, 9 >, stencil::D2Q9 > Pi;
typedef StencilRestrictedPackInfo< GhostLayerField< T >, stencil::D2Q9 > Pi;
py::class_< Pi, shared_ptr< Pi >, walberla::communication::UniformPackInfo >(m, "StencilRestrictedPackInfo_D2Q9");
}
{
typedef StencilRestrictedPackInfo< GhostLayerField< T, 7 >, stencil::D3Q7 > Pi;
typedef StencilRestrictedPackInfo< GhostLayerField< T >, stencil::D3Q7 > Pi;
py::class_< Pi, shared_ptr< Pi >, walberla::communication::UniformPackInfo >(m, "StencilRestrictedPackInfo_D3Q7");
}
{
typedef StencilRestrictedPackInfo< GhostLayerField< T, 15 >, stencil::D3Q15 > Pi;
typedef StencilRestrictedPackInfo< GhostLayerField< T >, stencil::D3Q15 > Pi;
py::class_< Pi, shared_ptr< Pi >, walberla::communication::UniformPackInfo >(m,
"StencilRestrictedPackInfo_D3Q15");
}
{
typedef StencilRestrictedPackInfo< GhostLayerField< T, 19 >, stencil::D3Q19 > Pi;
typedef StencilRestrictedPackInfo< GhostLayerField< T >, stencil::D3Q19 > Pi;
py::class_< Pi, shared_ptr< Pi >, walberla::communication::UniformPackInfo >(m,
"StencilRestrictedPackInfo_D3Q19");
}
{
typedef StencilRestrictedPackInfo< GhostLayerField< T, 27 >, stencil::D3Q27 > Pi;
typedef StencilRestrictedPackInfo< GhostLayerField< T >, stencil::D3Q27 > Pi;
py::class_< Pi, shared_ptr< Pi >, walberla::communication::UniformPackInfo >(m,
"StencilRestrictedPackInfo_D3Q27");
}
......
......@@ -123,9 +123,9 @@ class GhostLayerFieldDataHandling : public field::BlockDataHandling< GhostLayerF
public:
typedef typename GhostLayerField_T::value_type Value_T;
GhostLayerFieldDataHandling(const weak_ptr< StructuredBlockStorage >& blocks, const uint_t nrOfGhostLayers,
GhostLayerFieldDataHandling(const weak_ptr< StructuredBlockStorage >& blocks, const uint_t fSize, const uint_t nrOfGhostLayers,
const Value_T& initValue, const Layout layout, uint_t alignment = 0)
: blocks_(blocks), nrOfGhostLayers_(nrOfGhostLayers), initValue_(initValue), layout_(layout),
: blocks_(blocks), fSize_(fSize), nrOfGhostLayers_(nrOfGhostLayers), initValue_(initValue), layout_(layout),
alignment_(alignment)
{}
......@@ -135,7 +135,7 @@ class GhostLayerFieldDataHandling : public field::BlockDataHandling< GhostLayerF
WALBERLA_CHECK_NOT_NULLPTR(blocks, "Trying to access 'AlwaysInitializeBlockDataHandling' for a block "
"storage object that doesn't exist anymore");
GhostLayerField_T* field = new GhostLayerField_T(
blocks->getNumberOfXCells(*block), blocks->getNumberOfYCells(*block), blocks->getNumberOfZCells(*block),
blocks->getNumberOfXCells(*block), blocks->getNumberOfYCells(*block), blocks->getNumberOfZCells(*block), fSize_,
nrOfGhostLayers_, initValue_, layout_, getAllocator< Value_T >(alignment_));
return field;
}
......@@ -145,6 +145,7 @@ class GhostLayerFieldDataHandling : public field::BlockDataHandling< GhostLayerF
private:
weak_ptr< StructuredBlockStorage > blocks_;
uint_t fSize_;
uint_t nrOfGhostLayers_;
Value_T initValue_;
Layout layout_;
......@@ -207,14 +208,14 @@ void field_swapDataPointers(Field_T& f1, Field_T& f2)
template< typename Field_T >
py::object copyAdaptorToField(const Field_T& f)
{
typedef GhostLayerField< typename Field_T::value_type, Field_T::F_SIZE > ResField;
auto res = make_shared< ResField >(f.xSize(), f.ySize(), f.zSize(), f.nrOfGhostLayers());
typedef GhostLayerField< typename Field_T::value_type > ResField;
auto res = make_shared< ResField >(f.xSize(), f.ySize(), f.zSize(), f.fSize(), f.nrOfGhostLayers());
auto srcIt = f.beginWithGhostLayerXYZ();
auto dstIt = res->beginWithGhostLayerXYZ();
while (srcIt != f.end())
{
for (cell_idx_t fCoord = 0; fCoord < cell_idx_c(Field_T::F_SIZE); ++fCoord)
for (cell_idx_t fCoord = 0; fCoord < cell_idx_c(f.fSize()); ++fCoord)
dstIt.getF(fCoord) = srcIt.getF(fCoord);
++srcIt;
......@@ -287,13 +288,12 @@ struct FieldExporter
void operator()(python_coupling::NonCopyableWrap< FieldType >) const
{
typedef typename FieldType::value_type T;
const uint_t F_SIZE = FieldType::F_SIZE;
typedef GhostLayerField< T, F_SIZE > GlField_T;
typedef Field< T, F_SIZE > Field_T;
typedef GhostLayerField< T > GlField_T;
typedef Field< T > Field_T;
std::string data_type_name = PythonFormatString<T>::get();
std::string class_name = "Field_" + data_type_name + "_" + std::to_string(FieldType::F_SIZE);
std::string class_name = "Field_" + data_type_name;
py::class_< Field_T, shared_ptr< Field_T > >(m_, class_name.c_str())
.def_property_readonly("layout", &field_layout< Field_T >)
......@@ -314,7 +314,7 @@ struct FieldExporter
.def("__array__", &toNumpyArray< Field_T >);
std::string class_nameGL =
"GhostLayerField_" + data_type_name + "_" + std::to_string(FieldType::F_SIZE);
"GhostLayerField_" + data_type_name;
py::class_< GlField_T, shared_ptr< GlField_T >, Field_T >(m_, class_nameGL.c_str())
.def_property_readonly("sizeWithGhostLayer", &GlField_T::xSizeWithGhostLayer)
......@@ -322,11 +322,11 @@ struct FieldExporter
.def("__array__", &toNumpyArrayWithGhostLayers< GlField_T >);
using field::communication::PackInfo;
std::string FieldPackInfo_name = "FieldPackInfo_" + data_type_name + "_" + std::to_string(FieldType::F_SIZE);
std::string FieldPackInfo_name = "FieldPackInfo_" + data_type_name;
py::class_< PackInfo< GlField_T >, shared_ptr< PackInfo< GlField_T > >, walberla::communication::UniformPackInfo >(m_, FieldPackInfo_name.c_str());
using field::communication::UniformMPIDatatypeInfo;
std::string FieldMPIDataTypeInfo_name = "FieldMPIDataTypeInfo_" + data_type_name + "_" + std::to_string(FieldType::F_SIZE);
std::string FieldMPIDataTypeInfo_name = "FieldMPIDataTypeInfo_" + data_type_name;
py::class_< UniformMPIDatatypeInfo< GlField_T >, shared_ptr< UniformMPIDatatypeInfo< GlField_T > >, walberla::communication::UniformMPIDatatypeInfo >(
m_, FieldMPIDataTypeInfo_name.c_str());
}
......@@ -368,13 +368,11 @@ class AddToStorageExporter
{
using namespace py;
typedef typename FieldType::value_type T;
const uint_t F_SIZE = FieldType::F_SIZE;
if (F_SIZE != fs_) return;
if(python_coupling::isCppEqualToPythonType<T>(py::cast<std::string>(dtype_.attr("__name__"))))
{
typedef internal::GhostLayerFieldDataHandling< GhostLayerField< T, F_SIZE > > DataHandling;
auto dataHandling = walberla::make_shared< DataHandling >(blocks_, gl_, initValue_, layout_, alignment_);
typedef internal::GhostLayerFieldDataHandling< GhostLayerField< T > > DataHandling;
auto dataHandling = walberla::make_shared< DataHandling >(blocks_, fs_, gl_, initValue_, layout_,