fmm_cheb.hpp 4.4 KB

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