QMCPACK
SplineBound.hpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2023 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 #ifndef QMCPLUSPLUS_SPLINEBOUND_HPP
14 #define QMCPLUSPLUS_SPLINEBOUND_HPP
15 
16 namespace qmcplusplus
17 {
18 
19 /** break x into the integer part and residual part and apply bounds
20  * @param x input coordinate
21  * @param nmax input upper bound of the integer part
22  * @param ind output integer part
23  * @param dx output fractional part
24  *
25  * x in the range of [0, nmax+1) will be split correctly.
26  * x < 0, ind = 0, dx = 0
27  * x >= nmax+1, ind = nmax, dx = 1 - epsilon
28  *
29  * Attention: nmax is not the number grid points but the maximum allowed grid index
30  * For example, ng is the number of grid point.
31  * the actual grid points indices are 0, 1, ..., ng - 1.
32  * In a periodic/anti periodic spline, set nmax = ng - 1
33  * In a natural boundary spline, set nmax = ng - 2
34  * because the end point should be excluded and the last grid point has an index ng - 2.
35  */
36 template<typename T, typename TRESIDUAL>
37 inline void getSplineBound(const T x, const int nmax, int& ind, TRESIDUAL& dx)
38 {
39  // lower bound
40  if (x < 0)
41  {
42  ind = 0;
43  dx = T(0);
44  }
45  else
46  {
47 #if defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_CLANG_COMPILER)
48  T ipart = std::floor(x);
49  dx = x - ipart;
50 #else
51  T ipart;
52  dx = std::modf(x, &ipart);
53 #endif
54  ind = static_cast<int>(ipart);
55  // upper bound
56  if (ind > nmax)
57  {
58  ind = nmax;
59  dx = T(1) - std::numeric_limits<T>::epsilon();
60  }
61  }
62 }
63 } // namespace qmcplusplus
64 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void getSplineBound(const T x, const int nmax, int &ind, TRESIDUAL &dx)
break x into the integer part and residual part and apply bounds
Definition: SplineBound.hpp:37
MakeReturn< UnaryNode< FnFloor, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t floor(const Vector< T1, C1 > &l)