forked from QMCPACK/qmcpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into value-alias
- Loading branch information
Showing
23 changed files
with
329 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source License. | ||
// See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2023 QMCPACK developers. | ||
// | ||
// File developed by: Ye Luo, [email protected], Argonne National Laboratory | ||
// | ||
// File created by: Ye Luo, [email protected], Argonne National Laboratory | ||
// | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#ifndef QMCPLUSPLUS_SPLINEBOUND_HPP | ||
#define QMCPLUSPLUS_SPLINEBOUND_HPP | ||
|
||
namespace qmcplusplus | ||
{ | ||
|
||
/** break x into the integer part and residual part and apply bounds | ||
* @param x input coordinate | ||
* @param nmax input upper bound of the integer part | ||
* @param ind output integer part | ||
* @param dx output fractional part | ||
* | ||
* x in the range of [0, nmax+1) will be split correctly. | ||
* x < 0, ind = 0, dx = 0 | ||
* x >= nmax+1, ind = nmax, dx = 1 - epsilon | ||
* | ||
* Attention: nmax is not the number grid points but the maximum allowed grid index | ||
* For example, ng is the number of grid point. | ||
* the actual grid points indices are 0, 1, ..., ng - 1. | ||
* In a periodic/anti periodic spline, set nmax = ng - 1 | ||
* In a natural boundary spline, set nmax = ng - 2 | ||
* because the end point should be excluded and the last grid point has an index ng - 2. | ||
*/ | ||
template<typename T, typename TRESIDUAL> | ||
inline void getSplineBound(const T x, const int nmax, int& ind, TRESIDUAL& dx) | ||
{ | ||
// lower bound | ||
if (x < 0) | ||
{ | ||
ind = 0; | ||
dx = T(0); | ||
} | ||
else | ||
{ | ||
#if defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_CLANG_COMPILER) | ||
T ipart = std::floor(x); | ||
dx = x - ipart; | ||
#else | ||
T ipart; | ||
dx = std::modf(x, &ipart); | ||
#endif | ||
ind = static_cast<int>(ipart); | ||
// upper bound | ||
if (ind > nmax) | ||
{ | ||
ind = nmax; | ||
dx = T(1) - std::numeric_limits<T>::epsilon(); | ||
} | ||
} | ||
} | ||
} // namespace qmcplusplus | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
// This file is distributed under the University of Illinois/NCSA Open Source License. | ||
// See LICENSE file in top directory for details. | ||
// | ||
// Copyright (c) 2018 Jeongnim Kim and QMCPACK developers. | ||
// | ||
// File developed by: Mark Dewing, [email protected], Argonne National Laboratory | ||
// | ||
// File created by: Mark Dewing, [email protected], Argonne National Laboratory | ||
////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#include "catch.hpp" | ||
#include "Numerics/SplineBound.hpp" | ||
|
||
namespace qmcplusplus | ||
{ | ||
template<typename T> | ||
void test_spline_bounds() | ||
{ | ||
T x = 2.2; | ||
T dx; | ||
int ind; | ||
int ng = 10; | ||
getSplineBound(x, ng, ind, dx); | ||
CHECK(dx == Approx(0.2)); | ||
REQUIRE(ind == 2); | ||
|
||
// check clamping to a maximum index value | ||
x = 10.5; | ||
getSplineBound(x, ng, ind, dx); | ||
CHECK(dx == Approx(0.5)); | ||
REQUIRE(ind == 10); | ||
|
||
x = 11.5; | ||
getSplineBound(x, ng, ind, dx); | ||
CHECK(dx == Approx(1.0)); | ||
REQUIRE(ind == 10); | ||
|
||
// check clamping to a zero index value | ||
x = -1.3; | ||
getSplineBound(x, ng, ind, dx); | ||
CHECK(dx == Approx(0.0)); | ||
REQUIRE(ind == 0); | ||
} | ||
|
||
TEST_CASE("getSplineBound double", "[numerics]") { test_spline_bounds<double>(); } | ||
TEST_CASE("getSplineBound float", "[numerics]") { test_spline_bounds<float>(); } | ||
} // namespace qmcplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.