From 3a413f827d5ca14df634c75a3272d8c48191ace7 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Tue, 26 Mar 2024 13:29:19 +0000 Subject: [PATCH] Update DDC See merge request gysela-developpers/gyselalibxx!421 -------------------------------------------- --- vendor/ddc/.github/workflows/reuse.yml | 15 -- vendor/ddc/.github/workflows/tests.yml | 7 +- vendor/ddc/LICENSES/CC0-1.0.txt | 121 ------------ vendor/ddc/README.md | 8 + .../splines/constant_extrapolation_rule.hpp | 76 ++++++++ .../splines/greville_interpolation_points.hpp | 42 ++++- .../ddc/kernels/splines/spline_builder.hpp | 95 ++++++++++ .../ddc/kernels/splines/spline_builder_2d.hpp | 114 ++++++++++++ .../kernels/splines/spline_evaluator_2d.hpp | 175 +++++++++++++++++- .../ddc/include/ddc/misc/ginkgo_executors.hpp | 4 + vendor/ddc/tests/splines/bsplines.cpp | 3 +- 11 files changed, 517 insertions(+), 143 deletions(-) delete mode 100644 vendor/ddc/.github/workflows/reuse.yml delete mode 100644 vendor/ddc/LICENSES/CC0-1.0.txt diff --git a/vendor/ddc/.github/workflows/reuse.yml b/vendor/ddc/.github/workflows/reuse.yml deleted file mode 100644 index c4002dd7e..000000000 --- a/vendor/ddc/.github/workflows/reuse.yml +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-FileCopyrightText: 2022 Free Software Foundation Europe e.V. -# -# SPDX-License-Identifier: CC0-1.0 - -name: REUSE Compliance Check - -on: [push, pull_request] - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: REUSE Compliance Check - uses: fsfe/reuse-action@v3 diff --git a/vendor/ddc/.github/workflows/tests.yml b/vendor/ddc/.github/workflows/tests.yml index c9100e6e2..6a7ff61da 100644 --- a/vendor/ddc/.github/workflows/tests.yml +++ b/vendor/ddc/.github/workflows/tests.yml @@ -17,6 +17,9 @@ jobs: exclude: '' extensions: 'hpp,cpp' clangFormatVersion: 12 + - name: REUSE Compliance Check + if: always() + uses: fsfe/reuse-action@v3 id_repo: runs-on: ubuntu-latest @@ -133,12 +136,10 @@ jobs: export CC=hipcc export CXX=hipcc EXTRA_CMAKE_FLAGS="-DKokkos_ENABLE_HIP=ON -DKokkos_ARCH_VEGA90A=ON -DCMAKE_PREFIX_PATH=/opt/rocm" - CMAKE_CXX_FLAGS="-Wno-gnu-zero-variadic-macro-arguments" ;; 'cpu-clang') export CC=clang export CXX=clang++ - CMAKE_CXX_FLAGS="-Wno-gnu-zero-variadic-macro-arguments" ;; 'cpu-gcc') export CC=gcc @@ -154,7 +155,6 @@ jobs: -DCMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} \ -DCMAKE_CXX_STANDARD=${{matrix.cxx_version}} \ -DMDSPAN_CXX_STANDARD=${{matrix.cxx_version}} \ - -DKokkos_ENABLE_DEPRECATED_CODE_3=OFF \ -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \ -DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \ -DCMAKE_CXX_FLAGS="\ @@ -218,7 +218,6 @@ jobs: -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_CXX_STANDARD=17 \ -DMDSPAN_CXX_STANDARD=17 \ - -DKokkos_ENABLE_DEPRECATED_CODE_3=OFF \ -DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \ -DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \ -S /src \ diff --git a/vendor/ddc/LICENSES/CC0-1.0.txt b/vendor/ddc/LICENSES/CC0-1.0.txt deleted file mode 100644 index 0e259d42c..000000000 --- a/vendor/ddc/LICENSES/CC0-1.0.txt +++ /dev/null @@ -1,121 +0,0 @@ -Creative Commons Legal Code - -CC0 1.0 Universal - - CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE - LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN - ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS - INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES - REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS - PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM - THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED - HEREUNDER. - -Statement of Purpose - -The laws of most jurisdictions throughout the world automatically confer -exclusive Copyright and Related Rights (defined below) upon the creator -and subsequent owner(s) (each and all, an "owner") of an original work of -authorship and/or a database (each, a "Work"). - -Certain owners wish to permanently relinquish those rights to a Work for -the purpose of contributing to a commons of creative, cultural and -scientific works ("Commons") that the public can reliably and without fear -of later claims of infringement build upon, modify, incorporate in other -works, reuse and redistribute as freely as possible in any form whatsoever -and for any purposes, including without limitation commercial purposes. -These owners may contribute to the Commons to promote the ideal of a free -culture and the further production of creative, cultural and scientific -works, or to gain reputation or greater distribution for their Work in -part through the use and efforts of others. - -For these and/or other purposes and motivations, and without any -expectation of additional consideration or compensation, the person -associating CC0 with a Work (the "Affirmer"), to the extent that he or she -is an owner of Copyright and Related Rights in the Work, voluntarily -elects to apply CC0 to the Work and publicly distribute the Work under its -terms, with knowledge of his or her Copyright and Related Rights in the -Work and the meaning and intended legal effect of CC0 on those rights. - -1. Copyright and Related Rights. A Work made available under CC0 may be -protected by copyright and related or neighboring rights ("Copyright and -Related Rights"). Copyright and Related Rights include, but are not -limited to, the following: - - i. the right to reproduce, adapt, distribute, perform, display, - communicate, and translate a Work; - ii. moral rights retained by the original author(s) and/or performer(s); -iii. publicity and privacy rights pertaining to a person's image or - likeness depicted in a Work; - iv. rights protecting against unfair competition in regards to a Work, - subject to the limitations in paragraph 4(a), below; - v. rights protecting the extraction, dissemination, use and reuse of data - in a Work; - vi. database rights (such as those arising under Directive 96/9/EC of the - European Parliament and of the Council of 11 March 1996 on the legal - protection of databases, and under any national implementation - thereof, including any amended or successor version of such - directive); and -vii. other similar, equivalent or corresponding rights throughout the - world based on applicable law or treaty, and any national - implementations thereof. - -2. Waiver. To the greatest extent permitted by, but not in contravention -of, applicable law, Affirmer hereby overtly, fully, permanently, -irrevocably and unconditionally waives, abandons, and surrenders all of -Affirmer's Copyright and Related Rights and associated claims and causes -of action, whether now known or unknown (including existing as well as -future claims and causes of action), in the Work (i) in all territories -worldwide, (ii) for the maximum duration provided by applicable law or -treaty (including future time extensions), (iii) in any current or future -medium and for any number of copies, and (iv) for any purpose whatsoever, -including without limitation commercial, advertising or promotional -purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each -member of the public at large and to the detriment of Affirmer's heirs and -successors, fully intending that such Waiver shall not be subject to -revocation, rescission, cancellation, termination, or any other legal or -equitable action to disrupt the quiet enjoyment of the Work by the public -as contemplated by Affirmer's express Statement of Purpose. - -3. Public License Fallback. Should any part of the Waiver for any reason -be judged legally invalid or ineffective under applicable law, then the -Waiver shall be preserved to the maximum extent permitted taking into -account Affirmer's express Statement of Purpose. In addition, to the -extent the Waiver is so judged Affirmer hereby grants to each affected -person a royalty-free, non transferable, non sublicensable, non exclusive, -irrevocable and unconditional license to exercise Affirmer's Copyright and -Related Rights in the Work (i) in all territories worldwide, (ii) for the -maximum duration provided by applicable law or treaty (including future -time extensions), (iii) in any current or future medium and for any number -of copies, and (iv) for any purpose whatsoever, including without -limitation commercial, advertising or promotional purposes (the -"License"). The License shall be deemed effective as of the date CC0 was -applied by Affirmer to the Work. Should any part of the License for any -reason be judged legally invalid or ineffective under applicable law, such -partial invalidity or ineffectiveness shall not invalidate the remainder -of the License, and in such case Affirmer hereby affirms that he or she -will not (i) exercise any of his or her remaining Copyright and Related -Rights in the Work or (ii) assert any associated claims and causes of -action with respect to the Work, in either case contrary to Affirmer's -express Statement of Purpose. - -4. Limitations and Disclaimers. - - a. No trademark or patent rights held by Affirmer are waived, abandoned, - surrendered, licensed or otherwise affected by this document. - b. Affirmer offers the Work as-is and makes no representations or - warranties of any kind concerning the Work, express, implied, - statutory or otherwise, including without limitation warranties of - title, merchantability, fitness for a particular purpose, non - infringement, or the absence of latent or other defects, accuracy, or - the present or absence of errors, whether or not discoverable, all to - the greatest extent permissible under applicable law. - c. Affirmer disclaims responsibility for clearing rights of other persons - that may apply to the Work or any use thereof, including without - limitation any person's Copyright and Related Rights in the Work. - Further, Affirmer disclaims responsibility for obtaining any necessary - consents, permissions or other rights required for any use of the - Work. - d. Affirmer understands and acknowledges that Creative Commons is not a - party to this document and has no duty or obligation with respect to - this CC0 or use of the Work. diff --git a/vendor/ddc/README.md b/vendor/ddc/README.md index 69b055dc1..0ad192c11 100644 --- a/vendor/ddc/README.md +++ b/vendor/ddc/README.md @@ -24,3 +24,11 @@ All these abstractions are handled at compilation using C++ template meta-progra If you like the project, please leave us a github star. If you want to know more, join un on [Slack](https://join.slack.com/t/ddc-lib/shared_invite/zt-14b6rjcrn-AwSfM6_arEamAKk_VgQPhg) + +## Getting the code and basic configuration + +```bash +git clone --recurse-submodules -j8 https://github.com/CExA-project/ddc.git +cd ddc +cmake -B build -D DDC_BUILD_KERNELS_FFT=OFF -D DDC_BUILD_KERNELS_SPLINES=OFF -D DDC_BUILD_PDI_WRAPPER=OFF +``` diff --git a/vendor/ddc/include/ddc/kernels/splines/constant_extrapolation_rule.hpp b/vendor/ddc/include/ddc/kernels/splines/constant_extrapolation_rule.hpp index f0934098f..c93d5dc6f 100644 --- a/vendor/ddc/include/ddc/kernels/splines/constant_extrapolation_rule.hpp +++ b/vendor/ddc/include/ddc/kernels/splines/constant_extrapolation_rule.hpp @@ -13,6 +13,12 @@ struct ConstantExtrapolationRule { }; +/** + * @brief A functor for describing a spline boundary value by a constant extrapolation for 1D evaluator. + * + * To define the value of a function on B-splines out of the domain, we here use a constant + * extrapolation on the edge. + */ template struct ConstantExtrapolationRule { @@ -20,8 +26,26 @@ struct ConstantExtrapolationRule ddc::Coordinate m_eval_pos; public: + /** + * @brief Instantiate a ConstantExtrapolationRule. + * + * The boundary value will be the same as at the coordinate eval_pos given. + * + * @param[in] eval_pos + * Coordinate inside the domain where we will evaluate each points outside the domain. + */ explicit ConstantExtrapolationRule(ddc::Coordinate eval_pos) : m_eval_pos(eval_pos) {} + /** + * @brief Get the value of the function on B-splines at a coordinate outside the domain. + * + * @param[in] pos + * The coordinate where we want to evaluate the function on B-splines. + * @param[in] spline_coef + * The coefficients of the function on B-splines. + * + * @return A double with the value of the function on B-splines evaluated at the coordinate. + */ template KOKKOS_FUNCTION double operator()( CoordType, @@ -43,6 +67,12 @@ struct ConstantExtrapolationRule } }; +/** + * @brief A functor for describing a spline boundary value by a constant extrapolation for 2D evaluator. + * + * To define the value of a function on B-splines out of the domain, we here use a constant + * extrapolation on the edge. + */ template struct ConstantExtrapolationRule { @@ -52,6 +82,23 @@ struct ConstantExtrapolationRule ddc::Coordinate m_eval_pos_not_interest_max; public: + /** + * @brief Instantiate a ConstantExtrapolationRule. + * + * The boundary value will be the same as at the coordinate given in a dimension given. + * The dimension of the input defines the dimension of the boundary condition. + * The second and the third parameters are needed in case of non-periodic splines on the + * dimension off-interest (the complementary dimension of the boundary condition), + * because the evaluator can receive coordinates outside the domain in both dimension. + * + * @param[in] eval_pos_bc + * Coordinate in the dimension given inside the domain where we will evaluate + * each points outside the domain. + * @param[in] eval_pos_not_interest_min + * The minimum coordinate inside the domain on the complementary dimension of the boundary condition. + * @param[in] eval_pos_not_interest_max + * The maximum coordinate inside the domain on the complementary dimension of the boundary condition. + */ explicit ConstantExtrapolationRule( ddc::Coordinate eval_pos, ddc::Coordinate eval_pos_not_interest_min, @@ -62,6 +109,18 @@ struct ConstantExtrapolationRule { } + /** + * @brief Instantiate a ConstantExtrapolationRule. + * + * The boundary value will be the same as at the coordinate given in a dimension given. + * The dimension of the input defines the dimension of the boundary condition. + * No second and third parameters are needed in case of periodic splines on the + * dimension off-interest (the complementary dimension of the boundary condition). + * + * @param[in] eval_pos_bc + * Coordinate in the dimension given inside the domain where we will evaluate + * each points outside the domain. + */ template = 0> explicit ConstantExtrapolationRule(ddc::Coordinate eval_pos) : m_eval_pos(eval_pos) @@ -70,6 +129,23 @@ struct ConstantExtrapolationRule { } + /** + * @brief Get the value of the function on B-splines at a coordinate outside the domain. + * + * In the dimension defined in the constructor Dim1 (or Dim2), it sets the coordinate pos_1 (or pos_2) + * given at the m_eval_pos coordinate if it is outside the domain. + * If the coordinate on the complementary dimension of the boundary condition dimension ddc::select(coord_extrap) is + * outside the domain, then it also sets the coordinate at eval_pos_not_interest_min + * (if ddc::select(coord_extrap) @f$ < @f$ eval_pos_not_interest_min) or + * at eval_pos_not_interest_max (if ddc::select(coord_extrap) @f$ > @f$ eval_pos_not_interest_max). + * + * @param[in] coord_extrap + * The coordinates where we want to evaluate the function on B-splines + * @param[in] spline_coef + * The coefficients of the function on B-splines. + * + *@return A double with the value of the function on B-splines evaluated at the coordinate. + */ template KOKKOS_FUNCTION double operator()( CoordType coord_extrap, diff --git a/vendor/ddc/include/ddc/kernels/splines/greville_interpolation_points.hpp b/vendor/ddc/include/ddc/kernels/splines/greville_interpolation_points.hpp index 2ca9ebdad..576c36ae3 100644 --- a/vendor/ddc/include/ddc/kernels/splines/greville_interpolation_points.hpp +++ b/vendor/ddc/include/ddc/kernels/splines/greville_interpolation_points.hpp @@ -13,6 +13,13 @@ #include "spline_boundary_conditions.hpp" namespace ddc { +/** + * A class which provides helper functions to initialise the Greville points from a B-Spline definition. + * + * @tparam BSplines The bspline class relative to which the Greville points will be calculated. + * @tparam BcXmin The (left) boundary condition that will be used to build the splines. + * @tparam BcXmax The (right) boundary condition that will be used to build the splines. + */ template class GrevilleInterpolationPoints { @@ -39,7 +46,12 @@ class GrevilleInterpolationPoints using Sampling = ddc::NonUniformPointSampling; using SamplingImpl = typename Sampling::template Impl; - std::vector greville_points(ddc::discrete_space().nbasis()); + int n_greville_points = ddc::discrete_space().nbasis(); + if constexpr (U::is_periodic()) { + n_greville_points += 1; + } + + std::vector greville_points(n_greville_points); ddc::DiscreteDomain bspline_domain = ddc::discrete_space().full_domain().take_first( ddc::DiscreteVector(ddc::discrete_space().nbasis())); @@ -72,6 +84,10 @@ class GrevilleInterpolationPoints greville_points[ddc::discrete_space().nbasis() - npoints + i] = temp_knots[i]; } + + // Save a periodic point to initialise the domain size + greville_points[n_greville_points - 1] + = greville_points[0] + ddc::discrete_space().length(); } return SamplingImpl(greville_points); @@ -84,6 +100,15 @@ class GrevilleInterpolationPoints = U::is_uniform() && ((N_BE_MIN != 0 && N_BE_MAX != 0) || U::is_periodic()); public: + /** + * Get the UniformPointSampling defining the Greville points. + * + * This function is called when the result is a UniformPointSampling. This is the case + * when uniform splines are used with an odd degree and with boundary conditions which + * do not introduce additional interpolation points. + * + * @returns The mesh of uniform Greville points. + */ template < typename U = BSplines, std::enable_if_t< @@ -94,6 +119,11 @@ class GrevilleInterpolationPoints return uniform_greville_points(); } + /** + * Get the NonUniformPointSampling defining the Greville points. + * + * @returns The mesh of non-uniform Greville points. + */ template < typename U = BSplines, std::enable_if_t< @@ -187,8 +217,18 @@ class GrevilleInterpolationPoints } } + /** + * The type of the mesh. + * + * This is either NonUniformPointSampling or UniformPointSampling. + */ using interpolation_mesh_type = typename decltype(get_sampling())::discrete_dimension_type; + /** + * Get the domain which gives us access to all of the Greville points. + * + * @returns The domain of the Greville points. + */ static ddc::DiscreteDomain get_domain() { int const npoints = ddc::discrete_space().nbasis() - N_BE_MIN - N_BE_MAX; diff --git a/vendor/ddc/include/ddc/kernels/splines/spline_builder.hpp b/vendor/ddc/include/ddc/kernels/splines/spline_builder.hpp index 964b0fcf6..2d2b33a04 100644 --- a/vendor/ddc/include/ddc/kernels/splines/spline_builder.hpp +++ b/vendor/ddc/include/ddc/kernels/splines/spline_builder.hpp @@ -26,6 +26,15 @@ constexpr bool is_spline_interpolation_mesh_uniform( return is_uniform && ((N_BE_MIN != 0 && N_BE_MAX != 0) || is_periodic); } +/** + * @brief A class for creating a spline approximation of a function. + * + * A class which contains an operator () which can be used to build a spline approximation + * of a function. A spline approximation is represented by coefficients stored in a Chunk + * of BSplines. The spline is constructed such that it respects the boundary conditions + * BcXmin and BcXmax, and it interpolates the function at the points on the interpolation_mesh + * associated with interpolation_mesh_type. + */ template < class ExecSpace, class MemorySpace, @@ -52,12 +61,21 @@ class SplineBuilder using memory_space = MemorySpace; + /** + * @brief The type of the interpolation mesh used by this class. + */ using interpolation_mesh_type = InterpolationMesh; + /** + * @brief The type of the BSplines which are compatible with this class. + */ using bsplines_type = BSplines; using deriv_type = ddc::Deriv; + /** + * @brief The type of the domain for the interpolation mesh used by this class. + */ using interpolation_domain_type = ddc::DiscreteDomain; using vals_domain_type = ddc::DiscreteDomain; @@ -90,13 +108,47 @@ class SplineBuilder ddc::detail::TypeSeq, ddc::detail::TypeSeq>>; + /** + * @brief Indicates if the degree of the splines is odd or even. + */ static constexpr bool s_odd = BSplines::degree() % 2; + + /** + * @brief The number of equations which define the boundary conditions at the lower bound. + */ static constexpr int s_nbe_xmin = n_boundary_equations(BcXmin, BSplines::degree()); + + /** + * @brief The number of equations which define the boundary conditions at the upper bound. + */ static constexpr int s_nbe_xmax = n_boundary_equations(BcXmax, BSplines::degree()); + + /** + * @brief The number of boundary conditions which must be provided by the user at the lower bound. + * + * This value is usually equal to s_nbe_xmin, but it may be difference if the chosen boundary + * conditions impose a specific value (e.g. no values need to be provided for Dirichlet boundary + * conditions). + */ static constexpr int s_nbc_xmin = n_user_input(BcXmin, BSplines::degree()); + + /** + * @brief The number of boundary conditions which must be provided by the user at the upper bound. + * + * This value is usually equal to s_nbe_xmin, but it may be difference if the chosen boundary + * conditions impose a specific value (e.g. no values need to be provided for Dirichlet boundary + * conditions). + */ static constexpr int s_nbc_xmax = n_user_input(BcXmax, BSplines::degree()); + /** + * @brief The boundary condition implemented at the lower bound. + */ static constexpr ddc::BoundCond s_bc_xmin = BcXmin; + + /** + * @brief The boundary condition implemented at the upper bound. + */ static constexpr ddc::BoundCond s_bc_xmax = BcXmax; private: @@ -141,12 +193,23 @@ class SplineBuilder SplineBuilder(SplineBuilder const& x) = delete; + /** + * @brief Create a new SplineBuilder by copy + * + * @param x The SplineBuilder being copied. + */ SplineBuilder(SplineBuilder&& x) = default; ~SplineBuilder() = default; SplineBuilder& operator=(SplineBuilder const& x) = delete; + /** + * @brief Copy a SplineBuilder. + * + * @param x The SplineBuilder being copied. + * @returns A reference to this object. + */ SplineBuilder& operator=(SplineBuilder&& x) = default; vals_domain_type vals_domain() const noexcept @@ -154,6 +217,14 @@ class SplineBuilder return m_vals_domain; } + /** + * @brief Get the domain from which the approximation is defined. + * + * Get the domain on which values of the function must be provided in order + * to build a spline approximation of the function. + * + * @return The domain for the grid points. + */ interpolation_domain_type interpolation_domain() const noexcept { return interpolation_domain_type(vals_domain()); @@ -169,6 +240,14 @@ class SplineBuilder return ddc::discrete_space().full_domain(); } + /** + * @brief Get the domain on which the approximation is defined. + * + * Get the domain of the basis-splines for which the coefficients of the spline + * approximation must be calculated. + * + * @return The domain for the splines. + */ spline_domain_type spline_domain() const noexcept { return ddc::replace_dim_of< @@ -212,6 +291,22 @@ class SplineBuilder return *matrix; } + /** + * @brief Build a spline approximation of a function. + * + * Use the values of a function at known grid points (as specified by + * SplineBuilder::interpolation_domain) and the derivatives of the + * function at the boundaries (if necessary for the chosen boundary + * conditions) to calculate a spline approximation of a function. + * + * The spline approximation is stored as a ChunkSpan of coefficients + * associated with basis-splines. + * + * @param[out] spline The coefficients of the spline calculated by the function. + * @param[in] vals The values of the function at the grid points. + * @param[in] derivs_xmin The values of the derivatives at the lower boundary. + * @param[in] derivs_xmax The values of the derivatives at the upper boundary. + */ template void operator()( ddc::ChunkSpan spline, diff --git a/vendor/ddc/include/ddc/kernels/splines/spline_builder_2d.hpp b/vendor/ddc/include/ddc/kernels/splines/spline_builder_2d.hpp index 213e89308..73cd7ecec 100644 --- a/vendor/ddc/include/ddc/kernels/splines/spline_builder_2d.hpp +++ b/vendor/ddc/include/ddc/kernels/splines/spline_builder_2d.hpp @@ -8,6 +8,14 @@ namespace ddc { +/** + * @brief A class for creating a 2D spline approximation of a function. + * + * A class which contains an operator () which can be used to build a 2D spline approximation + * of a function. A 2D spline approximation uses a cross-product between two 1D spline builder. + * + * @see SplineBuilder + */ template < class ExecSpace, class MemorySpace, @@ -60,21 +68,48 @@ class SplineBuilder2D IDimX>...>; private: + /** + * @brief Tag the dimension of the first 1D SplineBuilder. + */ using tag_type1 = typename builder_type1::bsplines_type::tag_type; + /** + * @brief Tag the dimension of the second 1D SplineBuilder. + */ using tag_type2 = typename builder_type2::bsplines_type::tag_type; public: + /** + * @brief The type of the BSplines in the first dimension which are compatible with this class. + */ using bsplines_type1 = typename builder_type1::bsplines_type; + /** + * @brief The type of the BSplines in the second dimension which are compatible with this class. + */ using bsplines_type2 = typename builder_type2::bsplines_type; using deriv_type1 = typename builder_type1::deriv_type; using deriv_type2 = typename builder_type2::deriv_type; + /** + * @brief The type of the interpolation mesh in the first dimension used by this class. + */ using interpolation_mesh_type1 = typename builder_type1::interpolation_mesh_type; + /** + * @brief The type of the interpolation mesh in the second dimension used by this class. + */ using interpolation_mesh_type2 = typename builder_type2::interpolation_mesh_type; + /** + * @brief The type of the domain for the interpolation mesh is the first dimension used by this class. + */ using interpolation_domain_type1 = typename builder_type1::interpolation_mesh_type; + /** + * @brief The type of the domain for the interpolation mesh is the second dimension used by this class. + */ using interpolation_domain_type2 = typename builder_type2::interpolation_mesh_type; + /** + * @brief The type of the domain for the interpolation mesh is the 2D dimension used by this class. + */ using interpolation_domain_type = ddc::DiscreteDomain; @@ -109,6 +144,13 @@ class SplineBuilder2D builder_type2 m_spline_builder2; public: + /** + * @brief Create a new SplineBuilder2D. + * + * @param interpolation_domain + * The 2D domain on which points will be provided in order to + * create the 2D spline approximation. + */ explicit SplineBuilder2D( vals_domain_type const& vals_domain, std::optional cols_per_chunk = std::nullopt, @@ -126,14 +168,34 @@ class SplineBuilder2D { } + /** + * @brief Create a new SplineBuilder2D by copy + * + * @param x + * The SplineBuilder2D being copied. + */ SplineBuilder2D(SplineBuilder2D const& x) = delete; + /** + * @brief Create a new SplineBuilder2D by copy + * + * @param x + * The temporary SplineBuilder2D being copied. + */ SplineBuilder2D(SplineBuilder2D&& x) = default; ~SplineBuilder2D() = default; SplineBuilder2D& operator=(SplineBuilder2D const& x) = delete; + + /** + * @brief Copy a SplineBuilder2D. + * + * @param x + * The temporary SplineBuilder2D being copied. + * @returns A reference to this object. + */ SplineBuilder2D& operator=(SplineBuilder2D&& x) = default; vals_domain_type vals_domain() const noexcept @@ -141,6 +203,14 @@ class SplineBuilder2D return m_spline_builder1.vals_domain(); } + /** + * @brief Get the 2D dimension domain from which the approximation is defined. + * + * Get the 2D dimension domain on which values of the function must be provided in order + * to build a spline approximation of the function. + * + * @return The 2D dimension domain for the grid points. + */ interpolation_domain_type interpolation_domain() const noexcept { return ddc::DiscreteDomain( @@ -153,6 +223,14 @@ class SplineBuilder2D return ddc::remove_dims_of(vals_domain(), interpolation_domain()); } + /** + * @brief Get the 2D domain on which the approximation is defined. + * + * Get the 2D domain of the basis-splines for which the coefficients of the spline + * approximation must be calculated. + * + * @return The 2D domain for the splines. + */ ddc::DiscreteDomain bsplines_domain() const noexcept // TODO : clarify name { @@ -170,6 +248,42 @@ class SplineBuilder2D bsplines_domain()); } + /** + * @brief Build a 2D spline approximation of a function. + * + * Use the values of a function at known grid points (as specified by + * SplineBuilder2D::interpolation_domain_type) and the derivatives of the + * function at the boundaries (if necessary for the chosen boundary + * conditions) to calculate a 2D spline approximation of a function. + * + * The spline approximation is stored as a ChunkSpan of coefficients + * associated with basis-splines. + * + * @param[out] spline + * The coefficients of the spline calculated by the function. + * @param[in] vals + * The values of the function at the grid points. + * @param[in] derivs_xmin + * The values of the derivatives at the lower boundary in the first dimension. + * @param[in] derivs_xmax + * The values of the derivatives at the upper boundary in the first dimension. + * @param[in] derivs_ymin + * The values of the derivatives at the lower boundary in the second dimension. + * @param[in] derivs_ymax + * The values of the derivatives at the upper boundary in the second dimension. + * @param[in] mixed_derivs_xmin_ymin + * The values of the the cross-derivatives at the lower boundary in the first dimension + * and the lower boundary in the second dimension. + * @param[in] mixed_derivs_xmax_ymin + * The values of the the cross-derivatives at the upper boundary in the first dimension + * and the lower boundary in the second dimension. + * @param[in] mixed_derivs_xmin_ymax + * The values of the the cross-derivatives at the lower boundary in the first dimension + * and the upper boundary in the second dimension. + * @param[in] mixed_derivs_xmax_ymax + * The values of the the cross-derivatives at the upper boundary in the first dimension + * and the upper boundary in the second dimension. + */ template void operator()( ddc::ChunkSpan spline, diff --git a/vendor/ddc/include/ddc/kernels/splines/spline_evaluator_2d.hpp b/vendor/ddc/include/ddc/kernels/splines/spline_evaluator_2d.hpp index b32768275..792bab49a 100644 --- a/vendor/ddc/include/ddc/kernels/splines/spline_evaluator_2d.hpp +++ b/vendor/ddc/include/ddc/kernels/splines/spline_evaluator_2d.hpp @@ -13,6 +13,9 @@ namespace ddc { +/** + * @brief Define an evaluator 2D on B-splines. + */ template < class ExecSpace, class MemorySpace, @@ -28,11 +31,16 @@ template < class SplineEvaluator2D { private: - // Tags to determine what to evaluate + /** + * @brief Tag to indicate that the value of the spline should be evaluated. + */ struct eval_type { }; + /** + * @brief Tag to indicate that derivative of the spline should be evaluated. + */ struct eval_deriv_type { }; @@ -158,6 +166,24 @@ class SplineEvaluator2D "RightExtrapolationRule2::operator() has to be callable " "with usual arguments."); + /** + * @brief Instantiate an evaluator operator. + * + * @param[in] left_extrap_rule1 + * A SplineBoundaryValue2D object giving the value on the "left side" of the domain + * in the first dimension. + * @param[in] right_extrap_rule1 + * A SplineBoundaryValue2D object giving the value on the "right side" of the domain + * in the first dimension. + * @param[in] left_extrap_rule2 + * A SplineBoundaryValue2D object giving the value on the "left side" of the domain + * in the second dimension. + * @param[in] right_extrap_rule2 + * A SplineBoundaryValue2D object giving the value on the "right side" of the domain + * in the second dimension. + * + * @see SplineBoundaryValue2D + */ explicit SplineEvaluator2D( LeftExtrapolationRule1 const& left_extrap_rule1, RightExtrapolationRule1 const& right_extrap_rule1, @@ -170,14 +196,44 @@ class SplineEvaluator2D { } + /** + * @brief Instantiate a SplineEvaluator2D from another + * SplineEvaluator2D (lvalue). + * + * @param[in] x + * SplineEvaluator2D evaluator used to instantiate the new one. + */ SplineEvaluator2D(SplineEvaluator2D const& x) = default; + /** + * @brief Instantiate a SplineEvaluator2D from another temporary + * SplineEvaluator2D (rvalue). + * + * @param[in] x + * SplineEvaluator2D evaluator used to instantiate the new one. + */ SplineEvaluator2D(SplineEvaluator2D&& x) = default; ~SplineEvaluator2D() = default; + /** + * @brief Assign a SplineEvaluator2D from another SplineEvaluator2D (lvalue). + * + * @param[in] x + * SplineEvaluator2D mapping used to assign. + * + * @return The SplineEvaluator2D assigned. + */ SplineEvaluator2D& operator=(SplineEvaluator2D const& x) = default; + /** + * @brief Assign a SplineEvaluator2D from another temporary SplineEvaluator2D (rvalue). + * + * @param[in] x + * SplineEvaluator2D mapping used to assign. + * + * @return The SplineEvaluator2D assigned. + */ SplineEvaluator2D& operator=(SplineEvaluator2D&& x) = default; @@ -202,6 +258,16 @@ class SplineEvaluator2D return m_right_extrap_rule_2; } + /** + * @brief Get the value of the function on B-splines at the coordinate given. + * + * @param[in] coord_eval + * The 2D coordinate where we want to evaluate the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + * + * @return A double containing the value of the function at the coordinate given. + */ template KOKKOS_FUNCTION double operator()( ddc::Coordinate const& coord_eval, @@ -240,6 +306,16 @@ class SplineEvaluator2D }); } + /** + * @brief Get the value of the derivative of the first dimension of the function on B-splines at the coordinate given. + * + * @param[in] coord_eval + * The 2D coordinate where we want to evaluate the derivative of the first dimension of the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + * + * @return A double containing the value of the derivative of the first dimension of the function at the coordinate given. + */ template KOKKOS_FUNCTION double deriv_dim_1( ddc::Coordinate const& coord_eval, @@ -249,6 +325,16 @@ class SplineEvaluator2D return eval_no_bc(coord_eval, spline_coef); } + /** + * @brief Get the value of the derivative of the second dimension of the function on B-splines at the coordinate given. + * + * @param[in] coord_eval + * The 2D coordinate where we want to evaluate the derivative of the second dimension of the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + * + * @return A double containing the value of the derivative of the second dimension of the function at the coordinate given. + */ template KOKKOS_FUNCTION double deriv_dim_2( ddc::Coordinate const& coord_eval, @@ -258,6 +344,16 @@ class SplineEvaluator2D return eval_no_bc(coord_eval, spline_coef); } + /** + * @brief Get the value of the cross derivative of the function on B-splines at the coordinate given. + * + * @param[in] coord_eval + * The 2D coordinate where we want to evaluate the cross derivative of the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + * + * @return A double containing the value of the cross derivative of the function at the coordinate given. + */ template KOKKOS_FUNCTION double deriv_1_and_2( ddc::Coordinate const& coord_eval, @@ -308,6 +404,16 @@ class SplineEvaluator2D return deriv_1_and_2(coord_eval, spline_coef); } + /** + * @brief Get the values of the derivative of the first dimension of the function on B-splines at the coordinates given. + * + * @param[out] spline_eval + * A ChunkSpan with the values of the derivative of the first dimension of the function at the coordinates given. + * @param[in] coords_eval + * A ChunkSpan with the 2D coordinates where we want to evaluate the derivative of the first dimension of the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + */ template void deriv_dim_1( ddc::ChunkSpan const spline_eval, @@ -339,6 +445,16 @@ class SplineEvaluator2D }); } + /** + * @brief Get the values of the derivative of the second dimension of the function on B-splines at the coordinates given. + * + * @param[out] spline_eval + * A ChunkSpan with the values of the derivative of the second dimension of the function at the coordinates given. + * @param[in] coords_eval + * A ChunkSpan with the 2D coordinates where we want to evaluate the derivative of the second dimension of the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + */ template void deriv_dim_2( ddc::ChunkSpan const spline_eval, @@ -370,6 +486,16 @@ class SplineEvaluator2D }); } + /** + * @brief Get the values of the cross derivative of the function on B-splines at the coordinates given. + * + * @param[out] spline_eval + * A ChunkSpan with the values of the cross derivative of the function at the coordinates given. + * @param[in] coords_eval + * A ChunkSpan with the 2D coordinates where we want to evaluate the cross derivative of the function. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + */ template void deriv_1_and_2( ddc::ChunkSpan const spline_eval, @@ -458,6 +584,14 @@ class SplineEvaluator2D return deriv_1_and_2(spline_eval, coords_eval, spline_coef); } + /** + * @brief Get the the integral of the function on B-splines on the domain. + * + * @param[in] spline_coef + * The B-splines coefficients of the function we want to integrate. + * + * @return A double with the value of the integral of the function. + */ template void integrate( ddc::ChunkSpan const integrals, @@ -496,6 +630,25 @@ class SplineEvaluator2D } private: + /** + * @brief Evaluate the function on B-splines at the coordinate given. + * + * This function firstly deals with the boundary conditions and calls the SplineEvaluator2D::eval_no_bc function + * to evaluate. + * + * @param[in] coord_eval + * The 2D coordinate where we want to evaluate. + * @param[in] spline_coef + * The B-splines coefficients of the function we want to evaluate. + * @param[out] vals1 + * A ChunkSpan with the not-null values of each function of the spline in the first dimension. + * @param[out] vals2 + * A ChunkSpan with the not-null values of each function of the spline in the second dimension. + * + * @return A double with the value of the function at the coordinate given. + * + * @see SplineBoundaryValue + */ template KOKKOS_INLINE_FUNCTION double eval( ddc::Coordinate const& coord_eval, @@ -551,6 +704,26 @@ class SplineEvaluator2D spline_coef); } + /** + * @brief Evaluate the function or its derivative at the coordinate given. + * + * @param[in] coord_eval1 + * The coordinate on the first dimension where we want to evaluate. + * @param[in] coord_eval2 + * The coordinate on the second dimension where we want to evaluate. + * @param[in] splne_coef + * The B-splines coefficients of the function we want to evaluate. + * @param[out] vals1 + * A ChunkSpan with the not-null values of each function of the spline in the first dimension. + * @param[out] vals2 + * A ChunkSpan with the not-null values of each function of the spline in the second dimension. + * @param[in] eval_type_1 + * A flag indicating if we evaluate the function or its derivative in the first dimension. + * The type of this object is either `eval_type` or `eval_deriv_type`. + * @param[in] eval_type_2 + * A flag indicating if we evaluate the function or its derivative in the second dimension. + * The type of this object is either `eval_type` or `eval_deriv_type`. + */ template KOKKOS_INLINE_FUNCTION double eval_no_bc( ddc::Coordinate const& coord_eval, diff --git a/vendor/ddc/include/ddc/misc/ginkgo_executors.hpp b/vendor/ddc/include/ddc/misc/ginkgo_executors.hpp index a529ac2cf..f720a07f9 100644 --- a/vendor/ddc/include/ddc/misc/ginkgo_executors.hpp +++ b/vendor/ddc/include/ddc/misc/ginkgo_executors.hpp @@ -11,6 +11,8 @@ #include +namespace ddc::detail { + inline std::shared_ptr create_default_host_executor() { #ifdef KOKKOS_ENABLE_SERIAL @@ -59,3 +61,5 @@ std::shared_ptr create_gko_exec() } #endif } + +} // namespace ddc::detail diff --git a/vendor/ddc/tests/splines/bsplines.cpp b/vendor/ddc/tests/splines/bsplines.cpp index 99a3ee952..91bcd88be 100644 --- a/vendor/ddc/tests/splines/bsplines.cpp +++ b/vendor/ddc/tests/splines/bsplines.cpp @@ -35,7 +35,8 @@ using periodicity = std::integer_sequence; using Cases = tuple_to_types_t>; -TYPED_TEST_SUITE(BSplinesFixture, Cases); +// Trailing comma is needed to avoid spurious `gnu-zero-variadic-macro-arguments` warning with clang +TYPED_TEST_SUITE(BSplinesFixture, Cases, ); TYPED_TEST(BSplinesFixture, PartitionOfUnity_Uniform) {