BioDynaMo  v1.03.58-27764645
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
bdm::DiffusionGrid Class Referenceabstract

#include <diffusion_grid.h>

Inheritance diagram for bdm::DiffusionGrid:
[legend]
Collaboration diagram for bdm::DiffusionGrid:
[legend]

Public Member Functions

 DiffusionGrid ()=default
 
 DiffusionGrid (TRootIOCtor *p)
 
 DiffusionGrid (int substance_id, std::string substance_name, real_t dc, real_t mu, int resolution=11)
 
virtual ~DiffusionGrid ()=default
 
virtual void Initialize ()
 
virtual void Update ()
 
void Diffuse (real_t dt)
 
virtual void DiffuseWithClosedEdge (real_t dt)=0
 
virtual void DiffuseWithOpenEdge (real_t dt)=0
 
void CalculateGradient ()
 
void RunInitializers ()
 Initialize the diffusion grid according to the initialization functions. More...
 
void ChangeConcentrationBy (const Real3 &position, real_t amount)
 Increase the concentration at specified box with specified amount. More...
 
void ChangeConcentrationBy (size_t idx, real_t amount)
 Increase the concentration at specified box with specified amount. More...
 
real_t GetConcentration (const Real3 &position) const
 Get the concentration at specified position. More...
 
virtual void GetGradient (const Real3 &position, Real3 *gradient, bool normalize=true) const
 
std::array< uint32_t, 3 > GetBoxCoordinates (const Real3 &position) const
 
size_t GetBoxIndex (const std::array< uint32_t, 3 > &box_coord) const
 
size_t GetBoxIndex (const Real3 &position) const
 Calculates the box index of the substance at specified position. More...
 
void SetDecayConstant (real_t mu)
 
real_t GetLastTimestep ()
 Return the last timestep dt that was used to run Diffuse(dt) More...
 
void SetUpperThreshold (real_t t)
 
real_t GetUpperThreshold () const
 
void SetLowerThreshold (real_t t)
 
real_t GetLowerThreshold () const
 
const real_tGetAllConcentrations () const
 
const real_tGetAllGradients () const
 
std::array< size_t, 3 > GetNumBoxesArray () const
 
size_t GetNumBoxes () const
 
real_t GetBoxLength () const
 
int GetSubstanceId () const
 
const std::string & GetSubstanceName () const
 
real_t GetDecayConstant () const
 
const int32_t * GetDimensionsPtr () const
 
std::array< int32_t, 6 > GetDimensions () const
 
std::array< int32_t, 3 > GetGridSize () const
 
const std::array< real_t, 7 > & GetDiffusionCoefficients () const
 
size_t GetResolution () const
 
real_t GetBoxVolume () const
 
template<typename F >
void AddInitializer (F function)
 
bool IsFixedSubstance ()
 

Private Member Functions

void ParametersCheck (real_t dt)
 
void CopyOldData (const ParallelResizeVector< real_t > &old_c1, const ParallelResizeVector< Real3 > &old_gradients, size_t old_resolution)
 
 BDM_CLASS_DEF (DiffusionGrid, 1)
 

Private Attributes

int substance_ = 0
 The id of the substance of this grid. More...
 
std::string substance_name_ = ""
 The name of the substance of this grid. More...
 
real_t box_length_ = 0
 The side length of each box. More...
 
real_t box_volume_ = 0
 the volume of each box More...
 
ParallelResizeVector< Spinlocklocks_ = {}
 
ParallelResizeVector< real_tc1_ = {}
 The array of concentration values. More...
 
ParallelResizeVector< real_tc2_ = {}
 An extra concentration data buffer for faster value updating. More...
 
ParallelResizeVector< Real3gradients_ = {}
 The array of gradients (x, y, z) More...
 
real_t upper_threshold_ = 1e15
 The maximum concentration value that a box can have. More...
 
real_t lower_threshold_ = -1e15
 The minimum concentration value that a box can have. More...
 
std::array< real_t, 7 > dc_ = {{0}}
 The diffusion coefficients [cc, cw, ce, cs, cn, cb, ct]. More...
 
real_t mu_ = 0
 The decay constant. More...
 
std::array< int32_t, 2 > grid_dimensions_ = {{0}}
 The grid dimensions of the diffusion grid (cubic shaped) More...
 
uint64_t num_boxes_axis_ = 0
 The number of boxes at each axis [x, y, z] (same along each axis) More...
 
size_t total_num_boxes_ = 0
 The total number of boxes in the diffusion grid. More...
 
size_t resolution_ = 0
 
real_t last_dt_ = 0.0
 The last timestep dt used for the diffusion grid update Diffuse(dt) More...
 
bool parity_ = false
 If false, grid dimensions are even; if true, they are odd. More...
 
