BioDynaMo  v1.05.119-a4ff3934
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
bdm::UniformGridEnvironment Class Reference

A class that represents Cartesian 3D grid. More...

#include <uniform_grid_environment.h>

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

Classes

struct  AssignToBoxesFunctor
 
struct  Box
 A single unit cube of the grid. More...
 
class  GridNeighborMutexBuilder
 
class  LoadBalanceInfoUG
 
struct  NeighborIterator
 An iterator that iterates over the boxes in this grid. More...
 

Public Types

enum  Adjacency { kLow, kMedium, kHigh }
 Enum that determines the degree of adjacency in search neighbor boxes. More...
 

Public Member Functions

 UniformGridEnvironment (Adjacency adjacency=kHigh)
 
 UniformGridEnvironment (UniformGridEnvironment const &)=delete
 
void operator= (UniformGridEnvironment const &)=delete
 
 ~UniformGridEnvironment () override=default
 
void Clear () override
 Clears the grid. More...
 
void SetBoxLength (int32_t bl)
 
void SetDetermineSimSize (bool value)
 
int32_t GetBoxLength () const
 
real_t SquaredEuclideanDistance (const Real3 &pos1, const Real3 &pos2) const
 Calculates the squared euclidean distance between two points in 3D. More...
 
bool WithinSquaredEuclideanDistance (real_t squared_radius, const Real3 &pos1, const Real3 &pos2) const
 
LoadBalanceInfoGetLoadBalanceInfo () override
 
size_t GetBoxIndex (const Real3 &position) const
 Return the box index in the one dimensional array of the box that contains the position. More...
 
std::array< int32_t, 6 > GetDimensions () const override
 
bool ContainedInGrid (const Real3 &point) const
 
std::array< int32_t, 2 > GetDimensionThresholds () const override
 
void GetNumBoxesAxis (uint32_t *nba)
 
uint64_t GetNumBoxes () const
 
std::array< uint64_t, 3 > GetBoxCoordinates (size_t box_idx) const
 
void ForEachNeighbor (Functor< void, Agent *, real_t > &lambda, const Agent &query, real_t squared_radius) override
 Applies the given lambda to each neighbor of the specified agent is within the squared radius. More...
 
void ForEachNeighbor (Functor< void, Agent *, real_t > &lambda, const Real3 &query_position, real_t squared_radius, const Agent *query_agent=nullptr) override
 Applies the given lambda to each neighbor of the specified position within the squared radius. More...
 
void ForEachNeighbor (Functor< void, Agent * > &functor, const Agent &query, void *criteria) override
 Applies the given functor to each neighbor of the specified agent that is within the same box as the query agent or in the 26 surrounding boxes. More...
 
NeighborMutexBuilderGetNeighborMutexBuilder () override
 
- Public Member Functions inherited from bdm::Environment
virtual ~Environment ()=default
 
void MarkAsOutOfSync ()
 
void Update ()
 
void ForcedUpdate ()
 Updates the environment. Prefer Update() for implementations. More...
 
real_t GetLargestAgentSize () const
 Return the size of the largest agent. More...
 
real_t GetLargestAgentSizeSquared () const
 
bool HasGrown () const
 

Protected Member Functions

void UpdateImplementation () override
 Updates the grid, as agents may have moved, added or deleted. More...
 
- Protected Member Functions inherited from bdm::Environment
void CalcSimDimensionsAndLargestAgent (std::array< real_t, 6 > *ret_grid_dimensions)
 

Private Member Functions

void CheckGridGrowth ()
 
void RoundOffGridDimensions (const std::array< real_t, 6 > &grid_dimensions)
 
void GetMooreBoxes (FixedSizeVector< const Box *, 27 > *neighbor_boxes, size_t box_idx) const
 Gets the Moore (i.e adjacent) boxes of the query boxAlso adds the query box. More...
 
void GetMooreBoxIndices (FixedSizeVector< uint64_t, 27 > *box_indices, size_t box_idx) const
 Gets the box indices of all adjacent boxes. Also adds the query box index. More...
 
void GetHalfMooreBoxIndices (FixedSizeVector< size_t, 14 > *neighbor_boxes, size_t box_idx) const
 
const BoxGetBoxPointer (size_t index) const
 Gets the pointer to the box with the given index. More...
 
