BioDynaMo  v1.05.120-25dc9790
uniform_grid_environment.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_ENVIRONMENT_UNIFORM_GRID_ENVIRONMENT_H_
16 #define CORE_ENVIRONMENT_UNIFORM_GRID_ENVIRONMENT_H_
17 
18 #include <assert.h>
19 #include <omp.h>
20 
21 #include <algorithm>
22 #include <array>
23 #include <atomic>
24 #include <cmath>
25 #include <iostream>
26 #include <limits>
27 #include <memory>
28 #include <mutex>
29 #ifdef LINUX
30 #include <parallel/algorithm>
31 #endif // LINUX
32 #include <utility>
33 #include <vector>
34 
35 #include <morton/morton.h> // NOLINT
36 
44 #include "core/functor.h"
45 #include "core/load_balance_info.h"
46 #include "core/param/param.h"
47 #include "core/resource_manager.h"
48 #include "core/util/log.h"
49 #include "core/util/spinlock.h"
50 
51 namespace bdm {
52 
53 namespace detail {
54 struct InitializeGPUData;
55 } // namespace detail
56 
59  // MechanicalForcesOpCuda needs access to some UniformGridEnvironment private
60  // members to reconstruct
61  // the grid on GPU (same for MechanicalForcesOpOpenCL)
62  friend struct MechanicalForcesOpCuda;
63  friend struct ::bdm::detail::InitializeGPUData;
64  friend struct MechanicalForcesOpOpenCL;
65  friend class SchedulerTest;
66 
67  public:
69  struct Box {
73  uint16_t length_;
74  // std::atomic<bool> timestamp_;
75  uint32_t timestamp_;
79 
84  Box(const Box& other) : Box() {}
85 
86  Box& operator=(const Box& other) {
87  // start_ = other.start_.load(std::memory_order_relaxed);
88  // length_ = other.length_.load(std::memory_order_relaxed);
89  start_ = other.start_;
90  length_ = other.length_;
91  return *this;
92  }
93 
94  bool IsEmpty(uint64_t grid_timestamp) const {
95  return grid_timestamp != timestamp_;
96  }
97 
98  uint16_t Size(uint64_t grid_timestamp) const {
99  if (IsEmpty(grid_timestamp)) {
100  return 0;
101  }
102  return length_;
103  }
104 
110  UniformGridEnvironment* grid) {
111  std::lock_guard<Spinlock> lock_guard(lock_);
112  if (length_ == std::numeric_limits<uint16_t>::max()) {
113  Log::Fatal(
114  "UniformGridEnvironment::Box::AddObject",
115  "Box overflow. You have added too many agents to a single Box.");
116  }
117  if (timestamp_ != grid->timestamp_) {
118  timestamp_ = grid->timestamp_;
119  length_ = 1;
120  start_ = ah;
121  } else {
122  length_++;
123  (*successors)[ah] = start_;
124  start_ = ah;
125  }
126  }
127 
129  struct Iterator {
131  : grid_(grid), current_value_(box->start_), countdown_(box->length_) {
132  if (grid->timestamp_ != box->timestamp_) {
133  countdown_ = 0;
134  }
135  }
136 
137  bool IsAtEnd() const { return countdown_ <= 0; }
138 
140  countdown_--;
141  if (countdown_ > 0) {
143  }
144  return *this;
145  }
146 
148 
154  int countdown_ = 0;
155  };
156 
157  Iterator begin(UniformGridEnvironment* grid) const { // NOLINT
158  return Iterator(grid, this);
159  }
160  };
161 
166  const FixedSizeVector<const Box*, 27>& neighbor_boxes,
167  uint64_t grid_timestamp)
168  : grid_(grid),
169  neighbor_boxes_(neighbor_boxes),
170  // start iterator from box 0
171  box_iterator_(neighbor_boxes_[0]->begin(grid)),
172  grid_timestamp_(grid_timestamp) {
173  // if first box is empty
174  if (neighbor_boxes_[0]->IsEmpty(grid_timestamp)) {
175  ForwardToNonEmptyBox(grid_timestamp);
176  }
177  }
178 
179  bool IsAtEnd() const { return is_end_; }
180 
181  AgentHandle operator*() const { return *box_iterator_; }
182 
185  ++box_iterator_;
186  // if iterator of current box has come to an end, continue with next box
187  if (box_iterator_.IsAtEnd()) {
189  }
190  return *this;
191  }
192 
193  private:
200  uint64_t grid_timestamp_;
202  uint16_t box_idx_ = 0;
204  bool is_end_ = false;
205 
208  NeighborIterator& ForwardToNonEmptyBox(uint64_t grid_timestamp) {
209  // increment box id until non empty box has been found
210  while (++box_idx_ < neighbor_boxes_.size()) {
211  // box is empty or uninitialized (padding box) -> continue
212  if (neighbor_boxes_[box_idx_]->IsEmpty(grid_timestamp)) {
213  continue;
214  }
215  // a non-empty box has been found
217  return *this;
218  }
219  // all remaining boxes have been empty; reached end
220  is_end_ = true;
221  return *this;
222  }
223  };
224 
226  // todo(ahmad): currently only kHigh is supported (hardcoded 26 several
227  // places)
228  enum Adjacency {
232  };
233 
234  explicit UniformGridEnvironment(Adjacency adjacency = kHigh)
235  : adjacency_(adjacency), lbi_(this) {}
236 
238  void operator=(UniformGridEnvironment const&) = delete;
239 
240  ~UniformGridEnvironment() override = default;
241 
243  void Clear() override {
244  if (!is_custom_box_length_) {
245  box_length_ = 1;
246  }
248  num_boxes_axis_ = {{0}};
249  num_boxes_xy_ = 0;
250  int32_t inf = std::numeric_limits<int32_t>::max();
251  grid_dimensions_ = {inf, -inf, inf, -inf, inf, -inf};
252  threshold_dimensions_ = {inf, -inf};
253  successors_.clear();
254  has_grown_ = false;
255  }
256 
257  struct AssignToBoxesFunctor : public Functor<void, Agent*, AgentHandle> {
259 
260  void operator()(Agent* agent, AgentHandle ah) override {
261  const auto& position = agent->GetPosition();
262  auto idx = grid_->GetBoxIndex(position);
263  auto box = grid_->GetBoxPointer(idx);
264  box->AddObject(ah, &(grid_->successors_), grid_);
265  assert(idx <= std::numeric_limits<uint32_t>::max());
266  agent->SetBoxIdx(static_cast<uint32_t>(idx));
267  }
268 
269  private:
271  };
272 
273  void SetBoxLength(int32_t bl) {
274  box_length_ = bl;
275  is_custom_box_length_ = true;
276  }
277 
278  void SetDetermineSimSize(bool value) { determine_sim_size_ = value; }
279 
280  int32_t GetBoxLength() const { return box_length_; }
281 
291  const Real3& pos2) const {
292  const real_t dx = pos2[0] - pos1[0];
293  const real_t dy = pos2[1] - pos1[1];
294  const real_t dz = pos2[2] - pos1[2];
295  return (dx * dx + dy * dy + dz * dz);
296  }
297 
298  inline bool WithinSquaredEuclideanDistance(real_t squared_radius,
299  const Real3& pos1,
300  const Real3& pos2) const {
301  const real_t dx = pos2[0] - pos1[0];
302  const real_t dx2 = dx * dx;
303  if (dx2 > squared_radius) {
304  return false;
305  }
306 
307  const real_t dy = pos2[1] - pos1[1];
308  const real_t dy2_plus_dx2 = dy * dy + dx2;
309  if (dy2_plus_dx2 > squared_radius) {
310  return false;
311  }
312 
313  const real_t dz = pos2[2] - pos1[2];
314  const real_t distance = dz * dz + dy2_plus_dx2;
315  return distance < squared_radius;
316  }
317 
319  lbi_.Update();
320  return &lbi_;
321  }
322 
330  size_t GetBoxIndex(const Real3& position) const {
331  // Check if conversion can be done without losing information
332  assert(floor(position[0]) <= std::numeric_limits<int32_t>::max());
333  assert(floor(position[1]) <= std::numeric_limits<int32_t>::max());
334  assert(floor(position[2]) <= std::numeric_limits<int32_t>::max());
335  std::array<uint64_t, 3> box_coord;
336  box_coord[0] =
337  (static_cast<int32_t>(floor(position[0])) - grid_dimensions_[0]) /
338  box_length_;
339  box_coord[1] =
340  (static_cast<int32_t>(floor(position[1])) - grid_dimensions_[2]) /
341  box_length_;
342  box_coord[2] =
343  (static_cast<int32_t>(floor(position[2])) - grid_dimensions_[4]) /
344  box_length_;
345 
346  return GetBoxIndex(box_coord);
347  }
348 
349  std::array<int32_t, 6> GetDimensions() const override {
350  return grid_dimensions_;
351  }
352 
356  bool ContainedInGrid(const Real3& point) const {
357  real_t xmin = static_cast<real_t>(grid_dimensions_[0]) + box_length_;
358  real_t xmax = static_cast<real_t>(grid_dimensions_[1]) - box_length_;
359  real_t ymin = static_cast<real_t>(grid_dimensions_[2]) + box_length_;
360  real_t ymax = static_cast<real_t>(grid_dimensions_[3]) - box_length_;
361  real_t zmin = static_cast<real_t>(grid_dimensions_[4]) + box_length_;
362  real_t zmax = static_cast<real_t>(grid_dimensions_[5]) - box_length_;
363  if (point[0] >= xmin && point[0] <= xmax && point[1] >= ymin &&
364  point[1] <= ymax && point[2] >= zmin && point[2] <= zmax) {
365  return true;
366  } else {
367  return false;
368  }
369  }
370 
371  std::array<int32_t, 2> GetDimensionThresholds() const override {
372  return threshold_dimensions_;
373  }
374 
375  void GetNumBoxesAxis(uint32_t* nba) {
376  // Check if conversion can be done without losing information
377  assert(num_boxes_axis_[0] <= std::numeric_limits<uint32_t>::max());
378  assert(num_boxes_axis_[1] <= std::numeric_limits<uint32_t>::max());
379  assert(num_boxes_axis_[2] <= std::numeric_limits<uint32_t>::max());
380  nba[0] = static_cast<uint32_t>(num_boxes_axis_[0]);
381  nba[1] = static_cast<uint32_t>(num_boxes_axis_[1]);
382  nba[2] = static_cast<uint32_t>(num_boxes_axis_[2]);
383  }
384 
385  uint64_t GetNumBoxes() const { return boxes_.size(); }
386 
387  std::array<uint64_t, 3> GetBoxCoordinates(size_t box_idx) const {
388  std::array<uint64_t, 3> box_coord;
389  box_coord[2] = box_idx / num_boxes_xy_;
390  auto remainder = box_idx % num_boxes_xy_;
391  box_coord[1] = remainder / num_boxes_axis_[0];
392  box_coord[0] = remainder % num_boxes_axis_[0];
393  return box_coord;
394  }
395 
407  const Agent& query, real_t squared_radius) override {
408  ForEachNeighbor(lambda, query.GetPosition(), squared_radius, &query);
409  }
410 
422  const Real3& query_position, real_t squared_radius,
423  const Agent* query_agent = nullptr) override {
424  if (squared_radius > box_length_squared_) {
425  Log::Fatal(
426  "UniformGridEnvironment::ForEachNeighbor",
427  "The requested search radius (", std::sqrt(squared_radius), ")",
428  " of the neighborhood search exceeds the "
429  "box length (",
430  box_length_, "). The resulting neighborhood would be incomplete.");
431  }
432  const auto& position = query_position;
433  // Use uint32_t for compatibility with Agent::GetBoxIdx();
434  uint32_t idx{std::numeric_limits<uint32_t>::max()};
435  if (query_agent != nullptr) {
436  idx = query_agent->GetBoxIdx();
437  }
438  // If the point is not inside the inner grid (excluding the bounding boxes)
439  // as well as there was no previous box index assigned to the agent, we
440  // cannot reliably detect the neighbors and warn the user.
441  if (!ContainedInGrid(query_position) &&
442  idx == std::numeric_limits<uint32_t>::max()) {
443  Log::Warning(
444  "UniformGridEnvironment::ForEachNeighbor",
445  "You provided a query_position that is outside of the environment. ",
446  "Neighbor search is not supported in this case. \n",
447  "query_position: ", query_position,
448  "\ngrid_dimensions: ", grid_dimensions_[0] + box_length_, ", ",
449  grid_dimensions_[1] - box_length_, ", ",
450  grid_dimensions_[2] + box_length_, ", ",
451  grid_dimensions_[3] - box_length_, ", ",
452  grid_dimensions_[4] + box_length_, ", ",
454  return;
455  }
456  // Freshly created agents are initialized with the largest uint32_t number
457  // available. The above line assumes that the agent has already been located
458  // in the grid, but this assumption does not hold for new agents. Hence, for
459  // new agents, we manually compute the box index. This is also necessary if
460  // we want to find the neighbors of a arbitrary 3D coordinate rather than
461  // the neighbors of an agent.
462  if (idx == std::numeric_limits<uint32_t>::max()) {
463  size_t idx_tmp = GetBoxIndex(position);
464  // Check if conversion can be done without losing information
465  assert(idx_tmp <= std::numeric_limits<uint32_t>::max());
466  idx = static_cast<uint32_t>(idx_tmp);
467  }
468 
469  FixedSizeVector<const Box*, 27> neighbor_boxes;
470  GetMooreBoxes(&neighbor_boxes, idx);
471 
473 
474  NeighborIterator ni(this, neighbor_boxes, timestamp_);
475  const unsigned batch_size = 64;
476  uint64_t size = 0;
477  Agent* agents[batch_size] __attribute__((aligned(64)));
478  real_t x[batch_size] __attribute__((aligned(64)));
479  real_t y[batch_size] __attribute__((aligned(64)));
480  real_t z[batch_size] __attribute__((aligned(64)));
481  real_t squared_distance[batch_size] __attribute__((aligned(64)));
482 
483  auto process_batch = [&]() {
484 #pragma omp simd
485  for (uint64_t i = 0; i < size; ++i) {
486  const real_t dx = x[i] - position[0];
487  const real_t dy = y[i] - position[1];
488  const real_t dz = z[i] - position[2];
489 
490  squared_distance[i] = dx * dx + dy * dy + dz * dz;
491  }
492 
493  for (uint64_t i = 0; i < size; ++i) {
494  if (squared_distance[i] < squared_radius) {
495  lambda(agents[i], squared_distance[i]);
496  }
497  }
498  size = 0;
499  };
500 
501  while (!ni.IsAtEnd()) {
502  auto ah = *ni;
503  // increment iterator already here to hide memory latency
504  ++ni;
505  auto* agent = rm->GetAgent(ah);
506  if (agent != query_agent) {
507  agents[size] = agent;
508  const auto& pos = agent->GetPosition();
509  x[size] = pos[0];
510  y[size] = pos[1];
511  z[size] = pos[2];
512  size++;
513  if (size == batch_size) {
514  process_batch();
515  }
516  }
517  }
518  process_batch();
519  };
520 
532  void ForEachNeighbor(Functor<void, Agent*>& functor, const Agent& query,
533  void* criteria) override;
534 
535  // NeighborMutex ---------------------------------------------------------
536 
541  public:
547  public:
549  GridNeighborMutexBuilder* mutex_builder)
550  : mutex_indices_(mutex_indices), mutex_builder_(mutex_builder) {
551  // Deadlocks occur if multiple threads try to acquire the same locks,
552  // but in different order.
553  // -> sort to avoid deadlocks - see lock ordering
554  std::sort(mutex_indices_.begin(), mutex_indices_.end());
555  }
556 
557  ~GridNeighborMutex() override = default;
558 
559  void lock() override { // NOLINT
560  for (auto idx : mutex_indices_) {
561  auto& mutex = mutex_builder_->mutexes_[idx].mutex_;
562  while (mutex.test_and_set(std::memory_order_acquire)) {
563  // acquire lock and spin if another thread is holding it
564  }
565  }
566  }
567 
568  void unlock() override { // NOLINT
569  for (auto idx : mutex_indices_) {
570  auto& mutex = mutex_builder_->mutexes_[idx].mutex_;
571  mutex.clear(std::memory_order_release);
572  }
573  }
574 
576  mutex_indices_ = indices;
577  std::sort(mutex_indices_.begin(), mutex_indices_.end());
578  }
579 
580  private:
583  };
584 
587  struct MutexWrapper {
588  MutexWrapper() = default;
590  std::atomic_flag mutex_ = ATOMIC_FLAG_INIT;
591  };
592 
593  ~GridNeighborMutexBuilder() override = default;
594 
595  void Update() {
596  auto* grid = static_cast<UniformGridEnvironment*>(
598  mutexes_.resize(grid->GetNumBoxes());
599  }
600 
601  NeighborMutex* GetMutex(uint64_t box_idx) override;
602 
603  private:
605  std::vector<MutexWrapper> mutexes_;
606  };
607 
611  return nb_mutex_builder_.get();
612  }
613 
614  protected:
616  void UpdateImplementation() override;
617 
618  private:
620  public:
622  ~LoadBalanceInfoUG() override;
623  void Update();
625  uint64_t start, uint64_t end,
626  Functor<void, Iterator<AgentHandle>*>& f) const override;
627 
628  private:
633 
634  struct InitializeVectorFunctor : public Functor<void, Iterator<uint64_t>*> {
636  uint64_t start;
639 
641  decltype(sorted_boxes) sorted_boxes,
643  ~InitializeVectorFunctor() override;
644 
645  void operator()(Iterator<uint64_t>* it) override;
646  };
647 
648  void AllocateMemory();
649  void InitializeVectors();
650  };
651 
658  uint32_t timestamp_ = 0;
660  int32_t box_length_ = 1;
662  int32_t box_length_squared_ = 1;
664  bool is_custom_box_length_ = false;
668  bool determine_sim_size_ = true;
670  std::array<uint64_t, 3> num_boxes_axis_ = {{0}};
672  size_t num_boxes_xy_ = 0;
674  uint64_t total_num_boxes_ = 0;
685  std::array<int32_t, 6> grid_dimensions_;
688  std::array<int32_t, 2> threshold_dimensions_;
689 
691 
695  std::unique_ptr<GridNeighborMutexBuilder> nb_mutex_builder_ =
696  std::make_unique<GridNeighborMutexBuilder>();
697 
699  // Determine if the grid dimensions have changed (changed in the sense that
700  // the grid has grown outwards)
701  auto min_gd =
702  *std::min_element(grid_dimensions_.begin(), grid_dimensions_.end());
703  auto max_gd =
704  *std::max_element(grid_dimensions_.begin(), grid_dimensions_.end());
705  if (min_gd < threshold_dimensions_[0]) {
706  threshold_dimensions_[0] = min_gd;
707  has_grown_ = true;
708  }
709  if (max_gd > threshold_dimensions_[1]) {
710  Log::Info("UniformGridEnvironment",
711  "Your agents are getting near the edge of "
712  "the simulation space. Be aware of boundary conditions that "
713  "may come into play!");
714  threshold_dimensions_[1] = max_gd;
715  has_grown_ = true;
716  }
717  }
718 
719  void RoundOffGridDimensions(const std::array<real_t, 6>& grid_dimensions) {
720  // Check if conversion can be done without losing information
721  assert(floor(grid_dimensions_[0]) >= std::numeric_limits<int32_t>::min());
722  assert(floor(grid_dimensions_[2]) >= std::numeric_limits<int32_t>::min());
723  assert(floor(grid_dimensions_[4]) >= std::numeric_limits<int32_t>::min());
724  assert(ceil(grid_dimensions_[1]) <= std::numeric_limits<int32_t>::max());
725  assert(ceil(grid_dimensions_[3]) <= std::numeric_limits<int32_t>::max());
726  assert(ceil(grid_dimensions_[3]) <= std::numeric_limits<int32_t>::max());
727  grid_dimensions_[0] = static_cast<int32_t>(floor(grid_dimensions[0]));
728  grid_dimensions_[2] = static_cast<int32_t>(floor(grid_dimensions[2]));
729  grid_dimensions_[4] = static_cast<int32_t>(floor(grid_dimensions[4]));
730  grid_dimensions_[1] = static_cast<int32_t>(ceil(grid_dimensions[1]));
731  grid_dimensions_[3] = static_cast<int32_t>(ceil(grid_dimensions[3]));
732  grid_dimensions_[5] = static_cast<int32_t>(ceil(grid_dimensions[5]));
733  }
734 
743  size_t box_idx) const {
744  neighbor_boxes->push_back(GetBoxPointer(box_idx));
745 
746  // Adjacent 6 (top, down, left, right, front and back)
747  if (adjacency_ >= kLow) {
748  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_xy_));
749  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_xy_));
750  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_axis_[0]));
751  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_axis_[0]));
752  neighbor_boxes->push_back(GetBoxPointer(box_idx - 1));
753  neighbor_boxes->push_back(GetBoxPointer(box_idx + 1));
754  }
755 
756  // Adjacent 12
757  if (adjacency_ >= kMedium) {
758  neighbor_boxes->push_back(
760  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_xy_ - 1));
761  neighbor_boxes->push_back(
762  GetBoxPointer(box_idx - num_boxes_axis_[0] - 1));
763  neighbor_boxes->push_back(
765  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_xy_ - 1));
766  neighbor_boxes->push_back(
767  GetBoxPointer(box_idx + num_boxes_axis_[0] - 1));
768  neighbor_boxes->push_back(
770  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_xy_ + 1));
771  neighbor_boxes->push_back(
772  GetBoxPointer(box_idx - num_boxes_axis_[0] + 1));
773  neighbor_boxes->push_back(
775  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_xy_ + 1));
776  neighbor_boxes->push_back(
777  GetBoxPointer(box_idx + num_boxes_axis_[0] + 1));
778  }
779 
780  // Adjacent 8
781  if (adjacency_ >= kHigh) {
782  neighbor_boxes->push_back(
783  GetBoxPointer(box_idx - num_boxes_xy_ - num_boxes_axis_[0] - 1));
784  neighbor_boxes->push_back(
785  GetBoxPointer(box_idx - num_boxes_xy_ - num_boxes_axis_[0] + 1));
786  neighbor_boxes->push_back(
787  GetBoxPointer(box_idx - num_boxes_xy_ + num_boxes_axis_[0] - 1));
788  neighbor_boxes->push_back(
789  GetBoxPointer(box_idx - num_boxes_xy_ + num_boxes_axis_[0] + 1));
790  neighbor_boxes->push_back(
791  GetBoxPointer(box_idx + num_boxes_xy_ - num_boxes_axis_[0] - 1));
792  neighbor_boxes->push_back(
793  GetBoxPointer(box_idx + num_boxes_xy_ - num_boxes_axis_[0] + 1));
794  neighbor_boxes->push_back(
795  GetBoxPointer(box_idx + num_boxes_xy_ + num_boxes_axis_[0] - 1));
796  neighbor_boxes->push_back(
797  GetBoxPointer(box_idx + num_boxes_xy_ + num_boxes_axis_[0] + 1));
798  }
799  }
800 
808  size_t box_idx) const {
809  box_indices->push_back(box_idx);
810 
811  // Adjacent 6 (top, down, left, right, front and back)
812  if (adjacency_ >= kLow) {
813  box_indices->push_back(box_idx - num_boxes_xy_);
814  box_indices->push_back(box_idx + num_boxes_xy_);
815  box_indices->push_back(box_idx - num_boxes_axis_[0]);
816  box_indices->push_back(box_idx + num_boxes_axis_[0]);
817  box_indices->push_back(box_idx - 1);
818  box_indices->push_back(box_idx + 1);
819  }
820 
821  // Adjacent 12
822  if (adjacency_ >= kMedium) {
823  box_indices->push_back(box_idx - num_boxes_xy_ - num_boxes_axis_[0]);
824  box_indices->push_back(box_idx - num_boxes_xy_ - 1);
825  box_indices->push_back(box_idx - num_boxes_axis_[0] - 1);
826  box_indices->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0]);
827  box_indices->push_back(box_idx + num_boxes_xy_ - 1);
828  box_indices->push_back(box_idx + num_boxes_axis_[0] - 1);
829  box_indices->push_back(box_idx - num_boxes_xy_ + num_boxes_axis_[0]);
830  box_indices->push_back(box_idx - num_boxes_xy_ + 1);
831  box_indices->push_back(box_idx - num_boxes_axis_[0] + 1);
832  box_indices->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0]);
833  box_indices->push_back(box_idx + num_boxes_xy_ + 1);
834  box_indices->push_back(box_idx + num_boxes_axis_[0] + 1);
835  }
836 
837  // Adjacent 8
838  if (adjacency_ >= kHigh) {
839  box_indices->push_back(box_idx - num_boxes_xy_ - num_boxes_axis_[0] - 1);
840  box_indices->push_back(box_idx - num_boxes_xy_ - num_boxes_axis_[0] + 1);
841  box_indices->push_back(box_idx - num_boxes_xy_ + num_boxes_axis_[0] - 1);
842  box_indices->push_back(box_idx - num_boxes_xy_ + num_boxes_axis_[0] + 1);
843  box_indices->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0] - 1);
844  box_indices->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0] + 1);
845  box_indices->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0] - 1);
846  box_indices->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0] + 1);
847  }
848  }
849 
886  size_t box_idx) const {
887  // C
888  neighbor_boxes->push_back(box_idx);
889  // BW
890  neighbor_boxes->push_back(box_idx + num_boxes_axis_[0] - 1);
891  // FNW
892  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0] - 1);
893  // NW
894  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - 1);
895  // BNW
896  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0] - 1);
897  // B
898  neighbor_boxes->push_back(box_idx + num_boxes_axis_[0]);
899  // FN
900  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0]);
901  // N
902  neighbor_boxes->push_back(box_idx + num_boxes_xy_);
903  // BN
904  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0]);
905  // E
906  neighbor_boxes->push_back(box_idx + 1);
907  // BE
908  neighbor_boxes->push_back(box_idx + num_boxes_axis_[0] + 1);
909  // FNE
910  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0] + 1);
911  // NE
912  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + 1);
913  // BNE
914  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0] + 1);
915  }
916 
923  const Box* GetBoxPointer(size_t index) const {
924  assert(index < boxes_.size());
925  return &(boxes_[index]);
926  }
927 
934  Box* GetBoxPointer(size_t index) {
935  assert(index < boxes_.size());
936  return &(boxes_[index]);
937  }
938 
946  size_t GetBoxIndex(const std::array<uint64_t, 3>& box_coord) const {
947  size_t box_idx = box_coord[2] * num_boxes_xy_ +
948  box_coord[1] * num_boxes_axis_[0] + box_coord[0];
949  assert(box_idx < boxes_.size());
950  return box_idx;
951  }
952 };
953 
954 } // namespace bdm
955 
956 #endif // CORE_ENVIRONMENT_UNIFORM_GRID_ENVIRONMENT_H_
bdm::UniformGridEnvironment::LoadBalanceInfoUG::sorted_boxes_
ParallelResizeVector< Box * > sorted_boxes_
Definition: uniform_grid_environment.h:631
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::lock
void lock() override
Definition: uniform_grid_environment.h:559
bdm::FixedSizeVector::begin
const T * begin() const
Definition: fixed_size_vector.h:81
bdm::UniformGridEnvironment::Box::start_
AgentHandle start_
Definition: uniform_grid_environment.h:78
bdm::UniformGridEnvironment::GetLoadBalanceInfo
LoadBalanceInfo * GetLoadBalanceInfo() override
Definition: uniform_grid_environment.h:318
inline_vector.h
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::InitializeVectorFunctor
InitializeVectorFunctor(UniformGridEnvironment *grid, uint64_t start, decltype(sorted_boxes) sorted_boxes, decltype(cummulated_agents) cummulated_agents)
Definition: uniform_grid_environment.cc:262
bdm::UniformGridEnvironment::kLow
@ kLow
Definition: uniform_grid_environment.h:229
bdm::UniformGridEnvironment::GetBoxIndex
size_t GetBoxIndex(const std::array< uint64_t, 3 > &box_coord) const
Definition: uniform_grid_environment.h:946
bdm::UniformGridEnvironment::SquaredEuclideanDistance
real_t SquaredEuclideanDistance(const Real3 &pos1, const Real3 &pos2) const
Calculates the squared euclidean distance between two points in 3D.
Definition: uniform_grid_environment.h:290
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::mutex_builder_
GridNeighborMutexBuilder * mutex_builder_
Definition: uniform_grid_environment.h:582
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectors
void InitializeVectors()
Definition: uniform_grid_environment.cc:53
bdm::FixedSizeVector
Definition: fixed_size_vector.h:30
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::unlock
void unlock() override
Definition: uniform_grid_environment.h:568
spinlock.h
bdm::UniformGridEnvironment::determine_sim_size_
bool determine_sim_size_
Definition: uniform_grid_environment.h:668
bdm::Environment::NeighborMutexBuilder
Definition: environment.h:103
fixed_size_vector.h
bdm::UniformGridEnvironment::LoadBalanceInfoUG::Update
void Update()
Definition: uniform_grid_environment.cc:30
bdm::UniformGridEnvironment::NeighborIterator::IsAtEnd
bool IsAtEnd() const
Definition: uniform_grid_environment.h:179
bdm::UniformGridEnvironment::Adjacency
Adjacency
Enum that determines the degree of adjacency in search neighbor boxes.
Definition: uniform_grid_environment.h:228
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::~GridNeighborMutexBuilder
~GridNeighborMutexBuilder() override=default
bdm::UniformGridEnvironment::~UniformGridEnvironment
~UniformGridEnvironment() override=default
bdm::UniformGridEnvironment::NeighborIterator::box_idx_
uint16_t box_idx_
The id of the box to be considered (i.e. value between 0 - 26)
Definition: uniform_grid_environment.h:202
bdm::UniformGridEnvironment::LoadBalanceInfoUG::CallHandleIteratorConsumer
void CallHandleIteratorConsumer(uint64_t start, uint64_t end, Functor< void, Iterator< AgentHandle > * > &f) const override
Definition: uniform_grid_environment.cc:246
bdm::UniformGridEnvironment::LoadBalanceInfoUG::grid_
UniformGridEnvironment * grid_
Definition: uniform_grid_environment.h:629
bdm::UniformGridEnvironment::kMedium
@ kMedium
Definition: uniform_grid_environment.h:230
bdm
Definition: agent.cc:39
bdm::UniformGridEnvironment::GetBoxCoordinates
std::array< uint64_t, 3 > GetBoxCoordinates(size_t box_idx) const
Definition: uniform_grid_environment.h:387
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::~GridNeighborMutex
~GridNeighborMutex() override=default
bdm::UniformGridEnvironment::Box::Size
uint16_t Size(uint64_t grid_timestamp) const
Definition: uniform_grid_environment.h:98
bdm::UniformGridEnvironment::ForEachNeighbor
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.
Definition: uniform_grid_environment.h:406
bdm::Iterator< AgentHandle >
bdm::UniformGridEnvironment::Box::Iterator
An iterator that iterates over the cells in this box.
Definition: uniform_grid_environment.h:129
bdm::FixedSizeVector::end
const T * end() const
Definition: fixed_size_vector.h:82
bdm::UniformGridEnvironment::Box::Iterator::countdown_
int countdown_
The remain number of agents to consider.
Definition: uniform_grid_environment.h:154
bdm::UniformGridEnvironment::NeighborIterator::grid_
UniformGridEnvironment * grid_
Definition: uniform_grid_environment.h:194
bdm::UniformGridEnvironment
A class that represents Cartesian 3D grid.
Definition: uniform_grid_environment.h:58
bdm::UniformGridEnvironment::box_length_squared_
int32_t box_length_squared_
Length of a Box squared.
Definition: uniform_grid_environment.h:662
bdm::UniformGridEnvironment::NeighborIterator::box_iterator_
Box::Iterator box_iterator_
Definition: uniform_grid_environment.h:199
bdm::FixedSizeVector::push_back
void push_back(const T &value)
Definition: fixed_size_vector.h:74
bdm::UniformGridEnvironment::GetBoxPointer
Box * GetBoxPointer(size_t index)
Gets the pointer to the box with the given index.
Definition: uniform_grid_environment.h:934
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::cummulated_agents
ParallelResizeVector< uint64_t > & cummulated_agents
Definition: uniform_grid_environment.h:638
bdm::UniformGridEnvironment::num_boxes_xy_
size_t num_boxes_xy_
Number of boxes in the xy plane (=num_boxes_axis_[0] * num_boxes_axis_[1])
Definition: uniform_grid_environment.h:672
bdm::UniformGridEnvironment::Box::timestamp_
uint32_t timestamp_
Definition: uniform_grid_environment.h:75
bdm::UniformGridEnvironment::Box::Iterator::IsAtEnd
bool IsAtEnd() const
Definition: uniform_grid_environment.h:137
bdm::real_t
double real_t
Definition: real_t.h:21
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GetMutex
NeighborMutex * GetMutex(uint64_t box_idx) override
Definition: uniform_grid_environment.cc:295
bdm::UniformGridEnvironment::LoadBalanceInfoUG::cummulated_agents_
ParallelResizeVector< uint64_t > cummulated_agents_
Definition: uniform_grid_environment.h:632
bdm::UniformGridEnvironment::UniformGridEnvironment
UniformGridEnvironment(Adjacency adjacency=kHigh)
Definition: uniform_grid_environment.h:234
bdm::UniformGridEnvironment::GetBoxLength
int32_t GetBoxLength() const
Definition: uniform_grid_environment.h:280
bdm::UniformGridEnvironment::GridNeighborMutexBuilder
Definition: uniform_grid_environment.h:540
bdm::UniformGridEnvironment::NeighborIterator::NeighborIterator
NeighborIterator(UniformGridEnvironment *grid, const FixedSizeVector< const Box *, 27 > &neighbor_boxes, uint64_t grid_timestamp)
Definition: uniform_grid_environment.h:164
bdm::MechanicalForcesOpCuda
Defines the 3D physical interactions between physical objects.
Definition: mechanical_forces_op_cuda.h:31
bdm::UniformGridEnvironment::Box::Box
Box(const Box &other)
Definition: uniform_grid_environment.h:84
bdm::UniformGridEnvironment::AssignToBoxesFunctor::AssignToBoxesFunctor
AssignToBoxesFunctor(UniformGridEnvironment *grid)
Definition: uniform_grid_environment.h:258
bdm::ParallelResizeVector
std::vector with parallel resize
Definition: parallel_resize_vector.h:27
bdm::UniformGridEnvironment::boxes_
ParallelResizeVector< Box > boxes_
Definition: uniform_grid_environment.h:655
bdm::UniformGridEnvironment::LoadBalanceInfoUG::LoadBalanceInfoUG
LoadBalanceInfoUG(UniformGridEnvironment *grid)
Definition: uniform_grid_environment.cc:22
bdm::Environment::NeighborMutexBuilder::NeighborMutex
Definition: environment.h:108
bdm::UniformGridEnvironment::NeighborIterator
An iterator that iterates over the boxes in this grid.
Definition: uniform_grid_environment.h:163
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper::MutexWrapper
MutexWrapper()=default
bdm::LoadBalanceInfo
Definition: load_balance_info.h:24
bdm::UniformGridEnvironment::Box::Iterator::operator++
Iterator & operator++()
Definition: uniform_grid_environment.h:139
load_balance_info.h
bdm::UniformGridEnvironment::LoadBalanceInfoUG::~LoadBalanceInfoUG
~LoadBalanceInfoUG() override
bdm::UniformGridEnvironment::threshold_dimensions_
std::array< int32_t, 2 > threshold_dimensions_
Definition: uniform_grid_environment.h:688
bdm::UniformGridEnvironment::lbi_
LoadBalanceInfoUG lbi_
Definition: uniform_grid_environment.h:690
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::mutex_indices_
FixedSizeVector< uint64_t, 27 > mutex_indices_
Definition: uniform_grid_environment.h:581
bdm::UniformGridEnvironment::adjacency_
Adjacency adjacency_
Determines which boxes to search neighbors in (see enum Adjacency)
Definition: uniform_grid_environment.h:682
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::operator()
void operator()(Iterator< uint64_t > *it) override
Definition: uniform_grid_environment.cc:276
bdm::UniformGridEnvironment::NeighborIterator::ForwardToNonEmptyBox
NeighborIterator & ForwardToNonEmptyBox(uint64_t grid_timestamp)
Definition: uniform_grid_environment.h:208
bdm::Environment::has_grown_
bool has_grown_
Definition: environment.h:126
bdm::UniformGridEnvironment::LoadBalanceInfoUG
Definition: uniform_grid_environment.h:619
bdm::UniformGridEnvironment::Box
A single unit cube of the grid.
Definition: uniform_grid_environment.h:69
bdm::UniformGridEnvironment::successors_
AgentVector< AgentHandle > successors_
Definition: uniform_grid_environment.h:680
bdm::UniformGridEnvironment::LoadBalanceInfoUG::AllocateMemory
void AllocateMemory()
Definition: uniform_grid_environment.cc:43
bdm::Agent
Contains code required by all agents.
Definition: agent.h:79
bdm::UniformGridEnvironment::GetMooreBoxIndices
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.
Definition: uniform_grid_environment.h:807
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::sorted_boxes
ParallelResizeVector< Box * > & sorted_boxes
Definition: uniform_grid_environment.h:637
bdm::UniformGridEnvironment::Box::length_
uint16_t length_
Definition: uniform_grid_environment.h:73
parallel_resize_vector.h
bdm::MortonOrder
Definition: morton_order.h:27
bdm::UniformGridEnvironment::WithinSquaredEuclideanDistance
bool WithinSquaredEuclideanDistance(real_t squared_radius, const Real3 &pos1, const Real3 &pos2) const
Definition: uniform_grid_environment.h:298
bdm::Functor
Definition: functor.h:24
bdm::UniformGridEnvironment::NeighborIterator::operator++
NeighborIterator & operator++()
Version where empty neighbor boxes are allowed.
Definition: uniform_grid_environment.h:184
bdm::Log::Warning
static void Warning(const std::string &location, const Args &... parts)
Prints warning message.
Definition: log.h:67
bdm::Agent::SetBoxIdx
void SetBoxIdx(uint32_t idx)
Definition: agent.cc:127
bdm::UniformGridEnvironment::num_boxes_axis_
std::array< uint64_t, 3 > num_boxes_axis_
Stores the number of Boxes for each axis.
Definition: uniform_grid_environment.h:670
bdm::UniformGridEnvironment::AssignToBoxesFunctor::operator()
void operator()(Agent *agent, AgentHandle ah) override
Definition: uniform_grid_environment.h:260
bdm::UniformGridEnvironment::SetBoxLength
void SetBoxLength(int32_t bl)
Definition: uniform_grid_environment.h:273
bdm::UniformGridEnvironment::grid_dimensions_
std::array< int32_t, 6 > grid_dimensions_
Definition: uniform_grid_environment.h:685
bdm::Spinlock
Definition: spinlock.h:22
bdm::UniformGridEnvironment::GetDimensions
std::array< int32_t, 6 > GetDimensions() const override
Definition: uniform_grid_environment.h:349
bdm::UniformGridEnvironment::GetBoxIndex
size_t GetBoxIndex(const Real3 &position) const
Return the box index in the one dimensional array of the box that contains the position.
Definition: uniform_grid_environment.h:330
bdm::Log::Info
static void Info(const std::string &location, const Args &... parts)
Prints information message.
Definition: log.h:55
bdm::Simulation::GetResourceManager
ResourceManager * GetResourceManager()
Returns the ResourceManager instance.
Definition: simulation.cc:244
bdm::UniformGridEnvironment::Box::Iterator::grid_
UniformGridEnvironment * grid_
Pointer to the neighbor grid; for accessing the successor_ list.
Definition: uniform_grid_environment.h:150
bdm::UniformGridEnvironment::LoadBalanceInfoUG::mo_
MortonOrder mo_
Definition: uniform_grid_environment.h:630
bdm::UniformGridEnvironment::Clear
void Clear() override
Clears the grid.
Definition: uniform_grid_environment.h:243
bdm::UniformGridEnvironment::Box::Iterator::Iterator
Iterator(UniformGridEnvironment *grid, const Box *box)
Definition: uniform_grid_environment.h:130
bdm::UniformGridEnvironment::Box::Iterator::current_value_
AgentHandle current_value_
The current agent to be considered.
Definition: uniform_grid_environment.h:152
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::grid
UniformGridEnvironment * grid
Definition: uniform_grid_environment.h:635
bdm::UniformGridEnvironment::ContainedInGrid
bool ContainedInGrid(const Real3 &point) const
Definition: uniform_grid_environment.h:356
bdm::UniformGridEnvironment::Box::operator=
Box & operator=(const Box &other)
Definition: uniform_grid_environment.h:86
math_array.h
bdm::UniformGridEnvironment::kHigh
@ kHigh
Definition: uniform_grid_environment.h:231
bdm::AgentVector
Definition: agent_vector.h:31
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::mutexes_
std::vector< MutexWrapper > mutexes_
one mutex for each box in UniformGridEnvironment::boxes_
Definition: uniform_grid_environment.h:605
bdm::UniformGridEnvironment::Box::Box
Box()
Definition: uniform_grid_environment.h:80
bdm::UniformGridEnvironment::GetDimensionThresholds
std::array< int32_t, 2 > GetDimensionThresholds() const override
Definition: uniform_grid_environment.h:371
bdm::UniformGridEnvironment::box_length_
int32_t box_length_
Length of a Box.
Definition: uniform_grid_environment.h:660
bdm::UniformGridEnvironment::timestamp_
uint32_t timestamp_
Definition: uniform_grid_environment.h:658
bdm::Log::Fatal
static void Fatal(const std::string &location, const Args &... parts)
Prints fatal error message.
Definition: log.h:115
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::Update
void Update()
Definition: uniform_grid_environment.h:595
bdm::UniformGridEnvironment::AssignToBoxesFunctor::grid_
UniformGridEnvironment * grid_
Definition: uniform_grid_environment.h:270
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor
Definition: uniform_grid_environment.h:634
log.h
bdm::UniformGridEnvironment::SchedulerTest
friend class SchedulerTest
Definition: uniform_grid_environment.h:65
bdm::UniformGridEnvironment::is_custom_box_length_
bool is_custom_box_length_
True when the box length was set manually.
Definition: uniform_grid_environment.h:664
bdm::UniformGridEnvironment::CheckGridGrowth
void CheckGridGrowth()
Definition: uniform_grid_environment.h:698
bdm::UniformGridEnvironment::RoundOffGridDimensions
void RoundOffGridDimensions(const std::array< real_t, 6 > &grid_dimensions)
Definition: uniform_grid_environment.h:719
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::~InitializeVectorFunctor
~InitializeVectorFunctor() override
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::SetMutexIndices
void SetMutexIndices(const FixedSizeVector< uint64_t, 27 > &indices)
Definition: uniform_grid_environment.h:575
bdm::UniformGridEnvironment::NeighborIterator::neighbor_boxes_
const FixedSizeVector< const Box *, 27 > & neighbor_boxes_
The 27 neighbor boxes that will be searched for agents.
Definition: uniform_grid_environment.h:196
bdm::UniformGridEnvironment::GetBoxPointer
const Box * GetBoxPointer(size_t index) const
Gets the pointer to the box with the given index.
Definition: uniform_grid_environment.h:923
bdm::UniformGridEnvironment::NeighborIterator::grid_timestamp_
uint64_t grid_timestamp_
Definition: uniform_grid_environment.h:200
bdm::UniformGridEnvironment::Box::begin
Iterator begin(UniformGridEnvironment *grid) const
Definition: uniform_grid_environment.h:157
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::start
uint64_t start
Definition: uniform_grid_environment.h:636
bdm::UniformGridEnvironment::GetMooreBoxes
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.
Definition: uniform_grid_environment.h:742
bdm::UniformGridEnvironment::UpdateImplementation
void UpdateImplementation() override
Updates the grid, as agents may have moved, added or deleted.
Definition: uniform_grid_environment.cc:112
bdm::UniformGridEnvironment::GetNeighborMutexBuilder
NeighborMutexBuilder * GetNeighborMutexBuilder() override
Definition: uniform_grid_environment.h:610
bdm::Simulation::GetEnvironment
Environment * GetEnvironment()
Definition: simulation.cc:260
bdm::UniformGridEnvironment::NeighborIterator::operator*
AgentHandle operator*() const
Definition: uniform_grid_environment.h:181
environment.h
bdm::UniformGridEnvironment::NeighborIterator::is_end_
bool is_end_
Flag to indicate that all the neighbor boxes have been searched through.
Definition: uniform_grid_environment.h:204
bdm::UniformGridEnvironment::Box::Iterator::operator*
AgentHandle operator*() const
Definition: uniform_grid_environment.h:147
bdm::UniformGridEnvironment::operator=
void operator=(UniformGridEnvironment const &)=delete
bdm::UniformGridEnvironment::total_num_boxes_
uint64_t total_num_boxes_
The total number of boxes in the uniform grid.
Definition: uniform_grid_environment.h:674
bdm::UniformGridEnvironment::nb_mutex_builder_
std::unique_ptr< GridNeighborMutexBuilder > nb_mutex_builder_
Definition: uniform_grid_environment.h:695
bdm::MathArray< real_t, 3 >
bdm::MechanicalForcesOpOpenCL
Defines the 3D physical interactions between physical objects.
Definition: mechanical_forces_op_opencl.h:25
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper::mutex_
std::atomic_flag mutex_
Definition: uniform_grid_environment.h:590
morton_order.h
bdm::UniformGridEnvironment::AssignToBoxesFunctor
Definition: uniform_grid_environment.h:257
bdm::Environment
Definition: environment.h:30
agent_vector.h
bdm::UniformGridEnvironment::Box::IsEmpty
bool IsEmpty(uint64_t grid_timestamp) const
Definition: uniform_grid_environment.h:94
bdm::Agent::GetPosition
virtual const Real3 & GetPosition() const =0
resource_manager.h
param.h
bdm::UniformGridEnvironment::Box::lock_
Spinlock lock_
Definition: uniform_grid_environment.h:70
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:68
bdm::UniformGridEnvironment::GetNumBoxes
uint64_t GetNumBoxes() const
Definition: uniform_grid_environment.h:385
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper::MutexWrapper
MutexWrapper(const MutexWrapper &)
Definition: uniform_grid_environment.h:589
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::GridNeighborMutex
GridNeighborMutex(const FixedSizeVector< uint64_t, 27 > &mutex_indices, GridNeighborMutexBuilder *mutex_builder)
Definition: uniform_grid_environment.h:548
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex
Definition: uniform_grid_environment.h:545
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper
Definition: uniform_grid_environment.h:587
functor.h
bdm::UniformGridEnvironment::ForEachNeighbor
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.
Definition: uniform_grid_environment.h:421
bdm::UniformGridEnvironment::GetHalfMooreBoxIndices
void GetHalfMooreBoxIndices(FixedSizeVector< size_t, 14 > *neighbor_boxes, size_t box_idx) const
Definition: uniform_grid_environment.h:885
bdm::UniformGridEnvironment::SetDetermineSimSize
void SetDetermineSimSize(bool value)
Definition: uniform_grid_environment.h:278
bdm::AgentHandle
Definition: agent_handle.h:29
bdm::UniformGridEnvironment::GetNumBoxesAxis
void GetNumBoxesAxis(uint32_t *nba)
Definition: uniform_grid_environment.h:375
bdm::UniformGridEnvironment::Box::AddObject
void AddObject(AgentHandle ah, AgentVector< AgentHandle > *successors, UniformGridEnvironment *grid)
Adds an agent to this box.
Definition: uniform_grid_environment.h:109