Stride Reference Manual  - generated for commit 9643b11
SimController.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2017, 2018, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "SimController.h"
22 
23 #include "pop/Population.h"
24 #include "sim/Sim.h"
25 #include "sim/SimRunner.h"
26 
27 #include <boost/property_tree/ptree.hpp>
28 
29 using namespace std;
30 using namespace stride::util;
31 using namespace boost::property_tree;
32 
33 namespace stride {
34 
35 SimController::SimController(const ptree& config, const string& name)
36  : ControlHelper(config, name), m_simulator(nullptr) {}
37 
39 {
40  // -----------------------------------------------------------------------------------------
41  // Prelims.
42  // -----------------------------------------------------------------------------------------
43  CheckEnv();
45  InstallLogger();
46  LogStartup();
47 
48  // -----------------------------------------------------------------------------------------
49  // Sim scenario: step 1, build a random number manager.
50  // -----------------------------------------------------------------------------------------
51  const RnInfo info{m_config.get<string>("run.rng_seed", "1,2,3,4"), "",
52  m_config.get<unsigned int>("run.num_threads")};
53  RnMan rnMan{info};
54 
55  // -----------------------------------------------------------------------------------------
56  // Sim scenario: step 2, create a population, as described by the parameter in the config.
57  // -----------------------------------------------------------------------------------------
58  auto pop = Population::Create(m_config, rnMan, m_stride_logger);
59 
60  // -----------------------------------------------------------------------------------------
61  // Sim scenario: step 3, create a simulator, as described by the parameter in the config.
62  // -----------------------------------------------------------------------------------------
63  m_simulator = Sim::Create(m_config, pop, rnMan);
64 
65  // -----------------------------------------------------------------------------------------
66  // Sim scenario: step , build a runner, register viewers and run.
67  // -----------------------------------------------------------------------------------------
68  auto runner = make_shared<SimRunner>(m_config, m_simulator);
69  RegisterViewers(runner);
70  runner->Run();
71 }
72 
73 } // namespace stride
void RegisterViewers(std::shared_ptr< SimRunner > runner)
Register the viewers of the SimRunner.
void Control()
Control the execution of the simulation.
boost::property_tree::ptree m_config
Main configuration for run and sim.
Definition: ControlHelper.h:78
void CheckEnv()
Check install environment.
static std::shared_ptr< Population > Create()
Create an empty Population, used in gengeopop.
Definition: Population.cpp:96
Utilities for the project.
std::shared_ptr< spdlog::logger > m_stride_logger
General logger.
Definition: ControlHelper.h:82
void LogStartup()
Logs info on setup for cli environment to stride_logger.
std::shared_ptr< Sim > m_simulator
Definition: SimController.h:57
static std::shared_ptr< Sim > Create(const boost::property_tree::ptree &config, std::shared_ptr< Population > pop, util::RnMan rnMan)
Create Sim initialized by the configuration in property tree and population.
STL namespace.
Header for the command line controller.
Header file for the core Population class.
Controls a simulation run initiated with the command line interface (cli).
Definition: ControlHelper.h:45
Header for the Simulator class.
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28
Information on random number management state.
Definition: RnInfo.h:32
void InstallLogger()
Make the appropriate logger for cli environment and register as stride_logger.
Header for the SimRunner class.