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