CellModules
BodyDiffusion.hpp
Go to the documentation of this file.
1#ifndef ONKO3D_3_0_BODYDIFFUSION_HPP
2#define ONKO3D_3_0_BODYDIFFUSION_HPP
3
9#include "DiffusionGrid.hpp"
10#include "../../../../src/core/BaseBody.hpp"
11#include <vector>
12#include <unordered_map>
13
14using namespace std;
15
20namespace Diffusion2D {
21
29 template<typename cell_t, class plugin_t>
30 class BodyDiffusion : public virtual BaseBody<plugin_t> {
31
32 private:
34 int nbMolecules = 0;
36 public:
37
42
48 inline explicit BodyDiffusion(int size) {
49 initNbMolecules(size);
50 }
51
57 void initNbMolecules(int n) {
58 if(n > nbMolecules) {
59 nbMolecules = n;
60 consumptions.assign(n, 0.);
61 }
62 }
63
72 double getQuantity(int x, int y, int mol) {
73 if(this->cellPlugin != nullptr) return getDiffusionGrid()->getMolecule(x, y, mol);
74 else return 0.;
75 }
76
83 double getConsumption(int mol) {
84 if(this->cellPlugin != nullptr) return consumptions[getDiffusionGrid()->moleculesDict[mol]];
85 else return consumptions[mol];
86 }
87
93
100 inline void setConsumption(int mol, double value) {
101 if(this->cellPlugin != nullptr) consumptions[getDiffusionGrid()->moleculesDict[mol]] = value;
102 else consumptions[mol] = value;
103 }
104
110 inline DiffusionGrid* getDiffusionGrid() { return this->cellPlugin->pluginDiffusion.getDiffusionGrid(); }
111
119 auto grid = getDiffusionGrid();
121 for(int i = 0; i < consumptions.size(); ++i) consumptions[i] = consCopy[grid->moleculesDict[i]];
122 }
123
124 };
125
126}
127
128#endif //ONKO3D_3_0_BODYDIFFUSION_HPP
Manages a 2D grid for molecule diffusion.
plugin_t * cellPlugin
Definition: BaseBody.hpp:9
Class for managing molecule diffusion in a cell body.
double getQuantity(int x, int y, int mol)
Gets the quantity of a molecule at a specific position.
std::vector< double > getConsumptions() const
Gets the consumptions of all molecules.
void onCellPluginLinking()
Hook called when the body is linked to the plugin.
std::vector< double > consumptions
double getConsumption(int mol)
Gets the consumption of a molecule.
BodyDiffusion()
Default constructor.
BodyDiffusion(int size)
Constructor with the number of existing molecules.
void setConsumption(int mol, double value)
Sets the consumption of a molecule.
void initNbMolecules(int n)
Initializes the quantities and consumptions.
DiffusionGrid * getDiffusionGrid()
Gets the diffusion grid.
Manages a grid of molecules for diffusion.
double getMolecule(int x, int y, int m)
Gets the quantity of a molecule at a specific position.
std::unordered_map< int, int > moleculesDict
size_t size() const
Returns the number of elements in the vector.
Definition: std.hpp:354
Namespace for 2D diffusion-related classes and functions.
Provides common mathematical functions and vector operations.
Definition: std.hpp:4