Block-Structured AMR Software Framework
AMReX_LOUtil_K.H
Go to the documentation of this file.
1 #ifndef AMREX_LO_UTIL_K_H_
2 #define AMREX_LO_UTIL_K_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_GpuQualifiers.H>
6 #include <AMReX_REAL.H>
7 
8 namespace amrex {
9 
10 // polyInterpCoeff:
11 //
12 // This routine returns the Lagrange interpolating coefficients for a
13 // polynomial through N points, evaluated at xInt (see Numerical Recipes,
14 // v2, p102, e.g.):
15 //
16 // (x-x2)(x-x3)...(x-xN) (x-x1)(x-x2)...(x-x(N-1))
17 // P(x) = ----------------------- y1 + ... + ------------------------ yN
18 // (x1-x2)(x1-x3)...(x1-xN) (x1-x2)(x1-x3)...(x1-xN)
19 //
20 // P(xInt) = sum_(i=1)^(N) y[i]*c[i]
21 
22 template <typename T>
24 void poly_interp_coeff (T xInt, T const* AMREX_RESTRICT x, int N, T* AMREX_RESTRICT c) noexcept
25 {
26  for (int j = 0; j < N; ++j) {
27  T num = T(1.0), den = T(1.0);
28  for (int i = 0; i < N; ++i) {
29  if (i != j) {
30  num *= xInt-x[i];
31  den *= x[j]-x[i];
32  }
33  }
34  c[j] = num / den;
35  }
36 }
37 
38 template <int N, typename T>
40 void poly_interp_coeff (T xInt, T const* AMREX_RESTRICT x, T* AMREX_RESTRICT c) noexcept
41 {
42  for (int j = 0; j < N; ++j) {
43  T num = T(1.0), den = T(1.0);
44  for (int i = 0; i < N; ++i) {
45  if (i != j) {
46  num *= xInt-x[i];
47  den *= x[j]-x[i];
48  }
49  }
50  c[j] = num / den;
51  }
52 }
53 
54 }
55 
56 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_RESTRICT
Definition: AMReX_Extension.H:37
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void poly_interp_coeff(T xInt, T const *AMREX_RESTRICT x, int N, T *AMREX_RESTRICT c) noexcept
Definition: AMReX_LOUtil_K.H:24