fmm_cheb.hpp 4.4 KB

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