CellModules
Diffusion::DiffusionGrid Class Reference

Class representing a grid for molecule diffusion. More...

#include <DiffusionGrid.hpp>

Public Member Functions

 DiffusionGrid ()=default
 Default constructor. More...
 
 DiffusionGrid (double dx, double accuracy)
 Constructor with grid parameters. More...
 
double getDx () const
 Gets the grid cell size. More...
 
void setDx (double _dx)
 Sets the grid cell size. More...
 
void setAccuracy (double a)
 Sets the diffusion accuracy. More...
 
MecaCell::Vec getIndexFromPosition (const MecaCell::Vec &v) const
 Gets the grid index from a position. More...
 
double getMolecule (MecaCell::Vec v, int m)
 Gets the quantity of a molecule at a position. More...
 
size_t size () const
 Gets the size of the grid. More...
 
unordered_map< MecaCell::Vec, GridCell > & getGrid ()
 Gets the grid. More...
 
double getCellSize () const
 Gets the grid cell size. More...
 
vector< MoleculegetMolecules () const
 Gets the molecules in the grid. More...
 
void addMolecule (int n, Molecule m)
 Adds a molecule to the grid. More...
 
template<typename world_t >
void updateBoundary (world_t *w)
 Updates the grid boundaries and consumptions. More...
 
template<typename world_t >
void computeMolecules (world_t *w)
 Updates the quantities of molecules in the grid. More...
 
double getMoleculeRealPos (const MecaCell::Vec &v, int mol)
 Gets the quantity of a molecule at a real position. More...
 

Public Attributes

unordered_map< int, int > moleculesDict
 

Private Member Functions

double deriv2nd (double xm1, double x, double xp1)
 Calculates the second derivative. More...
 
void nextStep (int i)
 Initializes the next step for a molecule. More...
 
void allCellEmpty ()
 Empties all cells. More...
 
void cleanCellOutBoundary ()
 Cleans cells that are out of boundaries. More...
 
bool isOutBoundary (const MecaCell::Vec &v)
 Checks if a position is out of boundaries. More...
 
double getDt (double D) const
 Gets the diffusion time step. More...
 
double computeStep (int i)
 Updates the quantity of a molecule for each cell and returns the total amount of this molecule. More...
 

Private Attributes

double dx = 5.
 
double accuracy = 0.1
 
unordered_map< MecaCell::Vec, GridCellgrid
 
vector< Moleculemolecules
 
MecaCell::Vec minBoundary
 
MecaCell::Vec maxBoundary
 

Detailed Description

Class representing a grid for molecule diffusion.

Definition at line 80 of file DiffusionGrid.hpp.

Constructor & Destructor Documentation

◆ DiffusionGrid() [1/2]

Diffusion::DiffusionGrid::DiffusionGrid ( )
default

Default constructor.

◆ DiffusionGrid() [2/2]

Diffusion::DiffusionGrid::DiffusionGrid ( double  dx,
double  accuracy 
)
inline

Constructor with grid parameters.

Parameters
dxGrid cell size
accuracyDiffusion accuracy

Definition at line 191 of file DiffusionGrid.hpp.

Member Function Documentation

◆ addMolecule()

void Diffusion::DiffusionGrid::addMolecule ( int  n,
Molecule  m 
)
inline

Adds a molecule to the grid.

Parameters
nMolecule index
mMolecule to be added

Definition at line 263 of file DiffusionGrid.hpp.

◆ allCellEmpty()

void Diffusion::DiffusionGrid::allCellEmpty ( )
inlineprivate

Empties all cells.

Definition at line 113 of file DiffusionGrid.hpp.

◆ cleanCellOutBoundary()

void Diffusion::DiffusionGrid::cleanCellOutBoundary ( )
inlineprivate

Cleans cells that are out of boundaries.

Definition at line 124 of file DiffusionGrid.hpp.

◆ computeMolecules()

template<typename world_t >
void Diffusion::DiffusionGrid::computeMolecules ( world_t *  w)
inline

Updates the quantities of molecules in the grid.

Template Parameters
world_tType of the world
Parameters
wPointer to the world

Definition at line 324 of file DiffusionGrid.hpp.

◆ computeStep()

double Diffusion::DiffusionGrid::computeStep ( int  i)
inlineprivate

Updates the quantity of a molecule for each cell and returns the total amount of this molecule.

Parameters
iMolecule index
Returns
Total quantity of the molecule

Definition at line 153 of file DiffusionGrid.hpp.

◆ deriv2nd()

double Diffusion::DiffusionGrid::deriv2nd ( double  xm1,
double  x,
double  xp1 
)
inlineprivate

Calculates the second derivative.

Parameters
xm1Value at x-1
xValue at x
xp1Value at x+1
Returns
Approximate second derivative at x

Definition at line 98 of file DiffusionGrid.hpp.

◆ getCellSize()

double Diffusion::DiffusionGrid::getCellSize ( ) const
inline