std::vector< std::function< real_t(real_t, real_t, real_t)> > initializers_
 
bool init_gradient_ = false
 

Friends

class RungeKuttaGrid
 
class EulerGrid
 
class TestGrid
 

Detailed Description

Definition at line 32 of file diffusion_grid.h.

Constructor & Destructor Documentation

◆ DiffusionGrid() [1/3]

bdm::DiffusionGrid::DiffusionGrid ( )
default

◆ DiffusionGrid() [2/3]

bdm::DiffusionGrid::DiffusionGrid ( TRootIOCtor *  p)
inlineexplicit

Definition at line 35 of file diffusion_grid.h.

◆ DiffusionGrid() [3/3]

bdm::DiffusionGrid::DiffusionGrid ( int  substance_id,
std::string  substance_name,
real_t  dc,
real_t  mu,
int  resolution = 11 
)
inline

Definition at line 36 of file diffusion_grid.h.

◆ ~DiffusionGrid()

virtual bdm::DiffusionGrid::~DiffusionGrid ( )
virtualdefault

Member Function Documentation

◆ AddInitializer()

template<typename F >
void bdm::DiffusionGrid::AddInitializer ( function)
inline

Definition at line 163 of file diffusion_grid.h.

◆ BDM_CLASS_DEF()

bdm::DiffusionGrid::BDM_CLASS_DEF ( DiffusionGrid  ,
 
)
private

◆ CalculateGradient()

void bdm::DiffusionGrid::CalculateGradient ( )

Calculates the gradient for each box in the diffusion grid. The gradient is calculated in each direction (x, y, z) as following:

c(x + box_length_) - c(x - box_length) / (2 * box_length_),

where c(x) implies the concentration at position x

At the edges the gradient is the same as the box next to it

Definition at line 223 of file diffusion_grid.cc.

◆ ChangeConcentrationBy() [1/2]

void bdm::DiffusionGrid::ChangeConcentrationBy ( const Real3 position,
real_t  amount 
)

Increase the concentration at specified box with specified amount.

Definition at line 289 of file diffusion_grid.cc.

◆ ChangeConcentrationBy() [2/2]

void bdm::DiffusionGrid::ChangeConcentrationBy ( size_t  idx,
real_t  amount 
)

Increase the concentration at specified box with specified amount.

Definition at line 296 of file diffusion_grid.cc.

◆ CopyOldData()

void bdm::DiffusionGrid::CopyOldData ( const ParallelResizeVector< real_t > &  old_c1,
const ParallelResizeVector< Real3 > &  old_gradients,
size_t  old_resolution 
)
private

Copies the concentration and gradients values to the new (larger) grid. In the 2D case it looks like the following:

                        [0 0  0  0]
          [v1 v2]  -->  [0 v1 v2 0]
          [v3 v4]  -->  [0 v3 v4 0]
                        [0 0  0  0]

The dimensions are doubled in this case from 2x2 to 4x4 If the dimensions would be increased from 2x2 to 3x3, it will still be increased to 4x4 in order for GetBoxIndex to function correctly

Definition at line 148 of file diffusion_grid.cc.

◆ Diffuse()

void bdm::DiffusionGrid::Diffuse ( real_t  dt)

Definition at line 68 of file diffusion_grid.cc.

◆ DiffuseWithClosedEdge()

virtual void bdm::DiffusionGrid::DiffuseWithClosedEdge ( real_t  dt)
pure virtual

Implemented in bdm::RungeKuttaGrid, and bdm::EulerGrid.

◆ DiffuseWithOpenEdge()

virtual void bdm::DiffusionGrid::DiffuseWithOpenEdge ( real_t  dt)
pure virtual

Implemented in bdm::RungeKuttaGrid, and bdm::EulerGrid.

◆ GetAllConcentrations()

const real_t* bdm::DiffusionGrid::GetAllConcentrations ( ) const
inline

Definition at line 113 of file diffusion_grid.h.

◆ GetAllGradients()

const real_t* bdm::DiffusionGrid::GetAllGradients ( ) const
inline

Definition at line 115 of file diffusion_grid.h.

◆ GetBoxCoordinates()

std::array< uint32_t, 3 > bdm::DiffusionGrid::GetBoxCoordinates ( const Real3 position) const

Definition at line 348 of file diffusion_grid.cc.

◆ GetBoxIndex() [1/2]

size_t bdm::DiffusionGrid::GetBoxIndex ( const Real3 position) const

Calculates the box index of the substance at specified position.

Definition at line 365 of file diffusion_grid.cc.

◆ GetBoxIndex() [2/2]

size_t bdm::DiffusionGrid::GetBoxIndex ( const std::array< uint32_t, 3 > &  box_coord) const

Definition at line 357 of file diffusion_grid.cc.

