fmm_node.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * \file fmm_node.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 12-11-2010
  5. * \brief This file contains the definition of the FMM_Node class.
  6. */
  7. #include <vector>
  8. #include <cstdlib>
  9. #include <pvfmm_common.hpp>
  10. #include <tree_node.hpp>
  11. #include <mpi_node.hpp>
  12. #include <fmm_pts.hpp>
  13. #include <vector.hpp>
  14. #ifndef _PVFMM_FMM_NODE_HPP_
  15. #define _PVFMM_FMM_NODE_HPP_
  16. namespace pvfmm{
  17. /**
  18. * \brief Base class for node of FMM_Node.
  19. */
  20. template <class Node>
  21. class FMM_Node: public Node{
  22. public:
  23. typedef Node Node_t; //Type of base node class (MPI_Node / Cheb_Node)
  24. typedef typename Node_t::Real_t Real_t;
  25. /**
  26. * \brief Base class for node data. Contains initialization data for the node.
  27. */
  28. class NodeData: public Node_t::NodeData{
  29. public:
  30. Vector<Real_t> src_coord; //Point sources.
  31. Vector<Real_t> src_value;
  32. Vector<Real_t> surf_coord; //Surface sources.
  33. Vector<Real_t> surf_value;
  34. Vector<Real_t> trg_coord; //Target coordinates.
  35. Vector<Real_t> trg_value;
  36. };
  37. /**
  38. * \brief Constructor.
  39. */
  40. FMM_Node(){
  41. Node_t();
  42. fmm_data=NULL;
  43. }
  44. /**
  45. * /brief Virtual destructor.
  46. */
  47. virtual ~FMM_Node();
  48. /**
  49. * \brief Initialize the node with relevant data.
  50. */
  51. virtual void Initialize(TreeNode* parent_, int path2node_, TreeNode::NodeData*) ;
  52. /**
  53. * \brief Returns list of coordinate and value vectors which need to be
  54. * sorted and partitioned across MPI processes and the scatter index is
  55. * saved.
  56. */
  57. virtual void NodeDataVec(std::vector<Vector<Real_t>*>& coord,
  58. std::vector<Vector<Real_t>*>& value,
  59. std::vector<Vector<size_t>*>& scatter){
  60. Node::NodeDataVec(coord, value, scatter);
  61. coord .push_back(&src_coord );
  62. value .push_back(&src_value );
  63. scatter.push_back(&src_scatter);
  64. coord .push_back(&surf_coord );
  65. value .push_back(&surf_value );
  66. scatter.push_back(&surf_scatter);
  67. coord .push_back(&trg_coord );
  68. value .push_back(&trg_value );
  69. scatter.push_back(&trg_scatter);
  70. }
  71. /**
  72. * \brief Clear node data.
  73. */
  74. virtual void ClearData();
  75. /**
  76. * \brief Clear FMM specific node (multipole and local expansion) data
  77. */
  78. void ClearFMMData();
  79. /**
  80. * \brief Returns reference to fmm_data.
  81. */
  82. FMM_Data<Real_t>*& FMMData(){return fmm_data;}
  83. /**
  84. * \brief Allocate a new object of the same type (as the derived class) and
  85. * return a pointer to it type cast as (TreeNode*).
  86. */
  87. virtual TreeNode* NewNode(TreeNode* n_=NULL);
  88. /**
  89. * \brief Evaluates and returns the subdivision condition for this node.
  90. * 'true' if node requires further subdivision.
  91. */
  92. virtual bool SubdivCond();
  93. /**
  94. * \brief Create child nodes and Initialize them.
  95. */
  96. virtual void Subdivide() ;
  97. /**
  98. * \brief Truncates the tree i.e. makes this a leaf node.
  99. */
  100. virtual void Truncate() ;
  101. /**
  102. * \brief Pack node for transmission using MPI.
  103. */
  104. virtual PackedData Pack(bool ghost=false, void* buff_ptr=NULL, size_t offset=0);
  105. /**
  106. * \brief Unpack node.
  107. */
  108. virtual void Unpack(PackedData p0, bool own_data=true);
  109. /**
  110. * \brief Pack the multipole expansion data to be transmitted to another
  111. * process. This is done during the reduction step at the end of the local
  112. * upward pass.
  113. */
  114. virtual PackedData PackMultipole(void* buff_ptr=NULL);
  115. /**
  116. * \brief Add to the multipole expansion of this node during reduction step.
  117. */
  118. virtual void AddMultipole(PackedData data);
  119. /**
  120. * \brief Initialize the multipole expansion with data from another process.
  121. * Used during broadcast step.
  122. */
  123. virtual void InitMultipole(PackedData data, bool own_data=true);
  124. Vector<Real_t> src_coord; //Point sources.
  125. Vector<Real_t> src_value;
  126. Vector<size_t> src_scatter;
  127. Vector<Real_t> surf_coord; //Surface sources.
  128. Vector<Real_t> surf_value; //Normal and src strength.
  129. Vector<size_t> surf_scatter;
  130. Vector<Real_t> trg_coord; //Target coordinates.
  131. Vector<Real_t> trg_value;
  132. Vector<size_t> trg_scatter;
  133. std::vector<std::vector<FMM_Node*> > interac_list;
  134. size_t node_id; //For translating node pointer to index.
  135. private:
  136. FMM_Data<Real_t>* fmm_data; //FMM specific data.
  137. Vector<char> pkd_data; //Temporary variable for storing packed data.
  138. };
  139. }//end namespace
  140. #include <fmm_node.txx>
  141. #endif //_PVFMM_FMM_NODE_HPP_