Commit 2754a384 authored by Markus Holzer's avatar Markus Holzer
Browse files

Implement varadic templates

parent dfb0d9c9
Pipeline #38585 failed with stages
in 8 minutes and 24 seconds
......@@ -5,7 +5,7 @@ mark_as_advanced( WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID )
configure_file( CMakeDefs.in.h CMakeDefs.h )
add_library( blockforest ../../tests/timeloop/TimeloopSweepManagementTest.cpp)
add_library( blockforest ../../tests/timeloop/TimeloopSweepManagementTest.cpp ../../tests/field/FieldTestWithTemplatedFSize.cpp)
target_link_libraries( blockforest PUBLIC communication core domain_decomposition stencil )
target_sources( blockforest
PRIVATE
......
......@@ -63,8 +63,11 @@ namespace field {
* See also \ref fieldPage
*/
//*******************************************************************************************************************
template<typename T, uint_t... fSize_>
class Field {};
template<typename T>
class Field
class Field<T>
{
public:
......@@ -376,7 +379,7 @@ namespace field {
friend class FieldIterator<T>;
friend class FieldIterator<const T>;
template <typename T2>
template <typename T2, uint_t... fSize2>
friend class Field;
#ifdef WALBERLA_FIELD_MONITORED_ACCESS
......@@ -386,6 +389,39 @@ namespace field {
}; // class Field
template<typename T, uint_t fSize_>
class Field<T, fSize_> : public Field<T> {
public:
Field(Field<T> field)
: Field<T>::Field(field)
{}
typedef typename std::conditional<VectorTrait<T>::F_SIZE!=0,
Field<typename VectorTrait<T>::OutputType, VectorTrait<T>::F_SIZE*fSize_>,
Field<T, fSize_>>::type FlattenedField;
template<typename ...Args>
Field(uint_t xSize, uint_t ySize, uint_t zSize, Args&&... args)
: Field<T>::Field(xSize, ySize, zSize, fSize_, std::forward<Args>(args)...)
{}
template<typename ...Args>
void init(uint_t xSize, uint_t ySize, uint_t zSize, Args&&... args)
{
Field<T>::init(xSize, ySize, zSize, fSize_, std::forward<Args>(args)...);
}
template<typename ...Args>
void resize(uint_t xSize, uint_t ySize, uint_t zSize)
{
Field<T>::resize(xSize, ySize, zSize, fSize_);
}
};
} // namespace field
} // namespace walberla
......
......@@ -48,8 +48,12 @@ namespace field
*
*/
//*******************************************************************************************************************
template< typename T >
class GhostLayerField : public Field< T >
template<typename T, uint_t... fSize_>
class GhostLayerField : public Field<T, fSize_...>{};
template<typename T>
class GhostLayerField<T> : public Field<T>
{
public:
//** Type Definitions *******************************************************************************************
......@@ -202,18 +206,56 @@ class GhostLayerField : public Field< T >
//** Shallow Copy ************************************************************************************************
/*! \name Shallow Copy */
//@{
Field< T >* cloneShallowCopyInternal() const override;
typename Field< T >::FlattenedField* flattenedShallowCopyInternal() const override;
GhostLayerField(const GhostLayerField< T >& other);
template< typename T2 >
GhostLayerField(const GhostLayerField< T2 >& other);
Field<T> * cloneShallowCopyInternal() const override;
typename Field<T>::FlattenedField * flattenedShallowCopyInternal() const override;
GhostLayerField(const GhostLayerField<T> & other);
template <typename T2>
GhostLayerField<T>(const GhostLayerField<T2> & other);
//@}
//****************************************************************************************************************
template< typename T2 >
template <typename T2, uint_t... fSize2>
friend class GhostLayerField;
};
#ifdef WALBERLA_CXX_COMPILER_IS_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#endif
template<typename T, uint_t fSize_>
class GhostLayerField<T, fSize_> : public GhostLayerField<T> {
public:
GhostLayerField(GhostLayerField<T> field)
: GhostLayerField<T>::GhostLayerField(field)
{}
typedef typename std::conditional<VectorTrait<T>::F_SIZE!=0,
GhostLayerField<typename VectorTrait<T>::OutputType, VectorTrait<T>::F_SIZE*fSize_>,
GhostLayerField<T, fSize_>>::type FlattenedField;
template<typename ...Args>
GhostLayerField(uint_t xSize, uint_t ySize, uint_t zSize, Args&&... args)
: GhostLayerField<T>::GhostLayerField(xSize, ySize, zSize, fSize_, std::forward<Args>(args)...)
{}
template<typename ...Args>
void init(uint_t xSize, uint_t ySize, uint_t zSize, Args&&... args)
{
GhostLayerField<T>::init(xSize, ySize, zSize, fSize_, std::forward<Args>(args)...);
}
template<typename ...Args>
void resize(uint_t xSize, uint_t ySize, uint_t zSize)
{
GhostLayerField<T>::resize(xSize, ySize, zSize, fSize_);
}
};
#ifdef WALBERLA_CXX_COMPILER_IS_CLANG
#pragma clang diagnostic pop
#endif
} // namespace field
} // namespace walberla
......
......@@ -38,7 +38,7 @@ namespace walberla {
namespace field {
template<typename T> class Field; // forward for friend declaration
template<typename T, uint_t... fSize_> class Field; // forward for friend declaration
......@@ -80,7 +80,7 @@ namespace field {
//** Copy Operations *********************************************************************************************
/*!\name Copy Operations */
//@{
FieldIterator ( const FieldIterator<T> & other );
FieldIterator ( const FieldIterator<T> & other );
FieldIterator<T>& operator=( const FieldIterator<T> & other );
//@}
//****************************************************************************************************************
......
......@@ -19,6 +19,9 @@ waLBerla_execute_test( NAME DistributionTest )
waLBerla_compile_test( FILES FieldTest.cpp )
waLBerla_execute_test( NAME FieldTest )
waLBerla_compile_test( FILES FieldTestWithTemplatedFSize.cpp )
waLBerla_execute_test( NAME FieldTestWithTemplatedFSize )
waLBerla_compile_test( FILES FieldOfCustomTypesTest.cpp )
waLBerla_execute_test( NAME FieldOfCustomTypesTest )
......
......@@ -15,6 +15,7 @@
//
//! \file FieldTest.cpp
//! \ingroup field
//! \author Markus Holzer <markus.holzer@fau.de>
//! \author Martin Bauer <martin.bauer@fau.de>
//! \brief Tests basic functionality of Field and GhostLayerField
//
......
This diff is collapsed.
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