Line data Source code
1 : #ifndef CB5591CC_6EF7_4F94_AEED_D2110A4FB7CE_HPP
2 : #define CB5591CC_6EF7_4F94_AEED_D2110A4FB7CE_HPP
3 :
4 : #include "MembraneType.hpp"
5 : #include "Settings.hpp"
6 : #include "Vector2d.hpp"
7 :
8 : #include <map>
9 : #include <string>
10 : #include <vector>
11 :
12 : #include <nlohmann/json.hpp>
13 :
14 : namespace cell
15 : {
16 :
17 : namespace config
18 : {
19 :
20 : inline const std::string cellMembraneTypeName = "Cell membrane";
21 :
22 : using PermeabilityMap = std::unordered_map<std::string, cell::MembraneType::Permeability>;
23 : using DiscTypeDistribution = std::unordered_map<std::string, double>;
24 :
25 : struct DiscType
26 : {
27 3 : std::string name;
28 3 : double radius = 0;
29 3 : double mass = 0;
30 3 : bool operator==(const DiscType&) const = default;
31 : };
32 :
33 : struct Disc
34 : {
35 1 : std::string discTypeName;
36 2 : double x = 0, y = 0;
37 2 : double vx = 0, vy = 0;
38 1 : bool operator==(const Disc&) const = default;
39 : };
40 :
41 : struct MembraneType
42 : {
43 2 : std::string name;
44 2 : double radius = 0;
45 2 : PermeabilityMap permeabilityMap;
46 :
47 : // Only used if distributions are enabled, not part of the actual membrane type:
48 2 : int discCount = 0;
49 2 : DiscTypeDistribution discTypeDistribution;
50 :
51 2 : bool operator==(const MembraneType&) const = default;
52 : };
53 :
54 : struct Membrane
55 : {
56 1 : std::string membraneTypeName;
57 2 : double x = 0, y = 0;
58 1 : bool operator==(const Membrane&) const = default;
59 : };
60 :
61 : struct Reaction
62 : {
63 16 : std::string educt1, educt2, product1, product2;
64 4 : double probability = 0;
65 4 : bool operator==(const Reaction&) const = default;
66 : };
67 :
68 : } // namespace config
69 :
70 : struct SimulationConfig
71 : {
72 1 : std::vector<config::DiscType> discTypes;
73 1 : std::vector<config::MembraneType> membraneTypes;
74 1 : std::vector<config::Reaction> reactions;
75 :
76 1 : config::MembraneType cellMembraneType{.name = config::cellMembraneTypeName, .radius = 1000, .permeabilityMap = {}};
77 :
78 : /**
79 : * @brief Time that passes between single simulation steps. Smaller value means more accurate collisions, but
80 : * requires more updates to advance the simulation in time. If this value is too small, the simulation might not be
81 : * able to keep up and start lagging
82 : */
83 1 : double simulationTimeStep = sf::milliseconds(1).asSeconds();
84 :
85 : /**
86 : * @brief Defines how many seconds should pass in real time for 1 second in the simulation.
87 : *
88 : * Example: If set to 2, we will advance the simulation by 2 seconds in 1 real time second, meaning we will (try to)
89 : * call the update() method of the world 2 * 1000/simulationTimeStep_ times per second
90 : */
91 1 : double simulationTimeScale = 1;
92 1 : double maxVelocity = 600;
93 :
94 1 : bool useDistribution = true;
95 :
96 : // In case not:
97 1 : std::vector<config::Disc> discs;
98 :
99 : // These never use a distribution
100 1 : std::vector<config::Membrane> membranes;
101 :
102 1 : bool operator==(const SimulationConfig&) const = default;
103 : };
104 :
105 : namespace config
106 : {
107 :
108 6 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DiscType, name, radius, mass)
109 2 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Disc, discTypeName, x, y, vx, vy)
110 4 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MembraneType, name, radius, permeabilityMap, discCount, discTypeDistribution)
111 2 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Membrane, membraneTypeName, x, y)
112 8 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Reaction, educt1, educt2, product1, product2, probability)
113 :
114 : } // namespace config
115 :
116 2 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SimulationConfig, discTypes, membraneTypes, reactions, cellMembraneType,
117 : simulationTimeStep, simulationTimeScale, maxVelocity, useDistribution, discs,
118 : membranes)
119 :
120 : cell::config::MembraneType& findMembraneTypeByName(cell::SimulationConfig& simulationConfig,
121 : std::string membraneTypeName);
122 :
123 : } // namespace cell
124 :
125 : #endif /* CB5591CC_6EF7_4F94_AEED_D2110A4FB7CE_HPP */
|