◆ GetBoxLength()

real_t bdm::DiffusionGrid::GetBoxLength ( ) const
inline

Definition at line 127 of file diffusion_grid.h.

◆ GetBoxVolume()

real_t bdm::DiffusionGrid::GetBoxVolume ( ) const
inline

Definition at line 160 of file diffusion_grid.h.

◆ GetConcentration()

real_t bdm::DiffusionGrid::GetConcentration ( const Real3 position) const

Get the concentration at specified position.

Definition at line 317 of file diffusion_grid.cc.

◆ GetDecayConstant()

real_t bdm::DiffusionGrid::GetDecayConstant ( ) const
inline

Definition at line 133 of file diffusion_grid.h.

◆ GetDiffusionCoefficients()

const std::array<real_t, 7>& bdm::DiffusionGrid::GetDiffusionCoefficients ( ) const
inline

Definition at line 156 of file diffusion_grid.h.

◆ GetDimensions()

std::array<int32_t, 6> bdm::DiffusionGrid::GetDimensions ( ) const
inline

Definition at line 137 of file diffusion_grid.h.

◆ GetDimensionsPtr()

const int32_t* bdm::DiffusionGrid::GetDimensionsPtr ( ) const
inline

Definition at line 135 of file diffusion_grid.h.

◆ GetGradient()

void bdm::DiffusionGrid::GetGradient ( const Real3 position,
Real3 gradient,
bool  normalize = true 
) const
virtual

Get the gradient at a specified position. By default, the obtained gradient is scaled to norm 1, but with normalize = false one can obtain the full gradient information (e.g. the un-normalized gradient). If the gradient is zero and normalize = true, this method returns a zero vector. Note that the gradient is computed via a central difference scheme on the underlying spatial discretization.

Definition at line 330 of file diffusion_grid.cc.

◆ GetGridSize()

std::array<int32_t, 3> bdm::DiffusionGrid::GetGridSize ( ) const
inline

Definition at line 148 of file diffusion_grid.h.

◆ GetLastTimestep()

real_t bdm::DiffusionGrid::GetLastTimestep ( )
inline

Return the last timestep dt that was used to run Diffuse(dt)

Definition at line 99 of file diffusion_grid.h.

◆ GetLowerThreshold()

real_t bdm::DiffusionGrid::GetLowerThreshold ( ) const
inline

Definition at line 111 of file diffusion_grid.h.

◆ GetNumBoxes()

size_t bdm::DiffusionGrid::GetNumBoxes ( ) const
inline

Definition at line 125 of file diffusion_grid.h.

◆ GetNumBoxesArray()

std::array<size_t, 3> bdm::DiffusionGrid::GetNumBoxesArray ( ) const
inline

Definition at line 117 of file diffusion_grid.h.

◆ GetResolution()

size_t bdm::DiffusionGrid::GetResolution ( ) const
inline

Definition at line 158 of file diffusion_grid.h.

◆ GetSubstanceId()

int bdm::DiffusionGrid::GetSubstanceId ( ) const
inline

Definition at line 129 of file diffusion_grid.h.

◆ GetSubstanceName()

const std::string& bdm::DiffusionGrid::GetSubstanceName ( ) const
inline

Definition at line 131 of file diffusion_grid.h.

◆ GetUpperThreshold()

real_t bdm::DiffusionGrid::GetUpperThreshold ( ) const
inline

Definition at line 105 of file diffusion_grid.h.

◆ Initialize()

void bdm::DiffusionGrid::Initialize ( )
virtual

Reimplemented in bdm::RungeKuttaGrid.

Definition at line 23 of file diffusion_grid.cc.

◆ IsFixedSubstance()

bool bdm::DiffusionGrid::IsFixedSubstance ( )
inline

Definition at line 168 of file diffusion_grid.h.

◆ ParametersCheck()

void bdm::DiffusionGrid::ParametersCheck ( real_t  dt)
private

Definition at line 370 of file diffusion_grid.cc.

◆ RunInitializers()

void bdm::DiffusionGrid::RunInitializers ( )

Initialize the diffusion grid according to the initialization functions.

Definition at line 190 of file diffusion_grid.cc.

◆ SetDecayConstant()

void bdm::DiffusionGrid::SetDecayConstant ( real_t  mu)
inline

Definition at line 96 of file diffusion_grid.h.

◆ SetLowerThreshold()

void bdm::DiffusionGrid::SetLowerThreshold ( real_t  t)
inline

Definition at line 108 of file diffusion_grid.h.

◆ SetUpperThreshold()

void bdm::DiffusionGrid::SetUpperThreshold ( real_t  t)
inline

Definition at line 102 of file diffusion_grid.h.

◆ Update()

void bdm::DiffusionGrid::Update ( )
virtual

