From 4342fb8960774f6fc2e248852391f19842f26ad4 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Thu, 12 Dec 2024 12:14:35 +0100 Subject: [PATCH 01/23] Adding of the math_tools/ folder and renaming od utils/math_tools.hpp into math_tools/Lnorm_tools.hpp --- .../geometryRTheta/diocotron/diocotron.cpp | 2 +- .../vortex_merger/vortex_merger.cpp | 2 +- .../guiding_center/guiding_center.cpp | 2 +- src/CMakeLists.txt | 17 +++++++++-------- src/geometryRTheta/advection/CMakeLists.txt | 1 + .../advection/advection_domain.hpp | 2 +- .../vortex_merger_equilibrium.hpp | 2 +- src/geometryRTheta/time_solver/bsl_predcorr.hpp | 2 +- .../time_integration/predcorr_RK2.hpp | 2 +- src/math_tools/CMakeLists.txt | 16 ++++++++++++++++ .../Lnorm_tools.hpp} | 0 src/multipatch/utils/multipatch_math_tools.hpp | 2 +- src/timestepper/CMakeLists.txt | 3 +-- src/timestepper/crank_nicolson.hpp | 2 +- .../advection_simulation_utils.hpp | 2 +- .../advection_field_gtest.cpp | 2 +- tests/geometryRTheta/quadrature/CMakeLists.txt | 1 + .../quadrature/tests_L1_and_L2_norms.cpp | 2 +- tests/timestepper/CMakeLists.txt | 1 + tests/timestepper/crank_nicolson_2d_mixed.cpp | 2 +- tests/timestepper/euler_2d_mixed.cpp | 2 +- tests/utils/CMakeLists.txt | 1 + tests/utils/test_math_tools.cpp | 2 +- 23 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 src/math_tools/CMakeLists.txt rename src/{utils/math_tools.hpp => math_tools/Lnorm_tools.hpp} (100%) diff --git a/simulations/geometryRTheta/diocotron/diocotron.cpp b/simulations/geometryRTheta/diocotron/diocotron.cpp index ae2d05523..f1b11f7c9 100644 --- a/simulations/geometryRTheta/diocotron/diocotron.cpp +++ b/simulations/geometryRTheta/diocotron/diocotron.cpp @@ -25,7 +25,7 @@ #include "euler.hpp" #include "geometry.hpp" #include "input.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "output.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" diff --git a/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp b/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp index aa852420e..8d673b2d5 100644 --- a/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp +++ b/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp @@ -25,7 +25,7 @@ #include "euler.hpp" #include "geometry.hpp" #include "input.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" #include "pdi_out.yml.hpp" diff --git a/simulations/geometryXY/guiding_center/guiding_center.cpp b/simulations/geometryXY/guiding_center/guiding_center.cpp index 12a6ef0a2..c61166fbe 100644 --- a/simulations/geometryXY/guiding_center/guiding_center.cpp +++ b/simulations/geometryXY/guiding_center/guiding_center.cpp @@ -18,7 +18,7 @@ #include "geometry.hpp" #include "initialization_Kelvin_Helmholtz.hpp" #include "input.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "output.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 031aaee03..37162b20f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,9 @@ # SPDX-License-Identifier: MIT +add_subdirectory(advection) +add_subdirectory(collisions) add_subdirectory(data_types) -add_subdirectory(utils) -add_subdirectory(speciesinfo) add_subdirectory(io) -add_subdirectory(paraconfpp) -add_subdirectory(quadrature) add_subdirectory(geometryXVx) add_subdirectory(geometryXY) add_subdirectory(geometryRTheta) @@ -13,9 +11,12 @@ add_subdirectory(geometryXYVxVy) add_subdirectory(geometryVparMu) add_subdirectory(interpolation) add_subdirectory(mapping) -add_subdirectory(multipatch) -add_subdirectory(advection) -add_subdirectory(timestepper) -add_subdirectory(collisions) +add_subdirectory(math_tools) add_subdirectory(mpi_parallelisation) +add_subdirectory(multipatch) +add_subdirectory(paraconfpp) add_subdirectory(pde_solvers) +add_subdirectory(quadrature) +add_subdirectory(speciesinfo) +add_subdirectory(timestepper) +add_subdirectory(utils) diff --git a/src/geometryRTheta/advection/CMakeLists.txt b/src/geometryRTheta/advection/CMakeLists.txt index 87a42efea..0f948a573 100644 --- a/src/geometryRTheta/advection/CMakeLists.txt +++ b/src/geometryRTheta/advection/CMakeLists.txt @@ -14,6 +14,7 @@ target_link_libraries(advection_rp gslx::geometry_RTheta gslx::interpolation_2D_rp gslx::mapping + gslx::math_tools gslx::utils ) add_library(gslx::advection_rp ALIAS advection_rp) diff --git a/src/geometryRTheta/advection/advection_domain.hpp b/src/geometryRTheta/advection/advection_domain.hpp index be629c055..1deee6341 100644 --- a/src/geometryRTheta/advection/advection_domain.hpp +++ b/src/geometryRTheta/advection/advection_domain.hpp @@ -13,7 +13,7 @@ #include "directional_tag.hpp" #include "geometry.hpp" #include "geometry_pseudo_cartesian.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp b/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp index a7c8741f8..02f35f2cd 100644 --- a/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp +++ b/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp @@ -7,7 +7,7 @@ #include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "geometry.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "poisson_like_rhs_function.hpp" #include "polarpoissonlikesolver.hpp" diff --git a/src/geometryRTheta/time_solver/bsl_predcorr.hpp b/src/geometryRTheta/time_solver/bsl_predcorr.hpp index f36e6d467..067ab938e 100644 --- a/src/geometryRTheta/time_solver/bsl_predcorr.hpp +++ b/src/geometryRTheta/time_solver/bsl_predcorr.hpp @@ -16,7 +16,7 @@ #include "geometry.hpp" #include "ifoot_finder.hpp" #include "itimesolver.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "poisson_like_rhs_function.hpp" #include "polarpoissonlikesolver.hpp" #include "rk2.hpp" diff --git a/src/geometryXY/time_integration/predcorr_RK2.hpp b/src/geometryXY/time_integration/predcorr_RK2.hpp index 369eef436..fe42f9e4c 100644 --- a/src/geometryXY/time_integration/predcorr_RK2.hpp +++ b/src/geometryXY/time_integration/predcorr_RK2.hpp @@ -13,7 +13,7 @@ #include "ddc_aliases.hpp" #include "directional_tag.hpp" #include "geometry.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "paraconfpp.hpp" #include "rk2.hpp" #include "vector_field.hpp" diff --git a/src/math_tools/CMakeLists.txt b/src/math_tools/CMakeLists.txt new file mode 100644 index 000000000..c6f68cddf --- /dev/null +++ b/src/math_tools/CMakeLists.txt @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT + +add_library("math_tools" INTERFACE) + +target_include_directories("math_tools" + INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}" +) + +target_link_libraries("math_tools" + INTERFACE + DDC::DDC + gslx::data_types +) + +add_library("gslx::math_tools" ALIAS "math_tools") + diff --git a/src/utils/math_tools.hpp b/src/math_tools/Lnorm_tools.hpp similarity index 100% rename from src/utils/math_tools.hpp rename to src/math_tools/Lnorm_tools.hpp diff --git a/src/multipatch/utils/multipatch_math_tools.hpp b/src/multipatch/utils/multipatch_math_tools.hpp index 513a945a9..7163db6ed 100644 --- a/src/multipatch/utils/multipatch_math_tools.hpp +++ b/src/multipatch/utils/multipatch_math_tools.hpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT #pragma once -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "multipatch_field.hpp" /** diff --git a/src/timestepper/CMakeLists.txt b/src/timestepper/CMakeLists.txt index a31078db6..4784f3a55 100644 --- a/src/timestepper/CMakeLists.txt +++ b/src/timestepper/CMakeLists.txt @@ -1,6 +1,4 @@ - - add_library(timestepper INTERFACE) target_include_directories(timestepper INTERFACE @@ -9,6 +7,7 @@ target_include_directories(timestepper target_link_libraries(timestepper INTERFACE DDC::DDC gslx::data_types + gslx::math_tools gslx::multipatch_data_types gslx::multipatch_utils gslx::utils diff --git a/src/timestepper/crank_nicolson.hpp b/src/timestepper/crank_nicolson.hpp index 3eb3e11ca..bfc56c598 100644 --- a/src/timestepper/crank_nicolson.hpp +++ b/src/timestepper/crank_nicolson.hpp @@ -5,7 +5,7 @@ #include "ddc_aliases.hpp" #include "ddc_helper.hpp" #include "itimestepper.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "multipatch_math_tools.hpp" #include "vector_field_common.hpp" diff --git a/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp index 524c7cfdc..be0cddadc 100644 --- a/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp +++ b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp @@ -16,7 +16,7 @@ #include "bsl_advection_rp.hpp" #include "directional_tag.hpp" #include "geometry.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" #include "quadrature.hpp" diff --git a/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp b/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp index dd757785a..d2030ef64 100644 --- a/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp +++ b/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp @@ -28,7 +28,7 @@ #include "crank_nicolson.hpp" #include "euler.hpp" #include "geometry.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "mesh_builder.hpp" #include "quadrature.hpp" #include "rk3.hpp" diff --git a/tests/geometryRTheta/quadrature/CMakeLists.txt b/tests/geometryRTheta/quadrature/CMakeLists.txt index 5130ec12a..99a5fd039 100644 --- a/tests/geometryRTheta/quadrature/CMakeLists.txt +++ b/tests/geometryRTheta/quadrature/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries(Li_norms_spline_quadrature_tests sll::SLL gslx::geometry_RTheta gslx::quadrature + gslx::math_tools gslx::utils ) diff --git a/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp b/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp index a950756af..85dbb061d 100644 --- a/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp +++ b/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp @@ -9,7 +9,7 @@ #include #include "geometry.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "mesh_builder.hpp" #include "quadrature.hpp" #include "spline_quadrature.hpp" diff --git a/tests/timestepper/CMakeLists.txt b/tests/timestepper/CMakeLists.txt index 76fefdb93..e83a99d71 100644 --- a/tests/timestepper/CMakeLists.txt +++ b/tests/timestepper/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries(unit_tests_timestepper GTest::gtest GTest::gmock paraconf::paraconf + gslx::math_tools gslx::multipatch_data_types gslx::multipatch_geometries gslx::timestepper diff --git a/tests/timestepper/crank_nicolson_2d_mixed.cpp b/tests/timestepper/crank_nicolson_2d_mixed.cpp index c60b37234..6ef113963 100644 --- a/tests/timestepper/crank_nicolson_2d_mixed.cpp +++ b/tests/timestepper/crank_nicolson_2d_mixed.cpp @@ -10,7 +10,7 @@ #include "crank_nicolson.hpp" #include "directional_tag.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/tests/timestepper/euler_2d_mixed.cpp b/tests/timestepper/euler_2d_mixed.cpp index c4e28c598..1a4497e30 100644 --- a/tests/timestepper/euler_2d_mixed.cpp +++ b/tests/timestepper/euler_2d_mixed.cpp @@ -11,7 +11,7 @@ #include "crank_nicolson.hpp" #include "directional_tag.hpp" #include "euler.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt index ac37d71a6..3146b2d68 100644 --- a/tests/utils/CMakeLists.txt +++ b/tests/utils/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(unit_tests_utils GTest::gtest GTest::gmock paraconf::paraconf + gslx::math_tools gslx::utils ) diff --git a/tests/utils/test_math_tools.cpp b/tests/utils/test_math_tools.cpp index 6395b81a1..a99eb3827 100644 --- a/tests/utils/test_math_tools.cpp +++ b/tests/utils/test_math_tools.cpp @@ -6,7 +6,7 @@ #include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "ddc_helper.hpp" -#include "math_tools.hpp" +#include "Lnorm_tools.hpp" namespace { From 9e3387e0d0cf8d00a89fb7713e3d8bf18094ab6f Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Thu, 12 Dec 2024 12:31:14 +0100 Subject: [PATCH 02/23] Modification of the title comment. --- src/math_tools/Lnorm_tools.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math_tools/Lnorm_tools.hpp b/src/math_tools/Lnorm_tools.hpp index dde1f6c2d..0b0a1a5f4 100644 --- a/src/math_tools/Lnorm_tools.hpp +++ b/src/math_tools/Lnorm_tools.hpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT /** - * @file math_tools.hpp - * File Describing useful mathematical functions. + * @file Lnorm_tools.hpp + * File Describing useful mathematical functions to compute Lnorms */ #pragma once From cf02192c95b655af4af4d994daf565ef0837e557 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Thu, 12 Dec 2024 15:03:41 +0100 Subject: [PATCH 03/23] Rename file Lnorm_tools.hpp -> l_norm_tools.hpp --- simulations/geometryRTheta/diocotron/diocotron.cpp | 2 +- simulations/geometryRTheta/vortex_merger/vortex_merger.cpp | 2 +- simulations/geometryXY/guiding_center/guiding_center.cpp | 2 +- src/geometryRTheta/advection/advection_domain.hpp | 2 +- src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp | 2 +- src/geometryRTheta/time_solver/bsl_predcorr.hpp | 2 +- src/geometryXY/time_integration/predcorr_RK2.hpp | 2 +- src/math_tools/{Lnorm_tools.hpp => l_norm_tools.hpp} | 2 +- src/multipatch/utils/multipatch_math_tools.hpp | 2 +- src/timestepper/crank_nicolson.hpp | 2 +- .../advection_2d_rp/advection_simulation_utils.hpp | 2 +- .../geometryRTheta/advection_field_rp/advection_field_gtest.cpp | 2 +- tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp | 2 +- tests/timestepper/crank_nicolson_2d_mixed.cpp | 2 +- tests/timestepper/euler_2d_mixed.cpp | 2 +- tests/utils/test_math_tools.cpp | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) rename src/math_tools/{Lnorm_tools.hpp => l_norm_tools.hpp} (99%) diff --git a/simulations/geometryRTheta/diocotron/diocotron.cpp b/simulations/geometryRTheta/diocotron/diocotron.cpp index f1b11f7c9..4df7d88bd 100644 --- a/simulations/geometryRTheta/diocotron/diocotron.cpp +++ b/simulations/geometryRTheta/diocotron/diocotron.cpp @@ -25,7 +25,7 @@ #include "euler.hpp" #include "geometry.hpp" #include "input.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "output.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" diff --git a/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp b/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp index 8d673b2d5..98b496567 100644 --- a/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp +++ b/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp @@ -25,7 +25,7 @@ #include "euler.hpp" #include "geometry.hpp" #include "input.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" #include "pdi_out.yml.hpp" diff --git a/simulations/geometryXY/guiding_center/guiding_center.cpp b/simulations/geometryXY/guiding_center/guiding_center.cpp index c61166fbe..c52f9e126 100644 --- a/simulations/geometryXY/guiding_center/guiding_center.cpp +++ b/simulations/geometryXY/guiding_center/guiding_center.cpp @@ -18,7 +18,7 @@ #include "geometry.hpp" #include "initialization_Kelvin_Helmholtz.hpp" #include "input.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "output.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" diff --git a/src/geometryRTheta/advection/advection_domain.hpp b/src/geometryRTheta/advection/advection_domain.hpp index 1deee6341..dbf82c9ff 100644 --- a/src/geometryRTheta/advection/advection_domain.hpp +++ b/src/geometryRTheta/advection/advection_domain.hpp @@ -13,7 +13,7 @@ #include "directional_tag.hpp" #include "geometry.hpp" #include "geometry_pseudo_cartesian.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp b/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp index 02f35f2cd..33f3aeb7f 100644 --- a/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp +++ b/src/geometryRTheta/initialization/vortex_merger_equilibrium.hpp @@ -7,7 +7,7 @@ #include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "geometry.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "poisson_like_rhs_function.hpp" #include "polarpoissonlikesolver.hpp" diff --git a/src/geometryRTheta/time_solver/bsl_predcorr.hpp b/src/geometryRTheta/time_solver/bsl_predcorr.hpp index 067ab938e..cd8ddc505 100644 --- a/src/geometryRTheta/time_solver/bsl_predcorr.hpp +++ b/src/geometryRTheta/time_solver/bsl_predcorr.hpp @@ -16,7 +16,7 @@ #include "geometry.hpp" #include "ifoot_finder.hpp" #include "itimesolver.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "poisson_like_rhs_function.hpp" #include "polarpoissonlikesolver.hpp" #include "rk2.hpp" diff --git a/src/geometryXY/time_integration/predcorr_RK2.hpp b/src/geometryXY/time_integration/predcorr_RK2.hpp index fe42f9e4c..9732f2595 100644 --- a/src/geometryXY/time_integration/predcorr_RK2.hpp +++ b/src/geometryXY/time_integration/predcorr_RK2.hpp @@ -13,7 +13,7 @@ #include "ddc_aliases.hpp" #include "directional_tag.hpp" #include "geometry.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "paraconfpp.hpp" #include "rk2.hpp" #include "vector_field.hpp" diff --git a/src/math_tools/Lnorm_tools.hpp b/src/math_tools/l_norm_tools.hpp similarity index 99% rename from src/math_tools/Lnorm_tools.hpp rename to src/math_tools/l_norm_tools.hpp index 0b0a1a5f4..fb33d0c78 100644 --- a/src/math_tools/Lnorm_tools.hpp +++ b/src/math_tools/l_norm_tools.hpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT /** - * @file Lnorm_tools.hpp + * @file l_norm_tools.hpp * File Describing useful mathematical functions to compute Lnorms */ diff --git a/src/multipatch/utils/multipatch_math_tools.hpp b/src/multipatch/utils/multipatch_math_tools.hpp index 7163db6ed..10e6ace8e 100644 --- a/src/multipatch/utils/multipatch_math_tools.hpp +++ b/src/multipatch/utils/multipatch_math_tools.hpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT #pragma once -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "multipatch_field.hpp" /** diff --git a/src/timestepper/crank_nicolson.hpp b/src/timestepper/crank_nicolson.hpp index bfc56c598..35b210e0e 100644 --- a/src/timestepper/crank_nicolson.hpp +++ b/src/timestepper/crank_nicolson.hpp @@ -5,7 +5,7 @@ #include "ddc_aliases.hpp" #include "ddc_helper.hpp" #include "itimestepper.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "multipatch_math_tools.hpp" #include "vector_field_common.hpp" diff --git a/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp index be0cddadc..a12f037a5 100644 --- a/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp +++ b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp @@ -16,7 +16,7 @@ #include "bsl_advection_rp.hpp" #include "directional_tag.hpp" #include "geometry.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "paraconfpp.hpp" #include "params.yaml.hpp" #include "quadrature.hpp" diff --git a/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp b/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp index d2030ef64..87a90bdd6 100644 --- a/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp +++ b/tests/geometryRTheta/advection_field_rp/advection_field_gtest.cpp @@ -28,7 +28,7 @@ #include "crank_nicolson.hpp" #include "euler.hpp" #include "geometry.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "mesh_builder.hpp" #include "quadrature.hpp" #include "rk3.hpp" diff --git a/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp b/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp index 85dbb061d..bc16afac5 100644 --- a/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp +++ b/tests/geometryRTheta/quadrature/tests_L1_and_L2_norms.cpp @@ -9,7 +9,7 @@ #include #include "geometry.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "mesh_builder.hpp" #include "quadrature.hpp" #include "spline_quadrature.hpp" diff --git a/tests/timestepper/crank_nicolson_2d_mixed.cpp b/tests/timestepper/crank_nicolson_2d_mixed.cpp index 6ef113963..902db456e 100644 --- a/tests/timestepper/crank_nicolson_2d_mixed.cpp +++ b/tests/timestepper/crank_nicolson_2d_mixed.cpp @@ -10,7 +10,7 @@ #include "crank_nicolson.hpp" #include "directional_tag.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/tests/timestepper/euler_2d_mixed.cpp b/tests/timestepper/euler_2d_mixed.cpp index 1a4497e30..582e40e99 100644 --- a/tests/timestepper/euler_2d_mixed.cpp +++ b/tests/timestepper/euler_2d_mixed.cpp @@ -11,7 +11,7 @@ #include "crank_nicolson.hpp" #include "directional_tag.hpp" #include "euler.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/tests/utils/test_math_tools.cpp b/tests/utils/test_math_tools.cpp index a99eb3827..c083bd224 100644 --- a/tests/utils/test_math_tools.cpp +++ b/tests/utils/test_math_tools.cpp @@ -6,7 +6,7 @@ #include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "ddc_helper.hpp" -#include "Lnorm_tools.hpp" +#include "l_norm_tools.hpp" namespace { From 0727d786f12a23ad29accd8e6851690cfdce3fd1 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Thu, 12 Dec 2024 15:31:58 +0100 Subject: [PATCH 04/23] Remove dead link --- src/multipatch/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/multipatch/README.md b/src/multipatch/README.md index c1f2cfff4..2fd8fdebc 100644 --- a/src/multipatch/README.md +++ b/src/multipatch/README.md @@ -6,8 +6,6 @@ The `multipatch` folder contains all the code describing methods and classes whi - [data\_types](./data_types/README.md) - Defines classes to handle objects on a multipatch domain more conveniently. -- [interface\_derivatives](./interface_derivatives/README.md) - Ongoing work only available on GitLab. - - [spline](./spline/README.md) - Defines structures and methods to deal with different splines on every patches. - [utils](./utils/README.md) - Defines utility functions to operate over multiple patches. From 8a5c51ba8102180c20ba01d4e222601020ab2a0b Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Thu, 12 Dec 2024 16:05:53 +0100 Subject: [PATCH 05/23] Rename tests/utils/test_math_tools.cpp into tests/math_tools/test_lnorm_tools.cpp. --- tests/CMakeLists.txt | 1 + tests/math_tools/CMakeLists.txt | 20 +++++++++++++++++++ .../test_lnorm_tools.cpp} | 0 tests/utils/CMakeLists.txt | 2 -- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/math_tools/CMakeLists.txt rename tests/{utils/test_math_tools.cpp => math_tools/test_lnorm_tools.cpp} (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8006490d8..243039b91 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,6 +22,7 @@ add_subdirectory(geometryRTheta) add_subdirectory(geometryVparMu) add_subdirectory(multipatch) add_subdirectory(mpi_parallelisation) +add_subdirectory(math_tools) add_subdirectory(pde_solvers) add_subdirectory(quadrature) add_subdirectory(timestepper) diff --git a/tests/math_tools/CMakeLists.txt b/tests/math_tools/CMakeLists.txt new file mode 100644 index 000000000..64a3aaa57 --- /dev/null +++ b/tests/math_tools/CMakeLists.txt @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT + + +include(GoogleTest) + +add_executable(unit_tests_math_tools + test_lnorm_tools.cpp + ../main.cpp +) +target_link_libraries(unit_tests_math_tools + PUBLIC + DDC::pdi + GTest::gtest + GTest::gmock + paraconf::paraconf + gslx::math_tools + gslx::utils +) + +gtest_discover_tests(unit_tests_math_tools DISCOVERY_MODE PRE_TEST) diff --git a/tests/utils/test_math_tools.cpp b/tests/math_tools/test_lnorm_tools.cpp similarity index 100% rename from tests/utils/test_math_tools.cpp rename to tests/math_tools/test_lnorm_tools.cpp diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt index 8dea41d6d..6fec4492e 100644 --- a/tests/utils/CMakeLists.txt +++ b/tests/utils/CMakeLists.txt @@ -5,7 +5,6 @@ include(GoogleTest) add_executable(unit_tests_utils test_ddcHelpers.cpp - test_math_tools.cpp transpose.cpp ../main.cpp ) @@ -15,7 +14,6 @@ target_link_libraries(unit_tests_utils GTest::gtest GTest::gmock paraconf::paraconf - gslx::math_tools gslx::utils ) From 8b5b68b0bf99b90fd48ac8fa623aa757a7d19eef Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Thu, 12 Dec 2024 16:17:52 +0100 Subject: [PATCH 06/23] Add missing README.md. --- src/README.md | 1 + src/math_tools/README.md | 9 +++++++++ src/utils/README.md | 6 ------ tests/README.md | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 src/math_tools/README.md diff --git a/src/README.md b/src/README.md index e5754394e..f7bb2dcf3 100644 --- a/src/README.md +++ b/src/README.md @@ -13,6 +13,7 @@ The `src/` folder contains all the code necessary to build a gyrokinetic semi-La - [interpolation](./interpolation/README.md) - Code describing interpolation methods. - [io](./io/README.md) - Code describing tools for inputting and outputting data in a simulation. - [mapping](./mapping/README.md) - Code describing tools for handling different coordinate systems. +- [math_tools](./math_tools/README.md) - Code describing math tools functions. - [multipatch](./multipatch/README.md) - Code describing multipatch geometry. - [mpi\_parallelisation](./mpi_parallelisation/README.md) - Code describing the MPI parallelisation. diff --git a/src/math_tools/README.md b/src/math_tools/README.md new file mode 100644 index 000000000..2d012cf67 --- /dev/null +++ b/src/math_tools/README.md @@ -0,0 +1,9 @@ +# Utility Functions + +This folder contains mathematical classes and functions. + +## Utility tools + +The l\_norm\_tools.hpp file contains functions computing the infinity norm. For now, it computes the infinity norm of +- a double: $`\Vert x \Vert_{\infty} = x`$; +- a coordinate: $`\Vert x \Vert_{\infty} = \max_{i} (|x_i|)`$. diff --git a/src/utils/README.md b/src/utils/README.md index af7c7d14f..31b8ccd8c 100644 --- a/src/utils/README.md +++ b/src/utils/README.md @@ -5,9 +5,3 @@ This folder contains classes and functions which facilitate the writing of the r The class ddcHelper exists to provide functionalities which are currently missing from DDC. The class NDTag exists to provide a way to group directional tags together. This is notably useful in order to create a vector field. - -## Utility tools - -The utils\_tools.hpp file contains functions computing the infinity norm. For now, it computes the infinity norm of -- a double: $`\Vert x \Vert_{\infty} = x`$; -- a coordinate: $`\Vert x \Vert_{\infty} = \max_{i} (|x_i|)`$. diff --git a/tests/README.md b/tests/README.md index 85fd344a6..49524c429 100644 --- a/tests/README.md +++ b/tests/README.md @@ -10,6 +10,7 @@ It is broken up into the following sub-folders: - geometryVparMu - Tests in the vpar-mu geometry. - geometryXVx - Tests in the x-vx geometry. - geometryXYVxVy - Tests in the x,y-vx,vy geometry. + - math_tools - Test for mathematical functions. - MPI parallelism - Tests for the templated MPI operators. - [multipatch](./multipatch/README.md) - Tests for the classes that work over multipatch geometries. - PDE solvers - Tests for the templated Partial Differential Equation solvers. From 9be65737025c197f5607b7f3af1848b4a6fcc7a3 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Thu, 12 Dec 2024 23:51:55 +0100 Subject: [PATCH 07/23] [GEOM TOKAMAXI] Add partial_derivatives.hpp. --- src/math_tools/partial_derivatives.hpp | 71 ++++++++++ tests/math_tools/CMakeLists.txt | 1 + tests/math_tools/test_partial_derivatives.cpp | 121 ++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 src/math_tools/partial_derivatives.hpp create mode 100644 tests/math_tools/test_partial_derivatives.cpp diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp new file mode 100644 index 000000000..159cc5658 --- /dev/null +++ b/src/math_tools/partial_derivatives.hpp @@ -0,0 +1,71 @@ + +// SPDX-License-Identifier: MIT +/** + * @file partial_derivatives.hpp + * File containing functions to compute the partial derivatives + */ + +#pragma once + +#include + +#include "ddc_alias_inline_functions.hpp" +#include "ddc_aliases.hpp" + + +/** + * @brief Compute the partial derivative of a + * + * For a given field @f$F(X1,X2)@f$ , compute + * @f$\partial_{Xi} F(X1,X2)@f$ with i=1 or 2. + * + * @param[in] Xi + * The given coordinate for the partial derivative. + * + * @return @f$\partial_{Xi} F(X1,X2)@f$ + */ + +template < + class GridXi, + class GridX1, + class GridX2, + class FieldX1Builder, + class FieldX1Evaluator> +class PartialDerivative +{ +private: + using IdxRangeX1X2 = IdxRange; + using IdxX1X2 = typename IdxRangeX1X2::discrete_element_type; + using DFieldX1X2 = DField; + using DConstFieldX1X2 = DConstField; + + // Type for spline representation of the field + using IdxRangeBSFieldX1 = typename FieldX1Builder::batched_spline_domain_type; + using FieldX1SplineMem = DFieldMem; + using FieldX1SplineCoeffs = DField; + + FieldX1Builder const& m_fieldx1_builder; + FieldX1Evaluator const& m_fieldx1_evaluator; + +public: + explicit PartialDerivative( + FieldX1Builder const& fieldx1_builder, + FieldX1Evaluator const& fieldx1_evaluator) + : m_fieldx1_builder(fieldx1_builder) + , m_fieldx1_evaluator(fieldx1_evaluator) + { + } + + ~PartialDerivative() = default; + + DFieldX1X2 operator()(DFieldX1X2 dfield_dx1_x1x2, DConstFieldX1X2 field_x1x2) + { + // Build spline representation of the field .................................... + FieldX1SplineMem fieldx1_coefs_alloc( + m_fieldx1_builder.batched_spline_domain()); + FieldX1SplineCoeffs fieldx1_coefs = get_field(fieldx1_coefs_alloc); + + m_fieldx1_builder(fieldx1_coefs, get_const_field(field_x1x2)); + m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, fieldx1_coefs); + } +}; \ No newline at end of file diff --git a/tests/math_tools/CMakeLists.txt b/tests/math_tools/CMakeLists.txt index 64a3aaa57..1fbedcfb0 100644 --- a/tests/math_tools/CMakeLists.txt +++ b/tests/math_tools/CMakeLists.txt @@ -5,6 +5,7 @@ include(GoogleTest) add_executable(unit_tests_math_tools test_lnorm_tools.cpp + test_partial_derivatives.cpp ../main.cpp ) target_link_libraries(unit_tests_math_tools diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp new file mode 100644 index 000000000..36fecac22 --- /dev/null +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: MIT +#include + +#include + +//VG//#include "ddc_alias_inline_functions.hpp" +#include "ddc_aliases.hpp" +//VG//#include "ddc_helper.hpp" +#include "partial_derivatives.hpp" + +namespace { + +struct X +{ + static bool constexpr PERIODIC = false; +}; +using CoordX = Coord; +struct BSplinesX : ddc::UniformBSplines +{ +}; +auto constexpr SplineXBoundary = ddc::BoundCond::GREVILLE; +using SplineInterpPointsX + = ddc::GrevilleInterpolationPoints; + +struct GridX : SplineInterpPointsX::interpolation_discrete_dimension_type +{ +}; +using IdxX = Idx; +using IdxStepX = IdxStep; +using IdxRangeX = IdxRange; + +struct Y +{ + static bool constexpr PERIODIC = false; +}; +using CoordY = Coord; +struct BSplinesY : ddc::UniformBSplines +{ +}; +auto constexpr SplineYBoundary = ddc::BoundCond::GREVILLE; +using SplineInterpPointsY + = ddc::GrevilleInterpolationPoints; +struct GridY : SplineInterpPointsY::interpolation_discrete_dimension_type +{ +}; +using IdxY = Idx; +using IdxStepY = IdxStep; +using IdxRangeY = IdxRange; + +using IdxXY = Idx; +using IdxRangeXY = IdxRange; +using DFieldMemXY = DFieldMem; +using DFieldXY = DField; +using DConstFieldXY = DConstField; + +// --- Operators --- +using SplineXBuilder = ddc::SplineBuilder< + Kokkos::DefaultExecutionSpace, + Kokkos::DefaultExecutionSpace::memory_space, + BSplinesX, + GridX, + SplineXBoundary, + SplineXBoundary, + ddc::SplineSolver::LAPACK, + GridX>; +using SplineXEvaluator = ddc::SplineEvaluator< + Kokkos::DefaultExecutionSpace, + Kokkos::DefaultExecutionSpace::memory_space, + BSplinesX, + GridX, + ddc::ConstantExtrapolationRule, + ddc::ConstantExtrapolationRule, + GridX, + GridY>; + +TEST(PartialDerivative, PartialDerivativeDx) +{ + int n_elems_x(10); + int n_elems_y(20); + + Coord const x_min(0.0); + Coord const x_max(1.0); + IdxStepX x_ncells(n_elems_x); + + Coord const y_min(0.0); + Coord const y_max(2.0); + IdxStepY y_ncells(n_elems_y); + + ddc::init_discrete_space(x_min, x_max, x_ncells); + ddc::init_discrete_space(SplineInterpPointsX::get_sampling()); + IdxRangeX idxrange_x(SplineInterpPointsX::get_domain()); + + ddc::init_discrete_space(y_min, y_max, y_ncells); + ddc::init_discrete_space(SplineInterpPointsY::get_sampling()); + IdxRangeY idxrange_y(SplineInterpPointsY::get_domain()); + + SplineXBuilder const builder_x(idxrange_x); + ddc::ConstantExtrapolationRule bv_x_min(x_min); + ddc::ConstantExtrapolationRule bv_x_max(x_max); + SplineXEvaluator const spline_evaluator_x(bv_x_min, bv_x_max); + + IdxRangeXY idxrange_xy(idxrange_x, idxrange_y); + DFieldMemXY field_xy_alloc(idxrange_xy); + DFieldXY field_xy = get_field(field_xy_alloc); + + ddc::parallel_for_each( + Kokkos::DefaultExecutionSpace(), + idxrange_xy, + KOKKOS_LAMBDA(IdxXY const idx_xy) { + IdxX idx_x(idx_xy); + IdxY idx_y(idx_xy); + field_xy(idx_xy) = ddc::coordinate(idx_x)*ddc::coordinate(idx_x) * ddc::coordinate(idx_y); + }); + + PartialDerivative partial_dx(builder_x, spline_evaluator_x); + DFieldMemXY dfield_dx_xy_alloc(idxrange_xy); + DFieldXY dfield_dx_xy = get_field(dfield_dx_xy_alloc); + partial_dx(dfield_dx_xy, field_xy); +} + +} // namespace From 648f9c595ed484bdf787ed0ac009f253c1649857 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 08:39:29 +0100 Subject: [PATCH 08/23] Add computation of max error for test_partial_derivatives. --- src/math_tools/partial_derivatives.hpp | 6 +++--- tests/math_tools/test_partial_derivatives.cpp | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 159cc5658..0d6226328 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -36,8 +36,8 @@ class PartialDerivative private: using IdxRangeX1X2 = IdxRange; using IdxX1X2 = typename IdxRangeX1X2::discrete_element_type; - using DFieldX1X2 = DField; - using DConstFieldX1X2 = DConstField; + using DFieldX1X2 = DField; + using DConstFieldX1X2 = DConstField; // Type for spline representation of the field using IdxRangeBSFieldX1 = typename FieldX1Builder::batched_spline_domain_type; @@ -66,6 +66,6 @@ class PartialDerivative FieldX1SplineCoeffs fieldx1_coefs = get_field(fieldx1_coefs_alloc); m_fieldx1_builder(fieldx1_coefs, get_const_field(field_x1x2)); - m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, fieldx1_coefs); + m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, get_const_field(fieldx1_coefs)); } }; \ No newline at end of file diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index 36fecac22..78313444c 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -115,7 +115,21 @@ TEST(PartialDerivative, PartialDerivativeDx) PartialDerivative partial_dx(builder_x, spline_evaluator_x); DFieldMemXY dfield_dx_xy_alloc(idxrange_xy); DFieldXY dfield_dx_xy = get_field(dfield_dx_xy_alloc); - partial_dx(dfield_dx_xy, field_xy); + partial_dx(dfield_dx_xy, get_const_field(field_xy)); + + double max_error = 0; + + ddc::parallel_for_each( + Kokkos::DefaultExecutionSpace(), + idxrange_xy, + KOKKOS_LAMBDA(IdxXY const idx_xy) { + IdxX idx_x(idx_xy); + IdxY idx_y(idx_xy); + dfield_dx_xy(idx_xy) = + Kokkos::max(abs(dfield_dx_xy(idx_xy) - + 2. * ddc::coordinate(idx_x) * ddc::coordinate(idx_y)), max_error); + }); + EXPECT_LE(max_error, 1e-12); } } // namespace From 78ca7512ca23a286360a5c1d20aa92111755655b Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Fri, 13 Dec 2024 09:09:49 +0100 Subject: [PATCH 09/23] The SplineBuilder must be batched --- tests/math_tools/test_partial_derivatives.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index 78313444c..f5747a464 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -62,7 +62,8 @@ using SplineXBuilder = ddc::SplineBuilder< SplineXBoundary, SplineXBoundary, ddc::SplineSolver::LAPACK, - GridX>; + GridX, + GridY>; using SplineXEvaluator = ddc::SplineEvaluator< Kokkos::DefaultExecutionSpace, Kokkos::DefaultExecutionSpace::memory_space, @@ -94,12 +95,13 @@ TEST(PartialDerivative, PartialDerivativeDx) ddc::init_discrete_space(SplineInterpPointsY::get_sampling()); IdxRangeY idxrange_y(SplineInterpPointsY::get_domain()); - SplineXBuilder const builder_x(idxrange_x); + IdxRangeXY idxrange_xy(idxrange_x, idxrange_y); + + SplineXBuilder const builder_x(idxrange_xy); ddc::ConstantExtrapolationRule bv_x_min(x_min); ddc::ConstantExtrapolationRule bv_x_max(x_max); SplineXEvaluator const spline_evaluator_x(bv_x_min, bv_x_max); - IdxRangeXY idxrange_xy(idxrange_x, idxrange_y); DFieldMemXY field_xy_alloc(idxrange_xy); DFieldXY field_xy = get_field(field_xy_alloc); From ae00a5d37f92c39d329b2d6b4fb3c14407a94da6 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Fri, 13 Dec 2024 09:10:58 +0100 Subject: [PATCH 10/23] Add missing return --- src/math_tools/partial_derivatives.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 0d6226328..667f08aec 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -67,5 +67,7 @@ class PartialDerivative m_fieldx1_builder(fieldx1_coefs, get_const_field(field_x1x2)); m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, get_const_field(fieldx1_coefs)); + + return dfield_dx1_x1x2; } -}; \ No newline at end of file +}; From 53e1472c9ee944bff76ccb524a19024d5c319ec0 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 09:33:08 +0100 Subject: [PATCH 11/23] Correct the test on partial derivatives. --- tests/math_tools/test_partial_derivatives.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index f5747a464..51719ed9c 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -119,17 +119,16 @@ TEST(PartialDerivative, PartialDerivativeDx) DFieldXY dfield_dx_xy = get_field(dfield_dx_xy_alloc); partial_dx(dfield_dx_xy, get_const_field(field_xy)); - double max_error = 0; - - ddc::parallel_for_each( + double max_error = ddc::parallel_transform_reduce( Kokkos::DefaultExecutionSpace(), idxrange_xy, + 0., + ddc::reducer::max(), KOKKOS_LAMBDA(IdxXY const idx_xy) { IdxX idx_x(idx_xy); IdxY idx_y(idx_xy); - dfield_dx_xy(idx_xy) = - Kokkos::max(abs(dfield_dx_xy(idx_xy) - - 2. * ddc::coordinate(idx_x) * ddc::coordinate(idx_y)), max_error); + double const dfield_dx_anal = 2. * ddc::coordinate(idx_x) * ddc::coordinate(idx_y); + return Kokkos::abs(dfield_dx_xy(idx_xy) - dfield_dx_anal); }); EXPECT_LE(max_error, 1e-12); } From 599f139fce458c46bedbe2ff0d944da3dae17150 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 09:41:23 +0100 Subject: [PATCH 12/23] Fix markdown problems. --- src/README.md | 2 +- tests/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/README.md b/src/README.md index f7bb2dcf3..ca72513eb 100644 --- a/src/README.md +++ b/src/README.md @@ -13,7 +13,7 @@ The `src/` folder contains all the code necessary to build a gyrokinetic semi-La - [interpolation](./interpolation/README.md) - Code describing interpolation methods. - [io](./io/README.md) - Code describing tools for inputting and outputting data in a simulation. - [mapping](./mapping/README.md) - Code describing tools for handling different coordinate systems. -- [math_tools](./math_tools/README.md) - Code describing math tools functions. +- [math\_tools](./math_tools/README.md) - Code describing math tools functions. - [multipatch](./multipatch/README.md) - Code describing multipatch geometry. - [mpi\_parallelisation](./mpi_parallelisation/README.md) - Code describing the MPI parallelisation. diff --git a/tests/README.md b/tests/README.md index 49524c429..c6d3de9cf 100644 --- a/tests/README.md +++ b/tests/README.md @@ -10,7 +10,7 @@ It is broken up into the following sub-folders: - geometryVparMu - Tests in the vpar-mu geometry. - geometryXVx - Tests in the x-vx geometry. - geometryXYVxVy - Tests in the x,y-vx,vy geometry. - - math_tools - Test for mathematical functions. + - math\_tools - Test for mathematical functions. - MPI parallelism - Tests for the templated MPI operators. - [multipatch](./multipatch/README.md) - Tests for the classes that work over multipatch geometries. - PDE solvers - Tests for the templated Partial Differential Equation solvers. From ca24c183859d88d7465ce3ef4e0a3c55b357fed9 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 11:04:42 +0100 Subject: [PATCH 13/23] Generalisation of partial derivatives to more than 2D. --- src/math_tools/partial_derivatives.hpp | 46 +++++++++---------- tests/math_tools/test_partial_derivatives.cpp | 4 +- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 667f08aec..94c6df50b 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -26,48 +26,44 @@ */ template < - class GridXi, - class GridX1, - class GridX2, - class FieldX1Builder, - class FieldX1Evaluator> + class FieldXiBuilderBatched, + class FieldXiEvaluatorBatched> class PartialDerivative { private: - using IdxRangeX1X2 = IdxRange; - using IdxX1X2 = typename IdxRangeX1X2::discrete_element_type; - using DFieldX1X2 = DField; - using DConstFieldX1X2 = DConstField; + using IdxRangeFieldVal = typename FieldXiBuilderBatched::batched_interpolation_domain_type; + using DFieldVal = DField; + using DConstFieldVal = DConstField; // Type for spline representation of the field - using IdxRangeBSFieldX1 = typename FieldX1Builder::batched_spline_domain_type; - using FieldX1SplineMem = DFieldMem; - using FieldX1SplineCoeffs = DField; + using IdxRangeBSFieldXi = typename FieldXiBuilderBatched::batched_spline_domain_type; + using FieldXiSplineMem = DFieldMem; + using FieldXiSplineCoeffs = DField; - FieldX1Builder const& m_fieldx1_builder; - FieldX1Evaluator const& m_fieldx1_evaluator; + FieldXiBuilderBatched const& m_fieldxi_builder; + FieldXiEvaluatorBatched const& m_fieldxi_evaluator; public: explicit PartialDerivative( - FieldX1Builder const& fieldx1_builder, - FieldX1Evaluator const& fieldx1_evaluator) - : m_fieldx1_builder(fieldx1_builder) - , m_fieldx1_evaluator(fieldx1_evaluator) + FieldXiBuilderBatched const& fieldxi_builder, + FieldXiEvaluatorBatched const& fieldxi_evaluator) + : m_fieldxi_builder(fieldxi_builder) + , m_fieldxi_evaluator(fieldxi_evaluator) { } ~PartialDerivative() = default; - DFieldX1X2 operator()(DFieldX1X2 dfield_dx1_x1x2, DConstFieldX1X2 field_x1x2) + DFieldVal operator()(DFieldVal dfieldval_dxi, DConstFieldVal fieldval) { // Build spline representation of the field .................................... - FieldX1SplineMem fieldx1_coefs_alloc( - m_fieldx1_builder.batched_spline_domain()); - FieldX1SplineCoeffs fieldx1_coefs = get_field(fieldx1_coefs_alloc); + FieldXiSplineMem fieldxi_coefs_alloc( + m_fieldxi_builder.batched_spline_domain()); + FieldXiSplineCoeffs fieldxi_coefs = get_field(fieldxi_coefs_alloc); - m_fieldx1_builder(fieldx1_coefs, get_const_field(field_x1x2)); - m_fieldx1_evaluator.deriv(dfield_dx1_x1x2, get_const_field(fieldx1_coefs)); + m_fieldxi_builder(fieldxi_coefs, get_const_field(fieldval)); + m_fieldxi_evaluator.deriv(dfieldval_dxi, get_const_field(fieldxi_coefs)); - return dfield_dx1_x1x2; + return dfieldval_dxi; } }; diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index 51719ed9c..62db011c8 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -114,7 +114,7 @@ TEST(PartialDerivative, PartialDerivativeDx) field_xy(idx_xy) = ddc::coordinate(idx_x)*ddc::coordinate(idx_x) * ddc::coordinate(idx_y); }); - PartialDerivative partial_dx(builder_x, spline_evaluator_x); + PartialDerivative partial_dx(builder_x, spline_evaluator_x); DFieldMemXY dfield_dx_xy_alloc(idxrange_xy); DFieldXY dfield_dx_xy = get_field(dfield_dx_xy_alloc); partial_dx(dfield_dx_xy, get_const_field(field_xy)); @@ -130,7 +130,7 @@ TEST(PartialDerivative, PartialDerivativeDx) double const dfield_dx_anal = 2. * ddc::coordinate(idx_x) * ddc::coordinate(idx_y); return Kokkos::abs(dfield_dx_xy(idx_xy) - dfield_dx_anal); }); - EXPECT_LE(max_error, 1e-12); + EXPECT_LE(max_error, 1e-14); } } // namespace From f5efa98f028091da62b66111f21dc18241fd7079 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 11:13:38 +0100 Subject: [PATCH 14/23] Add static assert. --- src/math_tools/partial_derivatives.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 94c6df50b..297558f36 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -28,8 +28,12 @@ template < class FieldXiBuilderBatched, class FieldXiEvaluatorBatched> -class PartialDerivative -{ +class PartialDerivative{ + static_assert(std::is_same_v); + static_assert(std::is_same_v); + private: using IdxRangeFieldVal = typename FieldXiBuilderBatched::batched_interpolation_domain_type; using DFieldVal = DField; @@ -49,7 +53,7 @@ class PartialDerivative FieldXiEvaluatorBatched const& fieldxi_evaluator) : m_fieldxi_builder(fieldxi_builder) , m_fieldxi_evaluator(fieldxi_evaluator) - { + { } ~PartialDerivative() = default; From aa8dd432783c835e5f0783eba9deffdc849703d8 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard <49058376+gdgirard@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:17:46 +0100 Subject: [PATCH 15/23] Update src/math_tools/README.md Co-authored-by: Emily Bourne --- src/math_tools/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/math_tools/README.md b/src/math_tools/README.md index 2d012cf67..660ac849c 100644 --- a/src/math_tools/README.md +++ b/src/math_tools/README.md @@ -2,6 +2,12 @@ This folder contains mathematical classes and functions. +## Derivative tools + +Functions for calculating derivatives with different methods: + +- `partial_derivatives.hpp` : calculate derivatives using spline interpolation + ## Utility tools The l\_norm\_tools.hpp file contains functions computing the infinity norm. For now, it computes the infinity norm of From a7b9d2273e80baa20c602554cbba40cbefa8af0d Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard <49058376+gdgirard@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:19:47 +0100 Subject: [PATCH 16/23] Apply suggestions from code review Co-authored-by: Emily Bourne --- tests/math_tools/CMakeLists.txt | 2 +- tests/timestepper/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/math_tools/CMakeLists.txt b/tests/math_tools/CMakeLists.txt index 1fbedcfb0..69bcbf123 100644 --- a/tests/math_tools/CMakeLists.txt +++ b/tests/math_tools/CMakeLists.txt @@ -14,7 +14,7 @@ target_link_libraries(unit_tests_math_tools GTest::gtest GTest::gmock paraconf::paraconf - gslx::math_tools + gslx::math_tools gslx::utils ) diff --git a/tests/timestepper/CMakeLists.txt b/tests/timestepper/CMakeLists.txt index ddb27a828..ed85439c4 100644 --- a/tests/timestepper/CMakeLists.txt +++ b/tests/timestepper/CMakeLists.txt @@ -20,7 +20,7 @@ target_link_libraries(unit_tests_timestepper GTest::gtest GTest::gmock paraconf::paraconf - gslx::math_tools + gslx::math_tools gslx::multipatch_data_types gslx::multipatch_geometries gslx::timestepper From 68e23eec84d3b1065f568e1296fd6d26d6cff307 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard <49058376+gdgirard@users.noreply.github.com> Date: Fri, 13 Dec 2024 11:21:57 +0100 Subject: [PATCH 17/23] Delete unuseful comment Co-authored-by: Emily Bourne --- tests/math_tools/test_partial_derivatives.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index 62db011c8..f1604d9ef 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -3,9 +3,7 @@ #include -//VG//#include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" -//VG//#include "ddc_helper.hpp" #include "partial_derivatives.hpp" namespace { From 509e7b51293d9cb1c7d1518ec11bfd83d4763246 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 11:39:11 +0100 Subject: [PATCH 18/23] Add missing comments in class PartialDerivative. --- src/math_tools/partial_derivatives.hpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 297558f36..bab054ccc 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -16,15 +16,14 @@ /** * @brief Compute the partial derivative of a * - * For a given field @f$F(X1,X2)@f$ , compute - * @f$\partial_{Xi} F(X1,X2)@f$ with i=1 or 2. + * For a given field @f$F(X)@f$ with ,@f$X=(X1,..,Xn)@f$ compute + * @f$\partial_{Xi} F(X1,..,Xn)@f$ * * @param[in] Xi * The given coordinate for the partial derivative. * - * @return @f$\partial_{Xi} F(X1,X2)@f$ + * @return @f$\partial_{Xi} F(X1,..,Xn)@f$ */ - template < class FieldXiBuilderBatched, class FieldXiEvaluatorBatched> @@ -48,6 +47,12 @@ class PartialDerivative{ FieldXiEvaluatorBatched const& m_fieldxi_evaluator; public: + /** + * @brief Construct an instance of the class PartialDerivative. + * + * @param fieldxi_builder Builder for intermediate interpolation representation. + * @param fieldxi_evaluator Evaluator for intermediate interpolation representation. + */ explicit PartialDerivative( FieldXiBuilderBatched const& fieldxi_builder, FieldXiEvaluatorBatched const& fieldxi_evaluator) @@ -56,8 +61,12 @@ class PartialDerivative{ { } - ~PartialDerivative() = default; - + /** + * @brief Compute the partial derivative of @f$ F(X1,..,Xn)@f$ in Xi direction. + * + * @param[out] dfieldval_dxi Partial derivatives in Xi direction. + * @param[in] fieldval Values of the field @f$ F(X1,..,Xn)@f$. + */ DFieldVal operator()(DFieldVal dfieldval_dxi, DConstFieldVal fieldval) { // Build spline representation of the field .................................... From 90e55ea59b55f9661c15eab8d99cc427b29c7d75 Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 11:53:39 +0100 Subject: [PATCH 19/23] Correct the indentation. --- src/math_tools/partial_derivatives.hpp | 28 +++++++++---------- tests/math_tools/test_partial_derivatives.cpp | 5 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index bab054ccc..9b54dfba3 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -24,15 +24,16 @@ * * @return @f$\partial_{Xi} F(X1,..,Xn)@f$ */ -template < - class FieldXiBuilderBatched, - class FieldXiEvaluatorBatched> -class PartialDerivative{ - static_assert(std::is_same_v); - static_assert(std::is_same_v); - +template +class PartialDerivative +{ + static_assert(std::is_same_v< + typename FieldXiBuilderBatched::batched_spline_domain_type, + typename FieldXiEvaluatorBatched::batched_spline_domain_type>); + static_assert(std::is_same_v< + typename FieldXiBuilderBatched::batched_interpolation_domain_type, + typename FieldXiEvaluatorBatched::batched_evaluation_domain_type>); + private: using IdxRangeFieldVal = typename FieldXiBuilderBatched::batched_interpolation_domain_type; using DFieldVal = DField; @@ -54,10 +55,10 @@ class PartialDerivative{ * @param fieldxi_evaluator Evaluator for intermediate interpolation representation. */ explicit PartialDerivative( - FieldXiBuilderBatched const& fieldxi_builder, - FieldXiEvaluatorBatched const& fieldxi_evaluator) + FieldXiBuilderBatched const& fieldxi_builder, + FieldXiEvaluatorBatched const& fieldxi_evaluator) : m_fieldxi_builder(fieldxi_builder) - , m_fieldxi_evaluator(fieldxi_evaluator) + , m_fieldxi_evaluator(fieldxi_evaluator) { } @@ -70,8 +71,7 @@ class PartialDerivative{ DFieldVal operator()(DFieldVal dfieldval_dxi, DConstFieldVal fieldval) { // Build spline representation of the field .................................... - FieldXiSplineMem fieldxi_coefs_alloc( - m_fieldxi_builder.batched_spline_domain()); + FieldXiSplineMem fieldxi_coefs_alloc(m_fieldxi_builder.batched_spline_domain()); FieldXiSplineCoeffs fieldxi_coefs = get_field(fieldxi_coefs_alloc); m_fieldxi_builder(fieldxi_coefs, get_const_field(fieldval)); diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp index f1604d9ef..ee81a2da2 100644 --- a/tests/math_tools/test_partial_derivatives.cpp +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -28,7 +28,7 @@ using IdxStepX = IdxStep; using IdxRangeX = IdxRange; struct Y -{ +{ static bool constexpr PERIODIC = false; }; using CoordY = Coord; @@ -109,7 +109,8 @@ TEST(PartialDerivative, PartialDerivativeDx) KOKKOS_LAMBDA(IdxXY const idx_xy) { IdxX idx_x(idx_xy); IdxY idx_y(idx_xy); - field_xy(idx_xy) = ddc::coordinate(idx_x)*ddc::coordinate(idx_x) * ddc::coordinate(idx_y); + field_xy(idx_xy) + = ddc::coordinate(idx_x) * ddc::coordinate(idx_x) * ddc::coordinate(idx_y); }); PartialDerivative partial_dx(builder_x, spline_evaluator_x); From 92c5a3cd47528bfef72ca244397625ad5ed80a6c Mon Sep 17 00:00:00 2001 From: Virginie Grandgirard Date: Fri, 13 Dec 2024 11:59:59 +0100 Subject: [PATCH 20/23] Correct comments. --- src/math_tools/partial_derivatives.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp index 9b54dfba3..1d04adf4f 100644 --- a/src/math_tools/partial_derivatives.hpp +++ b/src/math_tools/partial_derivatives.hpp @@ -68,7 +68,7 @@ class PartialDerivative * @param[out] dfieldval_dxi Partial derivatives in Xi direction. * @param[in] fieldval Values of the field @f$ F(X1,..,Xn)@f$. */ - DFieldVal operator()(DFieldVal dfieldval_dxi, DConstFieldVal fieldval) + void operator()(DFieldVal dfieldval_dxi, DConstFieldVal fieldval) { // Build spline representation of the field .................................... FieldXiSplineMem fieldxi_coefs_alloc(m_fieldxi_builder.batched_spline_domain()); @@ -76,7 +76,5 @@ class PartialDerivative m_fieldxi_builder(fieldxi_coefs, get_const_field(fieldval)); m_fieldxi_evaluator.deriv(dfieldval_dxi, get_const_field(fieldxi_coefs)); - - return dfieldval_dxi; } }; From 698786e441d6eb245a3bbc7ef127d0d4ecbd5d0c Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Fri, 13 Dec 2024 13:40:05 +0100 Subject: [PATCH 21/23] Add missing compilation flags --- .github/actions/build_code/action.yml | 2 +- .github/actions/run_tests/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/build_code/action.yml b/.github/actions/build_code/action.yml index 814d47d9c..28e0f00c8 100644 --- a/.github/actions/build_code/action.yml +++ b/.github/actions/build_code/action.yml @@ -11,6 +11,6 @@ runs: - name: Compile code run: | cmake -DCMAKE_TOOLCHAIN=${{ inputs.toolchain }} -B build -S . - cmake --build build + cmake --build build --parallel 4 shell: bash diff --git a/.github/actions/run_tests/action.yml b/.github/actions/run_tests/action.yml index 91bfd53b3..a92d19077 100644 --- a/.github/actions/run_tests/action.yml +++ b/.github/actions/run_tests/action.yml @@ -5,7 +5,7 @@ runs: steps: - name: "Run tests" run: | - ctest -j 2 --timeout 5 --output-junit tests.xml + ctest -j 2 --timeout 5 --output-junit tests.xml --output-on-failure shell: bash working-directory: ./build From d3b8a9d5fb94adcd5daa20fce9220a976d67f828 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Fri, 13 Dec 2024 14:10:46 +0100 Subject: [PATCH 22/23] Allow MPI to run as root (this is fine inside a docker) --- .github/actions/run_tests/action.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/actions/run_tests/action.yml b/.github/actions/run_tests/action.yml index a92d19077..af8b13446 100644 --- a/.github/actions/run_tests/action.yml +++ b/.github/actions/run_tests/action.yml @@ -7,8 +7,10 @@ runs: run: | ctest -j 2 --timeout 5 --output-junit tests.xml --output-on-failure shell: bash - working-directory: - ./build + working-directory: ./build + env: + OMPI_ALLOW_RUN_AS_ROOT: 1 + OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1 - name: Publish Test Report uses: mikepenz/action-junit-report@v4 if: success() || failure() # always run even if the previous step fails From 975e67eca2257bb5e370a08ccca5b18f1e49a85b Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Fri, 13 Dec 2024 16:15:11 +0100 Subject: [PATCH 23/23] Fix indentation --- .github/actions/run_tests/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/run_tests/action.yml b/.github/actions/run_tests/action.yml index af8b13446..afec2e306 100644 --- a/.github/actions/run_tests/action.yml +++ b/.github/actions/run_tests/action.yml @@ -10,7 +10,7 @@ runs: working-directory: ./build env: OMPI_ALLOW_RUN_AS_ROOT: 1 - OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1 + OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1 - name: Publish Test Report uses: mikepenz/action-junit-report@v4 if: success() || failure() # always run even if the previous step fails