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 <map>
8 : #include <string>
9 : #include <vector>
10 :
11 : #include <nlohmann/json.hpp>
12 :
13 : namespace cell
14 : {
15 :
16 : namespace config
17 : {
18 :
19 : inline const std::string cellMembraneTypeName = "Cell membrane";
20 : inline const double cellMembraneTypeDefaultRadius = 1000;
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{
77 : .name = config::cellMembraneTypeName, .radius = config::cellMembraneTypeDefaultRadius, .permeabilityMap = {}};
78 :
79 : /**
80 : * @brief Time that passes between single simulation steps in seconds. Smaller value means more accurate collisions,
81 : * but requires more updates to advance the simulation in time. If this value is too small, the simulation might not
82 : * be able to keep up and start lagging
83 : */
84 1 : double simulationTimeStep = 1e-3;
85 :
86 : /**
87 : * @brief Defines how many seconds should pass in real time for 1 second in the simulation.
88 : *
89 : * Example: If set to 2, we will advance the simulation by 2 seconds in 1 real time second, meaning we will (try to)
90 : * call the update() method of the world 2 * 1000/simulationTimeStep_ times per second
91 : */
92 1 : double simulationTimeScale = 1;
93 1 : double mostProbableSpeed = 600;
94 :
95 1 : bool useDistribution = true;
96 :
97 : // In case of no distribution, these are used
98 1 : std::vector<config::Disc> discs;
99 :
100 : // These never use a distribution
101 1 : std::vector<config::Membrane> membranes;
102 :
103 1 : bool operator==(const SimulationConfig&) const = default;
104 : };
105 :
106 : namespace config
107 : {
108 :
109 6 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DiscType, name, radius, mass)
110 2 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Disc, discTypeName, x, y, vx, vy)
111 4 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MembraneType, name, radius, permeabilityMap, discCount, discTypeDistribution)
112 2 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Membrane, membraneTypeName, x, y)
113 8 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Reaction, educt1, educt2, product1, product2, probability)
114 :
115 : } // namespace config
116 :
117 2 : NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(SimulationConfig, discTypes, membraneTypes, reactions, cellMembraneType,
118 : simulationTimeStep, simulationTimeScale, mostProbableSpeed, useDistribution, discs,
119 : membranes)
120 :
121 : cell::config::MembraneType& findMembraneTypeByName(cell::SimulationConfig& simulationConfig,
122 : std::string membraneTypeName);
123 :
124 : } // namespace cell
125 :
126 : #endif /* CB5591CC_6EF7_4F94_AEED_D2110A4FB7CE_HPP */
|