NearInteraction.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _NEAR_INTERAC_HPP_
  2. #define _NEAR_INTERAC_HPP_
  3. #include <sctl.hpp>
  4. template <class Real, int DIM> class NearInteraction {
  5. typedef sctl::Morton<DIM> MID;
  6. typedef sctl::Long Long;
  7. struct ObjData {
  8. int operator<(const ObjData& p1) const { return mid < p1.mid; }
  9. MID mid;
  10. Long Rglb;
  11. Real rad;
  12. Real coord[DIM];
  13. //sctl::StaticArray<Real,DIM> coord; // not trivially copyable
  14. };
  15. public:
  16. NearInteraction() {}
  17. NearInteraction(sctl::Comm comm) : comm_(comm) {
  18. for (sctl::Integer i = 0; i < DIM; i++) {
  19. period_length[i] = 0;
  20. period_length0[i] = 0;
  21. }
  22. }
  23. void SetPeriodLength(sctl::Integer d, Real len) {
  24. period_length[d] = len;
  25. }
  26. template <class SrcObj, class TrgObj> void SetupRepartition(const std::vector<SrcObj>& src_vec, const std::vector<TrgObj>& trg_vec);
  27. template <class SrcObj, class TrgObj> void SetupNearInterac(const std::vector<SrcObj>& src_vec, const std::vector<TrgObj>& trg_vec);
  28. const std::vector<std::pair<Long,Long>>& GetInteractionList() const { return trg_src_pair; }
  29. template <class ObjType> void ForwardScatterSrc(const std::vector<ObjType>& in, std::vector<ObjType>& out) const;
  30. template <class ObjType> void ForwardScatterTrg(const std::vector<ObjType>& in, std::vector<ObjType>& out) const;
  31. template <class ObjType> void ReverseScatterTrg(const std::vector<ObjType>& in, std::vector<ObjType>& out) const;
  32. private:
  33. template <class ObjType> void ForwardScatter(const std::vector<ObjType>& in_vec, std::vector<ObjType>& out_vec, const sctl::Vector<Long>& recv_idx) const;
  34. template <class ObjType> void ReverseScatter(const std::vector<ObjType>& in_vec, std::vector<ObjType>& out_vec, const sctl::Vector<Long>& send_idx) const;
  35. sctl::Comm comm_;
  36. sctl::Vector<Long> TRglb, SRglb;
  37. sctl::Vector<std::pair<Long,Long>> TSPair;
  38. std::vector<std::pair<Long, Long>> trg_src_pair;
  39. sctl::StaticArray<Real, DIM> period_length, period_length0;
  40. sctl::Integer depth;
  41. sctl::Vector<ObjData> SData_, TData_; // Globally sorted
  42. };
  43. #include <NearInteraction.txx>
  44. #endif //_NEAR_INTERAC_HPP_