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
29
30
31public:
32
33 double dt = 360.;
34 int maxStep = 999999;
35
36 /*isigen:insert@functions'''
37 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()]))
38
39 '''*/
40
41
42 /*isigen:insert@attributes'''
43 print('\n'.join(["{type} {value};".format(type=a['type'],value=a['value']) for a in builderData["scenario"]["attributes"] if a['source'] != 'core']))
44 '''*/
45
52 return world;
53 }
54
60 void addCell(Cell *c) { world.addCell(c); }
61
67 double getDt() const { return world.getDt(); }
68
74 void setDt(double dt) { world.setDt(dt); }
75
82
94 Cell * c = new Cell(pos, &m);
95 c->setType(t);
96 world.addCell(c);
97 c->init();
98 return c;
99 }
100
111 Cell * c = new Cell(pos, &m);
112 world.addCell(c);
113 c->init();
114 return c;
115 }
116
126 Cell * createCell(Type t){
127 Cell * c = new Cell(&m);
128 c->setType(t);
129 world.addCell(c);
130 c->init();
131 return c;
132 }
133
148 Cell * c = new Cell(&m);
149 world.addCell(c);
150 c->init();
151 return c;
152 }
153
159 void init(nlohmann::json config){
160 m.loadModel(config["input"]);
161 m.initScenario(this);
162 world.setDt(dt);
163
164 /*isigen:insert@init'''
165 print(builderData["scenario"]["codeInit"].replace('\n','//isigen:metaDataDebug[init] {}\n',1))
166 '''*/
168 }
169
173 void loop(){
174 world.update();
175 /*isigen:insert@loop'''
176 print(builderData["scenario"]["codeLoop"].replace('\n','//isigen:metaDataDebug[loop] {}\n',1))
177 '''*/
178 }
179
185 bool stop() { return world.getNbUpdates() >= maxStep; }
186};
187
188#endif //BASEPROJECT_BASESCENARIO_HPP
189//'''
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:25
double getDt() const
Definition: world.hpp:260
void setUpdateBehaviorPeriod(size_t p)
sets the period at which the world must call the updateBehavior method of each cell....
Definition: world.hpp:274
size_t getNbUpdates() const
get the number of update since the creation of the world
Definition: world.hpp:193
void setDt(double d)
sets the amount by which time is increased at each update() call.
Definition: world.hpp:256
void addNewCells()
effectively adds the new cells that were registered by addCell triggers addCell hooks if there is som...
Definition: world.hpp:232
void update()
main update method
Definition: world.hpp:323
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:219
Definition: Model.hpp:41
void initScenario(Scenario *s)
Definition: Model.hpp:80
void loadModel(nlohmann::json config)
Definition: Model.hpp:69
Represents a cell in the simulation.
Definition: PrimoCell.hpp:53
void init()
Initializes the cell.
Definition: PrimoCell.hpp:214
void setType(Type t)
Sets the type of the cell and modifies parameters accordingly.
Definition: PrimoCell.hpp:240
Manages the simulation scenario.
Definition: Scenario.hpp:24
Model m
Definition: Scenario.hpp:28
Cell * createCell()
Creates a cell.
Definition: Scenario.hpp:147
World & getWorld()
Gets the world of the scenario.
Definition: Scenario.hpp:51
void init(nlohmann::json config)
Initializes the scenario with a configuration.
Definition: Scenario.hpp:159
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:93
double getDt() const
Gets the time step of the world.
Definition: Scenario.hpp:67
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:126
void loop()
Runs the main loop of the scenario.
Definition: Scenario.hpp:173
double dt
Definition: Scenario.hpp:33
int maxStep
Definition: Scenario.hpp:34
void setUpdateBehaviorPeriod(int n)
Sets the update behavior period of the world.
Definition: Scenario.hpp:81
void addCell(Cell *c)
Adds a cell to the world.
Definition: Scenario.hpp:60
void setDt(double dt)
Sets the time step of the world.
Definition: Scenario.hpp:74
Cell * createCell(MecaCell::Vec pos)
Creates a cell at a specific position, adds it to the world, and initializes it.
Definition: Scenario.hpp:110
bool stop()
Checks if the scenario should stop.
Definition: Scenario.hpp:185
a class to store JSON values
Definition: json.hpp:12931
Vector3D Vec
alias for Vector3D
Definition: utils.hpp:22