fmm_node.hpp 4.3 KB

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