fmm_pts.hpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * \file fmm_pts.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 3-07-2011
  5. * \brief This file contains the definition of the FMM_Pts class.
  6. * This handles all the translations for point sources and targets.
  7. */
  8. #ifndef _PVFMM_FMM_PTS_HPP_
  9. #define _PVFMM_FMM_PTS_HPP_
  10. #include <pvfmm_common.hpp>
  11. #include <mpi.h>
  12. #include <matrix.hpp>
  13. #include <precomp_mat.hpp>
  14. #include <interac_list.hpp>
  15. #include <kernel.hpp>
  16. #include <mpi_node.hpp>
  17. #if defined(PVFMM_HAVE_CUDA)
  18. #include <cuda_func.hpp>
  19. #endif
  20. namespace pvfmm{
  21. /**
  22. * \brief This class contains FMM specific data that each node contains
  23. * along with the functions for manipulating the data.
  24. */
  25. template <class Real_t>
  26. class FMM_Data{
  27. public:
  28. virtual ~FMM_Data(){}
  29. virtual FMM_Data* NewData(){return new FMM_Data;}
  30. /**
  31. * \brief Clear all data.
  32. */
  33. virtual void Clear();
  34. /**
  35. * \brief Pack multipole expansion.
  36. */
  37. virtual PackedData PackMultipole(void* buff_ptr=NULL);
  38. /**
  39. * \brief Add the multipole expansion from p0 to the current multipole
  40. * expansion.
  41. */
  42. virtual void AddMultipole(PackedData p0);
  43. /**
  44. * \brief Initialize multipole expansion using p0.
  45. */
  46. virtual void InitMultipole(PackedData p0, bool own_data=true);
  47. //FMM specific node data.
  48. Vector<Real_t> upward_equiv;
  49. Vector<Real_t> dnward_equiv;
  50. };
  51. template <class Real_t>
  52. struct SetupData{
  53. int level;
  54. Kernel<Real_t>* kernel;
  55. std::vector<Mat_Type> interac_type;
  56. std::vector<void*> nodes_in ;
  57. std::vector<void*> nodes_out;
  58. std::vector<Vector<Real_t>*> input_vector;
  59. std::vector<Vector<Real_t>*> output_vector;
  60. //#####################################################
  61. Matrix< char> interac_data;
  62. Matrix< char>* precomp_data;
  63. Matrix<Real_t>* coord_data;
  64. Matrix<Real_t>* input_data;
  65. Matrix<Real_t>* output_data;
  66. };
  67. template <class FMMNode>
  68. class FMM_Pts{
  69. public:
  70. typedef typename FMMNode::Real_t Real_t;
  71. typedef FMMNode FMMNode_t;
  72. class FMMData: public FMM_Data<Real_t>{
  73. public:
  74. virtual ~FMMData(){}
  75. virtual FMM_Data<Real_t>* NewData(){return new FMMData;}
  76. };
  77. /**
  78. * \brief Constructor.
  79. */
  80. FMM_Pts(): vprecomp_fft_flag(false), vlist_fft_flag(false),
  81. vlist_ifft_flag(false), mat(NULL){};
  82. /**
  83. * \brief Virtual destructor.
  84. */
  85. virtual ~FMM_Pts();
  86. /**
  87. * \brief Initialize all the translation matrices (or load from file).
  88. * \param[in] mult_order Order of multipole expansion.
  89. * \param[in] kernel Kernel functions and related data.
  90. */
  91. void Initialize(int mult_order, const MPI_Comm& comm, const Kernel<Real_t>* kernel, const Kernel<Real_t>* aux_kernel=NULL);
  92. /**
  93. * \brief Order for the multipole expansion.
  94. */
  95. int& MultipoleOrder(){return multipole_order;}
  96. /**
  97. * \brief Whether using homogeneous kernel?
  98. */
  99. bool& Homogen(){return kernel.homogen;}
  100. virtual void CollectNodeData(std::vector<FMMNode*>& nodes, std::vector<Matrix<Real_t> >& buff, std::vector<Vector<FMMNode_t*> >& n_list, std::vector<size_t> extra_size = std::vector<size_t>(0));
  101. void SetupPrecomp(SetupData<Real_t>& setup_data, bool device=false);
  102. void SetupInterac(SetupData<Real_t>& setup_data, bool device=false);
  103. void EvalList (SetupData<Real_t>& setup_data, bool device=false); // Run on CPU by default.
  104. void SetupInteracPts(SetupData<Real_t>& setup_data, bool shift_src, bool shift_trg, Matrix<Real_t>* M, bool device);
  105. void EvalListPts (SetupData<Real_t>& setup_data, bool device=false); // Run on CPU by default.
  106. /**
  107. * \brief Initialize multipole expansions for the given array of leaf nodes
  108. * at a given level.
  109. */
  110. virtual void InitMultipole(FMMNode**, size_t n, int level);
  111. /**
  112. * \brief Initialize multipole expansions for the given array of non-leaf
  113. * nodes from that of its children.
  114. */
  115. virtual void Up2Up(FMMNode**, size_t n, int level);
  116. virtual void PeriodicBC(FMMNode* node);
  117. /**
  118. * \brief Compute V-List intractions.
  119. */
  120. virtual void V_ListSetup(SetupData<Real_t>& setup_data, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  121. virtual void V_List (SetupData<Real_t>& setup_data, bool device=false);
  122. /**
  123. * \brief Compute X-List intractions.
  124. */
  125. virtual void X_ListSetup(SetupData<Real_t>& setup_data, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  126. virtual void X_List (SetupData<Real_t>& setup_data, bool device=false);
  127. /**
  128. * \brief Compute contribution of local expansion from the parent.
  129. */
  130. virtual void Down2DownSetup(SetupData<Real_t>& setup_data, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  131. virtual void Down2Down (SetupData<Real_t>& setup_data, bool device=false);
  132. /**
  133. * \brief Compute target potential from the local expansion.
  134. */
  135. virtual void Down2TargetSetup(SetupData<Real_t>& setup_data, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  136. virtual void Down2Target (SetupData<Real_t>& setup_data, bool device=false);
  137. /**
  138. * \brief Compute W-List intractions.
  139. */
  140. virtual void W_ListSetup(SetupData<Real_t>& setup_data, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  141. virtual void W_List (SetupData<Real_t>& setup_data, bool device=false);
  142. /**
  143. * \brief Compute U-List intractions.
  144. */
  145. virtual void U_ListSetup(SetupData<Real_t>& setup_data, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  146. virtual void U_List (SetupData<Real_t>& setup_data, bool device=false);
  147. virtual void PostProcessing(std::vector<FMMNode_t*>& nodes);
  148. /**
  149. * \brief For each node, copy FMM output from FMM_Data to the node.
  150. */
  151. virtual void CopyOutput(FMMNode** nodes, size_t n);
  152. Vector<char> dev_buffer;
  153. Vector<char> cpu_buffer;
  154. protected:
  155. virtual void PrecompAll(Mat_Type type, int level=-1);
  156. virtual Permutation<Real_t>& PrecompPerm(Mat_Type type, Perm_Type perm_indx);
  157. virtual Matrix<Real_t>& Precomp(int level, Mat_Type type, size_t mat_indx);
  158. typename FFTW_t<Real_t>::plan vprecomp_fftplan; bool vprecomp_fft_flag;
  159. void FFT_UpEquiv(size_t dof, size_t m, size_t ker_dim0, Vector<size_t>& fft_vec,
  160. Vector<Real_t>& input_data, Vector<Real_t>& output_data, Vector<Real_t>& buffer_);
  161. typename FFTW_t<Real_t>::plan vlist_fftplan; bool vlist_fft_flag;
  162. void FFT_Check2Equiv(size_t dof, size_t m, size_t ker_dim0, Vector<size_t>& ifft_vec,
  163. Vector<Real_t>& input_data, Vector<Real_t>& output_data, Vector<Real_t>& buffer_, Matrix<Real_t>& M);
  164. typename FFTW_t<Real_t>::plan vlist_ifftplan; bool vlist_ifft_flag;
  165. std::vector<Vector<Real_t> > upwd_check_surf;
  166. std::vector<Vector<Real_t> > upwd_equiv_surf;
  167. std::vector<Vector<Real_t> > dnwd_check_surf;
  168. std::vector<Vector<Real_t> > dnwd_equiv_surf;
  169. InteracList<FMMNode> interac_list;
  170. Kernel<Real_t> kernel; //The kernel function.
  171. Kernel<Real_t> aux_kernel; //Auxiliary kernel for source-to-source translations.
  172. PrecompMat<Real_t>* mat; //Handles storage of matrices.
  173. std::string mat_fname;
  174. int multipole_order; //Order of multipole expansion.
  175. MPI_Comm comm;
  176. };
  177. }//end namespace
  178. #include <fmm_pts.txx>
  179. #endif //_PVFMM_FMM_PTS_HPP_