CellModules
MecaCell::World< Cell, Integrator > Class Template Reference

Where "everything" happens. More...

#include <world.hpp>

Classes

struct  dumb
 
struct  embedded_plugin_type
 
struct  embedded_plugin_type< T, void_t< typename T::embedded_plugin_t > >
 

Public Types

using cell_t = Cell
 
using integrator_t = Integrator
 
using hook_s = void(World *)
 
using cellPlugin_t = typename embedded_plugin_type< cell_t >::type
 

Public Member Functions

DECLARE_HOOK(onAddCell, beginUpdate, preBehaviorUpdate, preDeleteDeadCellsUpdate, postBehaviorUpdate, endUpdate, allForcesAppliedToCells, destructor) std World (size_t nThreads=0)
 cells that are registered to be added More...
 
void setParallelUpdateBehavior (bool p)
 enables or disables the parallelisation of the cells' updateBehavior methods Only has effect if nbThreads > 0; More...
 
size_t getNbThreads ()
 the size of the threadpool that can be used by plugins to launch asynchronous jobs and also directly in the world class to launch the updateBehavior methods in parallel. See setParallelUpdateBehavior. More...
 
void setNbThreads (size_t n)
 
void registerHook (const Hooks &h, hook_t f)
 register a single hook method. cf registerPlugins() More...
 
template<typename P , typename... Rest>
void registerPlugins (P &&p, Rest &&... otherPlugins)
 Registers a plugin. A plugin is a class or struct that contains hooks. More...
 
void registerPlugins ()
 
void clearHooks ()
 end of recursion More...
 
size_t getNbUpdates () const
 get the number of update since the creation of the world More...
 
template<typename... Args>
CellcreateCell (Args &&... args)
 Creates a new cell and adds it through addCell() More...
 
void addCell (Cell *c)
 adds a cell to the new cells batch (which will be added to the main cells container at the end of the update cycle - or can be forced manually) More...
 
void addNewCells ()
 effectively adds the new cells that were registered by addCell triggers addCell hooks if there is something to add More...
 
void allForcesHaveBeenAppliedToCells ()
 this method triggers the allForcesAppliedToCells. It should be called by the embedded physics plugin just before updating positions More...
 
void setDt (double d)
 sets the amount by which time is increased at each update() call. More...
 
void setDtInS (double d)
 
void setDtInMn (double d)
 
void setDtInH (double d)
 
double getDt () const
 
double getDtInS () const
 
double getDtInMn () const
 
double getDtInH () const
 
void setShuffleCells (bool s)
 
void setUpdateBehaviorPeriod (size_t p)
 sets the period at which the world must call the updateBehavior method of each cell. This can be useful, for example, when the physics code must run at a different timescale than the behavior code. More...
 
size_t getUpdateBehaviorPeriod () const
 
std::vector< std::pair< cell_t *, cell_t * > > getConnectedCellsList ()
 returns a list of pair of connected cells More...
 
void callUpdateBehavior ()
 calls the updateBehavior of each cell, potentially in parallel (see parallelUpdateBehavior and nbThreads) More...
 
void update ()
 main update method More...
 
 ~World ()
 World's destructor. Triggers the destructor hooks and delete all cells. More...
 
 EXPORTABLE (World, KV(frame), KV(cells))
 @ignore More...
 

Public Attributes

ThreadPool threadpool
 
double dt = 1.0 / 100.0
 
double dtMn = dt/60.
 The amount by which time is increased every update. More...
 
double dtH = dt/3600.
 
cellPlugin_t cellPlugin
 
vector< Cell * > newCells
 

Protected Member Functions

void deleteDeadCells ()
 removes all cells marked dead More...
 

Protected Attributes

size_t frame = 0
 
size_t nbAddedCells = 0
 +1 at each update. cf getNbUpdates() More...
 
size_t updtBhvPeriod = 1
 +1 on cell add. Used for cell's unique ids More...
 
bool parallelUpdateBehavior = false
 period at which the world should call the cells updateBehavior method. More...
 
bool shuffleCells = true
 

Private Attributes

size_t nbThreads = 0
 

Detailed Description

template<typename Cell, typename Integrator = Euler>
class MecaCell::World< Cell, Integrator >

Where "everything" happens.

Handles the addition and deletion of cells and the main update routine. Hooks can be added either through the registerPlugin method or through the addHook and addHooks methods

Template Parameters
Cellthe user's cell type
Integratorthe type of integrator to use. Defaults to semi-explicit Euler

Definition at line 25 of file world.hpp.

Member Typedef Documentation

◆ cell_t

template<typename Cell , typename Integrator = Euler>
using MecaCell::World< Cell, Integrator >::cell_t = Cell

Definition at line 30 of file world.hpp.

◆ cellPlugin_t

template<typename Cell , typename Integrator = Euler>
using MecaCell::World< Cell, Integrator >::cellPlugin_t = typename embedded_plugin_type<cell_t>::type

Definition at line 57 of file world.hpp.

◆ hook_s

template<typename Cell , typename Integrator = Euler>
using MecaCell::World< Cell, Integrator >::hook_s = void(World *)

Definition at line 32 of file world.hpp.

◆ integrator_t

template<typename Cell , typename Integrator = Euler>
using MecaCell::World< Cell, Integrator >::integrator_t = Integrator

Definition at line 31 of file world.hpp.

Constructor & Destructor Documentation

◆ World()

template<typename Cell , typename Integrator = Euler>
DECLARE_HOOK(onAddCell, beginUpdate, preBehaviorUpdate, preDeleteDeadCellsUpdate, postBehaviorUpdate, endUpdate, allForcesAppliedToCells, destructor) std MecaCell::World< Cell, Integrator >::World ( size_t  nThreads = 0)
inline

cells that are registered to be added

all the cells are in this container

World constructor, registers the (optional) cell type's embedded plugin instance.

Parameters
nbThreadsthe number of threads to be used by plugins (physics, for example) or cells (through their updateBehavior method) that can take advantage of parallelism

Definition at line 109 of file world.hpp.

◆ ~World()

template<typename Cell , typename Integrator = Euler>
MecaCell::World< Cell, Integrator >::~World ( )
inline

World's destructor. Triggers the destructor hooks and delete all cells.

Definition at line 338 of file world.hpp.

Member Function Documentation

◆ addCell()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::addCell ( Cell c)
inline

adds a cell to the new cells batch (which will be added to the main cells container at the end of the update cycle - or can be forced manually)

Construction can be done by the user but deletion is automatically handled by the world (ex. ' addCell(new MyCell()); ' ). createCell(...) should probably be used instead.

Parameters
ca pointer to the cell

Definition at line 219 of file world.hpp.

◆ addNewCells()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::addNewCells ( )
inline

effectively adds the new cells that were registered by addCell triggers addCell hooks if there is something to add

Definition at line 232 of file world.hpp.

◆ allForcesHaveBeenAppliedToCells()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::allForcesHaveBeenAppliedToCells ( )
inline

this method triggers the allForcesAppliedToCells. It should be called by the embedded physics plugin just before updating positions

Definition at line 244 of file world.hpp.

◆ callUpdateBehavior()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::callUpdateBehavior ( )
inline

calls the updateBehavior of each cell, potentially in parallel (see parallelUpdateBehavior and nbThreads)

Definition at line 299 of file world.hpp.

◆ clearHooks()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::clearHooks ( )
inline

end of recursion

clear all registered hooks. CAUTION: it will also delete any default embedded plugins the cell type could provide (specific collision manager for example)

Definition at line 180 of file world.hpp.

◆ createCell()

template<typename Cell , typename Integrator = Euler>
template<typename... Args>
Cell * MecaCell::World< Cell, Integrator >::createCell ( Args &&...  args)
inline

Creates a new cell and adds it through addCell()

Template Parameters
Args
Parameters
argsCell's constructor parameters
Returns
a pointer to the new Cell

Definition at line 203 of file world.hpp.

◆ deleteDeadCells()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::deleteDeadCells ( )
inlineprotected

removes all cells marked dead

Definition at line 71 of file world.hpp.

◆ EXPORTABLE()

template<typename Cell , typename Integrator = Euler>
MecaCell::World< Cell, Integrator >::EXPORTABLE ( World< Cell, Integrator >  ,
KV(frame ,
KV(cells)   
)

@ignore

◆ getConnectedCellsList()

template<typename Cell , typename Integrator = Euler>
std::vector< std::pair< cell_t *, cell_t * > > MecaCell::World< Cell, Integrator >::getConnectedCellsList ( )
inline

returns a list of pair of connected cells

Returns

Definition at line 284 of file world.hpp.

◆ getDt()

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::getDt ( ) const
inline

Definition at line 260 of file world.hpp.

◆ getDtInH()

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::getDtInH ( ) const
inline

Definition at line 263 of file world.hpp.

◆ getDtInMn()

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::getDtInMn ( ) const
inline

Definition at line 262 of file world.hpp.

◆ getDtInS()

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::getDtInS ( ) const
inline

Definition at line 261 of file world.hpp.

◆ getNbThreads()

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::getNbThreads ( )
inline

the size of the threadpool that can be used by plugins to launch asynchronous jobs and also directly in the world class to launch the updateBehavior methods in parallel. See setParallelUpdateBehavior.

Returns
the number of threads in the threadpool

Definition at line 128 of file world.hpp.

◆ getNbUpdates()

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::getNbUpdates ( ) const
inline

get the number of update since the creation of the world

Returns
number of updates

Definition at line 193 of file world.hpp.

◆ getUpdateBehaviorPeriod()

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::getUpdateBehaviorPeriod ( ) const
inline

Definition at line 276 of file world.hpp.

◆ registerHook()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::registerHook ( const Hooks &  h,
hook_t  f 
)
inline

register a single hook method. cf registerPlugins()

Parameters
hhook type (same name as hook method)
fthe actual hook

Definition at line 145 of file world.hpp.

◆ registerPlugins() [1/2]

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::registerPlugins ( )
inline

Definition at line 174 of file world.hpp.

◆ registerPlugins() [2/2]

template<typename Cell , typename Integrator = Euler>
template<typename P , typename... Rest>
void MecaCell::World< Cell, Integrator >::registerPlugins ( P &&  p,
Rest &&...  otherPlugins 
)
inline

Registers a plugin. A plugin is a class or struct that contains hooks.

This method takes an arbitrary number of plugin classes and registers them in the order of appearance, which is also the order in which similar hooks will be called.

Signatures of hooks methods must be void (World*) Available hooks are:

  • beginUpdate: called at each world update before everything else
  • preBehaviorUpdate: called the world calls every individual updateBehavior(World&) cells methods
  • postBehaviorUpdate: called after updateBehavior(World&) and just before dead cells are removed (this is where death-related cleanup should be made, before the cell is automatically effectively removed from the world)
  • endUpdate: called at the end of each world update routine
  • addCell: called after each cell addition to the world (the new cell is thus guaranteed to be the last one in the cells container)
  • destructor: called when world's destructor is called, just before all of the cells are deleted.

Definition at line 169 of file world.hpp.

◆ setDt()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setDt ( double  d)
inline

sets the amount by which time is increased at each update() call.

smaller dt values generally results in more stable physics (at the expense of slower simulations)

Parameters
dthe new dt value

Definition at line 256 of file world.hpp.

◆ setDtInH()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setDtInH ( double  d)
inline

Definition at line 259 of file world.hpp.

◆ setDtInMn()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setDtInMn ( double  d)
inline

Definition at line 258 of file world.hpp.

◆ setDtInS()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setDtInS ( double  d)
inline

Definition at line 257 of file world.hpp.

◆ setNbThreads()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setNbThreads ( size_t  n)
inline

Definition at line 130 of file world.hpp.

◆ setParallelUpdateBehavior()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setParallelUpdateBehavior ( bool  p)
inline

enables or disables the parallelisation of the cells' updateBehavior methods Only has effect if nbThreads > 0;

Parameters
p

Definition at line 119 of file world.hpp.

◆ setShuffleCells()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setShuffleCells ( bool  s)
inline

Definition at line 265 of file world.hpp.

◆ setUpdateBehaviorPeriod()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::setUpdateBehaviorPeriod ( size_t  p)
inline

sets the period at which the world must call the updateBehavior method of each cell. This can be useful, for example, when the physics code must run at a different timescale than the behavior code.

Parameters
pthe new period. updateBehavior will be called every p updates.

Definition at line 274 of file world.hpp.

◆ update()

template<typename Cell , typename Integrator = Euler>
void MecaCell::World< Cell, Integrator >::update ( )
inline

main update method

this should be manually called at each time step by the user. It calls the core logics of the adhesions & collisions systemi, updateis every forces, speeds and positions and calls the individual updateBehavior of each cells. 4 type of hooks are triggered:

  • beginUpdate
  • preBehaviorUpdate
  • postBehaviorUpdate
  • endUpdate

Definition at line 323 of file world.hpp.

Member Data Documentation

◆ cellPlugin

template<typename Cell , typename Integrator = Euler>
cellPlugin_t MecaCell::World< Cell, Integrator >::cellPlugin

Definition at line 88 of file world.hpp.

◆ dt

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::dt = 1.0 / 100.0

Definition at line 84 of file world.hpp.

◆ dtH

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::dtH = dt/3600.

Definition at line 86 of file world.hpp.

◆ dtMn

template<typename Cell , typename Integrator = Euler>
double MecaCell::World< Cell, Integrator >::dtMn = dt/60.

The amount by which time is increased every update.

Definition at line 85 of file world.hpp.

◆ frame

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::frame = 0
protected

Definition at line 62 of file world.hpp.

◆ nbAddedCells

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::nbAddedCells = 0
protected

+1 at each update. cf getNbUpdates()

Definition at line 63 of file world.hpp.

◆ nbThreads

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::nbThreads = 0
private

Definition at line 27 of file world.hpp.

◆ newCells

template<typename Cell , typename Integrator = Euler>
vector<Cell *> MecaCell::World< Cell, Integrator >::newCells

Definition at line 91 of file world.hpp.

◆ parallelUpdateBehavior

template<typename Cell , typename Integrator = Euler>
bool MecaCell::World< Cell, Integrator >::parallelUpdateBehavior = false
protected

period at which the world should call the cells updateBehavior method.

Definition at line 65 of file world.hpp.

◆ shuffleCells

template<typename Cell , typename Integrator = Euler>
bool MecaCell::World< Cell, Integrator >::shuffleCells = true
protected

Definition at line 66 of file world.hpp.

◆ threadpool

template<typename Cell , typename Integrator = Euler>
ThreadPool MecaCell::World< Cell, Integrator >::threadpool

hook signature, as they should appear in plugins classes. cf. hooks & plugins section

Definition at line 35 of file world.hpp.

◆ updtBhvPeriod

template<typename Cell , typename Integrator = Euler>
size_t MecaCell::World< Cell, Integrator >::updtBhvPeriod = 1
protected

+1 on cell add. Used for cell's unique ids

Definition at line 64 of file world.hpp.


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