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
11#include "DiffusionGrid.hpp"
12#include "../../../../src/core/BaseBody.hpp"
13#include <vector>
14#include <hash_map>
15
16using namespace std;
17
21namespace Diffusion2D {
22
23
30 template<typename cell_t, class plugin_t>
31 class BodyDiffusion : public virtual BaseBody<plugin_t> {
32
33 private:
35 int nbMolecules = 0;
37 public:
38
43
48 inline explicit BodyDiffusion(int size){
49 initNbMolecules(size);
50 }
51
56 void initNbMolecules(int n){
57 if(n > nbMolecules) {
58 nbMolecules = n;
59 consumptions.assign(n,0.);
60 }
61 }
62
70 double getQuantity(int x, int y, int mol) {
71 if(this->cellPlugin != nullptr) return getDiffusionGrid()->getMolecule(x,y,mol);
72 else return 0.;
73 }
74
80 double getConsumption(int mol) {
81 if(this->cellPlugin != nullptr) return consumptions[getDiffusionGrid()->moleculesDict[mol]];
82 else return consumptions[mol];
83 }
84
90
96 inline void setConsumption(int mol, double value){
97 if(this->cellPlugin != nullptr) consumptions[getDiffusionGrid()->moleculesDict[mol]] = value;
98 else consumptions[mol] = value;
99 }
100
106 inline DiffusionGrid * getDiffusionGrid() { return this->cellPlugin->pluginDiffusion.getDiffusionGrid(); }
107
117 auto grid = getDiffusionGrid();
119 for(int i=0; i<consumptions.size(); ++i) consumptions[i] = consCopy[grid->moleculesDict[i]];
120 }
121
122 };
123
124}
125
126
127#endif //ONKO3D_3_0_BODYDIFFUSION_HPP
molecules 2D Grid manager
plugin_t * cellPlugin
Definition: BaseBody.hpp:9
molecules diffusion body class
double getQuantity(int x, int y, int mol)
quantities getter
vector< double > getConsumptions() const
consumptions getter
void onCellPluginLinking()
plugin linking hook
double getConsumption(int mol)
consumption getter
BodyDiffusion()
default constructor
vector< double > consumptions
BodyDiffusion(int size)
constructor
void setConsumption(int mol, double value)
consumption setter
void initNbMolecules(int n)
quantities & consumptions initializer
DiffusionGrid * getDiffusionGrid()
grid getter
molecules grid based class
double getMolecule(int x, int y, int m)
molecule quantity getter
unordered_map< int, int > moleculesDict
size_t size() const
Returns the number of elements in the vector.
Definition: std.hpp:320
Provides common mathematical functions and vector operations.
Definition: std.hpp:4