GridTransfer.hpp 1.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#pragma once

#include <vector>

#include <amdis/linear_algebra/DOFVectorInterface.hpp>

namespace AMDiS
{
  template <class Grid>
  class GridTransfer
  {
    using Self = GridTransfer;

  public:
    GridTransfer(Grid& grid)
      : grid_(&grid)
    {}

    /// Attach a data container to the grid transfer, that gets interpolated during grid change
    void attach(DOFVectorInterface* vec)
    {
      data_.push_back(vec);
    }

    /// Prepare the grid and the data for the adaption
    bool preAdapt()
    {
      mightCoarsen_ = grid_->preAdapt(); // any element might be coarsened in adapt()
      for (auto* vec : data_)
        vec->preAdapt(mightCoarsen_);
      return mightCoarsen_;
    }

    /// do the grid adaption
    bool adapt()
    {
      refined_ = grid_->adapt(); // returns true if a least one entity was refined
      return refined_;
    }

    // Perform data adaption to the new grid
    void postAdapt()
    {
      if (mightCoarsen_ || refined_) {
        for (auto* vec : data_)
          vec->postAdapt(refined_);
      }
      grid_->postAdapt();
    }

  protected:
    Grid* grid_;
    std::vector<DOFVectorInterface*> data_;
    bool mightCoarsen_ = false;
    bool refined_ = false;
  };

} // end namespace AMDiS