Updates the grid dimensions, based on the given threshold values. The diffusion grid dimensions need always be larger than the neighbor grid dimensions, so that each simulation object can obtain its local concentration / gradient

Reimplemented in bdm::RungeKuttaGrid.

Definition at line 93 of file diffusion_grid.cc.

Friends And Related Function Documentation

◆ EulerGrid

friend class EulerGrid
friend

Definition at line 175 of file diffusion_grid.h.

◆ RungeKuttaGrid

friend class RungeKuttaGrid
friend

Definition at line 174 of file diffusion_grid.h.

◆ TestGrid

friend class TestGrid
friend

Definition at line 176 of file diffusion_grid.h.

Member Data Documentation

◆ box_length_

real_t bdm::DiffusionGrid::box_length_ = 0
private

The side length of each box.

Definition at line 201 of file diffusion_grid.h.

◆ box_volume_

real_t bdm::DiffusionGrid::box_volume_ = 0
private

the volume of each box

Definition at line 203 of file diffusion_grid.h.

◆ c1_

ParallelResizeVector<real_t> bdm::DiffusionGrid::c1_ = {}
private

The array of concentration values.

Definition at line 208 of file diffusion_grid.h.

◆ c2_

ParallelResizeVector<real_t> bdm::DiffusionGrid::c2_ = {}
private

An extra concentration data buffer for faster value updating.

Definition at line 210 of file diffusion_grid.h.

◆ dc_

std::array<real_t, 7> bdm::DiffusionGrid::dc_ = {{0}}
private

The diffusion coefficients [cc, cw, ce, cs, cn, cb, ct].

Definition at line 218 of file diffusion_grid.h.

◆ gradients_

ParallelResizeVector<Real3> bdm::DiffusionGrid::gradients_ = {}
private

The array of gradients (x, y, z)

Definition at line 212 of file diffusion_grid.h.

◆ grid_dimensions_

std::array<int32_t, 2> bdm::DiffusionGrid::grid_dimensions_ = {{0}}
private

The grid dimensions of the diffusion grid (cubic shaped)

Definition at line 222 of file diffusion_grid.h.

◆ init_gradient_

bool bdm::DiffusionGrid::init_gradient_ = false
private

Definition at line 239 of file diffusion_grid.h.

◆ initializers_

std::vector<std::function<real_t(real_t, real_t, real_t)> > bdm::DiffusionGrid::initializers_
private
Initial value:
=
{}

A list of functions that initialize this diffusion grid ROOT currently doesn't support IO of std::function

Definition at line 236 of file diffusion_grid.h.

◆ last_dt_

real_t bdm::DiffusionGrid::last_dt_ = 0.0
private

The last timestep dt used for the diffusion grid update Diffuse(dt)

Definition at line 231 of file diffusion_grid.h.

◆ locks_

ParallelResizeVector<Spinlock> bdm::DiffusionGrid::locks_ = {}
mutableprivate

Lock for each voxel used to prevent race conditions between multiple threads

Definition at line 206 of file diffusion_grid.h.

◆ lower_threshold_

real_t bdm::DiffusionGrid::lower_threshold_ = -1e15
private

The minimum concentration value that a box can have.

Definition at line 216 of file diffusion_grid.h.

◆ mu_

real_t bdm::DiffusionGrid::mu_ = 0
private

The decay constant.

Definition at line 220 of file diffusion_grid.h.

◆ num_boxes_axis_

uint64_t bdm::DiffusionGrid::num_boxes_axis_ = 0
private

The number of boxes at each axis [x, y, z] (same along each axis)

Definition at line 224 of file diffusion_grid.h.

◆ parity_

bool bdm::DiffusionGrid::parity_ = false
private

If false, grid dimensions are even; if true, they are odd.

Definition at line 233 of file diffusion_grid.h.

◆ resolution_

size_t bdm::DiffusionGrid::resolution_ = 0
private

The resolution of the diffusion grid (i.e. number of boxes along each axis)

Definition at line 229 of file diffusion_grid.h.

◆ substance_

int bdm::DiffusionGrid::substance_ = 0
private

The id of the substance of this grid.

Definition at line 197 of file diffusion_grid.h.

◆ substance_name_

std::string bdm::DiffusionGrid::substance_name_ = ""
private

The name of the substance of this grid.

Definition at line 199 of file diffusion_grid.h.

◆ total_num_boxes_

size_t bdm::DiffusionGrid::total_num_boxes_ = 0
private

The total number of boxes in the diffusion grid.

Definition at line 226 of file diffusion_grid.h.

◆ upper_threshold_

real_t bdm::DiffusionGrid::upper_threshold_ = 1e15
private

The maximum concentration value that a box can have.

Definition at line 214 of file diffusion_grid.h.


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