BoxGetBoxPointer (size_t index)
 Gets the pointer to the box with the given index. More...
 
size_t GetBoxIndex (const std::array< uint64_t, 3 > &box_coord) const
 

Private Attributes

ParallelResizeVector< Boxboxes_
 
uint32_t timestamp_ = 0
 
int32_t box_length_ = 1
 Length of a Box. More...
 
int32_t box_length_squared_ = 1
 Length of a Box squared. More...
 
bool is_custom_box_length_ = false
 True when the box length was set manually. More...
 
bool determine_sim_size_ = true
 
std::array< uint64_t, 3 > num_boxes_axis_ = {{0}}
 Stores the number of Boxes for each axis. More...
 
size_t num_boxes_xy_ = 0
 Number of boxes in the xy plane (=num_boxes_axis_[0] * num_boxes_axis_[1]) More...
 
uint64_t total_num_boxes_ = 0
 The total number of boxes in the uniform grid. More...
 
AgentVector< AgentHandlesuccessors_
 
Adjacency adjacency_
 Determines which boxes to search neighbors in (see enum Adjacency) More...
 
std::array< int32_t, 6 > grid_dimensions_
 
std::array< int32_t, 2 > threshold_dimensions_
 
LoadBalanceInfoUG lbi_
 
std::unique_ptr< GridNeighborMutexBuildernb_mutex_builder_
 

Friends

struct MechanicalForcesOpCuda
 
struct ::bdm::detail::InitializeGPUData
 
struct MechanicalForcesOpOpenCL
 
class SchedulerTest
 

Additional Inherited Members

- Protected Attributes inherited from bdm::Environment
bool has_grown_ = false
 
real_t largest_object_size_ = 0.0
 The size of the largest object in the simulation. More...
 
real_t largest_object_size_squared_ = 0.0
 

Detailed Description

A class that represents Cartesian 3D grid.

Definition at line 58 of file uniform_grid_environment.h.

Member Enumeration Documentation

◆ Adjacency

Enum that determines the degree of adjacency in search neighbor boxes.

Enumerator
kLow 

The closest 8 neighboring boxes

kMedium 

The closest 18 neighboring boxes

kHigh 

The closest 26 neighboring boxes

Definition at line 228 of file uniform_grid_environment.h.

Constructor & Destructor Documentation

◆ UniformGridEnvironment() [1/2]

bdm::UniformGridEnvironment::UniformGridEnvironment ( Adjacency  adjacency = kHigh)
inlineexplicit

Definition at line 234 of file uniform_grid_environment.h.

◆ UniformGridEnvironment() [2/2]

bdm::UniformGridEnvironment::UniformGridEnvironment ( UniformGridEnvironment const &  )
delete

◆ ~UniformGridEnvironment()

bdm::UniformGridEnvironment::~UniformGridEnvironment ( )
overridedefault

Member Function Documentation

◆ CheckGridGrowth()

void bdm::UniformGridEnvironment::CheckGridGrowth ( )
inlineprivate

Definition at line 698 of file uniform_grid_environment.h.

◆ Clear()

void bdm::UniformGridEnvironment::Clear ( )
inlineoverridevirtual

Clears the grid.

Implements bdm::Environment.

Definition at line 243 of file uniform_grid_environment.h.

◆ ContainedInGrid()

bool bdm::UniformGridEnvironment::ContainedInGrid ( const Real3 point) const
inline

Returns true if the provided point is inside the simulation domain. Compares the points coordinates against grid_dimensions_ (without bounding boxes).

Definition at line 356 of file uniform_grid_environment.h.

◆ ForEachNeighbor() [1/3]

void bdm::UniformGridEnvironment::ForEachNeighbor ( Functor< void, Agent * > &  functor,
const Agent query,
void *  criteria 
)
overridevirtual

Applies the given functor to each neighbor of the specified agent that is within the same box as the query agent or in the 26 surrounding boxes.

In simulation code do not use this function directly. Use the same function from the execution context (e.g. InPlaceExecutionContext)

Parameters
[in]functorThe operation as a functor
[in]queryThe query object
[in]criteriaThis parameter is ignored. Pass a nullptr.

Implements bdm::Environment.

Definition at line 307 of file uniform_grid_environment.cc.

◆ ForEachNeighbor() [2/3]

