Commit 1e596bf3 authored by Marcus Mohr's avatar Marcus Mohr
Browse files

Reworks numberOfLocal/GlobalDoFs for Block/GenericFunction

We now treat the special case of having a BlockFunction or GenericFunction
in the templated function numberOfLocal/GlobalDoFs directly using a
constexpr-if. Makes it much easier for the compiler, which otherwise
sometimes had problems finding the correct variant.

For this to work BlockFunction::ValueType was renamed to
BlockFunction::valueType like in the other functions and a similar
typedef was added to GenericFunction.
parent ea620af6
Pipeline #34453 failed with stages
in 88 minutes and 33 seconds
......@@ -39,7 +39,7 @@ template < typename value_t >
class BlockFunction
{
public:
typedef value_t ValueType;
typedef value_t valueType;
template < typename VType >
using FunctionType = BlockFunction< VType >;
......@@ -267,11 +267,11 @@ class BlockFunction
std::vector< uint_t > doFsPerRank = walberla::mpi::allGather( counterDoFs );
ValueType offset = 0;
valueType offset = 0;
for ( uint_t i = 0; i < uint_c( walberla::MPIManager::instance()->rank() ); ++i )
{
offset += static_cast< ValueType >( doFsPerRank[i] );
offset += static_cast< valueType >( doFsPerRank[i] );
}
for ( uint_t k = 0; k < subFunc_.size(); k++ )
......@@ -296,22 +296,4 @@ class BlockFunction
}
};
// Special version of numberOfLocalDoFs for BlockFunctions
template < typename value_t >
inline uint_t numberOfLocalDoFs( const BlockFunction< value_t >& func, const uint_t& level )
{
return func.getNumberOfLocalDoFs( level );
}
// Special version of numberOfGlobalDoFs for BlockFunctions
template < typename value_t >
inline uint_t numberOfGlobalDoFs( const BlockFunction< value_t >& func,
const uint_t& level,
const MPI_Comm& communicator = walberla::mpi::MPIManager::instance()->comm(),
const bool& onRootOnly = false )
{
return func.getNumberOfGlobalDoFs( level, communicator, onRootOnly );
}
} // namespace hyteg
......@@ -30,6 +30,10 @@ using walberla::real_c;
using walberla::real_t;
using namespace walberla::mpistubs;
// some forward declarations
template < typename value_t > class BlockFunction;
template < typename value_t > class GenericFunction;
template < typename FunctionTag_T, typename PrimitiveType >
inline uint_t numberOfInnerDoFs( const uint_t& level );
......@@ -186,7 +190,15 @@ inline uint_t numberOfLocalDoFs< P2P2StokesFunctionTag >( const PrimitiveStorage
template < typename func_t >
inline uint_t numberOfLocalDoFs( const func_t& func, const uint_t& level )
{
return numberOfLocalDoFs< typename func_t::Tag >( *( func.getStorage() ), level );
if constexpr ( std::is_base_of< BlockFunction< typename func_t::valueType >, func_t >::value ||
std::is_same< GenericFunction< typename func_t::valueType >, func_t >::value )
{
return func.getNumberOfLocalDoFs( level );
}
else
{
return numberOfLocalDoFs< typename func_t::Tag >( *( func.getStorage() ), level );
}
}
template < typename FunctionTag_T >
......@@ -214,7 +226,15 @@ inline uint_t numberOfGlobalDoFs( const func_t& func,
const MPI_Comm& communicator = walberla::mpi::MPIManager::instance()->comm(),
const bool& onRootOnly = false )
{
return numberOfGlobalDoFs< typename func_t::Tag >( *( func.getStorage() ), level, communicator, onRootOnly );
if constexpr ( std::is_base_of< BlockFunction< typename func_t::valueType >, func_t >::value ||
std::is_same< GenericFunction< typename func_t::valueType >, func_t >::value )
{
return func.getNumberOfGlobalDoFs( level, communicator, onRootOnly );
}
else
{
return numberOfGlobalDoFs< typename func_t::Tag >( *( func.getStorage() ), level, communicator, onRootOnly );
}
}
template < typename FunctionTag_T >
......
......@@ -42,6 +42,8 @@ class GenericFunction
public:
virtual ~GenericFunction(){};
typedef value_t valueType;
template < typename func_t >
func_t& unwrap()
{
......@@ -148,21 +150,4 @@ class GenericFunction
#endif
};
// Special version of numberOfLocalDoFs for GenericFunctions
template < typename value_t >
inline uint_t numberOfLocalDoFs( const GenericFunction< value_t >& func, const uint_t& level )
{
return func.getNumberOfLocalDoFs( level );
}
// Special version of numberOfLocalDoFs for GenericFunctions
template < typename value_t >
inline uint_t numberOfGlobalDoFs( const GenericFunction< value_t >& func,
const uint_t& level,
const MPI_Comm& communicator = walberla::mpi::MPIManager::instance()->comm(),
const bool& onRootOnly = false )
{
return func.getNumberOfGlobalDoFs( level, communicator, onRootOnly );
}
} // namespace hyteg
......@@ -36,11 +36,11 @@ using walberla::real_t;
template < class srcBlockFunc_t, class dstBlockFunc_t >
class BlockOperator : public Operator< srcBlockFunc_t, dstBlockFunc_t >,
public GSSmoothable< srcBlockFunc_t >,
public GSSmoothable< GenericFunction< typename srcBlockFunc_t::ValueType > >
public GSSmoothable< GenericFunction< typename srcBlockFunc_t::valueType > >
{
public:
// temporary, need to add corresponding FunctionTrait?
typedef typename srcBlockFunc_t::ValueType value_t;
typedef typename srcBlockFunc_t::valueType value_t;
BlockOperator( const std::shared_ptr< PrimitiveStorage >& storage,
size_t minLevel,
......
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