Skip to content

Commit

Permalink
Merge pull request #5273 from BeyondEspresso/topic-update-tweac-unit-…
Browse files Browse the repository at this point in the history
…test-2

Allow double precision in TWTSTight unit test
  • Loading branch information
ikbuibui authored Feb 14, 2025
2 parents 02fba7f + 0a669d2 commit be1d994
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions share/picongpu/unit/TWTSTight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ using namespace pmacc;
* @return true if equal, else false
*/
template<typename T>
static bool isApproxEqual(T const& a, T const& b, T const& epsilon = std::numeric_limits<T>::epsilon())
static bool isApproxEqual(T const& a, T const& b, T const& epsilon)
{
return a == Catch::Approx(b).margin(epsilon);
}

template<typename T>
static bool isApproxEqual(T const& a, T const& b)
{
T const epsilon = std::numeric_limits<T>::epsilon() * max(abs(a), abs(b));
return a == Catch::Approx(b).margin(epsilon);
}

template<uint32_t T_numThreadsPerBlock>
struct GenerateEvals
{
Expand Down Expand Up @@ -156,11 +163,11 @@ struct twtsTightNumberTest
resultHost.copyFrom(resultDevice);

auto res = resultHost.getDataBox();
auto hostEfield = float3_X(
auto hostEfield = float3_T(
testEfield.calcTWTSFieldX(pos, time),
testEfield.calcTWTSFieldY(pos, time),
testEfield.calcTWTSFieldZ(pos, time));
auto hostBfield = float3_X(
auto hostBfield = float3_T(
testBfield.calcTWTSFieldX(pos, time),
testBfield.calcTWTSFieldY(pos, time),
testBfield.calcTWTSFieldZ(pos, time));
Expand All @@ -177,7 +184,7 @@ struct twtsTightNumberTest
* PMacc with boost library calls that also work on device. */
const float_T epsilonAlgebra = float_T(5.0e-6);
/* Epsilon to compare host implementation to device implementation */
const float_T epsilonHostDevice = float_T(5.0e-15);
const float_T epsilonHostDevice = float_T(1.0e-7);
for(uint32_t i = 0; i < 3; i++)
{
CHECK(isApproxEqual(refEfieldT[i], res[i], epsilonAlgebra));
Expand Down

0 comments on commit be1d994

Please sign in to comment.