/** * \file fmm_pts.hpp * \author Dhairya Malhotra, dhairya.malhotra@gmail.com * \date 3-07-2011 * \brief This file contains the definition of the FMM_Pts class. * This handles all the translations for point sources and targets. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef _PVFMM_FMM_PTS_HPP_ #define _PVFMM_FMM_PTS_HPP_ namespace pvfmm{ /** * \brief This class contains FMM specific data that each node contains * along with the functions for manipulating the data. */ template class FMM_Data{ public: virtual ~FMM_Data(){} virtual FMM_Data* NewData(){return new FMM_Data;} /** * \brief Clear all data. */ virtual void Clear(); /** * \brief Pack multipole expansion. */ virtual PackedData PackMultipole(void* buff_ptr=NULL); /** * \brief Add the multipole expansion from p0 to the current multipole * expansion. */ virtual void AddMultipole(PackedData p0); /** * \brief Initialize multipole expansion using p0. */ virtual void InitMultipole(PackedData p0, bool own_data=true); //FMM specific node data. Vector upward_equiv; Vector dnward_equiv; }; template struct SetupData{ int level; const Kernel* kernel; std::vector interac_type; std::vector nodes_in ; std::vector nodes_out; std::vector*> input_vector; std::vector*> output_vector; //##################################################### Matrix< char> interac_data; Matrix< char>* precomp_data; Matrix* coord_data; Matrix* input_data; Matrix* output_data; }; template class FMM_Tree; template class FMM_Pts{ public: typedef FMM_Tree > FMMTree_t; typedef typename FMMNode::Real_t Real_t; typedef FMMNode FMMNode_t; class FMMData: public FMM_Data{ public: virtual ~FMMData(){} virtual FMM_Data* NewData(){return new FMMData;} }; /** * \brief Constructor. */ FMM_Pts(mem::MemoryManager* mem_mgr_=NULL): mem_mgr(mem_mgr_), vprecomp_fft_flag(false), vlist_fft_flag(false), vlist_ifft_flag(false), mat(NULL), kernel(NULL){}; /** * \brief Virtual destructor. */ virtual ~FMM_Pts(); /** * \brief Initialize all the translation matrices (or load from file). * \param[in] mult_order Order of multipole expansion. * \param[in] kernel Kernel functions and related data. */ void Initialize(int mult_order, const MPI_Comm& comm, const Kernel* kernel); /** * \brief Order for the multipole expansion. */ int MultipoleOrder(){return multipole_order;} /** * \brief Whether using homogeneous kernel? */ bool Homogen(){return kernel->homogen;} virtual void CollectNodeData(FMMTree_t* tree, std::vector& nodes, std::vector >& buff, std::vector >& n_list, std::vector* > > vec_list = std::vector* > >(0)); void SetupPrecomp(SetupData& setup_data, bool device=false); void SetupInterac(SetupData& setup_data, bool device=false); template void EvalList (SetupData& setup_data, bool device=false); // Run on CPU by default. void SetupInteracPts(SetupData& setup_data, bool shift_src, bool shift_trg, Matrix* M, bool device); template void EvalListPts (SetupData& setup_data, bool device=false); // Run on CPU by default. /** * \brief Initialize multipole expansions for the given array of leaf nodes * at a given level. */ virtual void Source2UpSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void Source2Up (SetupData& setup_data, bool device=false); /** * \brief Initialize multipole expansions for the given array of non-leaf * nodes from that of its children. */ virtual void Up2UpSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void Up2Up (SetupData& setup_data, bool device=false); virtual void PeriodicBC(FMMNode* node); /** * \brief Compute V-List intractions. */ virtual void V_ListSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void V_List (SetupData& setup_data, bool device=false); /** * \brief Compute X-List intractions. */ virtual void X_ListSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void X_List (SetupData& setup_data, bool device=false); /** * \brief Compute contribution of local expansion from the parent. */ virtual void Down2DownSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void Down2Down (SetupData& setup_data, bool device=false); /** * \brief Compute target potential from the local expansion. */ virtual void Down2TargetSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void Down2Target (SetupData& setup_data, bool device=false); /** * \brief Compute W-List intractions. */ virtual void W_ListSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void W_List (SetupData& setup_data, bool device=false); /** * \brief Compute U-List intractions. */ virtual void U_ListSetup(SetupData& setup_data, FMMTree_t* tree, std::vector >& node_data, std::vector >& n_list, int level, bool device); virtual void U_List (SetupData& setup_data, bool device=false); virtual void PostProcessing(std::vector& nodes); /** * \brief For each node, copy FMM output from FMM_Data to the node. */ virtual void CopyOutput(FMMNode** nodes, size_t n); Vector dev_buffer; Vector cpu_buffer; protected: virtual void PrecompAll(Mat_Type type, int level=-1); virtual Permutation& PrecompPerm(Mat_Type type, Perm_Type perm_indx); virtual Matrix& Precomp(int level, Mat_Type type, size_t mat_indx); typename FFTW_t::plan vprecomp_fftplan; bool vprecomp_fft_flag; void FFT_UpEquiv(size_t dof, size_t m, size_t ker_dim0, Vector& fft_vec, Vector& fft_scl, Vector& input_data, Vector& output_data, Vector& buffer_); typename FFTW_t::plan vlist_fftplan; bool vlist_fft_flag; void FFT_Check2Equiv(size_t dof, size_t m, size_t ker_dim0, Vector& ifft_vec, Vector& ifft_scl, Vector& input_data, Vector& output_data, Vector& buffer_, Matrix& M); typename FFTW_t::plan vlist_ifftplan; bool vlist_ifft_flag; mem::MemoryManager* mem_mgr; InteracList interac_list; const Kernel* kernel; //The kernel function. PrecompMat* mat; //Handles storage of matrices. std::string mat_fname; int multipole_order; //Order of multipole expansion. MPI_Comm comm; }; }//end namespace #include #endif //_PVFMM_FMM_PTS_HPP_