cheb_utils.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * \file cheb_utils.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 2-11-2011
  5. * \brief This file contains chebyshev related functions.
  6. */
  7. #include <vector>
  8. #include <pvfmm_common.hpp>
  9. #include <vector.hpp>
  10. #include <kernel.hpp>
  11. #ifndef _PVFMM_CHEB_UTILS_HPP_
  12. #define _PVFMM_CHEB_UTILS_HPP_
  13. namespace pvfmm{
  14. /**
  15. * \brief Returns the sum of the absolute value of coeffecients of the highest
  16. * order polynomial as an estimate of error.
  17. */
  18. template <class T>
  19. T cheb_err(T* cheb_coeff, int deg, int dof);
  20. /**
  21. * \brief Computes Chebyshev approximation from function values at cheb node points.
  22. */
  23. template <class T, class Y>
  24. T cheb_approx(T* fn_v, int d, int dof, T* out, mem::MemoryManager* mem_mgr=NULL);
  25. /**
  26. * \brief Evaluates polynomial values from input coefficients at points on
  27. * a regular grid defined by in_x, in_y, in_z the values in the input vector.
  28. */
  29. template <class T>
  30. void cheb_eval(const Vector<T>& coeff_, int cheb_deg, const std::vector<T>& in_x, const std::vector<T>& in_y, const std::vector<T>& in_z, Vector<T>& out, mem::MemoryManager* mem_mgr=NULL);
  31. /**
  32. * \brief Evaluates polynomial values from input coefficients at points on
  33. * a regular grid defined by the values in the input vector.
  34. */
  35. template <class T>
  36. void cheb_eval(Vector<T>& coeff_, int cheb_deg, std::vector<T>& coord, Vector<T>& out);
  37. /**
  38. * \brief Computes a least squares solution for Chebyshev approximation over a
  39. * cube from point samples.
  40. * \param[in] deg Maximum degree of the polynomial.
  41. * \param[in] coord Coordinates of points (x,y,z interleaved).
  42. * \param[in] node_coord Coordinates of the octant.
  43. * \param[in] node_size Length of the side of the octant.
  44. * \param[out] cheb_coeff Output coefficients.
  45. */
  46. template <class T>
  47. void points2cheb(int deg, T* coord, T* val, int n, int dim, T* node_coord, T node_size, Vector<T>& cheb_coeff);
  48. /**
  49. * \brief Returns an n-point quadrature rule with points 'x' and weights 'w'.
  50. * Gauss-Legendre quadrature rule for double precision and Chebyshev quadrature
  51. * rule for other data types.
  52. */
  53. template <class T>
  54. void quad_rule(int n, T* x, T* w);
  55. /**
  56. * \brief
  57. * \param[in] r Length of the side of cubic region.
  58. */
  59. template <class T>
  60. std::vector<T> cheb_integ(int m, T* s, T r, const Kernel<T>& kernel);
  61. /**
  62. * \brief Returns coordinates of Chebyshev node points in 'dim' dimensional
  63. * space.
  64. */
  65. template <class T>
  66. std::vector<T> cheb_nodes(int deg, int dim);
  67. template <class T>
  68. void cheb_grad(const Vector<T>& A, int deg, Vector<T>& B, mem::MemoryManager* mem_mgr=NULL);
  69. template <class T>
  70. void cheb_laplacian(T* A, int deg, T* B);
  71. template <class T>
  72. void cheb_curl(T* A, int deg, T* B);
  73. /*
  74. * \brief Computes image of the chebyshev interpolation along the specified axis.
  75. */
  76. template <class T>
  77. void cheb_img(T* A, T* B, int cheb_deg, int dir, bool neg_);
  78. }//end namespace
  79. #include <cheb_utils.txx>
  80. #endif //_PVFMM_CHEB_UTILS_HPP_