void bdm::UniformGridEnvironment::ForEachNeighbor ( Functor< void, Agent *, real_t > &  lambda,
const Agent query,
real_t  squared_radius 
)
inlineoverridevirtual

Applies the given lambda to each neighbor of the specified agent is within the squared radius.

In simulation code do not use this function directly. Use the same function from the execution context (e.g. InPlaceExecutionContext)

Parameters
[in]lambdaThe operation as a lambda
queryThe query object
squared_radiusThe squared search radius (type: real_t*)

Implements bdm::Environment.

Definition at line 406 of file uniform_grid_environment.h.

◆ ForEachNeighbor() [3/3]

void bdm::UniformGridEnvironment::ForEachNeighbor ( Functor< void, Agent *, real_t > &  lambda,
const Real3 query_position,
real_t  squared_radius,
const Agent query_agent = nullptr 
)
inlineoverridevirtual

Applies the given lambda to each neighbor of the specified position within the squared radius.

In simulation code do not use this function directly. Use the same function from the execution context (e.g. InPlaceExecutionContext)

Parameters
[in]lambdaThe operation as a lambda
query_positionThe query position
squared_radiusThe squared search radius (type: real_t*)

Implements bdm::Environment.

Definition at line 421 of file uniform_grid_environment.h.

◆ GetBoxCoordinates()

std::array<uint64_t, 3> bdm::UniformGridEnvironment::GetBoxCoordinates ( size_t  box_idx) const
inline

Definition at line 387 of file uniform_grid_environment.h.

◆ GetBoxIndex() [1/2]

size_t bdm::UniformGridEnvironment::GetBoxIndex ( const Real3 position) const
inline

Return the box index in the one dimensional array of the box that contains the position.

Parameters
[in]positionThe position of the object
Returns
The box index.

Definition at line 330 of file uniform_grid_environment.h.

◆ GetBoxIndex() [2/2]

size_t bdm::UniformGridEnvironment::GetBoxIndex ( const std::array< uint64_t, 3 > &  box_coord) const
inlineprivate

Returns the box index in the one dimensional array based on box coordinates in space

Parameters
box_coordbox coordinates in space (x, y, z)
Returns
The box index.

Definition at line 946 of file uniform_grid_environment.h.

◆ GetBoxLength()

int32_t bdm::UniformGridEnvironment::GetBoxLength ( ) const
inline

Definition at line 280 of file uniform_grid_environment.h.

◆ GetBoxPointer() [1/2]

Box* bdm::UniformGridEnvironment::GetBoxPointer ( size_t  index)
inlineprivate

Gets the pointer to the box with the given index.

Parameters
[in]indexThe index of the box
Returns
The pointer to the box

Definition at line 934 of file uniform_grid_environment.h.

◆ GetBoxPointer() [2/2]

const Box* bdm::UniformGridEnvironment::GetBoxPointer ( size_t  index) const
inlineprivate

Gets the pointer to the box with the given index.

Parameters
[in]indexThe index of the box
Returns
The pointer to the box

Definition at line 923 of file uniform_grid_environment.h.

◆ GetDimensions()

std::array<int32_t, 6> bdm::UniformGridEnvironment::GetDimensions ( ) const
inlineoverridevirtual

Implements bdm::Environment.

Definition at line 349 of file uniform_grid_environment.h.

◆ GetDimensionThresholds()

std::array<int32_t, 2> bdm::UniformGridEnvironment::GetDimensionThresholds ( ) const
inlineoverridevirtual

Implements bdm::Environment.

Definition at line 371 of file uniform_grid_environment.h.

◆ GetHalfMooreBoxIndices()

void bdm::UniformGridEnvironment::GetHalfMooreBoxIndices ( FixedSizeVector< size_t, 14 > *  neighbor_boxes,
size_t  box_idx 
) const
inlineprivate

Determines current box based on parameter box_idx and adds it together with half of the surrounding boxes to the vector. Legend: C = center, N = north, E = east, S = south, W = west, F = front, B = back For each box pair which is centro-symmetric only one box is taken – e.g. E-W: E, or BNW-FSE: BNW

   (x-axis to the right \ y-axis up)
   z=1
   +-----+----+-----+
   | BNW | BN | BNE |
   +-----+----+-----+
   | NW  | N  | NE  |
   +-----+----+-----+
   | FNW | FN | FNE |
   +-----+----+-----+

   z = 0
   +-----+----+-----+
   | BW  | B  | BE  |
   +-----+----+-----+
   | W   | C  | E   |
   +-----+----+-----+
   | FW  | F  | FE  |
   +-----+----+-----+

   z = -1
   +-----+----+-----+
   | BSW | BS | BSE |
   +-----+----+-----+
   | SW  | S  | SE  |
   +-----+----+-----+
   | FSW | FS | FSE |
   +-----+----+-----+

