walberla::timeloop::SweepTimeloop< TP > Class Template Reference

Detailed Description

template<typename TP = timing::WcPolicy>
class walberla::timeloop::SweepTimeloop< TP >

Timeloop that runs a collection of sweeps.

A Sweep is defined as an operation that processes a single block, i.e. a function "void sweepFunc ( IBlock * )" A sweep is usually some numeric kernel, for example a LBM Stream-Collide step. For all sweeps Before- and AfterFunctions can be registered. This are void(void) functions that are run before or after the sweep. Here one can register functions that have a close relation to the sweep, for example communication steps that are necessary before the sweep can run.

The SweepTimeloop supports the Selectable concept, so that the execution of sweeps can depend on the current uid::globalState(), together with the current block state. This mechanism makes the registration of Sweeps somewhat complex.

Simple Registration

When registering sweeps (even without Selectable concept) the syntax may seem a little strange. Lets do an example where we register simple C functions as sweeps:

// The callback functions
void mySweep ( IBlock * ) { ... }
void myBeforeFunction () { ... }
void myAfterFunction () { ... }
SweepTimeloop timeloop;
timeloop.add() << BeforeFunction( & myBeforeFunction, "MyBeforeFunction")
<< Sweep ( & mySweep, "MySweep" )
<< AfterFunction ( & myAfterFunction, "MyAfterFunction );

So we do not pass the parameters directly to add(), but add() returns an object, where the different functions can be piped in. The BeforeFunction, Sweep and AfterFunction take additional selector arguments, so multiple of them can be piped into one sweep, as long a unique sweep can be determined using the selectors.

Instead of registering plain C functions, it is usually a good idea to use functors as sweeps, since they can have additional data. Be aware that the state of such functor sweeps is the same for all blocks. To store data per block register it as BlockData or use SweepOnBlock:

Sweeps on Block

Sometimes a sweep functor class needs to store data per block, not per process ( which is the default ). The solution in this case would be, to put this data into a separate data structure and register that as BlockData. The alternative is to register the sweep class itself as BlockData, whereas the actual sweep function (which is the same for all blocks ) then only consists of fetching the sweep class and executing it. This second solution is used by SweepOnBlock:

The starting point is a class, that has members which should be placed block local:

class MyLBMClass {
public:
MyLBMClass( real_t omega, PdfField * pdfField );
private:
Type someBlockLocalData;
};

The second step is to write a so called creator class, which acts as the interface between the waLBerla block data mechanism and your data. It basically is the initialization function for the blockdata:

struct MyLBMClassCreator {
MyLBMClassCreator( BlockDataID pdfFieldID ): pdfFieldID_(pdfFieldID) {}
MyLBMClass * operator() ( IBlock * const block ) {
return new MyLBMClass( block->getData<PdfField>( pdfFieldID_ ) );
}
private:
BlockDataID pdfFieldID_
}

This is then registered like this:

timeloop.add() << SweepOnBlock<MyLBMClass>( MyLBMClassCreator(pdfFieldID) );

#include <SweepTimeloop.h>

+ Inheritance diagram for walberla::timeloop::SweepTimeloop< TP >:

Public Member Functions

Constructor & Destructor
 SweepTimeloop (BlockStorage &blockStorage, uint_t nrOfTimeSteps)
 
 SweepTimeloop (const shared_ptr< StructuredBlockStorage > &structuredBlockStorage, uint_t nrOfTimeSteps)
 
 ~SweepTimeloop () override
 
- Public Member Functions inherited from walberla::timeloop::Timeloop< timing::WcPolicy >
 Timeloop (uint_t nrOfTimeSteps)
 
 ~Timeloop () override=default
 
void run () override
 
void run (const bool logTimeStep)
 
void run (timing::TimingPool< timing::WcPolicy > &timing, const bool logTimeStep=true)
 
void singleStep () override
 
void singleStep (const bool logTimeStep)
 
void singleStep (timing::TimingPool< timing::WcPolicy > &timing, const bool logTimeStep=true)
 
void stop () override
 Stops the timeloop, has to be called on every process. More...
 
void synchronizedStop (bool stop) override
 Similar to stop - useful if the stop signal is only known on a single process. More...
 
void setCurrentTimeStepToZero ()
 
void setCurrentTimeStep (uint_t ts) override
 
FctHandle addFuncBeforeTimeStep (const VoidFctNoArguments &f, const std::string &identifier=std::string(), const Set< SUID > &require=Set< SUID >::emptySet(), const Set< SUID > &incompatible=Set< SUID >::emptySet())
 
void addFuncBeforeTimeStep (const FctHandle &fctToBindTo, const VoidFctNoArguments &f, const std::string &identifier=std::string(), const Set< SUID > &require=Set< SUID >::emptySet(), const Set< SUID > &incompatible=Set< SUID >::emptySet())
 
FctHandle addFuncAfterTimeStep (const VoidFctNoArguments &f, const std::string &identifier=std::string(), const Set< SUID > &require=Set< SUID >::emptySet(), const Set< SUID > &exludingSelector=Set< SUID >::emptySet())
 
void addFuncAfterTimeStep (const FctHandle &fctToBindTo, const VoidFctNoArguments &f, const std::string &identifier=std::string(), const Set< SUID > &require=Set< SUID >::emptySet(), const Set< SUID > &incompatible=Set< SUID >::emptySet())
 
uint_t getCurrentTimeStep () const override
 
uint_t getNrOfTimeSteps () const override
 
- Public Member Functions inherited from walberla::timeloop::ITimeloop
virtual ~ITimeloop ()=default
 
virtual uint_t getCurrentTimeStep () const =0
 
virtual uint_t getNrOfTimeSteps () const =0
 

Registering of Sweeps and Before/After Functions

BlockStorageblockStorage_
 
uint_t nextId_
 
std::vector< uint_tsweepsToDelete_
 
std::map< uint_t, SweepAdder * > sweeps_
 
bool firstRun_
 required to register timer in doTimeStep( selectors, timingPool) More...
 
SweepAdderadd ()
 
void remove (SweepAdder &sweep)
 
void removeForDeletionMarkedSweeps ()
 
void doTimeStep (const Set< SUID > &selectors) override
 
void doTimeStep (const Set< SUID > &selectors, timing::TimingPool< TP > &tp) override
 

Additional Inherited Members

- Public Types inherited from walberla::timeloop::Timeloop< timing::WcPolicy >
using FctHandle = size_t
 
- Protected Types inherited from walberla::timeloop::Timeloop< timing::WcPolicy >
using SelectableFunc = selectable::SetSelectableObject< VoidFctNoArguments, SUID >
 
- Protected Member Functions inherited from walberla::timeloop::Timeloop< timing::WcPolicy >
virtual void doTimeStep (const Set< SUID > &selectors, timing::TimingPool< timing::WcPolicy > &timing)=0
 
void executeSelectable (const selectable::SetSelectableObject< VoidFctNoArguments, SUID > &selectable, const Set< SUID > &selector, const std::string &what)
 
void executeSelectable (const selectable::SetSelectableObject< VoidFctNoArguments, SUID > &selectable, const Set< SUID > &selector, const std::string &what, timing::TimingPool< timing::WcPolicy > &tp)
 
- Protected Attributes inherited from walberla::timeloop::Timeloop< timing::WcPolicy >
uint_t curTimeStep_
 current time step More...
 
uint_t nrOfTimeSteps_
 total number of time steps More...
 
std::vector< SelectableFuncbeforeFunctions_
 
std::vector< SelectableFuncafterFunctions_
 
bool stop_
 

Constructor & Destructor Documentation

◆ SweepTimeloop() [1/2]

template<typename TP = timing::WcPolicy>
walberla::timeloop::SweepTimeloop< TP >::SweepTimeloop ( BlockStorage blockStorage,
uint_t  nrOfTimeSteps 
)
inline

◆ SweepTimeloop() [2/2]

template<typename TP = timing::WcPolicy>
walberla::timeloop::SweepTimeloop< TP >::SweepTimeloop ( const shared_ptr< StructuredBlockStorage > &  structuredBlockStorage,
uint_t  nrOfTimeSteps 
)
inline

◆ ~SweepTimeloop()

template<typename TP = timing::WcPolicy>
walberla::timeloop::SweepTimeloop< TP >::~SweepTimeloop ( )
inlineoverride

Member Function Documentation

◆ add()

template<typename TP = timing::WcPolicy>
SweepAdder& walberla::timeloop::SweepTimeloop< TP >::add ( )
inline

◆ doTimeStep() [1/2]

template<typename TP >
void walberla::timeloop::SweepTimeloop< TP >::doTimeStep ( const Set< SUID > &  selectors)
overrideprotectedvirtual

◆ doTimeStep() [2/2]

template<typename TP >
void walberla::timeloop::SweepTimeloop< TP >::doTimeStep ( const Set< SUID > &  selectors,
timing::TimingPool< TP > &  tp 
)
overrideprotected

◆ remove()

template<typename TP = timing::WcPolicy>
void walberla::timeloop::SweepTimeloop< TP >::remove ( SweepAdder sweep)
inline

◆ removeForDeletionMarkedSweeps()

template<typename TP = timing::WcPolicy>
void walberla::timeloop::SweepTimeloop< TP >::removeForDeletionMarkedSweeps ( )
inlineprotected

Member Data Documentation

◆ blockStorage_

template<typename TP = timing::WcPolicy>
BlockStorage& walberla::timeloop::SweepTimeloop< TP >::blockStorage_
protected

◆ firstRun_

template<typename TP = timing::WcPolicy>
bool walberla::timeloop::SweepTimeloop< TP >::firstRun_
protected

required to register timer in doTimeStep( selectors, timingPool)

◆ nextId_

template<typename TP = timing::WcPolicy>
uint_t walberla::timeloop::SweepTimeloop< TP >::nextId_
protected

◆ sweeps_

template<typename TP = timing::WcPolicy>
std::map< uint_t,SweepAdder* > walberla::timeloop::SweepTimeloop< TP >::sweeps_
protected

◆ sweepsToDelete_

template<typename TP = timing::WcPolicy>
std::vector<uint_t> walberla::timeloop::SweepTimeloop< TP >::sweepsToDelete_
protected

The documentation for this class was generated from the following files:
SweepTimeloop(BlockStorage &blockStorage, uint_t nrOfTimeSteps)
Definition: SweepTimeloop.h:124
FuncCreator< void(IBlock *)> Sweep
Definition: SelectableFunctionCreators.h:133
float real_t
Definition: DataTypes.h:167