cheb_node.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * \file cheb_node.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 1-22-2011
  5. * \brief This is a derived cheb class of MPI_Node.
  6. */
  7. #ifndef _PVFMM_CHEB_NODE_HPP_
  8. #define _PVFMM_CHEB_NODE_HPP_
  9. #include <pvfmm_common.hpp>
  10. #include <assert.h>
  11. #include <vector.hpp>
  12. #include <mpi_node.hpp>
  13. #include <mortonid.hpp>
  14. #include <cheb_utils.hpp>
  15. namespace pvfmm{
  16. /**
  17. * \brief
  18. */
  19. template <class Real_t>
  20. class Cheb_Node: public MPI_Node<Real_t>{
  21. public:
  22. typedef void (*fn_ptr)(Real_t* coord, int n, Real_t* out);
  23. /**
  24. * \brief Base class for node data. Contains initialization data for the node.
  25. */
  26. class NodeData: public MPI_Node<Real_t>::NodeData{
  27. public:
  28. Vector<Real_t> cheb_coord; //Chebyshev point samples.
  29. Vector<Real_t> cheb_value;
  30. fn_ptr input_fn; // Function pointer.
  31. int data_dof; // Dimension of Chebyshev data.
  32. int cheb_deg; // Chebyshev degree
  33. Real_t tol; // Tolerance for adaptive refinement.
  34. };
  35. /**
  36. * \brief Initialize pointers to NULL.
  37. */
  38. Cheb_Node(): MPI_Node<Real_t>(), input_fn(NULL), cheb_deg(0){}
  39. /**
  40. * \brief Virtual destructor.
  41. */
  42. virtual ~Cheb_Node();
  43. /**
  44. * \brief Initialize the node by passing the relevant data.
  45. */
  46. virtual void Initialize(TreeNode* parent_, int path2node_, TreeNode::NodeData*);
  47. /**
  48. * \brief Returns list of coordinate and value vectors which need to be
  49. * sorted and partitioned across MPI processes and the scatter index is
  50. * saved.
  51. */
  52. virtual void NodeDataVec(std::vector<Vector<Real_t>*>& coord,
  53. std::vector<Vector<Real_t>*>& value,
  54. std::vector<Vector<size_t>*>& scatter){
  55. MPI_Node<Real_t>::NodeDataVec(coord, value, scatter);
  56. coord .push_back(&cheb_coord );
  57. value .push_back(&cheb_value );
  58. scatter.push_back(&cheb_scatter);
  59. coord .push_back( NULL);
  60. value .push_back(&cheb_coeff);
  61. scatter.push_back( NULL);
  62. }
  63. /**
  64. * \brief Clear node data.
  65. */
  66. virtual void ClearData();
  67. /**
  68. * \brief Returns the cost of this node. Used for load balancing.
  69. */
  70. virtual Real_t NodeCost(){return 1;}
  71. /**
  72. * \brief Degree of Chebyshev polynomials used.
  73. */
  74. int ChebDeg(){return cheb_deg;}
  75. /**
  76. * \brief Error tolerance for adaptive refinement of the Chebyshev Tree.
  77. */
  78. Real_t& MaxErr(){return tol;}
  79. /**
  80. * \brief Chebyshev coefficients for the source distribution.
  81. */
  82. Vector<Real_t>& ChebData(){return cheb_coeff;}
  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 Return degrees of freedom of data.
  103. */
  104. int& DataDOF(){return data_dof;}
  105. /**
  106. * \brief Pack this node to be transmitted to another process. The node
  107. * is responsible for allocating and freeing the memory for the actual data.
  108. */
  109. virtual PackedData Pack(bool ghost=false, void* buff_ptr=NULL, size_t offset=0);
  110. /**
  111. * \brief Initialize the node with data from another process.
  112. */
  113. virtual void Unpack(PackedData data, bool own_data=true);
  114. /**
  115. * \brief Read source distribution at points on a grid defined by array of x,
  116. * y and z coordinates.
  117. */
  118. virtual void ReadVal(std::vector<Real_t> x,std::vector<Real_t> y, std::vector<Real_t> z, Real_t* val, bool show_ghost=true){
  119. read_val(x,y,z,x.size(),y.size(),z.size(),val,show_ghost);
  120. }
  121. /**
  122. * \brief Append node VTU data to vectors.
  123. */
  124. virtual void VTU_Data(std::vector<Real_t>& coord, std::vector<Real_t>& value, std::vector<int32_t>& connect, std::vector<int32_t>& offset, std::vector<uint8_t>& types, int lod=-1);
  125. /**
  126. * \brief Compute gradient of the data.
  127. */
  128. void Gradient();
  129. /**
  130. * \brief Compute divergence of the data.
  131. */
  132. void Divergence();
  133. /**
  134. * \brief Compute curl of the data.
  135. */
  136. void Curl();
  137. fn_ptr input_fn;
  138. Vector<Real_t> cheb_coord; //coordinates of points
  139. Vector<Real_t> cheb_value; //value at points
  140. Vector<size_t> cheb_scatter; //scatter index mapping original data.
  141. private:
  142. /**
  143. * \brief Read source distribution at points on a grid defined by array of x,
  144. * y and z coordinates.
  145. */
  146. void read_val(std::vector<Real_t> x,std::vector<Real_t> y, std::vector<Real_t> z, int nx, int ny, int nz, Real_t* val, bool show_ghost=true);
  147. Real_t tol;
  148. int cheb_deg;
  149. int data_dof;
  150. Vector<Real_t> cheb_coeff;
  151. };
  152. }//end namespace
  153. #include <cheb_node.txx>
  154. #endif //_PVFMM_CHEB_NODE_HPP_