CellModules
Scenario.hpp
Go to the documentation of this file.
1
6#ifndef BASEPROJECT_BASESCENARIO_HPP
7#define BASEPROJECT_BASESCENARIO_HPP
8
9#include <mecacell/mecacell.h>
10#include "../cells/PrimoCell.hpp"
11#include "../core/CellBody.hpp"
12#include "../tools/TimeConvert.hpp"
13#include "../tools/RandomManager.hpp"
14
15
19
24class Scenario {
25private:
26
27 World world; /* The world manages cell registration, IDs refresh, and plugins. */
28
31
32
33public:
34
35 double dt = 360.; /* time step used to configure the world (in seconds) */
36 int maxStep = 999999; /* Maximum number of world updates before stopping the scenario.*/
37
38 /*isigen:insert@functions'''
39 print('\n'.join([code.replace('\n','//isigen:metaDataDebug['+re.search(r'(\w+[\d_\w]+)\s*\‍(',code).group(1)+'] '+'{"idFunc":"'+idFunc+'"}\n',1) for idFunc,code in builderData["scenario"]["functions"].items()]))
40
41 '''*/
42
43
44 /*isigen:insert@attributes'''
45 print('\n'.join(["{type} {value};".format(type=a['type'],value=a['value']) for a in builderData["scenario"]["attributes"] if a['source'] != 'core']))
46 '''*/
47
54 return world;
55 }
56
62 void addCell(Cell *c) { world.addCell(c); }
63
69 double getDt() const { return world.getDt(); }
70
76 void setDt(double dt) { world.setDt(dt); }
77
84
96 Cell * c = new Cell(pos, &m);
97 c->setType(t);
98 world.addCell(c);
99 c->init();
100 return c;
101 }
102
113 Cell * c = new Cell(pos, &m);
114 world.addCell(c);
115 c->init();
116 return c;
117 }
118
128 Cell * createCell(Type t){
129 Cell * c = new Cell(&m);
130 c->setType(t);
131 world.addCell(c);
132 c->init();
133 return c;
134 }
135
150 Cell * c = new Cell(&m);
151 world.addCell(c);
152 c->init();
153 return c;
154 }
155
162 void init(nlohmann::json config){
163 m.loadModel(config["input"]);
164 m.initScenario(this);
165 world.setDt(dt);
166
167 /*isigen:insert@init'''
168 print(builderData["scenario"]["codeInit"].replace('\n','//isigen:metaDataDebug[init] {}\n',1))
169 '''*/
171 }
172
176 void loop(){
177 world.update();
178 /*isigen:insert@loop'''
179 print(builderData["scenario"]["codeLoop"].replace('\n','//isigen:metaDataDebug[loop] {}\n',1))
180 '''*/
181 }
182
185 }
186
187 std::string getBenchmarksJSON() const {
188 return world.getBenchmarksJSON();
189 }
190
191
197 bool stop() { return world.getNbUpdates() >= maxStep; }
198};
199
200#endif //BASEPROJECT_BASESCENARIO_HPP
201//'''
MecaCell::Vec pos
Definition: CellBody.hpp:34
PrimoCell< CellBody > Cell
Definition: Scenario.hpp:16
general purpose 3D vector/point class.
Definition: vector3D.h:20
Where "everything" happens.
Definition: world.hpp:29
double getDt() const
Definition: world.hpp:293
void setUpdateBehaviorPeriod(size_t p)
sets the period at which the world must call the updateBehavior method of each cell....
Definition: world.hpp:307
size_t getNbUpdates() const
get the number of update since the creation of the world
Definition: world.hpp:220
void setDt(double d)
sets the amount by which time is increased at each update() call.
Definition: world.hpp:289
void addNewCells()
effectively adds the new cells that were registered by addCell triggers addCell hooks if there is som...
Definition: world.hpp:265
void update()
main update method
Definition: world.hpp:371
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...
Definition: world.hpp:246
std::string getBenchmarksJSON() const
Definition: world.hpp:383
void showBenchmarksSummaries() const
Definition: world.hpp:433
Definition: Model.hpp:41
void initScenario(Scenario *s)
Definition: Model.hpp:85
void loadModel(nlohmann::json config)
Definition: Model.hpp:70
Represents a cell in the simulation.
Definition: PrimoCell.hpp:58
void init()
Initializes the cell.
Definition: PrimoCell.hpp:229
void setType(Type t)
Sets the type of the cell and modifies parameters accordingly.
Definition: PrimoCell.hpp:257
Manages the simulation scenario.
Definition: Scenario.hpp:24
Model m
@ignore
Definition: Scenario.hpp:30
Cell * createCell()
Creates a cell.
Definition: Scenario.hpp:149
World & getWorld()
Gets the world of the scenario.
Definition: Scenario.hpp:53
void init(nlohmann::json config)
Initializes the scenario with a configuration.
Definition: Scenario.hpp:162
Cell * createCell(MecaCell::Vec pos, Type t)
Creates a cell at a specific position and type, adds it to the world, and initializes it.
Definition: Scenario.hpp:95
double getDt() const
Gets the time step of the world.
Definition: Scenario.hpp:69
World world
Definition: Scenario.hpp:27
Cell * createCell(Type t)
Creates a cell of a specific type, adds it to the world, and initializes it.
Definition: Scenario.hpp:128
void loop()
Runs the main loop of the scenario.
Definition: Scenario.hpp:176
double dt
Definition: Scenario.hpp:35
void showBenchmarksSummaries() const
Definition: Scenario.hpp:183
int maxStep
Definition: Scenario.hpp:36
void setUpdateBehaviorPeriod(int n)
Sets the update behavior period of the world.
Definition: Scenario.hpp:83
void addCell(Cell *c)
Adds a cell to the world.
Definition: Scenario.hpp:62
void setDt(double dt)
Sets the time step of the world.
Definition: Scenario.hpp:76
Cell * createCell(MecaCell::Vec pos)
Creates a cell at a specific position, adds it to the world, and initializes it.
Definition: Scenario.hpp:112
bool stop()
Checks if the scenario should stop.
Definition: Scenario.hpp:197
std::string getBenchmarksJSON() const
Definition: Scenario.hpp:187
a class to store JSON values
Definition: json.hpp:12931
Vector3D Vec
alias for Vector3D
Definition: utils.hpp:22