Commit 11449739 authored by Marcus Mohr's avatar Marcus Mohr
Browse files

Add numberOfLocalDoFs() for Generic- and BlockFunctions

Our usual tag-based approach to the numberOfLocalDoFs() free functions
cannot work with Generic- and BlockFunctions, as for those we need an
object instance of the class to determine that value.

In order to remain somewhat compatible with the current approach this
commit adds a version of numberOfLocalDoFs() that takes as input a
function object. For our standard function classes work is then delegated
to the existing free functions by determining the function tag. For the
Generic- and BlockFunction we have special implementations that call
their getNumberOfLocalDoFs() member function.

For the case of the GenericFunction this member function is implemented
by this commit. As usual it is purely virtual and the actual implementation
happens in the FunctionWrapper class.

We use this new function variant in the construction of PETScVector for
testing and as this is where we will need it when converting
GenericFunction objects to PETScVector objects.

Additionally this commit implements enumerate() without an offset in
GenericFunction and FunctionWrapper.
parent 0aa1b95e
Pipeline #33767 passed with stages
in 109 minutes and 36 seconds
......@@ -305,4 +305,11 @@ class BlockFunction
};
// Special version of numberOfLocalDoFs for GenericFunctions
template < typename value_t >
inline uint_t numberOfLocalDoFs( const BlockFunction< value_t >& func, const uint_t& level )
{
return func.getNumberOfLocalDoFs( level );
}
} // namespace hyteg
......@@ -182,6 +182,13 @@ inline uint_t numberOfLocalDoFs< P2P2StokesFunctionTag >( const PrimitiveStorage
return ( primitiveStorage.hasGlobalCells() ? 4 : 3 ) * numberOfLocalDoFs< P2FunctionTag >( primitiveStorage, level );
}
/// variant of numberOfLocalDoFs that works on a function object
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 );
}
template < typename FunctionTag_T >
inline uint_t numberOfGlobalDoFs( const PrimitiveStorage& primitiveStorage,
const uint_t& level,
......
......@@ -156,8 +156,15 @@ class FunctionWrapper final : public GenericFunction< typename FunctionTrait< fu
wrappedFunc_->copyFrom( other.template unwrap< func_t >(), level, localPrimitiveIDsToRank, otherPrimitiveIDsToRank );
};
void enumerate( uint_t level ) const { wrappedFunc_->enumerate( level ); };
void enumerate( uint_t level, value_t& offset ) const { wrappedFunc_->enumerate( level, offset ); };
uint_t getNumberOfLocalDoFs( uint_t level ) const
{
return numberOfLocalDoFs< typename FunctionType::Tag >( *( getStorage() ), level );
}
private:
std::unique_ptr< func_t > wrappedFunc_;
};
......
......@@ -69,6 +69,8 @@ class GenericFunction
virtual functionTraits::FunctionKind getFunctionKind() const = 0;
virtual uint_t getNumberOfLocalDoFs( uint_t level ) const = 0;
virtual std::shared_ptr< PrimitiveStorage > getStorage() const = 0;
virtual void multElementwise( const std::vector< std::reference_wrapper< const GenericFunction< value_t > > >& functions,
......@@ -120,7 +122,16 @@ class GenericFunction
this->setBoundaryCondition( other.getBoundaryCondition() );
};
virtual void enumerate( uint_t level ) const = 0;
virtual void enumerate( uint_t level, value_t& offset ) const = 0;
};
// 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 );
}
} // namespace hyteg
......@@ -49,9 +49,7 @@ class PETScVector
const DoFType& flag = All,
const std::string& name = "Vec",
const MPI_Comm& petscCommunicator = walberla::mpi::MPIManager::instance()->comm() )
: PETScVector( numberOfLocalDoFs< typename FunctionType< ValueType >::Tag >( *function.getStorage(), level ),
name,
petscCommunicator )
: PETScVector( numberOfLocalDoFs( function, level ), name, petscCommunicator )
{
createVectorFromFunction( function, numerator, level, flag );
}
......
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