Definition at line 885 of file uniform_grid_environment.h.

◆ GetLoadBalanceInfo()

LoadBalanceInfo* bdm::UniformGridEnvironment::GetLoadBalanceInfo ( )
inlineoverridevirtual

Implements bdm::Environment.

Definition at line 318 of file uniform_grid_environment.h.

◆ GetMooreBoxes()

void bdm::UniformGridEnvironment::GetMooreBoxes ( FixedSizeVector< const Box *, 27 > *  neighbor_boxes,
size_t  box_idx 
) const
inlineprivate

Gets the Moore (i.e adjacent) boxes of the query boxAlso adds the query box.

Parameters
[out]neighbor_boxesThe neighbor boxes
[in]box_idxThe query box

Definition at line 742 of file uniform_grid_environment.h.

◆ GetMooreBoxIndices()

void bdm::UniformGridEnvironment::GetMooreBoxIndices ( FixedSizeVector< uint64_t, 27 > *  box_indices,
size_t  box_idx 
) const
inlineprivate

Gets the box indices of all adjacent boxes. Also adds the query box index.

Parameters
[out]box_indicesResult containing all box indices
[in]box_idxThe query box

Definition at line 807 of file uniform_grid_environment.h.

◆ GetNeighborMutexBuilder()

NeighborMutexBuilder* bdm::UniformGridEnvironment::GetNeighborMutexBuilder ( )
inlineoverridevirtual

Returns the NeighborMutexBuilder. The client use it to create a NeighborMutex.

Implements bdm::Environment.

Definition at line 610 of file uniform_grid_environment.h.

◆ GetNumBoxes()

uint64_t bdm::UniformGridEnvironment::GetNumBoxes ( ) const
inline

Definition at line 385 of file uniform_grid_environment.h.

◆ GetNumBoxesAxis()

void bdm::UniformGridEnvironment::GetNumBoxesAxis ( uint32_t *  nba)
inline

Definition at line 375 of file uniform_grid_environment.h.

◆ operator=()

void bdm::UniformGridEnvironment::operator= ( UniformGridEnvironment const &  )
delete

◆ RoundOffGridDimensions()

void bdm::UniformGridEnvironment::RoundOffGridDimensions ( const std::array< real_t, 6 > &  grid_dimensions)
inlineprivate

Definition at line 719 of file uniform_grid_environment.h.

◆ SetBoxLength()

void bdm::UniformGridEnvironment::SetBoxLength ( int32_t  bl)
inline

Definition at line 273 of file uniform_grid_environment.h.

◆ SetDetermineSimSize()

void bdm::UniformGridEnvironment::SetDetermineSimSize ( bool  value)
inline

Definition at line 278 of file uniform_grid_environment.h.

◆ SquaredEuclideanDistance()

real_t bdm::UniformGridEnvironment::SquaredEuclideanDistance ( const Real3 pos1,
const Real3 pos2 
) const
inline

Calculates the squared euclidean distance between two points in 3D.

Parameters
[in]pos1Position of the first point
[in]pos2Position of the second point
Returns
The distance between the two points

Definition at line 290 of file uniform_grid_environment.h.

◆ UpdateImplementation()

void bdm::UniformGridEnvironment::UpdateImplementation ( )
overrideprotectedvirtual

Updates the grid, as agents may have moved, added or deleted.

Implements bdm::Environment.

Definition at line 112 of file uniform_grid_environment.cc.

◆ WithinSquaredEuclideanDistance()

bool bdm::UniformGridEnvironment::WithinSquaredEuclideanDistance ( real_t  squared_radius,
const Real3 pos1,
const Real3 pos2 
) const
inline

Definition at line 298 of file uniform_grid_environment.h.

Friends And Related Function Documentation

◆ ::bdm::detail::InitializeGPUData

friend struct ::bdm::detail::InitializeGPUData
friend

