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..afec2e306 100644 --- a/.github/actions/run_tests/action.yml +++ b/.github/actions/run_tests/action.yml @@ -5,10 +5,12 @@ 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 + 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 diff --git a/simulations/geometryRTheta/diocotron/diocotron.cpp b/simulations/geometryRTheta/diocotron/diocotron.cpp index 1e15e4cff..94dd927e0 100644 --- a/simulations/geometryRTheta/diocotron/diocotron.cpp +++ b/simulations/geometryRTheta/diocotron/diocotron.cpp @@ -26,7 +26,7 @@ #include "euler.hpp" #include "geometry.hpp" #include "input.hpp" -#include "math_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 9a0960939..2e3a2b9fb 100644 --- a/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp +++ b/simulations/geometryRTheta/vortex_merger/vortex_merger.cpp @@ -26,7 +26,7 @@ #include "euler.hpp" #include "geometry.hpp" #include "input.hpp" -#include "math_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 ad6cccad7..526d395d0 100644 --- a/simulations/geometryXY/guiding_center/guiding_center.cpp +++ b/simulations/geometryXY/guiding_center/guiding_center.cpp @@ -19,7 +19,7 @@ #include "geometry.hpp" #include "initialization_Kelvin_Helmholtz.hpp" #include "input.hpp" -#include "math_tools.hpp" +#include "l_norm_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/README.md b/src/README.md index e5754394e..ca72513eb 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/geometryRTheta/advection/CMakeLists.txt b/src/geometryRTheta/advection/CMakeLists.txt index dd74c9137..650480247 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..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 "math_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 9cd40d865..6bf641b9d 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 "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 0003ff9a4..6381a2c27 100644 --- a/src/geometryRTheta/time_solver/bsl_predcorr.hpp +++ b/src/geometryRTheta/time_solver/bsl_predcorr.hpp @@ -17,7 +17,7 @@ #include "geometry.hpp" #include "ifoot_finder.hpp" #include "itimesolver.hpp" -#include "math_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 369eef436..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 "math_tools.hpp" +#include "l_norm_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/math_tools/README.md b/src/math_tools/README.md new file mode 100644 index 000000000..660ac849c --- /dev/null +++ b/src/math_tools/README.md @@ -0,0 +1,15 @@ +# Utility Functions + +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 +- a double: $`\Vert x \Vert_{\infty} = x`$; +- a coordinate: $`\Vert x \Vert_{\infty} = \max_{i} (|x_i|)`$. diff --git a/src/utils/math_tools.hpp b/src/math_tools/l_norm_tools.hpp similarity index 98% rename from src/utils/math_tools.hpp rename to src/math_tools/l_norm_tools.hpp index dde1f6c2d..fb33d0c78 100644 --- a/src/utils/math_tools.hpp +++ b/src/math_tools/l_norm_tools.hpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT /** - * @file math_tools.hpp - * File Describing useful mathematical functions. + * @file l_norm_tools.hpp + * File Describing useful mathematical functions to compute Lnorms */ #pragma once diff --git a/src/math_tools/partial_derivatives.hpp b/src/math_tools/partial_derivatives.hpp new file mode 100644 index 000000000..1d04adf4f --- /dev/null +++ b/src/math_tools/partial_derivatives.hpp @@ -0,0 +1,80 @@ + +// 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(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,..,Xn)@f$ + */ +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; + using DConstFieldVal = DConstField; + + // Type for spline representation of the field + using IdxRangeBSFieldXi = typename FieldXiBuilderBatched::batched_spline_domain_type; + using FieldXiSplineMem = DFieldMem; + using FieldXiSplineCoeffs = DField; + + FieldXiBuilderBatched const& m_fieldxi_builder; + 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) + : m_fieldxi_builder(fieldxi_builder) + , m_fieldxi_evaluator(fieldxi_evaluator) + { + } + + /** + * @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$. + */ + void operator()(DFieldVal dfieldval_dxi, DConstFieldVal fieldval) + { + // Build spline representation of the field .................................... + 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)); + m_fieldxi_evaluator.deriv(dfieldval_dxi, get_const_field(fieldxi_coefs)); + } +}; 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. diff --git a/src/multipatch/utils/multipatch_math_tools.hpp b/src/multipatch/utils/multipatch_math_tools.hpp index 513a945a9..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 "math_tools.hpp" +#include "l_norm_tools.hpp" #include "multipatch_field.hpp" /** diff --git a/src/timestepper/CMakeLists.txt b/src/timestepper/CMakeLists.txt index 1a81e435d..c664a762f 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::core 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..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 "math_tools.hpp" +#include "l_norm_tools.hpp" #include "multipatch_math_tools.hpp" #include "vector_field_common.hpp" 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/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/README.md b/tests/README.md index 85fd344a6..c6d3de9cf 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. diff --git a/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp b/tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp index 524c7cfdc..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 "math_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 dd757785a..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 "math_tools.hpp" +#include "l_norm_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 26a86cc71..fecd941e0 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..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 "math_tools.hpp" +#include "l_norm_tools.hpp" #include "mesh_builder.hpp" #include "quadrature.hpp" #include "spline_quadrature.hpp" diff --git a/tests/math_tools/CMakeLists.txt b/tests/math_tools/CMakeLists.txt new file mode 100644 index 000000000..69bcbf123 --- /dev/null +++ b/tests/math_tools/CMakeLists.txt @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: MIT + + +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 + 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 99% rename from tests/utils/test_math_tools.cpp rename to tests/math_tools/test_lnorm_tools.cpp index 6395b81a1..c083bd224 100644 --- a/tests/utils/test_math_tools.cpp +++ b/tests/math_tools/test_lnorm_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 "l_norm_tools.hpp" namespace { diff --git a/tests/math_tools/test_partial_derivatives.cpp b/tests/math_tools/test_partial_derivatives.cpp new file mode 100644 index 000000000..ee81a2da2 --- /dev/null +++ b/tests/math_tools/test_partial_derivatives.cpp @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: MIT +#include + +#include + +#include "ddc_aliases.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, + GridY>; +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()); + + 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); + + 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, get_const_field(field_xy)); + + 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); + 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-14); +} + +} // namespace diff --git a/tests/timestepper/CMakeLists.txt b/tests/timestepper/CMakeLists.txt index 201318925..ed85439c4 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..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 "math_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 c4e28c598..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 "math_tools.hpp" +#include "l_norm_tools.hpp" #include "vector_field.hpp" #include "vector_field_mem.hpp" diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt index 053e446a4..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 )