Program Listing for File Simulation.h
↰ Return to documentation for file (include/flamegpu/simulation/Simulation.h
)
#ifndef INCLUDE_FLAMEGPU_SIMULATION_SIMULATION_H_
#define INCLUDE_FLAMEGPU_SIMULATION_SIMULATION_H_
#include <memory>
#include <string>
#include <ctime>
#include <utility>
#include <unordered_map>
#include <vector>
#include "flamegpu/defines.h"
#include "flamegpu/simulation/detail/AgentInterface.h"
#include "flamegpu/detail/Any.h"
namespace flamegpu {
namespace detail {
class EnvironmentManager;
class CUDAMacroEnvironment;
} // namespace detail
class AgentVector;
class HostAPI;
class ModelDescription;
struct ModelData;
struct RunLog;
class CUDASimulation;
class Simulation {
public:
struct Config {
Config();
void operator=(const Config &other) {
input_file = other.input_file;
step_log_file = other.step_log_file;
exit_log_file = other.exit_log_file;
common_log_file = other.common_log_file;
truncate_log_files = other.truncate_log_files;
random_seed = other.random_seed;
steps = other.steps;
verbosity = other.verbosity;
timing = other.timing;
silence_unknown_args = other.silence_unknown_args;
telemetry = other.telemetry;
#ifdef FLAMEGPU_VISUALISATION
console_mode = other.console_mode;
#endif
}
std::string input_file;
std::string step_log_file;
std::string exit_log_file;
std::string common_log_file;
bool truncate_log_files = false;
uint64_t random_seed;
unsigned int steps = 1;
flamegpu::Verbosity verbosity = Verbosity::Default;
bool timing = false;
bool silence_unknown_args = false;
bool telemetry = false;
#ifdef FLAMEGPU_VISUALISATION
bool console_mode = false;
#else
const bool console_mode = true;
#endif
};
virtual ~Simulation() = default;
explicit Simulation(const std::shared_ptr<const ModelData> &model);
protected:
explicit Simulation(const std::shared_ptr<SubModelData> &sub_model, CUDASimulation *master_model);
public:
void initialise(int argc, const char** argv);
virtual void initFunctions() = 0;
virtual bool step() = 0;
virtual void exitFunctions() = 0;
virtual void simulate() = 0;
void reset();
virtual unsigned int getStepCounter() = 0;
virtual void resetStepCounter() = 0;
const ModelData& getModelDescription() const;
void exportData(const std::string &path, bool prettyPrint = true);
void exportLog(const std::string &path, bool steps, bool exit, bool stepTime, bool exitTime, bool prettyPrint = true);
virtual void setPopulationData(AgentVector& population, const std::string& state_name = ModelData::DEFAULT_STATE) = 0;
virtual void getPopulationData(AgentVector& population, const std::string& state_name = ModelData::DEFAULT_STATE) = 0;
virtual const RunLog &getRunLog() const = 0;
Config &SimulationConfig();
const Config &getSimulationConfig() const;
void applyConfig();
protected:
virtual void reset(bool submodelReset) = 0;
virtual void applyConfig_derived() = 0;
virtual bool checkArgs_derived(int argc, const char** argv, int &i) = 0;
virtual void printHelp_derived() = 0;
unsigned int getInstanceID() const { return instance_id; }
virtual std::shared_ptr<detail::EnvironmentManager> getEnvironment() const = 0;
virtual std::shared_ptr<const detail::CUDAMacroEnvironment> getMacroEnvironment() const = 0;
unsigned int getMaximumLayerWidth() const { return maxLayerWidth; }
const std::shared_ptr<const ModelData> model;
const std::shared_ptr<const SubModelData> submodel;
CUDASimulation const * mastermodel;
Config config;
std::string loaded_input_file;
const unsigned int instance_id;
std::unordered_map<std::string, detail::Any> env_init;
std::unordered_map<std::string, std::vector<char>> macro_env_init;
unsigned int maxLayerWidth;
private:
static unsigned int get_instance_id();
void printHelp(const char *executable);
int checkArgs(int argc, const char** argv);
};
} // namespace flamegpu
#endif // INCLUDE_FLAMEGPU_SIMULATION_SIMULATION_H_