Gets the grid cell size.

Returns
Grid cell size

Definition at line 250 of file DiffusionGrid.hpp.

◆ getDt()

double Diffusion::DiffusionGrid::getDt ( double  D) const
inlineprivate

Gets the diffusion time step.

Parameters
DDiffusion constant of the molecule
Returns
Diffusion time step

Definition at line 146 of file DiffusionGrid.hpp.

◆ getDx()

double Diffusion::DiffusionGrid::getDx ( ) const
inline

Gets the grid cell size.

Returns
Grid cell size

Definition at line 197 of file DiffusionGrid.hpp.

◆ getGrid()

unordered_map< MecaCell::Vec, GridCell > & Diffusion::DiffusionGrid::getGrid ( )
inline

Gets the grid.

Returns
Grid

Definition at line 244 of file DiffusionGrid.hpp.

◆ getIndexFromPosition()

MecaCell::Vec Diffusion::DiffusionGrid::getIndexFromPosition ( const MecaCell::Vec v) const
inline

Gets the grid index from a position.

Parameters
vPosition vector
Returns
Grid index of the position

Definition at line 216 of file DiffusionGrid.hpp.

◆ getMolecule()

double Diffusion::DiffusionGrid::getMolecule ( MecaCell::Vec  v,
int  m 
)
inline

Gets the quantity of a molecule at a position.

Parameters
vPosition vector
mMolecule index
Returns
Quantity of the molecule at the position

Definition at line 227 of file DiffusionGrid.hpp.

◆ getMoleculeRealPos()

double Diffusion::DiffusionGrid::getMoleculeRealPos ( const MecaCell::Vec v,
int  mol 
)
inline

Gets the quantity of a molecule at a real position.

Parameters
vPosition vector
molMolecule index
Returns
Quantity of the molecule at the position

Definition at line 347 of file DiffusionGrid.hpp.

◆ getMolecules()

vector< Molecule > Diffusion::DiffusionGrid::getMolecules ( ) const
inline

Gets the molecules in the grid.

Returns
Molecules

Definition at line 256 of file DiffusionGrid.hpp.

◆ isOutBoundary()

bool Diffusion::DiffusionGrid::isOutBoundary ( const MecaCell::Vec v)
inlineprivate

Checks if a position is out of boundaries.

Parameters
vPosition vector
Returns
True if the position is out of boundaries, false otherwise

Definition at line 137 of file DiffusionGrid.hpp.

◆ nextStep()

void Diffusion::DiffusionGrid::nextStep ( int  i)
inlineprivate

Initializes the next step for a molecule.

Parameters
iMolecule index

Definition at line 104 of file DiffusionGrid.hpp.

◆ setAccuracy()

void Diffusion::DiffusionGrid::setAccuracy ( double  a)
inline

Sets the diffusion accuracy.

Parameters
aDiffusion accuracy

Definition at line 209 of file DiffusionGrid.hpp.

◆ setDx()

void Diffusion::DiffusionGrid::setDx ( double  _dx)
inline

Sets the grid cell size.

Parameters
_dxGrid cell size

Definition at line 203 of file DiffusionGrid.hpp.

◆ size()

size_t Diffusion::DiffusionGrid::size ( ) const
inline

Gets the size of the grid.

Returns
Size of the grid

Definition at line 238 of file DiffusionGrid.hpp.

◆ updateBoundary()

template<typename world_t >
void Diffusion::DiffusionGrid::updateBoundary ( world_t *  w)
inline

Updates the grid boundaries and consumptions.

Template Parameters
world_tType of the world
Parameters
wPointer to the world

Definition at line 274 of file DiffusionGrid.hpp.

Member Data Documentation

◆ accuracy

double Diffusion::DiffusionGrid::accuracy = 0.1
private

Precision of the diffusion

Definition at line 83 of file DiffusionGrid.hpp.

◆ dx

double Diffusion::DiffusionGrid::dx = 5.
private

Cell size

Definition at line 82 of file DiffusionGrid.hpp.

◆ grid

unordered_map<MecaCell::Vec, GridCell> Diffusion::DiffusionGrid::grid
private

Grid cells hashmap

Definition at line 84 of file DiffusionGrid.hpp.

◆ maxBoundary

MecaCell::Vec Diffusion::DiffusionGrid::maxBoundary
private

Definition at line 89 of file DiffusionGrid.hpp.

◆ minBoundary

MecaCell::Vec Diffusion::DiffusionGrid::minBoundary
private

Definition at line 88 of file DiffusionGrid.hpp.

◆ molecules

vector<Molecule> Diffusion::DiffusionGrid::molecules
private

Existing molecules in the simulation

Definition at line 85 of file DiffusionGrid.hpp.

◆ moleculesDict

unordered_map<int,int> Diffusion::DiffusionGrid::moleculesDict

Dictionary mapping molecule indices

Definition at line 179 of file DiffusionGrid.hpp.


The documentation for this class was generated from the following file: