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
22namespace Diffusion {
23
31 template<typename cell_t, class plugin_t>
32 class BodyDiffusion : virtual BaseBody<plugin_t> {
33
34 private:
36 DiffusionGrid * grid = nullptr;
37 int nbMolecules = 0;
38
39 public:
40
44 inline BodyDiffusion() : consumptions()//, quantities()
45 {}
46
51 inline explicit BodyDiffusion(int size){
52 initNbMolecules(size);
53 }
54
59 void initNbMolecules(int n){
60 if(n > nbMolecules) {
61 nbMolecules = n;
62 consumptions.assign(n,0.);
63 }
64 }
65
72 double getQuantity(MecaCell::Vec v, int mol) const{
73 if(this->cellPlugin != nullptr) return grid->getMoleculeRealPos(v, grid->moleculesDict[mol]);
74 else return 0.;
75 }
76
82 double getConsumption(int mol) const{
83 if(this->cellPlugin != nullptr) return consumptions[grid->moleculesDict[mol]];
84 else return consumptions[mol];
85 }
86
92 double getConsumptionByIndex(int i) const{
93 return consumptions[i];
94 }
95
101 inline void setConsumption(int mol, double value){
102 if(this->cellPlugin != nullptr) consumptions[grid->moleculesDict[mol]] = value;
103 else consumptions[mol] = value;
104 }
105
110 inline DiffusionGrid * getDiffusionGrid(){ return this->cellPlugin->pluginDiffusion.getGrid(); }
111
117 if(grid == nullptr){
119 for(int i=0; i<consumptions.size(); ++i) consumptions[i] = consCopy[g->moleculesDict[i]];
120 }
121 grid = g;
122 }
123
132 auto grid = getDiffusionGrid();
134 for(int i=0; i<consumptions.size(); ++i) consumptions[i] = consCopy[grid->moleculesDict[i]];
135 }
136
137 };
138
139}
140
141
142#endif //ONKO3D_3_0_BODYDIFFUSION_HPP
molecules 2D Grid manager
plugin_t * cellPlugin
Definition: BaseBody.hpp:9
Template class for a molecule diffusion body.
DiffusionGrid * getDiffusionGrid()
Gets the diffusion grid.
vector< double > consumptions
double getConsumptionByIndex(int i) const
Gets the consumption of a molecule by index.
void setDiffusionGrid(DiffusionGrid *g)
Sets the diffusion grid.
BodyDiffusion()
Default constructor.
double getQuantity(MecaCell::Vec v, int mol) const
Gets the quantity of a molecule.
double getConsumption(int mol) const
Gets the consumption of a molecule.
BodyDiffusion(int size)
Constructor with size parameter.
void initNbMolecules(int n)
Initializes the number of molecules.
void setConsumption(int mol, double value)
Sets the consumption of a molecule.
void onCellPluginLinking()
Hook called when the body has access to the plugin.
Class representing a grid for molecule diffusion.
unordered_map< int, int > moleculesDict
double getMoleculeRealPos(const MecaCell::Vec &v, int mol)
Gets the quantity of a molecule at a real position.
general purpose 3D vector/point class.
Definition: vector3D.h:20
size_t size() const
Returns the number of elements in the vector.
Definition: std.hpp:320
Namespace for diffusion-related structures and classes.
Provides common mathematical functions and vector operations.
Definition: std.hpp:4