CellModules
Diffusion2D::DiffusionGrid Class Reference

Manages a grid of molecules for diffusion. More...

#include <DiffusionGrid.hpp>

Public Member Functions

 DiffusionGrid ()=default
 
void setToreX (bool b)
 Sets the toroidal property on the x-axis. More...
 
void setToreY (bool b)
 Sets the toroidal property on the y-axis. More...
 
void setTore (bool x, bool y)
 Sets the toroidal properties on both axes. More...
 
double getMolecule (int x, int y, int m)
 Gets the quantity of a molecule at a specific position. More...
 
int getWidth () const
 Gets the width of the grid. More...
 
int getHeight () const
 Gets the height of the grid. More...
 
std::vector< std::vector< GridCell > > & getGrid ()
 Gets the grid. More...
 
std::vector< MoleculegetMolecules () const
 Gets the molecules in the grid. More...
 
void addMolecule (int id, Molecule m)
 Adds a molecule to the grid. More...
 
void initGrid (int w, int h)
 Initializes the grid with dimensions. More...
 
void initGrid (int size)
 Initializes the square grid. More...
 
template<typename world_t >
void computeMolecules (world_t *w)
 Computes the quantities of molecules in the grid. More...
 

Public Attributes

std::unordered_map< int, int > moleculesDict
 

Private Member Functions

void preStep ()
 Initializes cells for the next step. More...
 
void diffuse (int x, int y)
 Applies diffusion to the molecule at position (x, y). More...
 
void computeStep ()
 Updates the quantity of molecules for each cell. More...
 
template<typename world_t >
void updateConsumptions (world_t *w)
 Updates the consumptions for each cell. More...
 

Private Attributes

std::vector< std::vector< GridCell > > grid
 
std::vector< Moleculemolecules
 
bool toreX = true
 
bool toreY = true
 
int height = 10
 
int width = 10
 

Detailed Description

Manages a grid of molecules for diffusion.

Definition at line 71 of file DiffusionGrid.hpp.

Constructor & Destructor Documentation

◆ DiffusionGrid()

Diffusion2D::DiffusionGrid::DiffusionGrid ( )
default

Member Function Documentation

◆ addMolecule()

void Diffusion2D::DiffusionGrid::addMolecule ( int  id,
Molecule  m 
)
inline

Adds a molecule to the grid.

Parameters
idid of the molecule. if you use Enum, you can cast it to int.
mMolecule to be added.

Definition at line 250 of file DiffusionGrid.hpp.

◆ computeMolecules()

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

Computes the quantities of molecules in the grid.

Template Parameters
world_tType of the world.
Parameters
wPointer to the world.

Definition at line 287 of file DiffusionGrid.hpp.

◆ computeStep()

void Diffusion2D::DiffusionGrid::computeStep ( )
inlineprivate

Updates the quantity of molecules for each cell.

Definition at line 157 of file DiffusionGrid.hpp.

◆ diffuse()

void Diffusion2D::DiffusionGrid::diffuse ( int  x,
int  y 
)
inlineprivate

Applies diffusion to the molecule at position (x, y).

Parameters
xX-coordinate.
yY-coordinate.

Definition at line 103 of file DiffusionGrid.hpp.

◆ getGrid()

std::vector< std::vector< GridCell > > & Diffusion2D::DiffusionGrid::getGrid ( )
inline

Gets the grid.

Returns
Reference to the grid.

Definition at line 236 of file DiffusionGrid.hpp.

◆ getHeight()

int Diffusion2D::DiffusionGrid::getHeight ( ) const
inline

Gets the height of the grid.

Returns
Height of the grid.

Definition at line 230 of file DiffusionGrid.hpp.

◆ getMolecule()

double Diffusion2D::DiffusionGrid::getMolecule ( int  x,
int  y,
int  m 
)
inline

Gets the quantity of a molecule at a specific position.

Parameters
xX-coordinate.
yY-coordinate.
mNumber of the molecule.
Returns
Quantity of the molecule.

Definition at line 218 of file DiffusionGrid.hpp.

◆ getMolecules()

std::vector< Molecule > Diffusion2D::DiffusionGrid::getMolecules ( ) const
inline

Gets the molecules in the grid.

Returns
Vector of molecules.

Definition at line 242 of file DiffusionGrid.hpp.

◆ getWidth()

int Diffusion2D::DiffusionGrid::getWidth ( ) const
inline

Gets the width of the grid.

Returns
Width of the grid.

Definition at line 224 of file DiffusionGrid.hpp.

◆ initGrid() [1/2]

void Diffusion2D::DiffusionGrid::initGrid ( int  size)
inline

Initializes the square grid.

Parameters
sizeSize of the grid.

Definition at line 278 of file DiffusionGrid.hpp.

◆ initGrid() [2/2]

void Diffusion2D::DiffusionGrid::initGrid ( int  w,
int  h 
)
inline

Initializes the grid with dimensions.

Parameters
wWidth of the grid.
hHeight of the grid.

Definition at line 261 of file DiffusionGrid.hpp.

◆ preStep()

void Diffusion2D::DiffusionGrid::preStep ( )
inlineprivate

Initializes cells for the next step.

Definition at line 85 of file DiffusionGrid.hpp.

◆ setTore()

void Diffusion2D::DiffusionGrid::setTore ( bool  x,
bool  y 
)
inline

Sets the toroidal properties on both axes.

Parameters
xBoolean value for the x-axis.
yBoolean value for the y-axis.

Definition at line 208 of file DiffusionGrid.hpp.

◆ setToreX()

void Diffusion2D::DiffusionGrid::setToreX ( bool  b)
inline

Sets the toroidal property on the x-axis.

Parameters
bBoolean value for the toroidal property.

Definition at line 193 of file DiffusionGrid.hpp.

◆ setToreY()

void Diffusion2D::DiffusionGrid::setToreY ( bool  b)
inline

Sets the toroidal property on the y-axis.

Parameters
bBoolean value for the toroidal property.

Definition at line 200 of file DiffusionGrid.hpp.

◆ updateConsumptions()

template<typename world_t >
void Diffusion2D::DiffusionGrid::updateConsumptions ( world_t *  w)
inlineprivate

Updates the consumptions for each cell.

Template Parameters
world_tType of the world.
Parameters
wPointer to the world.

Definition at line 172 of file DiffusionGrid.hpp.

Member Data Documentation

◆ grid

std::vector<std::vector<GridCell> > Diffusion2D::DiffusionGrid::grid
private

Matrix of grid cells

Definition at line 73 of file DiffusionGrid.hpp.

◆ height

int Diffusion2D::DiffusionGrid::height = 10
private

Definition at line 79 of file DiffusionGrid.hpp.

◆ molecules

std::vector<Molecule> Diffusion2D::DiffusionGrid::molecules
private

Existing molecules in the simulation

Definition at line 74 of file DiffusionGrid.hpp.

◆ moleculesDict

std::unordered_map<int,int> Diffusion2D::DiffusionGrid::moleculesDict

Definition at line 184 of file DiffusionGrid.hpp.

◆ toreX

bool Diffusion2D::DiffusionGrid::toreX = true
private

Toroidal property on the x-axis

Definition at line 76 of file DiffusionGrid.hpp.

◆ toreY

bool Diffusion2D::DiffusionGrid::toreY = true
private

Toroidal property on the y-axis

Definition at line 77 of file DiffusionGrid.hpp.

◆ width

int Diffusion2D::DiffusionGrid::width = 10
private

Definition at line 80 of file DiffusionGrid.hpp.


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