GridTransfer.hpp 2.35 KB
 Praetorius, Simon committed Nov 15, 2018 1 2 #pragma once  Müller, Felix committed Nov 27, 2018 3 #include  Praetorius, Simon committed Nov 15, 2018 4 5 6  #include  Müller, Felix committed Nov 27, 2018 7 8 #include  Praetorius, Simon committed Nov 15, 2018 9 10 namespace AMDiS {  Müller, Felix committed Nov 27, 2018 11 12 13 14 15 16 17 18 19 20 21 22 23 24  class GridTransferInterface { public: virtual ~GridTransferInterface() = default; virtual void attach(DOFVectorInterface*) = 0; virtual void detach(DOFVectorInterface*) = 0; virtual bool preAdapt() = 0; virtual bool adapt() = 0; virtual void postAdapt() = 0; };  Praetorius, Simon committed Nov 15, 2018 25 26  template class GridTransfer  Müller, Felix committed Nov 27, 2018 27  : public GridTransferInterface  Praetorius, Simon committed Nov 15, 2018 28 29 30 31  { using Self = GridTransfer; public:  Müller, Felix committed Nov 27, 2018 32 33 34 35 36 37 38 39 40  void bind(Grid& grid) { grid_ = &grid; } void unbind() { grid_ = nullptr; }  Praetorius, Simon committed Nov 15, 2018 41 42  /// Attach a data container to the grid transfer, that gets interpolated during grid change  Müller, Felix committed Nov 27, 2018 43  virtual void attach(DOFVectorInterface* vec) override  Praetorius, Simon committed Nov 15, 2018 44 45 46 47  { data_.push_back(vec); }  Müller, Felix committed Nov 27, 2018 48 49 50 51 52 53 54 55 56  virtual void detach(DOFVectorInterface* vec) override { auto it = std::find(data_.begin(), data_.end(), vec); if (it != data_.end()) data_.erase(it); else warning("DOFVector to detach not found"); }  Praetorius, Simon committed Nov 15, 2018 57  /// Prepare the grid and the data for the adaption  Müller, Felix committed Nov 27, 2018 58  virtual bool preAdapt() override  Praetorius, Simon committed Nov 15, 2018 59  {  Müller, Felix committed Nov 27, 2018 60  assert(grid_ != nullptr);  Praetorius, Simon committed Nov 15, 2018 61  mightCoarsen_ = grid_->preAdapt(); // any element might be coarsened in adapt()  Müller, Felix committed Nov 27, 2018 62  for (auto* vec : this->data_)  Praetorius, Simon committed Nov 15, 2018 63 64 65 66 67  vec->preAdapt(mightCoarsen_); return mightCoarsen_; } /// do the grid adaption  Müller, Felix committed Nov 27, 2018 68  virtual bool adapt() override  Praetorius, Simon committed Nov 15, 2018 69  {  Müller, Felix committed Nov 27, 2018 70  assert(grid_ != nullptr);  Praetorius, Simon committed Nov 15, 2018 71 72 73 74 75  refined_ = grid_->adapt(); // returns true if a least one entity was refined return refined_; } // Perform data adaption to the new grid  Müller, Felix committed Nov 27, 2018 76  virtual void postAdapt() override  Praetorius, Simon committed Nov 15, 2018 77  {  Müller, Felix committed Nov 27, 2018 78  assert(grid_ != nullptr);  Praetorius, Simon committed Nov 15, 2018 79  if (mightCoarsen_ || refined_) {  Müller, Felix committed Nov 27, 2018 80  for (auto* vec : this->data_)  Praetorius, Simon committed Nov 15, 2018 81 82 83  vec->postAdapt(refined_); } grid_->postAdapt();  Praetorius, Simon committed Jan 19, 2019 84 85 86 87 88 89 90  changeIndex_++; } /// Returns the grid change index, see \ref changeIndex. unsigned long changeIndex() const { return changeIndex_;  Praetorius, Simon committed Nov 15, 2018 91 92  }  Müller, Felix committed Nov 27, 2018 93 94 95  private: Grid* grid_ = nullptr; std::list data_;  Praetorius, Simon committed Nov 15, 2018 96 97  bool mightCoarsen_ = false; bool refined_ = false;  Praetorius, Simon committed Jan 19, 2019 98 99 100 101  /// This index is incremented every time the grid is changed, e.g. by /// refinement or coarsening. unsigned long changeIndex_ = 0;  Praetorius, Simon committed Nov 15, 2018 102 103 104  }; } // end namespace AMDiS