walberla::timeloop::SweepTimeloop Class Reference

Detailed Description

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 litte 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:

Public Member Functions

Constructor & Destructor
 SweepTimeloop (BlockStorage &blockStorage, uint_t nrOfTimeSteps)
 
 SweepTimeloop (const shared_ptr< StructuredBlockStorage > &structuredBlockStorage, uint_t nrOfTimeSteps)
 
virtual ~SweepTimeloop ()
 
Registering of Sweeps and Before/After Functions
SweepAdderadd ()
 
void remove (SweepAdder &sweep)
 
- Public Member Functions inherited from walberla::timeloop::Timeloop
 Timeloop (uint_t nrOfTimeSteps)
 
virtual ~Timeloop ()
 
virtual void run ()
 
void run (const bool logTimeStep)
 
void run (WcTimingPool &timing, const bool logTimeStep=true)
 
virtual void singleStep ()
 
void singleStep (const bool logTimeStep)
 
void singleStep (WcTimingPool &timing, const bool logTimeStep=true)
 
void stop ()
 Stops the timeloop, has to be called on every process. More...
 
void synchronizedStop (bool stop)
 Similar to stop - useful if the stop signal is only known on a single process. More...
 
void setCurrentTimeStepToZero ()
 
void setCurrentTimeStep (uint_t ts)
 
uint_t getCurrentTimeStep () const
 
uint_t getNrOfTimeSteps () const
 
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())
 
- Public Member Functions inherited from walberla::timeloop::ITimeloop
virtual ~ITimeloop ()
 

Protected Member Functions

void removeForDeletionMarkedSweeps ()
 
virtual void doTimeStep (const Set< SUID > &selectors)
 
virtual void doTimeStep (const Set< SUID > &selectors, WcTimingPool &tp)
 
- Protected Member Functions inherited from walberla::timeloop::Timeloop
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, WcTimingPool &tp)
 

Protected Attributes

BlockStorage & blockStorage_
 
uint_t nextId_
 
std::vector< uint_tsweepsToDelete_
 
std::map< uint_t, SweepAdder * > sweeps_
 
bool firstRun_
 required to register timer in doTimeStep( selectors, timingPool) More...
 
- Protected Attributes inherited from walberla::timeloop::Timeloop
uint_t curTimeStep_
 current time step More...
 
uint_t nrOfTimeSteps_
 total number of time steps More...
 
std::vector< SelectableFuncbeforeFunctions_
 
std::vector< SelectableFuncafterFunctions_
 
bool stop_
 

Additional Inherited Members

- Public Types inherited from walberla::timeloop::Timeloop
typedef size_t FctHandle
 
- Protected Types inherited from walberla::timeloop::Timeloop
typedef selectable::SetSelectableObject< VoidFctNoArguments, SUID > SelectableFunc
 

Constructor & Destructor Documentation

walberla::timeloop::SweepTimeloop::SweepTimeloop ( BlockStorage &  blockStorage,
uint_t  nrOfTimeSteps 
)
inline
walberla::timeloop::SweepTimeloop::SweepTimeloop ( const shared_ptr< StructuredBlockStorage > &  structuredBlockStorage,
uint_t  nrOfTimeSteps 
)
inline
virtual walberla::timeloop::SweepTimeloop::~SweepTimeloop ( )
inlinevirtual

Member Function Documentation

SweepAdder& walberla::timeloop::SweepTimeloop::add ( )
inline
void walberla::timeloop::SweepTimeloop::doTimeStep ( const Set< SUID > &  selectors)
protectedvirtual
void walberla::timeloop::SweepTimeloop::doTimeStep ( const Set< SUID > &  selectors,
WcTimingPool tp 
)
protectedvirtual
void walberla::timeloop::SweepTimeloop::remove ( SweepAdder sweep)
inline
void walberla::timeloop::SweepTimeloop::removeForDeletionMarkedSweeps ( )
inlineprotected

Member Data Documentation

BlockStorage& walberla::timeloop::SweepTimeloop::blockStorage_
protected
bool walberla::timeloop::SweepTimeloop::firstRun_
protected

required to register timer in doTimeStep( selectors, timingPool)

uint_t walberla::timeloop::SweepTimeloop::nextId_
protected
std::map< uint_t,SweepAdder* > walberla::timeloop::SweepTimeloop::sweeps_
protected
std::vector<uint_t> walberla::timeloop::SweepTimeloop::sweepsToDelete_
protected

The documentation for this class was generated from the following files: