BioDynaMo  v1.03.57-cebe047f
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
bdm::Simulation Class Reference

#include <simulation.h>

Collaboration diagram for bdm::Simulation:
[legend]

Public Member Functions

 Simulation (TRootIOCtor *p)
 
 Simulation (int argc, const char **argv, const std::vector< std::string > &config_files={})
 
 Simulation (CommandLineOptions *clo, const std::vector< std::string > &config_files={})
 
 Simulation (const std::string &simulation_name, const std::vector< std::string > &config_files={})
 
 Simulation (int argc, const char **argv, const std::function< void(Param *)> &set_param, const std::vector< std::string > &config_files={})
 
 Simulation (CommandLineOptions *clo, const std::function< void(Param *)> &set_param, const std::vector< std::string > &config_files={})
 
 Simulation (const std::string &simulation_name, const std::function< void(Param *)> &set_param, const std::vector< std::string > &config_files={})
 
 ~Simulation ()
 
void Restore (Simulation &&restored)
 
void Activate ()
 Activates this simulation. More...
 
ResourceManagerGetResourceManager ()
 Returns the ResourceManager instance. More...
 
void SetResourceManager (ResourceManager *rm)
 
const ParamGetParam () const
 Returns the simulation parameters. More...
 
AgentUidGeneratorGetAgentUidGenerator ()
 
EnvironmentGetEnvironment ()
 
void SetEnvironment (Environment *env)
 
SchedulerGetScheduler ()
 
void Simulate (uint64_t steps)
 
RandomGetRandom ()
 Returns a thread local random number generator. More...
 
std::vector< Random * > & GetAllRandom ()
 Returns all thread local random number generator. More...
 
ExecutionContextGetExecutionContext ()
 Returns a thread local execution context. More...
 
std::vector< ExecutionContext * > & GetAllExecCtxts ()
 Returns all thread local execution contexts. More...
 
void SetAllExecCtxts (const std::vector< ExecutionContext * > &exec_ctxts)
 
MemoryManagerGetMemoryManager ()
 
OpenCLStateGetOpenCLState ()
 Return helper class for OpenCL environment. More...
 
const std::string & GetUniqueName () const
 Returns the name of the simulation. More...
 
const std::string & GetOutputDir () const
 Returns the output directory for this specific simulation. More...
 
experimental::TimeSeriesGetTimeSeries ()
 
void ReplaceScheduler (Scheduler *scheduler)
 

Static Public Member Functions

static SimulationGetActive ()
 This function returns the currently active Simulation simulation. More...
 

Private Member Functions

void Initialize (CommandLineOptions *clo, const std::function< void(Param *)> &set_param, const std::vector< std::string > &config_files)
 Initialize Simulation. More...
 
void InitializeMembers ()
 Initialize data members that have a dependency on Simulation. More...
 
void InitializeRuntimeParams (CommandLineOptions *clo, const std::function< void(Param *)> &set_param, const std::vector< std::string > &ctor_config)
 This function parses command line parameters and the configuration file. More...
 
void LoadConfigFiles (const std::vector< std::string > &ctor_configs, const std::vector< std::string > &cli_configs)
 
void InitializeUniqueName (const std::string &simulation_name)
 This function initialzes unique_name_ More...
 
void InitializeOutputDir ()
 Initializes output_dir_ and creates dir if it does not exist. More...
 
 BDM_CLASS_DEF_NV (Simulation, 1)
 

Private Attributes

std::vector< Random * > random_
 random number generator for each thread More...
 
std::vector< ExecutionContext * > exec_ctxt_
 Execution Context for each thread. More...
 
ResourceManagerrm_ = nullptr
 
Paramparam_ = nullptr
 
AgentUidGeneratoragent_uid_generator_ = nullptr
 
std::string name_
 
Environmentenvironment_ = nullptr
 
Schedulerscheduler_ = nullptr
 
OpenCLStateocl_state_ = nullptr
 
bool is_gpu_environment_initialized_ = false
 
uint64_t id_ = 0
 This id is unique for each simulation within the same process. More...
 
std::string unique_name_
 
std::string output_dir_
 cached value where unique_name_ is appended to Param::output_dir More...
 
std::string command_line_parameter_str_
 
MemoryManagermem_mgr_ = nullptr
 BioDynaMo memory manager. If nullptr, default allocator will be used. More...
 
int64_t ctor_ts_ = 0
 Timestep when constructor was called. More...
 
int64_t dtor_ts_ = 0
 Timestep when destructor was called. More...
 
experimental::TimeSeriestime_series_ = nullptr
 Collects time series information during the simulation. More...
 
friend SimulationTest
 
friend ParaviewAdaptorTest
 

Static Private Attributes

static Simulationactive_ = nullptr
 Currently active simulation. More...
 
static std::atomic< uint64_t > counter_
 Number of simulations in this process. More...
 

Friends

class DiffusionTest_CopyOldData_Test
 
std::ostream & operator<< (std::ostream &os, Simulation &sim)
 

Detailed Description

This is the central BioDynaMo object. It containes pointers to e.g. the ResourceManager, the scheduler, parameters, ...
It is possible to create multiple simulations, but only one can be active at the same time. Creating a new agent automatically activates it.

Definition at line 50 of file simulation.h.

Constructor & Destructor Documentation

◆ Simulation() [1/7]

bdm::Simulation::Simulation ( TRootIOCtor *  p)
explicit

Definition at line 69 of file simulation.cc.

◆ Simulation() [2/7]

bdm::Simulation::Simulation ( int  argc,
const char **  argv,
const std::vector< std::string > &  config_files = {} 
)

Constructor that takes the arguments from main to parse command line arguments. The simulation name is extracted from the executable name. Creation of a new simulation automatically activates it.

Definition at line 71 of file simulation.cc.

◆ Simulation() [3/7]

bdm::Simulation::Simulation ( CommandLineOptions clo,
const std::vector< std::string > &  config_files = {} 
)
explicit

Definition at line 81 of file simulation.cc.

◆ Simulation() [4/7]

bdm::Simulation::Simulation ( const std::string &  simulation_name,
const std::vector< std::string > &  config_files = {} 
)
explicit

Alternative constructor, if the arguments from function main are not available, or if a different simulation name should be chosen.
Command line arguments are not parsed!
Creation of a new simulation automatically activates it.

Parameters
config_fileUse a different config file than the default bdm.toml or bdm.json

Definition at line 76 of file simulation.cc.

◆ Simulation() [5/7]

bdm::Simulation::Simulation ( int  argc,
const char **  argv,
const std::function< void(Param *)> &  set_param,
const std::vector< std::string > &  config_files = {} 
)

Definition at line 93 of file simulation.cc.

◆ Simulation() [6/7]

bdm::Simulation::Simulation ( CommandLineOptions clo,
const std::function< void(Param *)> &  set_param,
const std::vector< std::string > &  config_files = {} 
)

Definition at line 87 of file simulation.cc.

◆ Simulation() [7/7]

bdm::Simulation::Simulation ( const std::string &  simulation_name,
const std::function< void(Param *)> &  set_param,
const std::vector< std::string > &  config_files = {} 
)

Definition at line 100 of file simulation.cc.

◆ ~Simulation()

bdm::Simulation::~Simulation ( )

Definition at line 213 of file simulation.cc.

Member Function Documentation

◆ Activate()

void bdm::Simulation::Activate ( )

Activates this simulation.

Definition at line 257 of file simulation.cc.

◆ BDM_CLASS_DEF_NV()

bdm::Simulation::BDM_CLASS_DEF_NV ( Simulation  ,
 
)
private

◆ GetActive()

Simulation * bdm::Simulation::GetActive ( )
static

This function returns the currently active Simulation simulation.

Definition at line 67 of file simulation.cc.

◆ GetAgentUidGenerator()

AgentUidGenerator * bdm::Simulation::GetAgentUidGenerator ( )

Definition at line 272 of file simulation.cc.

◆ GetAllExecCtxts()

std::vector< ExecutionContext * > & bdm::Simulation::GetAllExecCtxts ( )

Returns all thread local execution contexts.

Definition at line 291 of file simulation.cc.

◆ GetAllRandom()

std::vector< Random * > & bdm::Simulation::GetAllRandom ( )

Returns all thread local random number generator.

Definition at line 285 of file simulation.cc.

◆ GetEnvironment()

Environment * bdm::Simulation::GetEnvironment ( )

Definition at line 276 of file simulation.cc.

◆ GetExecutionContext()

ExecutionContext * bdm::Simulation::GetExecutionContext ( )

Returns a thread local execution context.

Definition at line 287 of file simulation.cc.

◆ GetMemoryManager()

MemoryManager* bdm::Simulation::GetMemoryManager ( )
inline

Definition at line 127 of file simulation.h.

◆ GetOpenCLState()

OpenCLState * bdm::Simulation::GetOpenCLState ( )

Return helper class for OpenCL environment.

Definition at line 295 of file simulation.cc.

◆ GetOutputDir()

const std::string & bdm::Simulation::GetOutputDir ( ) const

Returns the output directory for this specific simulation.

Returns the path to the simulation's output directory.

Definition at line 301 of file simulation.cc.

◆ GetParam()

const Param * bdm::Simulation::GetParam ( ) const

Returns the simulation parameters.

Definition at line 270 of file simulation.cc.

◆ GetRandom()

Random * bdm::Simulation::GetRandom ( )

Returns a thread local random number generator.

Returns a random number generator (thread-specific)

Definition at line 283 of file simulation.cc.

◆ GetResourceManager()

ResourceManager * bdm::Simulation::GetResourceManager ( )

Returns the ResourceManager instance.

Definition at line 260 of file simulation.cc.

◆ GetScheduler()

Scheduler * bdm::Simulation::GetScheduler ( )

Definition at line 278 of file simulation.cc.

◆ GetTimeSeries()

experimental::TimeSeries * bdm::Simulation::GetTimeSeries ( )

Definition at line 303 of file simulation.cc.

◆ GetUniqueName()

const std::string & bdm::Simulation::GetUniqueName ( ) const

Returns the name of the simulation.

See also
unique_name_

Definition at line 298 of file simulation.cc.

◆ Initialize()

void bdm::Simulation::Initialize ( CommandLineOptions clo,
const std::function< void(Param *)> &  set_param,
const std::vector< std::string > &  config_files 
)
private

Initialize Simulation.

Definition at line 310 of file simulation.cc.

◆ InitializeMembers()

void bdm::Simulation::InitializeMembers ( )
private

Initialize data members that have a dependency on Simulation.

Definition at line 330 of file simulation.cc.

◆ InitializeOutputDir()

void bdm::Simulation::InitializeOutputDir ( )
private

Initializes output_dir_ and creates dir if it does not exist.

Definition at line 556 of file simulation.cc.

◆ InitializeRuntimeParams()

void bdm::Simulation::InitializeRuntimeParams ( CommandLineOptions clo,
const std::function< void(Param *)> &  set_param,
const std::vector< std::string > &  ctor_config 
)
private

This function parses command line parameters and the configuration file.

Definition at line 396 of file simulation.cc.

◆ InitializeUniqueName()

void bdm::Simulation::InitializeUniqueName ( const std::string &  simulation_name)
private

This function initialzes unique_name_

Definition at line 546 of file simulation.cc.

◆ LoadConfigFiles()

void bdm::Simulation::LoadConfigFiles ( const std::vector< std::string > &  ctor_configs,
const std::vector< std::string > &  cli_configs 
)
private

Definition at line 476 of file simulation.cc.

◆ ReplaceScheduler()

void bdm::Simulation::ReplaceScheduler ( Scheduler scheduler)

Replaces the scheduler for this simulation. Existing scheduler will be deleted! Therefore, pointers to the old scheduler (obtained with GetScheduler()) will be invalidated.
Simulation will take ownership of the passed pointer

Definition at line 305 of file simulation.cc.

◆ Restore()

void bdm::Simulation::Restore ( Simulation &&  restored)

Copies / moves values from a restored simulation into this object. Thus, pointers to rm_, param_, ... are not invalidated.

Definition at line 108 of file simulation.cc.

◆ SetAllExecCtxts()

void bdm::Simulation::SetAllExecCtxts ( const std::vector< ExecutionContext * > &  exec_ctxts)

Definition at line 379 of file simulation.cc.

◆ SetEnvironment()

void bdm::Simulation::SetEnvironment ( Environment env)

Set a specific environment for the simulation. *env must point to an object instance of a subclass of Environment.

Definition at line 372 of file simulation.cc.

◆ SetResourceManager()

void bdm::Simulation::SetResourceManager ( ResourceManager rm)

Definition at line 262 of file simulation.cc.

◆ Simulate()

void bdm::Simulation::Simulate ( uint64_t  steps)

Definition at line 280 of file simulation.cc.

Friends And Related Function Documentation

◆ DiffusionTest_CopyOldData_Test

friend class DiffusionTest_CopyOldData_Test
friend

Definition at line 211 of file simulation.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
Simulation sim 
)
friend

Definition at line 137 of file simulation.cc.

Member Data Documentation

◆ active_

Simulation * bdm::Simulation::active_ = nullptr
staticprivate

Currently active simulation.

Definition at line 148 of file simulation.h.

◆ agent_uid_generator_

AgentUidGenerator* bdm::Simulation::agent_uid_generator_ = nullptr
private

Definition at line 160 of file simulation.h.

◆ command_line_parameter_str_

std::string bdm::Simulation::command_line_parameter_str_
private

Stores command line arguments if (argc,argv) or CommandLineOptions are passed to the constructor.

Definition at line 177 of file simulation.h.

◆ counter_

std::atomic< uint64_t > bdm::Simulation::counter_
staticprivate

Number of simulations in this process.

Implementation for Simulation: It must be separate to avoid circular dependencies.

Definition at line 150 of file simulation.h.

◆ ctor_ts_

int64_t bdm::Simulation::ctor_ts_ = 0
private

Timestep when constructor was called.

Definition at line 181 of file simulation.h.

◆ dtor_ts_

int64_t bdm::Simulation::dtor_ts_ = 0
private

Timestep when destructor was called.

Definition at line 183 of file simulation.h.

◆ environment_

Environment* bdm::Simulation::environment_ = nullptr
private

Definition at line 162 of file simulation.h.

◆ exec_ctxt_

std::vector<ExecutionContext*> bdm::Simulation::exec_ctxt_
private

Execution Context for each thread.

Definition at line 156 of file simulation.h.

◆ id_

uint64_t bdm::Simulation::id_ = 0
private

This id is unique for each simulation within the same process.

Definition at line 167 of file simulation.h.

◆ is_gpu_environment_initialized_

bool bdm::Simulation::is_gpu_environment_initialized_ = false
private

Definition at line 165 of file simulation.h.

◆ mem_mgr_

MemoryManager* bdm::Simulation::mem_mgr_ = nullptr
private

BioDynaMo memory manager. If nullptr, default allocator will be used.

Definition at line 179 of file simulation.h.

◆ name_

std::string bdm::Simulation::name_
private

Definition at line 161 of file simulation.h.

◆ ocl_state_

OpenCLState* bdm::Simulation::ocl_state_ = nullptr
private

Definition at line 164 of file simulation.h.

◆ output_dir_

std::string bdm::Simulation::output_dir_
private

cached value where unique_name_ is appended to Param::output_dir

Definition at line 174 of file simulation.h.

◆ param_

Param* bdm::Simulation::param_ = nullptr
private

Definition at line 159 of file simulation.h.

◆ ParaviewAdaptorTest

friend bdm::Simulation::ParaviewAdaptorTest
private

Definition at line 210 of file simulation.h.

◆ random_

std::vector<Random*> bdm::Simulation::random_
private

random number generator for each thread

Definition at line 153 of file simulation.h.

◆ rm_

ResourceManager* bdm::Simulation::rm_ = nullptr
private

Definition at line 158 of file simulation.h.

◆ scheduler_

Scheduler* bdm::Simulation::scheduler_ = nullptr
private

Definition at line 163 of file simulation.h.

◆ SimulationTest

friend bdm::Simulation::SimulationTest
private

Definition at line 209 of file simulation.h.

◆ time_series_

experimental::TimeSeries* bdm::Simulation::time_series_ = nullptr
private

Collects time series information during the simulation.

Definition at line 185 of file simulation.h.

◆ unique_name_

std::string bdm::Simulation::unique_name_
private

cached value where id_ is appended to name_ if id_ is not zero.
e.g. name_ = "my-sim" and id_ = 0 -> "my-sim"
e.g. name_ = "my-sim" and id_ = 4 -> "my-sim4"

Definition at line 172 of file simulation.h.


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