fmm_pts.hpp 7.2 KB

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