From 0f8ebae90cc35f8466fe4ccfef2c383f14c9e02e Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Fri, 12 Jun 2026 15:27:30 +0200 Subject: [PATCH 1/9] remove grid argument in generate random sample data --- tests/DirectSolver/directSolver.cpp | 48 +++++++++---------- .../extrapolated_smoother.cpp | 44 ++++++++--------- .../extrapolated_prolongation.cpp | 2 +- .../extrapolated_restriction.cpp | 2 +- tests/Interpolation/prolongation.cpp | 2 +- tests/Interpolation/restriction.cpp | 2 +- tests/Residual/residual.cpp | 8 ++-- tests/Smoother/smoother.cpp | 44 ++++++++--------- tests/test_tools.h | 6 +-- 9 files changed, 79 insertions(+), 79 deletions(-) diff --git a/tests/DirectSolver/directSolver.cpp b/tests/DirectSolver/directSolver.cpp index 34464e1b..21522c4e 100644 --- a/tests/DirectSolver/directSolver.cpp +++ b/tests/DirectSolver/directSolver.cpp @@ -71,10 +71,10 @@ TEST(DirectSolverTest, directSolver_DirBC_Interior) DirectSolverTake directSolverGive_operator(level.grid(), level.levelCache(), DirBC_Interior); DirectSolverGive directSolverTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector solution_Give = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector solution_Give = generate_random_sample_data(level.grid().numberOfNodes(), 69); directSolverGive_operator.solveInPlace(solution_Give); - HostVector solution_Take = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector solution_Take = generate_random_sample_data(level.grid().numberOfNodes(), 69); directSolverTake_operator.solveInPlace(solution_Take); ASSERT_EQ(solution_Give.size(), solution_Take.size()); @@ -120,10 +120,10 @@ TEST(DirectSolverTest, directSolver_AcrossOrigin) DirectSolverGive directSolverGive_operator(level.grid(), level.levelCache(), DirBC_Interior); DirectSolverTake directSolverTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector solution_Give = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector solution_Give = generate_random_sample_data(level.grid().numberOfNodes(), 69); directSolverGive_operator.solveInPlace(solution_Give); - HostVector solution_Take = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector solution_Take = generate_random_sample_data(level.grid().numberOfNodes(), 69); directSolverTake_operator.solveInPlace(solution_Take); ASSERT_EQ(solution_Give.size(), solution_Take.size()); @@ -171,7 +171,7 @@ TEST(DirectSolverTest_CircularGeometry, DirectSolverDirBC_Interior_CircularGeome DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -212,7 +212,7 @@ TEST(DirectSolverTest_CircularGeometry, DirectSolverAcrossOrigin_CircularGeometr DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -259,7 +259,7 @@ TEST(DirectSolverTest_ShafranovGeometry, DirectSolverDirBC_Interior_ShafranovGeo DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -302,7 +302,7 @@ TEST(DirectSolverTest_ShafranovGeometry, DirectSolverAcrossOrigin_ShafranovGeome DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -349,7 +349,7 @@ TEST(DirectSolverTest_CzarnyGeometry, DirectSolverDirBC_Interior_CzarnyGeometry) DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -392,7 +392,7 @@ TEST(DirectSolverTest_CzarnyGeometry, DirectSolverAcrossOrigin_CzarnyGeometry) DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -437,7 +437,7 @@ TEST(DirectSolverTest_CulhamGeometry, DirectSolverDirBC_Interior_CulhamGeometry) DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -478,7 +478,7 @@ TEST(DirectSolverTest_CulhamGeometry, DirectSolverAcrossOrigin_CulhamGeometry) DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -531,7 +531,7 @@ TEST(DirectSolverTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecision_ DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -572,7 +572,7 @@ TEST(DirectSolverTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecision2 DirectSolverGive solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -614,7 +614,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, DirectSolverDirBC_Interior_CircularG DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -655,7 +655,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, DirectSolverAcrossOrigin_CircularGeo DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -702,7 +702,7 @@ TEST(DirectSolverTakeTest_ShafranovGeometry, DirectSolverDirBC_Interior_Shafrano DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -745,7 +745,7 @@ TEST(DirectSolverTakeTest_ShafranovGeometry, DirectSolverAcrossOrigin_ShafranovG DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -792,7 +792,7 @@ TEST(DirectSolverTakeTest_CzarnyGeometry, DirectSolverDirBC_Interior_CzarnyGeome DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -835,7 +835,7 @@ TEST(DirectSolverTakeTest_CzarnyGeometry, DirectSolverAcrossOrigin_CzarnyGeometr DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -880,7 +880,7 @@ TEST(DirectSolverTakeTest_CulhamGeometry, DirectSolverDirBC_Interior_CulhamGeome DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -921,7 +921,7 @@ TEST(DirectSolverTakeTest_CulhamGeometry, DirectSolverAcrossOrigin_CulhamGeometr DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -972,7 +972,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecis DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); @@ -1013,7 +1013,7 @@ TEST(DirectSolverTakeTest_CircularGeometry, DirectSolverAcrossOriginHigherPrecis DirectSolverTake solver_op(level.grid(), level.levelCache(), DirBC_Interior); ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector solution("sol", rhs.size()); Kokkos::deep_copy(solution, rhs); solver_op.solveInPlace(solution); diff --git a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp index 61e4f827..91e79909 100644 --- a/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp +++ b/tests/ExtrapolatedSmoother/extrapolated_smoother.cpp @@ -61,9 +61,9 @@ TEST(ExtrapolatedSmootherTest, extrapolatedSmoother_DirBC_Interior) ExtrapolatedSmootherGive smootherGive_operator(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherTake smootherTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 69); - HostVector start = generate_random_sample_data(PolarGrid(level.grid()), 24); - HostVector temp = generate_random_sample_data(PolarGrid(level.grid()), 8); + HostVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 69); + HostVector start = generate_random_sample_data(level.grid().numberOfNodes(), 24); + HostVector temp = generate_random_sample_data(level.grid().numberOfNodes(), 8); HostVector solution_Give("solution_Give", start.size()); Kokkos::deep_copy(solution_Give, start); @@ -118,9 +118,9 @@ TEST(ExtrapolatedSmootherTest, extrapolatedSmoother_AcossOrigin) ExtrapolatedSmootherGive smootherGive_operator(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherTake smootherTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 69); - HostVector start = generate_random_sample_data(PolarGrid(level.grid()), 24); - HostVector temp = generate_random_sample_data(PolarGrid(level.grid()), 8); + HostVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 69); + HostVector start = generate_random_sample_data(level.grid().numberOfNodes(), 24); + HostVector temp = generate_random_sample_data(level.grid().numberOfNodes(), 8); HostVector solution_Give("solution_Give", start.size()); Kokkos::deep_copy(solution_Give, start); @@ -177,14 +177,14 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherDirBC_Interior) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherGive extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -258,7 +258,7 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherAcrossOrigin) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherGive extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); @@ -267,7 +267,7 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherAcrossOrigin) HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -340,7 +340,7 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherDirBC_Interior_SmallestGrid) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherGive extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); @@ -349,7 +349,7 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherDirBC_Interior_SmallestGrid) HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -422,14 +422,14 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherAcrossOrigin_SmallestGrid) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherGive extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -505,14 +505,14 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherTakeDirBC_Interior) ResidualTake residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherTake extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -586,14 +586,14 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherTakeAcrossOrigin) ResidualTake residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherTake extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -666,14 +666,14 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherTakeDirBC_Interior_SmallestGr ResidualTake residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherTake extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; @@ -746,14 +746,14 @@ TEST(ExtrapolatedSmootherTest, ExtrapolatedSmootherTakeAcrossOrigin_SmallestGrid ResidualTake residual_op(level.grid(), level.levelCache(), DirBC_Interior); ExtrapolatedSmootherTake extrapolated_smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); for (int i_r = 0; i_r < level.grid().nr(); i_r += 2) { for (int i_theta = 0; i_theta < level.grid().ntheta(); i_theta += 2) { smoother_solution[level.grid().index(i_r, i_theta)] = discrete_solution[level.grid().index(i_r, i_theta)]; diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index 137c8ab5..ffeacf44 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -55,7 +55,7 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) Interpolation I(/*DirBC*/ true); - HostVector h_coarse_values = generate_random_sample_data(h_coarse_grid, 1234, 0.0, 1.0); + HostVector h_coarse_values = generate_random_sample_data(coarse_grid.numberOfNodes(), 1234, 0.0, 1.0); Vector fine_result("fine_result", fine_grid.numberOfNodes()); auto coarse_values = Kokkos::create_mirror_view_and_copy(DefaultMemorySpace(), h_coarse_values); diff --git a/tests/Interpolation/extrapolated_restriction.cpp b/tests/Interpolation/extrapolated_restriction.cpp index d6b7273d..be74193e 100644 --- a/tests/Interpolation/extrapolated_restriction.cpp +++ b/tests/Interpolation/extrapolated_restriction.cpp @@ -54,7 +54,7 @@ TEST(ExtrapolatedRestrictionTest, ExtrapolatedRestrictionMatchesStencil) Interpolation I(/*DirBC*/ true); - HostVector h_fine_values = generate_random_sample_data(h_fine_grid, 9012, 0.0, 1.0); + HostVector h_fine_values = generate_random_sample_data(fine_grid.numberOfNodes(), 9012, 0.0, 1.0); Vector coarse_result("coarse_result", coarse_grid.numberOfNodes()); auto fine_values = Kokkos::create_mirror_view_and_copy(DefaultMemorySpace(), h_fine_values); diff --git a/tests/Interpolation/prolongation.cpp b/tests/Interpolation/prolongation.cpp index a9018f1b..bfb55eef 100644 --- a/tests/Interpolation/prolongation.cpp +++ b/tests/Interpolation/prolongation.cpp @@ -66,7 +66,7 @@ TEST(ProlongationTest, ProlongationMatchesStencil) Interpolation I(/*DirBC*/ true); - HostVector coarse_values = generate_random_sample_data(coarse_grid, 1234); + HostVector coarse_values = generate_random_sample_data(coarse_grid.numberOfNodes(), 1234); HostVector fine_result("fine_result", fine_grid.numberOfNodes()); I.applyProlongation(coarse_grid, fine_grid, fine_result, coarse_values); diff --git a/tests/Interpolation/restriction.cpp b/tests/Interpolation/restriction.cpp index 29821ff1..a0f1dc3b 100644 --- a/tests/Interpolation/restriction.cpp +++ b/tests/Interpolation/restriction.cpp @@ -62,7 +62,7 @@ TEST(RestrictionTest, RestrictionMatchesStencil) Interpolation I(/*DirBC*/ true); - HostVector fine_values = generate_random_sample_data(fine_grid, 5678, 0.0, 1.0); + HostVector fine_values = generate_random_sample_data(fine_grid.numberOfNodes(), 5678, 0.0, 1.0); HostVector coarse_result("coarse_result", coarse_grid.numberOfNodes()); I.applyRestriction(fine_grid, coarse_grid, coarse_result, fine_values); diff --git a/tests/Residual/residual.cpp b/tests/Residual/residual.cpp index c74dc5d7..2527a9fe 100644 --- a/tests/Residual/residual.cpp +++ b/tests/Residual/residual.cpp @@ -55,8 +55,8 @@ TEST(OperatorATest, applyA_DirBC_Interior) ResidualGive residualGive_operator(level.grid(), level.levelCache(), DirBC_Interior); ResidualTake residualTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector x = generate_random_sample_data(PolarGrid(level.grid()), 42); - HostVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector x = generate_random_sample_data(level.grid().numberOfNodes(), 42); + HostVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 69); HostVector result_Give("result_Give", level.grid().numberOfNodes()); residualGive_operator.computeResidual(result_Give, rhs, x); @@ -107,8 +107,8 @@ TEST(OperatorATest, applyA_AcrossOrigin) ResidualGive residualGive_operator(level.grid(), level.levelCache(), DirBC_Interior); ResidualTake residualTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector x = generate_random_sample_data(PolarGrid(level.grid()), 42); - HostVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector x = generate_random_sample_data(level.grid().numberOfNodes(), 42); + HostVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 69); HostVector result_Give("result_Give", level.grid().numberOfNodes()); residualGive_operator.computeResidual(result_Give, rhs, x); diff --git a/tests/Smoother/smoother.cpp b/tests/Smoother/smoother.cpp index 28f015ea..a8a9a5d6 100644 --- a/tests/Smoother/smoother.cpp +++ b/tests/Smoother/smoother.cpp @@ -61,9 +61,9 @@ TEST(SmootherTest, smoother_DirBC_Interior) SmootherGive smootherGive_operator(level.grid(), level.levelCache(), DirBC_Interior); SmootherTake smootherTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 69); - HostVector start = generate_random_sample_data(PolarGrid(level.grid()), 24); - HostVector temp = generate_random_sample_data(PolarGrid(level.grid()), 8); + HostVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 69); + HostVector start = generate_random_sample_data(level.grid().numberOfNodes(), 24); + HostVector temp = generate_random_sample_data(level.grid().numberOfNodes(), 8); HostVector solution_Give("solution_Give", start.size()); Kokkos::deep_copy(solution_Give, start); @@ -118,9 +118,9 @@ TEST(SmootherTest, smoother_AcrossOrigin) SmootherGive smootherGive_operator(level.grid(), level.levelCache(), DirBC_Interior); SmootherTake smootherTake_operator(level.grid(), level.levelCache(), DirBC_Interior); - HostVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 69); - HostVector start = generate_random_sample_data(PolarGrid(level.grid()), 24); - HostVector temp = generate_random_sample_data(PolarGrid(level.grid()), 8); + HostVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 69); + HostVector start = generate_random_sample_data(level.grid().numberOfNodes(), 24); + HostVector temp = generate_random_sample_data(level.grid().numberOfNodes(), 8); HostVector solution_Give("solution_Give", start.size()); Kokkos::deep_copy(solution_Give, start); @@ -176,14 +176,14 @@ TEST(SmootherTest, SmootherDirBC_Interior) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherGive smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -251,14 +251,14 @@ TEST(SmootherTest, SmootherAcrossOrigin) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherGive smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -325,14 +325,14 @@ TEST(SmootherTest, SmootherDirBC_Interior_SmallestGrid) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherGive smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -399,14 +399,14 @@ TEST(SmootherTest, SmootherAcrossOrigin_SmallestGrid) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherGive smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -476,14 +476,14 @@ TEST(SmootherTest, SmootherTakeDirBC_Interior) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherTake smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -551,14 +551,14 @@ TEST(SmootherTest, SmootherTakeAcrossOrigin) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherTake smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -625,14 +625,14 @@ TEST(SmootherTest, SmootherTakeDirBC_Interior_SmallestGrid) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherTake smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { @@ -699,14 +699,14 @@ TEST(SmootherTest, SmootherTakeAcrossOrigin_SmallestGrid) ResidualGive residual_op(level.grid(), level.levelCache(), DirBC_Interior); SmootherTake smoother_op(level.grid(), level.levelCache(), DirBC_Interior); - HostConstVector rhs = generate_random_sample_data(PolarGrid(level.grid()), 42); + HostConstVector rhs = generate_random_sample_data(level.grid().numberOfNodes(), 42); HostVector discrete_solution("discrete_solution", rhs.size()); Kokkos::deep_copy(discrete_solution, rhs); solver_op.solveInPlace(discrete_solution); HostVector temp("temp", level.grid().numberOfNodes()); HostVector error("error", level.grid().numberOfNodes()); - HostVector smoother_solution = generate_random_sample_data(PolarGrid(level.grid()), 69); + HostVector smoother_solution = generate_random_sample_data(level.grid().numberOfNodes(), 69); Kokkos::parallel_for("get error", Kokkos::RangePolicy(0, error.size()), [&](uint i) { diff --git a/tests/test_tools.h b/tests/test_tools.h index b4371332..4da69f8c 100644 --- a/tests/test_tools.h +++ b/tests/test_tools.h @@ -6,10 +6,10 @@ using namespace gmgpolar; -inline HostVector generate_random_sample_data(const PolarGrid& grid, unsigned int seed, - double min_val = -100.0, double max_val = 100.0) +inline HostVector generate_random_sample_data(const int n_nodes, unsigned int seed, double min_val = -100.0, + double max_val = 100.0) { - HostVector x("x", grid.numberOfNodes()); + HostVector x("x", n_nodes); std::mt19937 gen(seed); std::uniform_real_distribution dist(min_val, max_val); for (std::size_t i = 0; i < x.size(); ++i) { From 77ff767ac34da4f06f97108ac3592ffe5651e50f Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Mon, 15 Jun 2026 14:16:04 +0200 Subject: [PATCH 2/9] remove unused host grid --- tests/GMGPolar/pcg_tests.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/GMGPolar/pcg_tests.cpp b/tests/GMGPolar/pcg_tests.cpp index bfcfca88..ea3c2e73 100644 --- a/tests/GMGPolar/pcg_tests.cpp +++ b/tests/GMGPolar/pcg_tests.cpp @@ -690,8 +690,7 @@ void run_gmgpolar() solver.solve(boundary_conditions, source_term); // --- Retrieve solution and associated grid --- // - Vector solution = solver.solution(); - const PolarGrid& solution_grid = solver.grid(); + Vector solution = solver.solution(); if (TestFixture::verbose > 0) { solver.printTimings(); From 641c5fe62ca772dbb959e4fab17ff3f2befef071 Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Mon, 15 Jun 2026 14:38:11 +0200 Subject: [PATCH 3/9] remove unsed host allocated solution_grid --- tests/GMGPolar/solve_tests.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/GMGPolar/solve_tests.cpp b/tests/GMGPolar/solve_tests.cpp index d92ff349..3e2b5a74 100644 --- a/tests/GMGPolar/solve_tests.cpp +++ b/tests/GMGPolar/solve_tests.cpp @@ -693,8 +693,7 @@ void run_gmgpolar() solver.solve(boundary_conditions, source_term); // --- Retrieve solution and associated grid --- // - Vector solution = solver.solution(); - const PolarGrid& solution_grid = solver.grid(); + Vector solution = solver.solution(); if (TestFixture::verbose > 0) { solver.printTimings(); From 0e8b02de7bf183dac35b2b6252d743d55a4e67c8 Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Mon, 15 Jun 2026 15:23:35 +0200 Subject: [PATCH 4/9] run expected extrapolated computations on device --- .../extrapolated_prolongation.cpp | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index b530955d..efbe43bf 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -9,8 +9,8 @@ using namespace gmgpolar; // Helper that computes the mathematically expected extrapolated prolongation value -static double expected_extrapolated_value(const PolarGrid& coarse, - const PolarGrid& fine, HostConstVector coarse_vals, +static double expected_extrapolated_value(const PolarGrid& coarse, + const PolarGrid& fine, ConstVector coarse_vals, int i_r, int i_theta) { int i_r_coarse = i_r / 2; @@ -18,27 +18,32 @@ static double expected_extrapolated_value(const PolarGrid& co bool r_even = (i_r % 2 == 0); bool t_even = (i_theta % 2 == 0); + HostVector result_h("host_res", 1); + Vector result_d("device_res", 1); + Kokkos::parallel_for("expected_extrapolated", 1, [=](int idx) { + if (r_even && t_even) { + // Node coincides with a coarse node + result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; + } - if (r_even && t_even) { - // Node coincides with a coarse node - return coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; - } - - if (!r_even && t_even) { - // Radial midpoint - arithmetic mean of left and right - return 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]); - } + if (!r_even && t_even) { + // Radial midpoint - arithmetic mean of left and right + result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]); + } - if (r_even && !t_even) { - // Angular midpoint - arithmetic mean of bottom and top - return 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); - } + if (r_even && !t_even) { + // Angular midpoint - arithmetic mean of bottom and top + result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + } - // Center of coarse cell - arithmetic mean of diagonal nodes (bottom-right + top-left) - return 0.5 * (coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + // Center of coarse cell - arithmetic mean of diagonal nodes (bottom-right + top-left) + result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + }); + Kokkos::deep_copy(result_h, result_d); + return result_h(0); } TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) @@ -66,7 +71,7 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) for (int i_r = 0; i_r < fine_grid.nr(); ++i_r) { for (int i_theta = 0; i_theta < fine_grid.ntheta(); ++i_theta) { - double expected = expected_extrapolated_value(h_coarse_grid, h_fine_grid, h_coarse_values, i_r, i_theta); + double expected = expected_extrapolated_value(coarse_grid, fine_grid, coarse_values, i_r, i_theta); double got = h_fine_result[h_fine_grid.index(i_r, i_theta)]; ASSERT_NEAR(expected, got, 1e-10) << "Mismatch at (" << i_r << ", " << i_theta << ")"; } From f8624ec099a76752e6dc3f0a4edf245fd9308dd2 Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Tue, 16 Jun 2026 10:08:43 +0200 Subject: [PATCH 5/9] remove host grid from test file --- .../extrapolated_prolongation.cpp | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index efbe43bf..fd3d26e3 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -18,30 +18,34 @@ static double expected_extrapolated_value(const PolarGrid& c bool r_even = (i_r % 2 == 0); bool t_even = (i_theta % 2 == 0); + HostVector result_h("host_res", 1); Vector result_d("device_res", 1); - Kokkos::parallel_for("expected_extrapolated", 1, [=](int idx) { - if (r_even && t_even) { - // Node coincides with a coarse node - result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; - } - - if (!r_even && t_even) { - // Radial midpoint - arithmetic mean of left and right - result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]); - } - if (r_even && !t_even) { - // Angular midpoint - arithmetic mean of bottom and top - result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); - } - - // Center of coarse cell - arithmetic mean of diagonal nodes (bottom-right + top-left) - result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); - }); + Kokkos::parallel_for( + "loop", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + if (r_even && t_even) { + // Node coincides with a coarse node + result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; + } + + else if (!r_even && t_even) { + // Radial midpoint - arithmetic mean of left and right + result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]); + } + + else if (r_even && !t_even) { + // Angular midpoint - arithmetic mean of bottom and top + result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + } + else { + // Center of coarse cell - arithmetic mean of diagonal nodes (bottom-right + top-left) + result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + } + }); Kokkos::deep_copy(result_h, result_d); return result_h(0); } @@ -55,9 +59,6 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) PolarGrid fine_grid(fine_radii, fine_angles); PolarGrid coarse_grid = coarseningGrid(fine_grid); - PolarGrid h_fine_grid(fine_grid); - PolarGrid h_coarse_grid(coarse_grid); - Interpolation I(/*DirBC*/ true); Vector coarse_values = generate_random_sample_data(coarse_grid, 1234, 0.0, 1.0); @@ -72,7 +73,7 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) for (int i_r = 0; i_r < fine_grid.nr(); ++i_r) { for (int i_theta = 0; i_theta < fine_grid.ntheta(); ++i_theta) { double expected = expected_extrapolated_value(coarse_grid, fine_grid, coarse_values, i_r, i_theta); - double got = h_fine_result[h_fine_grid.index(i_r, i_theta)]; + double got = h_fine_result[fine_grid.index(i_r, i_theta)]; ASSERT_NEAR(expected, got, 1e-10) << "Mismatch at (" << i_r << ", " << i_theta << ")"; } } From a6e66eef9cf5a00eff4f6f988ed142175a71c471 Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Tue, 16 Jun 2026 12:54:38 +0200 Subject: [PATCH 6/9] remove host polar grid in prolongation tests --- .../extrapolated_prolongation.cpp | 2 +- tests/Interpolation/prolongation.cpp | 93 ++++++++++--------- 2 files changed, 50 insertions(+), 45 deletions(-) diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index fd3d26e3..c1de9c2a 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -23,7 +23,7 @@ static double expected_extrapolated_value(const PolarGrid& c Vector result_d("device_res", 1); Kokkos::parallel_for( - "loop", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + "extrap_prolongation_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { if (r_even && t_even) { // Node coincides with a coarse node result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; diff --git a/tests/Interpolation/prolongation.cpp b/tests/Interpolation/prolongation.cpp index 5e57bbb4..78850688 100644 --- a/tests/Interpolation/prolongation.cpp +++ b/tests/Interpolation/prolongation.cpp @@ -8,51 +8,59 @@ using namespace gmgpolar; // Helper that computes the mathematically expected prolongation value -static double expected_value(const PolarGrid& coarse, const PolarGrid& fine, - HostConstVector coarse_vals, int i_r, int i_theta) +static double expected_value(const PolarGrid& coarse, const PolarGrid& fine, + ConstVector coarse_vals, int i_r, int i_theta) { int i_r_coarse = i_r / 2; int i_theta_coarse = i_theta / 2; bool r_even = (i_r % 2 == 0); bool t_even = (i_theta % 2 == 0); - - if (r_even && t_even) { - // Node coincides with a coarse node - return coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; - } - - if (!r_even && t_even) { - // Radial midpoint - double h1 = fine.radialSpacing(i_r - 1); - double h2 = fine.radialSpacing(i_r); - - return (h1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - h2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]) / - (h1 + h2); - } - - if (r_even && !t_even) { - // Angular midpoint - double k1 = fine.angularSpacing(i_theta - 1); - double k2 = fine.angularSpacing(i_theta); - - return (k1 * coarse_vals[coarse.index(i_r_coarse, t_even ? i_theta_coarse : i_theta_coarse)] + - k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]) / - (k1 + k2); - } - - // Center of coarse cell - double h1 = fine.radialSpacing(i_r - 1); - double h2 = fine.radialSpacing(i_r); - double k1 = fine.angularSpacing(i_theta - 1); - double k2 = fine.angularSpacing(i_theta); - - return (h1 * k1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - h2 * k1 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + - h1 * k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)] + - h2 * k2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse + 1)]) / - ((h1 + h2) * (k1 + k2)); + HostVector result_h("host_res", 1); + Vector result_d("device_res", 1); + + Kokkos::parallel_for( + "prolongation_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + if (r_even && t_even) { + // Node coincides with a coarse node + result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; + } + + else if (!r_even && t_even) { + // Radial midpoint + double h1 = fine.radialSpacing(i_r - 1); + double h2 = fine.radialSpacing(i_r); + + result_d(0) = (h1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + h2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]) / + (h1 + h2); + } + + else if (r_even && !t_even) { + // Angular midpoint + double k1 = fine.angularSpacing(i_theta - 1); + double k2 = fine.angularSpacing(i_theta); + + result_d(0) = (k1 * coarse_vals[coarse.index(i_r_coarse, t_even ? i_theta_coarse : i_theta_coarse)] + + k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]) / + (k1 + k2); + } + else { + // Center of coarse cell + double h1 = fine.radialSpacing(i_r - 1); + double h2 = fine.radialSpacing(i_r); + double k1 = fine.angularSpacing(i_theta - 1); + double k2 = fine.angularSpacing(i_theta); + + result_d(0) = (h1 * k1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + h2 * k1 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + + h1 * k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)] + + h2 * k2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse + 1)]) / + ((h1 + h2) * (k1 + k2)); + } + }); + Kokkos::deep_copy(result_h, result_d); + return result_h(0); } TEST(ProlongationTest, ProlongationMatchesStencil) @@ -71,16 +79,13 @@ TEST(ProlongationTest, ProlongationMatchesStencil) I.applyProlongation(coarse_grid, fine_grid, fine_result, coarse_values); - PolarGrid h_fine_grid(fine_grid); - PolarGrid h_coarse_grid(coarse_grid); - auto h_coarse_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, coarse_values); auto h_fine_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, fine_result); for (int i_r = 0; i_r < fine_grid.nr(); ++i_r) { for (int i_theta = 0; i_theta < fine_grid.ntheta(); ++i_theta) { - double expected = expected_value(h_coarse_grid, h_fine_grid, h_coarse_values, i_r, i_theta); - double got = h_fine_result[h_fine_grid.index(i_r, i_theta)]; + double expected = expected_value(coarse_grid, fine_grid, coarse_values, i_r, i_theta); + double got = h_fine_result[fine_grid.index(i_r, i_theta)]; ASSERT_NEAR(expected, got, 1e-10) << "Mismatch at (" << i_r << ", " << i_theta << ")"; } } From 9f0845d1b28be71130a0a558e3d658c7927fb1ae Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Tue, 16 Jun 2026 12:54:56 +0200 Subject: [PATCH 7/9] remove host polar grid in restriction tests --- .../extrapolated_restriction.cpp | 63 +++++++------- tests/Interpolation/restriction.cpp | 85 ++++++++++--------- 2 files changed, 76 insertions(+), 72 deletions(-) diff --git a/tests/Interpolation/extrapolated_restriction.cpp b/tests/Interpolation/extrapolated_restriction.cpp index 14eb8d3a..cf210516 100644 --- a/tests/Interpolation/extrapolated_restriction.cpp +++ b/tests/Interpolation/extrapolated_restriction.cpp @@ -9,35 +9,39 @@ using namespace gmgpolar; // Helper that computes the mathematically expected extrapolated restriction value -static double expected_extrapolated_restriction_value(const PolarGrid& fine, - const PolarGrid& coarse, - HostConstVector fine_vals, int i_r_coarse, - int i_theta_coarse) +static double expected_extrapolated_restriction_value(const PolarGrid& fine, + const PolarGrid& coarse, + ConstVector fine_vals, int i_r_coarse, int i_theta_coarse) { int i_r = i_r_coarse * 2; int i_theta = i_theta_coarse * 2; - // Angular indices with periodic wrapping - int i_theta_M1 = fine.wrapThetaIndex(i_theta - 1); - int i_theta_P1 = fine.wrapThetaIndex(i_theta + 1); - - // Center + Angular contributions (always present) - double value = fine_vals[fine.index(i_r, i_theta)] + 0.5 * fine_vals[fine.index(i_r, i_theta_M1)] + - 0.5 * fine_vals[fine.index(i_r, i_theta_P1)]; - - // Left contributions (if not at inner boundary) - if (i_r_coarse > 0) { - value += 0.5 * fine_vals[fine.index(i_r - 1, i_theta)] + - 0.5 * fine_vals[fine.index(i_r - 1, i_theta_P1)]; // Top-Left diagonal - } - - // Right contributions (if not at outer boundary) - if (i_r_coarse < coarse.nr() - 1) { - value += 0.5 * fine_vals[fine.index(i_r + 1, i_theta)] + - 0.5 * fine_vals[fine.index(i_r + 1, i_theta_M1)]; // Bottom-Right diagonal - } - - return value; + HostVector result_h("host_res", 1); + Vector result_d("device_res", 1); + Kokkos::parallel_for( + "extrap_restriction_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + // Angular indices with periodic wrapping + int i_theta_M1 = fine.wrapThetaIndex(i_theta - 1); + int i_theta_P1 = fine.wrapThetaIndex(i_theta + 1); + + // Center + Angular contributions (always present) + result_d(0) = fine_vals[fine.index(i_r, i_theta)] + 0.5 * fine_vals[fine.index(i_r, i_theta_M1)] + + 0.5 * fine_vals[fine.index(i_r, i_theta_P1)]; + + // Left contributions (if not at inner boundary) + if (i_r_coarse > 0) { + result_d(0) += 0.5 * fine_vals[fine.index(i_r - 1, i_theta)] + + 0.5 * fine_vals[fine.index(i_r - 1, i_theta_P1)]; // Top-Left diagonal + } + + // Right contributions (if not at outer boundary) + if (i_r_coarse < coarse.nr() - 1) { + result_d(0) += 0.5 * fine_vals[fine.index(i_r + 1, i_theta)] + + 0.5 * fine_vals[fine.index(i_r + 1, i_theta_M1)]; // Bottom-Right diagonal + } + }); + Kokkos::deep_copy(result_h, result_d); + return result_h(0); } TEST(ExtrapolatedRestrictionTest, ExtrapolatedRestrictionMatchesStencil) @@ -49,9 +53,6 @@ TEST(ExtrapolatedRestrictionTest, ExtrapolatedRestrictionMatchesStencil) PolarGrid fine_grid(fine_radii, fine_angles); PolarGrid coarse_grid = coarseningGrid(fine_grid); - PolarGrid h_fine_grid(fine_grid); - PolarGrid h_coarse_grid(coarse_grid); - Interpolation I(/*DirBC*/ true); Vector fine_values = generate_random_sample_data(fine_grid, 9012, 0.0, 1.0); @@ -65,9 +66,9 @@ TEST(ExtrapolatedRestrictionTest, ExtrapolatedRestrictionMatchesStencil) for (int i_r_coarse = 0; i_r_coarse < coarse_grid.nr(); ++i_r_coarse) { for (int i_theta_coarse = 0; i_theta_coarse < coarse_grid.ntheta(); ++i_theta_coarse) { - double expected = expected_extrapolated_restriction_value(h_fine_grid, h_coarse_grid, h_fine_values, - i_r_coarse, i_theta_coarse); - double got = h_coarse_result[h_coarse_grid.index(i_r_coarse, i_theta_coarse)]; + double expected = expected_extrapolated_restriction_value(fine_grid, coarse_grid, fine_values, i_r_coarse, + i_theta_coarse); + double got = h_coarse_result[coarse_grid.index(i_r_coarse, i_theta_coarse)]; ASSERT_NEAR(expected, got, 1e-10) << "Mismatch at (" << i_r_coarse << ", " << i_theta_coarse << ")"; } } diff --git a/tests/Interpolation/restriction.cpp b/tests/Interpolation/restriction.cpp index eb037b9b..4d5f8e43 100644 --- a/tests/Interpolation/restriction.cpp +++ b/tests/Interpolation/restriction.cpp @@ -8,47 +8,52 @@ using namespace gmgpolar; // Helper that computes the mathematically expected restriction value -static double expected_restriction_value(const PolarGrid& fine, - const PolarGrid& coarse, HostConstVector fine_vals, +static double expected_restriction_value(const PolarGrid& fine, + const PolarGrid& coarse, ConstVector fine_vals, int i_r_coarse, int i_theta_coarse) { int i_r = i_r_coarse * 2; int i_theta = i_theta_coarse * 2; - - // Angular indices with periodic wrapping - int i_theta_M2 = fine.wrapThetaIndex(i_theta - 2); - int i_theta_M1 = fine.wrapThetaIndex(i_theta - 1); - int i_theta_P1 = fine.wrapThetaIndex(i_theta + 1); - - // Angular spacings - double k1 = fine.angularSpacing(i_theta_M2); - double k2 = fine.angularSpacing(i_theta_M1); - double k3 = fine.angularSpacing(i_theta); - double k4 = fine.angularSpacing(i_theta_P1); - - // Center + Angular contributions (always present) - double value = fine_vals[fine.index(i_r, i_theta)] + k2 / (k1 + k2) * fine_vals[fine.index(i_r, i_theta_M1)] + - k3 / (k3 + k4) * fine_vals[fine.index(i_r, i_theta_P1)]; - - // Left contributions (if not at inner boundary) - if (i_r_coarse > 0) { - double h1 = fine.radialSpacing(i_r - 2); - double h2 = fine.radialSpacing(i_r - 1); - value += h2 / (h1 + h2) * fine_vals[fine.index(i_r - 1, i_theta)] + - h2 * k2 / ((h1 + h2) * (k1 + k2)) * fine_vals[fine.index(i_r - 1, i_theta_M1)] + - h2 * k3 / ((h1 + h2) * (k3 + k4)) * fine_vals[fine.index(i_r - 1, i_theta_P1)]; - } - - // Right contributions (if not at outer boundary) - if (i_r_coarse < coarse.nr() - 1) { - double h3 = fine.radialSpacing(i_r); - double h4 = fine.radialSpacing(i_r + 1); - value += h3 / (h3 + h4) * fine_vals[fine.index(i_r + 1, i_theta)] + - h3 * k2 / ((h3 + h4) * (k1 + k2)) * fine_vals[fine.index(i_r + 1, i_theta_M1)] + - h3 * k3 / ((h3 + h4) * (k3 + k4)) * fine_vals[fine.index(i_r + 1, i_theta_P1)]; - } - - return value; + HostVector result_h("host_res", 1); + Vector result_d("device_res", 1); + Kokkos::parallel_for( + "restriction_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + // Angular indices with periodic wrapping + int i_theta_M2 = fine.wrapThetaIndex(i_theta - 2); + int i_theta_M1 = fine.wrapThetaIndex(i_theta - 1); + int i_theta_P1 = fine.wrapThetaIndex(i_theta + 1); + + // Angular spacings + double k1 = fine.angularSpacing(i_theta_M2); + double k2 = fine.angularSpacing(i_theta_M1); + double k3 = fine.angularSpacing(i_theta); + double k4 = fine.angularSpacing(i_theta_P1); + + // Center + Angular contributions (always present) + result_d(0) = fine_vals[fine.index(i_r, i_theta)] + + k2 / (k1 + k2) * fine_vals[fine.index(i_r, i_theta_M1)] + + k3 / (k3 + k4) * fine_vals[fine.index(i_r, i_theta_P1)]; + + // Left contributions (if not at inner boundary) + if (i_r_coarse > 0) { + double h1 = fine.radialSpacing(i_r - 2); + double h2 = fine.radialSpacing(i_r - 1); + result_d(0) += h2 / (h1 + h2) * fine_vals[fine.index(i_r - 1, i_theta)] + + h2 * k2 / ((h1 + h2) * (k1 + k2)) * fine_vals[fine.index(i_r - 1, i_theta_M1)] + + h2 * k3 / ((h1 + h2) * (k3 + k4)) * fine_vals[fine.index(i_r - 1, i_theta_P1)]; + } + + // Right contributions (if not at outer boundary) + if (i_r_coarse < coarse.nr() - 1) { + double h3 = fine.radialSpacing(i_r); + double h4 = fine.radialSpacing(i_r + 1); + result_d(0) += h3 / (h3 + h4) * fine_vals[fine.index(i_r + 1, i_theta)] + + h3 * k2 / ((h3 + h4) * (k1 + k2)) * fine_vals[fine.index(i_r + 1, i_theta_M1)] + + h3 * k3 / ((h3 + h4) * (k3 + k4)) * fine_vals[fine.index(i_r + 1, i_theta_P1)]; + } + }); + Kokkos::deep_copy(result_h, result_d); + return result_h(0); } TEST(RestrictionTest, RestrictionMatchesStencil) @@ -67,16 +72,14 @@ TEST(RestrictionTest, RestrictionMatchesStencil) I.applyRestriction(fine_grid, coarse_grid, coarse_result, fine_values); - PolarGrid h_fine_grid(fine_grid); - PolarGrid h_coarse_grid(coarse_grid); auto h_fine_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, fine_values); auto h_coarse_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, coarse_result); for (int i_r_coarse = 0; i_r_coarse < coarse_grid.nr(); ++i_r_coarse) { for (int i_theta_coarse = 0; i_theta_coarse < coarse_grid.ntheta(); ++i_theta_coarse) { double expected = - expected_restriction_value(h_fine_grid, h_coarse_grid, h_fine_values, i_r_coarse, i_theta_coarse); - double got = h_coarse_result[h_coarse_grid.index(i_r_coarse, i_theta_coarse)]; + expected_restriction_value(fine_grid, coarse_grid, fine_values, i_r_coarse, i_theta_coarse); + double got = h_coarse_result[coarse_grid.index(i_r_coarse, i_theta_coarse)]; ASSERT_NEAR(expected, got, 1e-10) << "Mismatch at (" << i_r_coarse << ", " << i_theta_coarse << ")"; } } From 7c675a840169ac7bf58a5de9344b60698fd479a2 Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Wed, 17 Jun 2026 15:20:57 +0200 Subject: [PATCH 8/9] remove unused host allocated fine or coarse result in tests --- tests/Interpolation/extrapolated_prolongation.cpp | 2 -- tests/Interpolation/extrapolated_restriction.cpp | 2 -- tests/Interpolation/prolongation.cpp | 3 +-- tests/Interpolation/restriction.cpp | 1 - 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index c1de9c2a..c9f74b5b 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -64,8 +64,6 @@ TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) Vector coarse_values = generate_random_sample_data(coarse_grid, 1234, 0.0, 1.0); Vector fine_result("fine_result", fine_grid.numberOfNodes()); - auto h_coarse_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), coarse_values); - I.applyExtrapolatedProlongation(coarse_grid, fine_grid, fine_result, coarse_values); auto h_fine_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), fine_result); diff --git a/tests/Interpolation/extrapolated_restriction.cpp b/tests/Interpolation/extrapolated_restriction.cpp index cf210516..e09e65c4 100644 --- a/tests/Interpolation/extrapolated_restriction.cpp +++ b/tests/Interpolation/extrapolated_restriction.cpp @@ -58,8 +58,6 @@ TEST(ExtrapolatedRestrictionTest, ExtrapolatedRestrictionMatchesStencil) Vector fine_values = generate_random_sample_data(fine_grid, 9012, 0.0, 1.0); Vector coarse_result("coarse_result", coarse_grid.numberOfNodes()); - auto h_fine_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), fine_values); - I.applyExtrapolatedRestriction(fine_grid, coarse_grid, coarse_result, fine_values); auto h_coarse_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), coarse_result); diff --git a/tests/Interpolation/prolongation.cpp b/tests/Interpolation/prolongation.cpp index 78850688..5bbc03a4 100644 --- a/tests/Interpolation/prolongation.cpp +++ b/tests/Interpolation/prolongation.cpp @@ -79,8 +79,7 @@ TEST(ProlongationTest, ProlongationMatchesStencil) I.applyProlongation(coarse_grid, fine_grid, fine_result, coarse_values); - auto h_coarse_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, coarse_values); - auto h_fine_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, fine_result); + auto h_fine_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, fine_result); for (int i_r = 0; i_r < fine_grid.nr(); ++i_r) { for (int i_theta = 0; i_theta < fine_grid.ntheta(); ++i_theta) { diff --git a/tests/Interpolation/restriction.cpp b/tests/Interpolation/restriction.cpp index 4d5f8e43..38f9ea2e 100644 --- a/tests/Interpolation/restriction.cpp +++ b/tests/Interpolation/restriction.cpp @@ -72,7 +72,6 @@ TEST(RestrictionTest, RestrictionMatchesStencil) I.applyRestriction(fine_grid, coarse_grid, coarse_result, fine_values); - auto h_fine_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, fine_values); auto h_coarse_result = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, coarse_result); for (int i_r_coarse = 0; i_r_coarse < coarse_grid.nr(); ++i_r_coarse) { From 386a9e4f882265129671bfbb1d763fad8f022ab8 Mon Sep 17 00:00:00 2001 From: KARA Abdelhadi 265943 Date: Thu, 18 Jun 2026 10:33:11 +0200 Subject: [PATCH 9/9] use parallel_reduce and avoid multiple allocations --- .../extrapolated_prolongation.cpp | 30 +++++++------- .../extrapolated_restriction.cpp | 27 ++++++------- tests/Interpolation/prolongation.cpp | 39 ++++++++++--------- tests/Interpolation/restriction.cpp | 34 ++++++++-------- 4 files changed, 67 insertions(+), 63 deletions(-) diff --git a/tests/Interpolation/extrapolated_prolongation.cpp b/tests/Interpolation/extrapolated_prolongation.cpp index c9f74b5b..3f6fcb77 100644 --- a/tests/Interpolation/extrapolated_prolongation.cpp +++ b/tests/Interpolation/extrapolated_prolongation.cpp @@ -19,35 +19,35 @@ static double expected_extrapolated_value(const PolarGrid& c bool r_even = (i_r % 2 == 0); bool t_even = (i_theta % 2 == 0); - HostVector result_h("host_res", 1); - Vector result_d("device_res", 1); - - Kokkos::parallel_for( - "extrap_prolongation_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + double result = 0; + Kokkos::parallel_reduce( + "extrap_prolongation_test", Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int idx, double& local_result) { if (r_even && t_even) { // Node coincides with a coarse node - result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; + local_result = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; } else if (!r_even && t_even) { // Radial midpoint - arithmetic mean of left and right - result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]); + local_result = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]); } else if (r_even && !t_even) { // Angular midpoint - arithmetic mean of bottom and top - result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + local_result = 0.5 * (coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); } else { // Center of coarse cell - arithmetic mean of diagonal nodes (bottom-right + top-left) - result_d(0) = 0.5 * (coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + - coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); + local_result = 0.5 * (coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + + coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]); } - }); - Kokkos::deep_copy(result_h, result_d); - return result_h(0); + }, + result); + + return result; } TEST(ExtrapolatedProlongationTest, ExtrapolatedProlongationMatchesStencil) diff --git a/tests/Interpolation/extrapolated_restriction.cpp b/tests/Interpolation/extrapolated_restriction.cpp index e09e65c4..3677f8a7 100644 --- a/tests/Interpolation/extrapolated_restriction.cpp +++ b/tests/Interpolation/extrapolated_restriction.cpp @@ -16,32 +16,33 @@ static double expected_extrapolated_restriction_value(const PolarGrid result_h("host_res", 1); - Vector result_d("device_res", 1); - Kokkos::parallel_for( - "extrap_restriction_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + double result = 0; + Kokkos::parallel_reduce( + "extrap_restriction_test", Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(const int idx, double& local_result) { // Angular indices with periodic wrapping int i_theta_M1 = fine.wrapThetaIndex(i_theta - 1); int i_theta_P1 = fine.wrapThetaIndex(i_theta + 1); // Center + Angular contributions (always present) - result_d(0) = fine_vals[fine.index(i_r, i_theta)] + 0.5 * fine_vals[fine.index(i_r, i_theta_M1)] + - 0.5 * fine_vals[fine.index(i_r, i_theta_P1)]; + local_result = fine_vals[fine.index(i_r, i_theta)] + 0.5 * fine_vals[fine.index(i_r, i_theta_M1)] + + 0.5 * fine_vals[fine.index(i_r, i_theta_P1)]; // Left contributions (if not at inner boundary) if (i_r_coarse > 0) { - result_d(0) += 0.5 * fine_vals[fine.index(i_r - 1, i_theta)] + - 0.5 * fine_vals[fine.index(i_r - 1, i_theta_P1)]; // Top-Left diagonal + local_result += 0.5 * fine_vals[fine.index(i_r - 1, i_theta)] + + 0.5 * fine_vals[fine.index(i_r - 1, i_theta_P1)]; // Top-Left diagonal } // Right contributions (if not at outer boundary) if (i_r_coarse < coarse.nr() - 1) { - result_d(0) += 0.5 * fine_vals[fine.index(i_r + 1, i_theta)] + - 0.5 * fine_vals[fine.index(i_r + 1, i_theta_M1)]; // Bottom-Right diagonal + local_result += 0.5 * fine_vals[fine.index(i_r + 1, i_theta)] + + 0.5 * fine_vals[fine.index(i_r + 1, i_theta_M1)]; // Bottom-Right diagonal } - }); - Kokkos::deep_copy(result_h, result_d); - return result_h(0); + }, + result); + + return result; } TEST(ExtrapolatedRestrictionTest, ExtrapolatedRestrictionMatchesStencil) diff --git a/tests/Interpolation/prolongation.cpp b/tests/Interpolation/prolongation.cpp index 5bbc03a4..76f3d91e 100644 --- a/tests/Interpolation/prolongation.cpp +++ b/tests/Interpolation/prolongation.cpp @@ -16,14 +16,14 @@ static double expected_value(const PolarGrid& coarse, const bool r_even = (i_r % 2 == 0); bool t_even = (i_theta % 2 == 0); - HostVector result_h("host_res", 1); - Vector result_d("device_res", 1); - Kokkos::parallel_for( - "prolongation_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + double result = 0; + Kokkos::parallel_reduce( + "prolongation_test", Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int idx, double& local_result) { if (r_even && t_even) { // Node coincides with a coarse node - result_d(0) = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; + local_result = coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)]; } else if (!r_even && t_even) { @@ -31,9 +31,9 @@ static double expected_value(const PolarGrid& coarse, const double h1 = fine.radialSpacing(i_r - 1); double h2 = fine.radialSpacing(i_r); - result_d(0) = (h1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - h2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]) / - (h1 + h2); + local_result = (h1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + h2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)]) / + (h1 + h2); } else if (r_even && !t_even) { @@ -41,9 +41,9 @@ static double expected_value(const PolarGrid& coarse, const double k1 = fine.angularSpacing(i_theta - 1); double k2 = fine.angularSpacing(i_theta); - result_d(0) = (k1 * coarse_vals[coarse.index(i_r_coarse, t_even ? i_theta_coarse : i_theta_coarse)] + - k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]) / - (k1 + k2); + local_result = (k1 * coarse_vals[coarse.index(i_r_coarse, t_even ? i_theta_coarse : i_theta_coarse)] + + k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)]) / + (k1 + k2); } else { // Center of coarse cell @@ -52,15 +52,16 @@ static double expected_value(const PolarGrid& coarse, const double k1 = fine.angularSpacing(i_theta - 1); double k2 = fine.angularSpacing(i_theta); - result_d(0) = (h1 * k1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + - h2 * k1 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + - h1 * k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)] + - h2 * k2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse + 1)]) / - ((h1 + h2) * (k1 + k2)); + local_result = (h1 * k1 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse)] + + h2 * k1 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse)] + + h1 * k2 * coarse_vals[coarse.index(i_r_coarse, i_theta_coarse + 1)] + + h2 * k2 * coarse_vals[coarse.index(i_r_coarse + 1, i_theta_coarse + 1)]) / + ((h1 + h2) * (k1 + k2)); } - }); - Kokkos::deep_copy(result_h, result_d); - return result_h(0); + }, + result); + + return result; } TEST(ProlongationTest, ProlongationMatchesStencil) diff --git a/tests/Interpolation/restriction.cpp b/tests/Interpolation/restriction.cpp index 38f9ea2e..355dfa7e 100644 --- a/tests/Interpolation/restriction.cpp +++ b/tests/Interpolation/restriction.cpp @@ -14,10 +14,11 @@ static double expected_restriction_value(const PolarGrid& fi { int i_r = i_r_coarse * 2; int i_theta = i_theta_coarse * 2; - HostVector result_h("host_res", 1); - Vector result_d("device_res", 1); - Kokkos::parallel_for( - "restriction_test", Kokkos::RangePolicy(0, 1), KOKKOS_LAMBDA(int idx) { + + double result = 0; + Kokkos::parallel_reduce( + "restriction_test", Kokkos::RangePolicy(0, 1), + KOKKOS_LAMBDA(int idx, double& local_result) { // Angular indices with periodic wrapping int i_theta_M2 = fine.wrapThetaIndex(i_theta - 2); int i_theta_M1 = fine.wrapThetaIndex(i_theta - 1); @@ -30,30 +31,31 @@ static double expected_restriction_value(const PolarGrid& fi double k4 = fine.angularSpacing(i_theta_P1); // Center + Angular contributions (always present) - result_d(0) = fine_vals[fine.index(i_r, i_theta)] + - k2 / (k1 + k2) * fine_vals[fine.index(i_r, i_theta_M1)] + - k3 / (k3 + k4) * fine_vals[fine.index(i_r, i_theta_P1)]; + local_result = fine_vals[fine.index(i_r, i_theta)] + + k2 / (k1 + k2) * fine_vals[fine.index(i_r, i_theta_M1)] + + k3 / (k3 + k4) * fine_vals[fine.index(i_r, i_theta_P1)]; // Left contributions (if not at inner boundary) if (i_r_coarse > 0) { double h1 = fine.radialSpacing(i_r - 2); double h2 = fine.radialSpacing(i_r - 1); - result_d(0) += h2 / (h1 + h2) * fine_vals[fine.index(i_r - 1, i_theta)] + - h2 * k2 / ((h1 + h2) * (k1 + k2)) * fine_vals[fine.index(i_r - 1, i_theta_M1)] + - h2 * k3 / ((h1 + h2) * (k3 + k4)) * fine_vals[fine.index(i_r - 1, i_theta_P1)]; + local_result += h2 / (h1 + h2) * fine_vals[fine.index(i_r - 1, i_theta)] + + h2 * k2 / ((h1 + h2) * (k1 + k2)) * fine_vals[fine.index(i_r - 1, i_theta_M1)] + + h2 * k3 / ((h1 + h2) * (k3 + k4)) * fine_vals[fine.index(i_r - 1, i_theta_P1)]; } // Right contributions (if not at outer boundary) if (i_r_coarse < coarse.nr() - 1) { double h3 = fine.radialSpacing(i_r); double h4 = fine.radialSpacing(i_r + 1); - result_d(0) += h3 / (h3 + h4) * fine_vals[fine.index(i_r + 1, i_theta)] + - h3 * k2 / ((h3 + h4) * (k1 + k2)) * fine_vals[fine.index(i_r + 1, i_theta_M1)] + - h3 * k3 / ((h3 + h4) * (k3 + k4)) * fine_vals[fine.index(i_r + 1, i_theta_P1)]; + local_result += h3 / (h3 + h4) * fine_vals[fine.index(i_r + 1, i_theta)] + + h3 * k2 / ((h3 + h4) * (k1 + k2)) * fine_vals[fine.index(i_r + 1, i_theta_M1)] + + h3 * k3 / ((h3 + h4) * (k3 + k4)) * fine_vals[fine.index(i_r + 1, i_theta_P1)]; } - }); - Kokkos::deep_copy(result_h, result_d); - return result_h(0); + }, + result); + + return result; } TEST(RestrictionTest, RestrictionMatchesStencil)