fmm_node.hpp 4.3 KB

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