fmm_cheb.hpp 4.1 KB

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