fmm_cheb.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * \file fmm_cheb.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 3-07-2011
  5. * \brief This file contains the definition of the FMM_Cheb class.
  6. * This handles all the translations through matrix multiplications.
  7. */
  8. #include <mpi.h>
  9. #include <vector>
  10. #include <cstdlib>
  11. #include <pvfmm_common.hpp>
  12. #include <precomp_mat.hpp>
  13. #include <mem_mgr.hpp>
  14. #include <fmm_pts.hpp>
  15. #include <vector.hpp>
  16. #include <matrix.hpp>
  17. #include <kernel.hpp>
  18. #ifndef _PVFMM_FMM_CHEB_HPP_
  19. #define _PVFMM_FMM_CHEB_HPP_
  20. namespace pvfmm{
  21. template <class FMMNode>
  22. class FMM_Cheb: public FMM_Pts<FMMNode>{
  23. public:
  24. typedef typename FMM_Pts<FMMNode>::FMMTree_t FMMTree_t;
  25. typedef typename FMMNode::Real_t Real_t;
  26. typedef FMMNode FMMNode_t;
  27. /**
  28. * \brief This class contains FMM specific data that each node contains
  29. * along with the functions functions for manipulating the data.
  30. */
  31. class FMMData: public FMM_Pts<FMMNode>::FMMData{
  32. public:
  33. virtual FMM_Data<Real_t>* NewData(){ return new FMMData;}
  34. //FMM specific node data.
  35. Vector<Real_t> cheb_out;
  36. };
  37. /**
  38. * \brief Constructor.
  39. */
  40. FMM_Cheb(mem::MemoryManager* mem_mgr=NULL){};
  41. /**
  42. * \brief Virtual destructor.
  43. */
  44. virtual ~FMM_Cheb();
  45. /**
  46. * \brief Initialize all the translation matrices (or load from file).
  47. * \param[in] mult_order Order of multipole expansion.
  48. * \param[in] cheb_deg Degree of Chebyshev polynomials.
  49. * \param[in] kernel Kernel functions and related data.
  50. */
  51. void Initialize(int mult_order, int cheb_deg, const MPI_Comm& comm, const Kernel<Real_t>* kernel);
  52. /**
  53. * \brief Number of source points per box (or the parameter describing the
  54. * order of approximation of source distribution).
  55. */
  56. int& ChebDeg(){return cheb_deg;}
  57. virtual void CollectNodeData(FMMTree_t* tree, std::vector<FMMNode*>& nodes, std::vector<Matrix<Real_t> >& buff, std::vector<Vector<FMMNode_t*> >& n_list, std::vector<std::vector<Vector<Real_t>* > > vec_list = std::vector<std::vector<Vector<Real_t>* > >(0));
  58. /**
  59. * \brief Initialize multipole expansions for the given array of leaf nodes
  60. * at a given level.
  61. */
  62. virtual void Source2UpSetup(SetupData<Real_t>& setup_data, FMMTree_t* tree, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  63. virtual void Source2Up (SetupData<Real_t>& setup_data, bool device=false);
  64. /**
  65. * \brief Compute X-List intractions.
  66. */
  67. virtual void X_ListSetup(SetupData<Real_t>& setup_data, FMMTree_t* tree, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  68. virtual void X_List (SetupData<Real_t>& setup_data, bool device=false);
  69. /**
  70. * \brief Compute target potential from the local expansion.
  71. */
  72. virtual void Down2TargetSetup(SetupData<Real_t>& setup_data, FMMTree_t* tree, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  73. virtual void Down2Target (SetupData<Real_t>& setup_data, bool device=false);
  74. /**
  75. * \brief Compute W-List intractions.
  76. */
  77. virtual void W_ListSetup(SetupData<Real_t>& setup_data, FMMTree_t* tree, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  78. virtual void W_List (SetupData<Real_t>& setup_data, bool device=false);
  79. /**
  80. * \brief Compute U-List intractions.
  81. */
  82. virtual void U_ListSetup(SetupData<Real_t>& setup_data, FMMTree_t* tree, std::vector<Matrix<Real_t> >& node_data, std::vector<Vector<FMMNode_t*> >& n_list, int level, bool device);
  83. virtual void U_List (SetupData<Real_t>& setup_data, bool device=false);
  84. virtual void PostProcessing(std::vector<FMMNode_t*>& nodes);
  85. /**
  86. * \brief For each node, copy FMM output from FMM_Data to the node.
  87. */
  88. virtual void CopyOutput(FMMNode** nodes, size_t n){
  89. for(size_t i=0;i<n;i++){
  90. nodes[i]->DataDOF()=this->kernel->ker_dim[1];
  91. if(nodes[i]->IsLeaf() && !nodes[i]->IsGhost()){
  92. Vector<Real_t>& cheb_data=nodes[i]->ChebData();
  93. Vector<Real_t>& cheb_out =((FMMData*)nodes[i]->FMMData())->cheb_out;
  94. if(cheb_data.Dim()!=cheb_out.Dim()) cheb_data.ReInit(0);
  95. cheb_data = cheb_out;
  96. }
  97. }
  98. FMM_Pts<FMMNode>::CopyOutput(nodes,n);
  99. }
  100. protected:
  101. virtual Permutation<Real_t>& PrecompPerm(Mat_Type type, Perm_Type perm_indx);
  102. virtual Matrix<Real_t>& Precomp(int level, Mat_Type type, size_t mat_indx);
  103. private:
  104. int cheb_deg; //Order of Cheb. approx.
  105. };
  106. }//end namespace
  107. #include <fmm_cheb.txx>
  108. #endif //_PVFMM_FMM_CHEB_HPP_