Definition at line 63 of file uniform_grid_environment.h.

◆ MechanicalForcesOpCuda

friend struct MechanicalForcesOpCuda
friend

Definition at line 62 of file uniform_grid_environment.h.

◆ MechanicalForcesOpOpenCL

friend struct MechanicalForcesOpOpenCL
friend

Definition at line 64 of file uniform_grid_environment.h.

◆ SchedulerTest

friend class SchedulerTest
friend

Definition at line 65 of file uniform_grid_environment.h.

Member Data Documentation

◆ adjacency_

Adjacency bdm::UniformGridEnvironment::adjacency_
private

Determines which boxes to search neighbors in (see enum Adjacency)

Definition at line 682 of file uniform_grid_environment.h.

◆ box_length_

int32_t bdm::UniformGridEnvironment::box_length_ = 1
private

Length of a Box.

Definition at line 660 of file uniform_grid_environment.h.

◆ box_length_squared_

int32_t bdm::UniformGridEnvironment::box_length_squared_ = 1
private

Length of a Box squared.

Definition at line 662 of file uniform_grid_environment.h.

◆ boxes_

ParallelResizeVector<Box> bdm::UniformGridEnvironment::boxes_
private

The vector containing all the boxes in the grid Using parallel resize vector to enable parallel initialization and thus better scalability.

Definition at line 655 of file uniform_grid_environment.h.

◆ determine_sim_size_

bool bdm::UniformGridEnvironment::determine_sim_size_ = true
private

If set to true, the UniformGridEnvironment determines the size of the simulation space automatically. If false, it uses param->min_bound and param->max_bound for each dimension

Definition at line 668 of file uniform_grid_environment.h.

◆ grid_dimensions_

std::array<int32_t, 6> bdm::UniformGridEnvironment::grid_dimensions_
private

Cube which contains all agents {x_min, x_max, y_min, y_max, z_min, z_max}

Definition at line 685 of file uniform_grid_environment.h.

◆ is_custom_box_length_

bool bdm::UniformGridEnvironment::is_custom_box_length_ = false
private

True when the box length was set manually.

Definition at line 664 of file uniform_grid_environment.h.

◆ lbi_

LoadBalanceInfoUG bdm::UniformGridEnvironment::lbi_
private

Definition at line 690 of file uniform_grid_environment.h.

◆ nb_mutex_builder_

std::unique_ptr<GridNeighborMutexBuilder> bdm::UniformGridEnvironment::nb_mutex_builder_
private
Initial value:
=
std::make_unique<GridNeighborMutexBuilder>()

Holds instance of NeighborMutexBuilder. NeighborMutexBuilder is updated if Param::thread_safety_mechanism is set to kAutomatic

Definition at line 695 of file uniform_grid_environment.h.

◆ num_boxes_axis_

std::array<uint64_t, 3> bdm::UniformGridEnvironment::num_boxes_axis_ = {{0}}
private

Stores the number of Boxes for each axis.

Definition at line 670 of file uniform_grid_environment.h.

◆ num_boxes_xy_

size_t bdm::UniformGridEnvironment::num_boxes_xy_ = 0
private

Number of boxes in the xy plane (=num_boxes_axis_[0] * num_boxes_axis_[1])

Definition at line 672 of file uniform_grid_environment.h.

◆ successors_

AgentVector<AgentHandle> bdm::UniformGridEnvironment::successors_
private

Implements linked list - array index = key, value: next element

// Usage
AgentHandle current_element = ...;
AgentHandle next_element = successors_[current_element]; 

Definition at line 680 of file uniform_grid_environment.h.

◆ threshold_dimensions_

std::array<int32_t, 2> bdm::UniformGridEnvironment::threshold_dimensions_
private

Stores the min / max dimension value that need to be surpassed in order to trigger a diffusion grid change

Definition at line 688 of file uniform_grid_environment.h.

◆ timestamp_

uint32_t bdm::UniformGridEnvironment::timestamp_ = 0
private

is incremented at each call to Update This is used to decide if boxes should be reinitialized

Definition at line 658 of file uniform_grid_environment.h.

◆ total_num_boxes_

uint64_t bdm::UniformGridEnvironment::total_num_boxes_ = 0
private

The total number of boxes in the uniform grid.

Definition at line 674 of file uniform_grid_environment.h.


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