BioDynaMo  v1.03.61-fe34ced0
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 
113  if (timestamp_ != grid->timestamp_) {
114  timestamp_ = grid->timestamp_;
115  length_ = 1;
116  start_ = ah;
117  } else {
118  length_++;
119  (*successors)[ah] = start_;
120  start_ = ah;
121  }
122  }
123 
125  struct Iterator {
127  : grid_(grid), current_value_(box->start_), countdown_(box->length_) {
128  if (grid->timestamp_ != box->timestamp_) {
129  countdown_ = 0;
130  }
131  }
132 
133  bool IsAtEnd() { return countdown_ <= 0; }
134 
136  countdown_--;
137  if (countdown_ > 0) {
139  }
140  return *this;
141  }
142 
144 
150  int countdown_ = 0;
151  };
152 
153  Iterator begin(UniformGridEnvironment* grid) const { // NOLINT
154  return Iterator(grid, this);
155  }
156  };
157 
162  const FixedSizeVector<const Box*, 27>& neighbor_boxes,
163  uint64_t grid_timestamp)
164  : grid_(grid),
165  neighbor_boxes_(neighbor_boxes),
166  // start iterator from box 0
167  box_iterator_(neighbor_boxes_[0]->begin(grid)),
168  grid_timestamp_(grid_timestamp) {
169  // if first box is empty
170  if (neighbor_boxes_[0]->IsEmpty(grid_timestamp)) {
171  ForwardToNonEmptyBox(grid_timestamp);
172  }
173  }
174 
175  bool IsAtEnd() const { return is_end_; }
176 
177  AgentHandle operator*() const { return *box_iterator_; }
178 
181  ++box_iterator_;
182  // if iterator of current box has come to an end, continue with next box
183  if (box_iterator_.IsAtEnd()) {
185  }
186  return *this;
187  }
188 
189  private:
196  uint64_t grid_timestamp_;
198  uint16_t box_idx_ = 0;
200  bool is_end_ = false;
201 
204  NeighborIterator& ForwardToNonEmptyBox(uint64_t grid_timestamp) {
205  // increment box id until non empty box has been found
206  while (++box_idx_ < neighbor_boxes_.size()) {
207  // box is empty or uninitialized (padding box) -> continue
208  if (neighbor_boxes_[box_idx_]->IsEmpty(grid_timestamp)) {
209  continue;
210  }
211  // a non-empty box has been found
213  return *this;
214  }
215  // all remaining boxes have been empty; reached end
216  is_end_ = true;
217  return *this;
218  }
219  };
220 
222  // todo(ahmad): currently only kHigh is supported (hardcoded 26 several
223  // places)
224  enum Adjacency {
228  };
229 
230  explicit UniformGridEnvironment(Adjacency adjacency = kHigh)
231  : adjacency_(adjacency), lbi_(this) {}
232 
234  void operator=(UniformGridEnvironment const&) = delete;
235 
236  virtual ~UniformGridEnvironment() = default;
237 
239  void Clear() override {
240  if (!is_custom_box_length_) {
241  box_length_ = 1;
242  }
244  num_boxes_axis_ = {{0}};
245  num_boxes_xy_ = 0;
246  int32_t inf = std::numeric_limits<int32_t>::max();
247  grid_dimensions_ = {inf, -inf, inf, -inf, inf, -inf};
248  threshold_dimensions_ = {inf, -inf};
249  successors_.clear();
250  has_grown_ = false;
251  }
252 
253  struct AssignToBoxesFunctor : public Functor<void, Agent*, AgentHandle> {
255 
256  void operator()(Agent* agent, AgentHandle ah) override {
257  const auto& position = agent->GetPosition();
258  auto idx = grid_->GetBoxIndex(position);
259  auto box = grid_->GetBoxPointer(idx);
260  box->AddObject(ah, &(grid_->successors_), grid_);
261  assert(idx <= std::numeric_limits<uint32_t>::max());
262  agent->SetBoxIdx(static_cast<uint32_t>(idx));
263  }
264 
265  private:
267  };
268 
269  void SetBoxLength(int32_t bl) {
270  box_length_ = bl;
271  is_custom_box_length_ = true;
272  }
273 
274  void SetDetermineSimSize(bool value) { determine_sim_size_ = value; }
275 
276  int32_t GetBoxLength() { return box_length_; }
277 
287  const Real3& pos2) const {
288  const real_t dx = pos2[0] - pos1[0];
289  const real_t dy = pos2[1] - pos1[1];
290  const real_t dz = pos2[2] - pos1[2];
291  return (dx * dx + dy * dy + dz * dz);
292  }
293 
294  inline bool WithinSquaredEuclideanDistance(real_t squared_radius,
295  const Real3& pos1,
296  const Real3& pos2) const {
297  const real_t dx = pos2[0] - pos1[0];
298  const real_t dx2 = dx * dx;
299  if (dx2 > squared_radius) {
300  return false;
301  }
302 
303  const real_t dy = pos2[1] - pos1[1];
304  const real_t dy2_plus_dx2 = dy * dy + dx2;
305  if (dy2_plus_dx2 > squared_radius) {
306  return false;
307  }
308 
309  const real_t dz = pos2[2] - pos1[2];
310  const real_t distance = dz * dz + dy2_plus_dx2;
311  return distance < squared_radius;
312  }
313 
315  lbi_.Update();
316  return &lbi_;
317  }
318 
326  size_t GetBoxIndex(const Real3& position) const {
327  // Check if conversion can be done without loosing information
328  assert(floor(position[0]) <= std::numeric_limits<int32_t>::max());
329  assert(floor(position[1]) <= std::numeric_limits<int32_t>::max());
330  assert(floor(position[2]) <= std::numeric_limits<int32_t>::max());
331  std::array<uint64_t, 3> box_coord;
332  box_coord[0] =
333  (static_cast<int32_t>(floor(position[0])) - grid_dimensions_[0]) /
334  box_length_;
335  box_coord[1] =
336  (static_cast<int32_t>(floor(position[1])) - grid_dimensions_[2]) /
337  box_length_;
338  box_coord[2] =
339  (static_cast<int32_t>(floor(position[2])) - grid_dimensions_[4]) /
340  box_length_;
341 
342  return GetBoxIndex(box_coord);
343  }
344 
345  std::array<int32_t, 6> GetDimensions() const override {
346  return grid_dimensions_;
347  }
348 
352  bool ContainedInGrid(const Real3& point) const {
353  real_t xmin = static_cast<real_t>(grid_dimensions_[0]) + box_length_;
354  real_t xmax = static_cast<real_t>(grid_dimensions_[1]) - box_length_;
355  real_t ymin = static_cast<real_t>(grid_dimensions_[2]) + box_length_;
356  real_t ymax = static_cast<real_t>(grid_dimensions_[3]) - box_length_;
357  real_t zmin = static_cast<real_t>(grid_dimensions_[4]) + box_length_;
358  real_t zmax = static_cast<real_t>(grid_dimensions_[5]) - box_length_;
359  if (point[0] >= xmin && point[0] <= xmax && point[1] >= ymin &&
360  point[1] <= ymax && point[2] >= zmin && point[2] <= zmax) {
361  return true;
362  } else {
363  return false;
364  }
365  }
366 
367  std::array<int32_t, 2> GetDimensionThresholds() const override {
368  return threshold_dimensions_;
369  }
370 
371  void GetNumBoxesAxis(uint32_t* nba) {
372  // Check if conversion can be done without loosing information
373  assert(num_boxes_axis_[0] <= std::numeric_limits<uint32_t>::max());
374  assert(num_boxes_axis_[1] <= std::numeric_limits<uint32_t>::max());
375  assert(num_boxes_axis_[2] <= std::numeric_limits<uint32_t>::max());
376  nba[0] = static_cast<uint32_t>(num_boxes_axis_[0]);
377  nba[1] = static_cast<uint32_t>(num_boxes_axis_[1]);
378  nba[2] = static_cast<uint32_t>(num_boxes_axis_[2]);
379  }
380 
381  uint64_t GetNumBoxes() const { return boxes_.size(); }
382 
383  std::array<uint64_t, 3> GetBoxCoordinates(size_t box_idx) const {
384  std::array<uint64_t, 3> box_coord;
385  box_coord[2] = box_idx / num_boxes_xy_;
386  auto remainder = box_idx % num_boxes_xy_;
387  box_coord[1] = remainder / num_boxes_axis_[0];
388  box_coord[0] = remainder % num_boxes_axis_[0];
389  return box_coord;
390  }
391 
403  const Agent& query, real_t squared_radius) override {
404  ForEachNeighbor(lambda, query.GetPosition(), squared_radius, &query);
405  }
406 
418  const Real3& query_position, real_t squared_radius,
419  const Agent* query_agent = nullptr) override {
420  if (squared_radius > box_length_squared_) {
421  Log::Fatal(
422  "UniformGridEnvironment::ForEachNeighbor",
423  "The requested search radius (", std::sqrt(squared_radius), ")",
424  " of the neighborhood search exceeds the "
425  "box length (",
426  box_length_, "). The resulting neighborhood would be incomplete.");
427  }
428  const auto& position = query_position;
429  // Use uint32_t for compatibility with Agent::GetBoxIdx();
430  uint32_t idx{std::numeric_limits<uint32_t>::max()};
431  if (query_agent != nullptr) {
432  idx = query_agent->GetBoxIdx();
433  }
434  // If the point is not inside the inner grid (excluding the bounding boxes)
435  // as well as there was no previous box index assigned to the agent, we
436  // cannot reliably detect the neighbors and warn the user.
437  if (!ContainedInGrid(query_position) &&
438  idx == std::numeric_limits<uint32_t>::max()) {
439  Log::Warning(
440  "UniformGridEnvironment::ForEachNeighbor",
441  "You provided a query_position that is outside of the environment. ",
442  "Neighbor search is not supported in this case. \n",
443  "query_position: ", query_position,
444  "\ngrid_dimensions: ", grid_dimensions_[0] + box_length_, ", ",
445  grid_dimensions_[1] - box_length_, ", ",
446  grid_dimensions_[2] + box_length_, ", ",
447  grid_dimensions_[3] - box_length_, ", ",
448  grid_dimensions_[4] + box_length_, ", ",
450  return;
451  }
452  // Freshly created agents are initialized with the largest uint32_t number
453  // available. The above line assumes that the agent has already been located
454  // in the grid, but this assumption does not hold for new agents. Hence, for
455  // new agents, we manually compute the box index. This is also necessary if
456  // we want to find the neighbors of a arbitrary 3D coordinate rather than
457  // the neighbors of an agent.
458  if (idx == std::numeric_limits<uint32_t>::max()) {
459  size_t idx_tmp = GetBoxIndex(position);
460  // Check if conversion can be done without loosing information
461  assert(idx_tmp <= std::numeric_limits<uint32_t>::max());
462  idx = static_cast<uint32_t>(idx_tmp);
463  }
464 
465  FixedSizeVector<const Box*, 27> neighbor_boxes;
466  GetMooreBoxes(&neighbor_boxes, idx);
467 
469 
470  NeighborIterator ni(this, neighbor_boxes, timestamp_);
471  const unsigned batch_size = 64;
472  uint64_t size = 0;
473  Agent* agents[batch_size] __attribute__((aligned(64)));
474  real_t x[batch_size] __attribute__((aligned(64)));
475  real_t y[batch_size] __attribute__((aligned(64)));
476  real_t z[batch_size] __attribute__((aligned(64)));
477  real_t squared_distance[batch_size] __attribute__((aligned(64)));
478 
479  auto process_batch = [&]() {
480 #pragma omp simd
481  for (uint64_t i = 0; i < size; ++i) {
482  const real_t dx = x[i] - position[0];
483  const real_t dy = y[i] - position[1];
484  const real_t dz = z[i] - position[2];
485 
486  squared_distance[i] = dx * dx + dy * dy + dz * dz;
487  }
488 
489  for (uint64_t i = 0; i < size; ++i) {
490  if (squared_distance[i] < squared_radius) {
491  lambda(agents[i], squared_distance[i]);
492  }
493  }
494  size = 0;
495  };
496 
497  while (!ni.IsAtEnd()) {
498  auto ah = *ni;
499  // increment iterator already here to hide memory latency
500  ++ni;
501  auto* agent = rm->GetAgent(ah);
502  if (agent != query_agent) {
503  agents[size] = agent;
504  const auto& pos = agent->GetPosition();
505  x[size] = pos[0];
506  y[size] = pos[1];
507  z[size] = pos[2];
508  size++;
509  if (size == batch_size) {
510  process_batch();
511  }
512  }
513  }
514  process_batch();
515  };
516 
528  void ForEachNeighbor(Functor<void, Agent*>& functor, const Agent& query,
529  void* criteria) override;
530 
531  // NeighborMutex ---------------------------------------------------------
532 
537  public:
543  public:
545  GridNeighborMutexBuilder* mutex_builder)
546  : mutex_indices_(mutex_indices), mutex_builder_(mutex_builder) {
547  // Deadlocks occur if mutliple threads try to acquire the same locks,
548  // but in different order.
549  // -> sort to avoid deadlocks - see lock ordering
550  std::sort(mutex_indices_.begin(), mutex_indices_.end());
551  }
552 
553  ~GridNeighborMutex() override = default;
554 
555  void lock() override { // NOLINT
556  for (auto idx : mutex_indices_) {
557  auto& mutex = mutex_builder_->mutexes_[idx].mutex_;
558  while (mutex.test_and_set(std::memory_order_acquire)) {
559  // acquire lock and spin if another thread is holding it
560  }
561  }
562  }
563 
564  void unlock() override { // NOLINT
565  for (auto idx : mutex_indices_) {
566  auto& mutex = mutex_builder_->mutexes_[idx].mutex_;
567  mutex.clear(std::memory_order_release);
568  }
569  }
570 
572  mutex_indices_ = indices;
573  std::sort(mutex_indices_.begin(), mutex_indices_.end());
574  }
575 
576  private:
579  };
580 
583  struct MutexWrapper {
584  MutexWrapper() = default;
586  std::atomic_flag mutex_ = ATOMIC_FLAG_INIT;
587  };
588 
589  ~GridNeighborMutexBuilder() override = default;
590 
591  void Update() {
592  auto* grid = static_cast<UniformGridEnvironment*>(
594  mutexes_.resize(grid->GetNumBoxes());
595  }
596 
597  NeighborMutex* GetMutex(uint64_t box_idx) override;
598 
599  private:
601  std::vector<MutexWrapper> mutexes_;
602  };
603 
607  return nb_mutex_builder_.get();
608  }
609 
610  protected:
612  void UpdateImplementation() override;
613 
614  private:
616  public:
618  virtual ~LoadBalanceInfoUG();
619  void Update();
621  uint64_t start, uint64_t end,
622  Functor<void, Iterator<AgentHandle>*>& f) const override;
623 
624  private:
629 
630  struct InitializeVectorFunctor : public Functor<void, Iterator<uint64_t>*> {
632  uint64_t start;
635 
637  decltype(sorted_boxes) sorted_boxes,
639  virtual ~InitializeVectorFunctor();
640 
641  void operator()(Iterator<uint64_t>* it) override;
642  };
643 
644  void AllocateMemory();
645  void InitializeVectors();
646  };
647 
654  uint32_t timestamp_ = 0;
656  int32_t box_length_ = 1;
658  int32_t box_length_squared_ = 1;
660  bool is_custom_box_length_ = false;
664  bool determine_sim_size_ = true;
666  std::array<uint64_t, 3> num_boxes_axis_ = {{0}};
668  size_t num_boxes_xy_ = 0;
670  uint64_t total_num_boxes_ = 0;
681  std::array<int32_t, 6> grid_dimensions_;
684  std::array<int32_t, 2> threshold_dimensions_;
685 
687 
691  std::unique_ptr<GridNeighborMutexBuilder> nb_mutex_builder_ =
692  std::make_unique<GridNeighborMutexBuilder>();
693 
695  // Determine if the grid dimensions have changed (changed in the sense that
696  // the grid has grown outwards)
697  auto min_gd =
698  *std::min_element(grid_dimensions_.begin(), grid_dimensions_.end());
699  auto max_gd =
700  *std::max_element(grid_dimensions_.begin(), grid_dimensions_.end());
701  if (min_gd < threshold_dimensions_[0]) {
702  threshold_dimensions_[0] = min_gd;
703  has_grown_ = true;
704  }
705  if (max_gd > threshold_dimensions_[1]) {
706  Log::Info("UniformGridEnvironment",
707  "Your agents are getting near the edge of "
708  "the simulation space. Be aware of boundary conditions that "
709  "may come into play!");
710  threshold_dimensions_[1] = max_gd;
711  has_grown_ = true;
712  }
713  }
714 
715  void RoundOffGridDimensions(const std::array<real_t, 6>& grid_dimensions) {
716  // Check if conversion can be done without loosing information
717  assert(floor(grid_dimensions_[0]) >= std::numeric_limits<int32_t>::min());
718  assert(floor(grid_dimensions_[2]) >= std::numeric_limits<int32_t>::min());
719  assert(floor(grid_dimensions_[4]) >= std::numeric_limits<int32_t>::min());
720  assert(ceil(grid_dimensions_[1]) <= std::numeric_limits<int32_t>::max());
721  assert(ceil(grid_dimensions_[3]) <= std::numeric_limits<int32_t>::max());
722  assert(ceil(grid_dimensions_[3]) <= std::numeric_limits<int32_t>::max());
723  grid_dimensions_[0] = static_cast<int32_t>(floor(grid_dimensions[0]));
724  grid_dimensions_[2] = static_cast<int32_t>(floor(grid_dimensions[2]));
725  grid_dimensions_[4] = static_cast<int32_t>(floor(grid_dimensions[4]));
726  grid_dimensions_[1] = static_cast<int32_t>(ceil(grid_dimensions[1]));
727  grid_dimensions_[3] = static_cast<int32_t>(ceil(grid_dimensions[3]));
728  grid_dimensions_[5] = static_cast<int32_t>(ceil(grid_dimensions[5]));
729  }
730 
739  size_t box_idx) const {
740  neighbor_boxes->push_back(GetBoxPointer(box_idx));
741 
742  // Adjacent 6 (top, down, left, right, front and back)
743  if (adjacency_ >= kLow) {
744  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_xy_));
745  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_xy_));
746  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_axis_[0]));
747  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_axis_[0]));
748  neighbor_boxes->push_back(GetBoxPointer(box_idx - 1));
749  neighbor_boxes->push_back(GetBoxPointer(box_idx + 1));
750  }
751 
752  // Adjacent 12
753  if (adjacency_ >= kMedium) {
754  neighbor_boxes->push_back(
756  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_xy_ - 1));
757  neighbor_boxes->push_back(
758  GetBoxPointer(box_idx - num_boxes_axis_[0] - 1));
759  neighbor_boxes->push_back(
761  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_xy_ - 1));
762  neighbor_boxes->push_back(
763  GetBoxPointer(box_idx + num_boxes_axis_[0] - 1));
764  neighbor_boxes->push_back(
766  neighbor_boxes->push_back(GetBoxPointer(box_idx - num_boxes_xy_ + 1));
767  neighbor_boxes->push_back(
768  GetBoxPointer(box_idx - num_boxes_axis_[0] + 1));
769  neighbor_boxes->push_back(
771  neighbor_boxes->push_back(GetBoxPointer(box_idx + num_boxes_xy_ + 1));
772  neighbor_boxes->push_back(
773  GetBoxPointer(box_idx + num_boxes_axis_[0] + 1));
774  }
775 
776  // Adjacent 8
777  if (adjacency_ >= kHigh) {
778  neighbor_boxes->push_back(
779  GetBoxPointer(box_idx - num_boxes_xy_ - num_boxes_axis_[0] - 1));
780  neighbor_boxes->push_back(
781  GetBoxPointer(box_idx - num_boxes_xy_ - num_boxes_axis_[0] + 1));
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  }
795  }
796 
804  size_t box_idx) const {
805  box_indices->push_back(box_idx);
806 
807  // Adjacent 6 (top, down, left, right, front and back)
808  if (adjacency_ >= kLow) {
809  box_indices->push_back(box_idx - num_boxes_xy_);
810  box_indices->push_back(box_idx + num_boxes_xy_);
811  box_indices->push_back(box_idx - num_boxes_axis_[0]);
812  box_indices->push_back(box_idx + num_boxes_axis_[0]);
813  box_indices->push_back(box_idx - 1);
814  box_indices->push_back(box_idx + 1);
815  }
816 
817  // Adjacent 12
818  if (adjacency_ >= kMedium) {
819  box_indices->push_back(box_idx - num_boxes_xy_ - num_boxes_axis_[0]);
820  box_indices->push_back(box_idx - num_boxes_xy_ - 1);
821  box_indices->push_back(box_idx - num_boxes_axis_[0] - 1);
822  box_indices->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0]);
823  box_indices->push_back(box_idx + num_boxes_xy_ - 1);
824  box_indices->push_back(box_idx + num_boxes_axis_[0] - 1);
825  box_indices->push_back(box_idx - num_boxes_xy_ + num_boxes_axis_[0]);
826  box_indices->push_back(box_idx - num_boxes_xy_ + 1);
827  box_indices->push_back(box_idx - num_boxes_axis_[0] + 1);
828  box_indices->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0]);
829  box_indices->push_back(box_idx + num_boxes_xy_ + 1);
830  box_indices->push_back(box_idx + num_boxes_axis_[0] + 1);
831  }
832 
833  // Adjacent 8
834  if (adjacency_ >= kHigh) {
835  box_indices->push_back(box_idx - num_boxes_xy_ - num_boxes_axis_[0] - 1);
836  box_indices->push_back(box_idx - num_boxes_xy_ - num_boxes_axis_[0] + 1);
837  box_indices->push_back(box_idx - num_boxes_xy_ + num_boxes_axis_[0] - 1);
838  box_indices->push_back(box_idx - num_boxes_xy_ + num_boxes_axis_[0] + 1);
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  }
844  }
845 
882  size_t box_idx) const {
883  // C
884  neighbor_boxes->push_back(box_idx);
885  // BW
886  neighbor_boxes->push_back(box_idx + num_boxes_axis_[0] - 1);
887  // FNW
888  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0] - 1);
889  // NW
890  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - 1);
891  // BNW
892  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0] - 1);
893  // B
894  neighbor_boxes->push_back(box_idx + num_boxes_axis_[0]);
895  // FN
896  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0]);
897  // N
898  neighbor_boxes->push_back(box_idx + num_boxes_xy_);
899  // BN
900  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0]);
901  // E
902  neighbor_boxes->push_back(box_idx + 1);
903  // BE
904  neighbor_boxes->push_back(box_idx + num_boxes_axis_[0] + 1);
905  // FNE
906  neighbor_boxes->push_back(box_idx + num_boxes_xy_ - num_boxes_axis_[0] + 1);
907  // NE
908  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + 1);
909  // BNE
910  neighbor_boxes->push_back(box_idx + num_boxes_xy_ + num_boxes_axis_[0] + 1);
911  }
912 
919  const Box* GetBoxPointer(size_t index) const {
920  assert(index < boxes_.size());
921  return &(boxes_[index]);
922  }
923 
930  Box* GetBoxPointer(size_t index) {
931  assert(index < boxes_.size());
932  return &(boxes_[index]);
933  }
934 
942  size_t GetBoxIndex(const std::array<uint64_t, 3>& box_coord) const {
943  size_t box_idx = box_coord[2] * num_boxes_xy_ +
944  box_coord[1] * num_boxes_axis_[0] + box_coord[0];
945  assert(box_idx < boxes_.size());
946  return box_idx;
947  }
948 };
949 
950 } // namespace bdm
951 
952 #endif // CORE_ENVIRONMENT_UNIFORM_GRID_ENVIRONMENT_H_
bdm::UniformGridEnvironment::LoadBalanceInfoUG::sorted_boxes_
ParallelResizeVector< Box * > sorted_boxes_
Definition: uniform_grid_environment.h:627
bdm::UniformGridEnvironment::GetBoxLength
int32_t GetBoxLength()
Definition: uniform_grid_environment.h:276
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::lock
void lock() override
Definition: uniform_grid_environment.h:555
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:314
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:225
bdm::UniformGridEnvironment::GetBoxIndex
size_t GetBoxIndex(const std::array< uint64_t, 3 > &box_coord) const
Definition: uniform_grid_environment.h:942
bdm::UniformGridEnvironment::SquaredEuclideanDistance
real_t SquaredEuclideanDistance(const Real3 &pos1, const Real3 &pos2) const
Calculates the squared euclidian distance between two points in 3D.
Definition: uniform_grid_environment.h:286
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::mutex_builder_
GridNeighborMutexBuilder * mutex_builder_
Definition: uniform_grid_environment.h:578
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:564
spinlock.h
bdm::UniformGridEnvironment::determine_sim_size_
bool determine_sim_size_
Definition: uniform_grid_environment.h:664
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:175
bdm::UniformGridEnvironment::Adjacency
Adjacency
Enum that determines the degree of adjacency in search neighbor boxes.
Definition: uniform_grid_environment.h:224
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::~GridNeighborMutexBuilder
~GridNeighborMutexBuilder() 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:198
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:625
bdm::UniformGridEnvironment::kMedium
@ kMedium
Definition: uniform_grid_environment.h:226
bdm
Definition: agent.cc:39
bdm::UniformGridEnvironment::GetBoxCoordinates
std::array< uint64_t, 3 > GetBoxCoordinates(size_t box_idx) const
Definition: uniform_grid_environment.h:383
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:402
bdm::Iterator< AgentHandle >
bdm::UniformGridEnvironment::Box::Iterator
An iterator that iterates over the cells in this box.
Definition: uniform_grid_environment.h:125
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:150
bdm::UniformGridEnvironment::NeighborIterator::grid_
UniformGridEnvironment * grid_
Definition: uniform_grid_environment.h:190
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:658
bdm::UniformGridEnvironment::NeighborIterator::box_iterator_
Box::Iterator box_iterator_
Definition: uniform_grid_environment.h:195
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:930
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::cummulated_agents
ParallelResizeVector< uint64_t > & cummulated_agents
Definition: uniform_grid_environment.h:634
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:668
bdm::UniformGridEnvironment::Box::timestamp_
uint32_t timestamp_
Definition: uniform_grid_environment.h:75
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:628
bdm::UniformGridEnvironment::UniformGridEnvironment
UniformGridEnvironment(Adjacency adjacency=kHigh)
Definition: uniform_grid_environment.h:230
bdm::UniformGridEnvironment::GridNeighborMutexBuilder
Definition: uniform_grid_environment.h:536
bdm::UniformGridEnvironment::NeighborIterator::NeighborIterator
NeighborIterator(UniformGridEnvironment *grid, const FixedSizeVector< const Box *, 27 > &neighbor_boxes, uint64_t grid_timestamp)
Definition: uniform_grid_environment.h:160
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:254
bdm::ParallelResizeVector
std::vector with parallel resize
Definition: parallel_resize_vector.h:27
bdm::UniformGridEnvironment::boxes_
ParallelResizeVector< Box > boxes_
Definition: uniform_grid_environment.h:651
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:159
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper::MutexWrapper
MutexWrapper()=default
bdm::UniformGridEnvironment::LoadBalanceInfoUG::~LoadBalanceInfoUG
virtual ~LoadBalanceInfoUG()
bdm::LoadBalanceInfo
Definition: load_balance_info.h:24
bdm::UniformGridEnvironment::Box::Iterator::operator++
Iterator & operator++()
Definition: uniform_grid_environment.h:135
load_balance_info.h
bdm::UniformGridEnvironment::threshold_dimensions_
std::array< int32_t, 2 > threshold_dimensions_
Definition: uniform_grid_environment.h:684
bdm::UniformGridEnvironment::lbi_
LoadBalanceInfoUG lbi_
Definition: uniform_grid_environment.h:686
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::mutex_indices_
FixedSizeVector< uint64_t, 27 > mutex_indices_
Definition: uniform_grid_environment.h:577
bdm::UniformGridEnvironment::adjacency_
Adjacency adjacency_
Determines which boxes to search neighbors in (see enum Adjacency)
Definition: uniform_grid_environment.h:678
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:204
bdm::Environment::has_grown_
bool has_grown_
Definition: environment.h:126
bdm::UniformGridEnvironment::LoadBalanceInfoUG
Definition: uniform_grid_environment.h:615
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:676
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:803
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::sorted_boxes
ParallelResizeVector< Box * > & sorted_boxes
Definition: uniform_grid_environment.h:633
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:294
bdm::Functor
Definition: functor.h:24
bdm::UniformGridEnvironment::NeighborIterator::operator++
NeighborIterator & operator++()
Version where empty neighbor boxes are allowed.
Definition: uniform_grid_environment.h:180
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:666
bdm::UniformGridEnvironment::AssignToBoxesFunctor::operator()
void operator()(Agent *agent, AgentHandle ah) override
Definition: uniform_grid_environment.h:256
bdm::UniformGridEnvironment::SetBoxLength
void SetBoxLength(int32_t bl)
Definition: uniform_grid_environment.h:269
bdm::UniformGridEnvironment::grid_dimensions_
std::array< int32_t, 6 > grid_dimensions_
Definition: uniform_grid_environment.h:681
bdm::Spinlock
Definition: spinlock.h:22
bdm::UniformGridEnvironment::GetDimensions
std::array< int32_t, 6 > GetDimensions() const override
Definition: uniform_grid_environment.h:345
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:326
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:261
bdm::UniformGridEnvironment::Box::Iterator::grid_
UniformGridEnvironment * grid_
Pointer to the neighbor grid; for accessing the successor_ list.
Definition: uniform_grid_environment.h:146
bdm::UniformGridEnvironment::LoadBalanceInfoUG::mo_
MortonOrder mo_
Definition: uniform_grid_environment.h:626
bdm::UniformGridEnvironment::Clear
void Clear() override
Clears the grid.
Definition: uniform_grid_environment.h:239
bdm::UniformGridEnvironment::Box::Iterator::Iterator
Iterator(UniformGridEnvironment *grid, const Box *box)
Definition: uniform_grid_environment.h:126
bdm::UniformGridEnvironment::Box::Iterator::current_value_
AgentHandle current_value_
The current agent to be considered.
Definition: uniform_grid_environment.h:148
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::grid
UniformGridEnvironment * grid
Definition: uniform_grid_environment.h:631
bdm::UniformGridEnvironment::ContainedInGrid
bool ContainedInGrid(const Real3 &point) const
Definition: uniform_grid_environment.h:352
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:227
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:601
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:367
bdm::UniformGridEnvironment::box_length_
int32_t box_length_
Length of a Box.
Definition: uniform_grid_environment.h:656
bdm::UniformGridEnvironment::timestamp_
uint32_t timestamp_
Definition: uniform_grid_environment.h:654
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:591
bdm::UniformGridEnvironment::AssignToBoxesFunctor::grid_
UniformGridEnvironment * grid_
Definition: uniform_grid_environment.h:266
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor
Definition: uniform_grid_environment.h:630
log.h
bdm::UniformGridEnvironment::~UniformGridEnvironment
virtual ~UniformGridEnvironment()=default
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:660
bdm::UniformGridEnvironment::CheckGridGrowth
void CheckGridGrowth()
Definition: uniform_grid_environment.h:694
bdm::UniformGridEnvironment::RoundOffGridDimensions
void RoundOffGridDimensions(const std::array< real_t, 6 > &grid_dimensions)
Definition: uniform_grid_environment.h:715
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::SetMutexIndices
void SetMutexIndices(const FixedSizeVector< uint64_t, 27 > &indices)
Definition: uniform_grid_environment.h:571
bdm::UniformGridEnvironment::Box::Iterator::IsAtEnd
bool IsAtEnd()
Definition: uniform_grid_environment.h:133
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:192
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:919
bdm::UniformGridEnvironment::NeighborIterator::grid_timestamp_
uint64_t grid_timestamp_
Definition: uniform_grid_environment.h:196
bdm::UniformGridEnvironment::Box::begin
Iterator begin(UniformGridEnvironment *grid) const
Definition: uniform_grid_environment.h:153
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::start
uint64_t start
Definition: uniform_grid_environment.h:632
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:738
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:606
bdm::Simulation::GetEnvironment
Environment * GetEnvironment()
Definition: simulation.cc:277
bdm::UniformGridEnvironment::LoadBalanceInfoUG::InitializeVectorFunctor::~InitializeVectorFunctor
virtual ~InitializeVectorFunctor()
bdm::UniformGridEnvironment::NeighborIterator::operator*
AgentHandle operator*() const
Definition: uniform_grid_environment.h:177
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:200
bdm::UniformGridEnvironment::Box::Iterator::operator*
AgentHandle operator*() const
Definition: uniform_grid_environment.h:143
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:670
bdm::UniformGridEnvironment::nb_mutex_builder_
std::unique_ptr< GridNeighborMutexBuilder > nb_mutex_builder_
Definition: uniform_grid_environment.h:691
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:586
morton_order.h
bdm::UniformGridEnvironment::AssignToBoxesFunctor
Definition: uniform_grid_environment.h:253
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:67
bdm::UniformGridEnvironment::GetNumBoxes
uint64_t GetNumBoxes() const
Definition: uniform_grid_environment.h:381
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper::MutexWrapper
MutexWrapper(const MutexWrapper &)
Definition: uniform_grid_environment.h:585
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex::GridNeighborMutex
GridNeighborMutex(const FixedSizeVector< uint64_t, 27 > &mutex_indices, GridNeighborMutexBuilder *mutex_builder)
Definition: uniform_grid_environment.h:544
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::GridNeighborMutex
Definition: uniform_grid_environment.h:541
bdm::UniformGridEnvironment::GridNeighborMutexBuilder::MutexWrapper
Definition: uniform_grid_environment.h:583
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:417
bdm::UniformGridEnvironment::GetHalfMooreBoxIndices
void GetHalfMooreBoxIndices(FixedSizeVector< size_t, 14 > *neighbor_boxes, size_t box_idx) const
Definition: uniform_grid_environment.h:881
bdm::UniformGridEnvironment::SetDetermineSimSize
void SetDetermineSimSize(bool value)
Definition: uniform_grid_environment.h:274
bdm::AgentHandle
Definition: agent_handle.h:29
bdm::UniformGridEnvironment::GetNumBoxesAxis
void GetNumBoxesAxis(uint32_t *nba)
Definition: uniform_grid_environment.h:371
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