From 0c10faad439c10be32fa9f2545d0496051f9c148 Mon Sep 17 00:00:00 2001 From: Emily Bourne Date: Mon, 21 Oct 2024 19:33:43 +0200 Subject: [PATCH] Add MultipatchField types Add two new multipatch types: - `MultipatchField` : To store all `Field` types (`Field`, `VectorField`, `DerivField`) - `MultipatchFieldMem` : To store all `FieldMem` types (`FieldMem`, `VectorFieldMem`, `DerivFieldMem`) The `MultipatchField` type is useful to provide all the aliases usually provided by `Field` types. The `MultipatchFieldMem` type is necessary to allow these types to have `__host__` only versions of the functions in `MultipatchField`. 2 utility booleans are added: - `has_data_access_methods_v` : To tell if a type is a `Field` type on which data access methods can be called: - `get_idx_range` - `get_field` - `get_const_field` - `is_mem_type_v` : To tell if a type might allocate a chunk of memory (`FieldMem`, `VectorFieldMem`, `DerivFieldMem`) These booleans are activated via `enable_X` booleans. See merge request gysela-developpers/gyselalibxx!735 -------------------------------------------- --- ci_tools/gyselalib_static_analysis.py | 2 +- src/data_types/derivative_field.hpp | 11 +- src/data_types/derivative_field_mem.hpp | 13 +- src/data_types/vector_field.hpp | 10 + src/data_types/vector_field_mem.hpp | 9 + .../data_types/multipatch_field.hpp | 189 ++++++++++++++++++ .../data_types/multipatch_field_mem.hpp | 175 ++++++++++++++++ src/multipatch/data_types/multipatch_type.hpp | 50 ++--- src/multipatch/data_types/types.hpp | 10 +- .../spline/multipatch_spline_evaluator_2d.hpp | 4 +- src/utils/ddc_alias_inline_functions.hpp | 67 ++++++- .../data_types/multipatch_field_2p.cpp | 11 +- .../data_types/multipatch_field_9p.cpp | 3 +- .../constant_extrapolation_rules_onion.cpp | 7 +- .../spline/multipatch_spline_builder.cpp | 16 +- .../spline/multipatch_spline_builder_2d.cpp | 49 +++-- .../spline/multipatch_spline_evaluator.cpp | 29 +-- .../spline/null_extrapolation_rules.cpp | 7 +- .../spline/spline_testing_tools.hpp | 5 +- 19 files changed, 561 insertions(+), 106 deletions(-) create mode 100644 src/multipatch/data_types/multipatch_field.hpp create mode 100644 src/multipatch/data_types/multipatch_field_mem.hpp diff --git a/ci_tools/gyselalib_static_analysis.py b/ci_tools/gyselalib_static_analysis.py index 6fcd314f3..3b8e9faf6 100644 --- a/ci_tools/gyselalib_static_analysis.py +++ b/ci_tools/gyselalib_static_analysis.py @@ -48,7 +48,7 @@ HOME_DIR = Path(__file__).parent.parent.absolute() global_folders = [HOME_DIR / f for f in ('src', 'simulations', 'tests')] -auto_functions = set() +auto_functions = set(['build_kokkos_layout']) field_mem_functions = set() def report_error(level, file, linenr, message): diff --git a/src/data_types/derivative_field.hpp b/src/data_types/derivative_field.hpp index 6b0e0aa02..0c1b056ef 100644 --- a/src/data_types/derivative_field.hpp +++ b/src/data_types/derivative_field.hpp @@ -27,6 +27,10 @@ template > = true; +template +inline constexpr bool enable_data_access_methods< + DerivField> = true; + namespace ddcHelper { /** @@ -170,7 +174,7 @@ class DerivField, LayoutStridedPolicy, MemorySpa using reference = typename chunk_type::reference; /// @brief The number of chunks which must be created to describe this object. - static constexpr int n_fields = base_type::n_fields; + using base_type::n_fields; private: /** @brief Get the subindex range to be extracted from a DerivFieldMem to build the internal_chunk at position ArrayIndex @@ -251,7 +255,8 @@ class DerivField, LayoutStridedPolicy, MemorySpa int NDerivs, class Allocator, class = std::enable_if_t>> - constexpr DerivField(DerivFieldMem& field) + explicit constexpr DerivField( + DerivFieldMem& field) : base_type( field.m_physical_idx_range, field.m_deriv_idx_range, @@ -273,7 +278,7 @@ class DerivField, LayoutStridedPolicy, MemorySpa int NDerivs, class Allocator, class = std::enable_if_t>> - constexpr DerivField( + explicit constexpr DerivField( DerivFieldMem const& field) : base_type( field.m_physical_idx_range, diff --git a/src/data_types/derivative_field_mem.hpp b/src/data_types/derivative_field_mem.hpp index afc30dada..4a97f1bcf 100644 --- a/src/data_types/derivative_field_mem.hpp +++ b/src/data_types/derivative_field_mem.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "derivative_field.hpp" #include "derivative_field_common.hpp" @@ -17,6 +18,14 @@ template inline constexpr bool enable_deriv_field> = true; +template +inline constexpr bool enable_data_access_methods< + DerivFieldMem> = true; + +template +inline constexpr bool + enable_mem_type> = true; + /** * @brief A class which holds a chunk of memory describing a field and its derivatives. @@ -132,7 +141,7 @@ class DerivFieldMem, NDerivs, MemSpace> using internal_mdspan_type = typename base_type::internal_mdspan_type; /// @brief The number of chunks which must be created to describe this object. - static constexpr int n_fields = base_type::n_fields; + using base_type::n_fields; private: /// @brief A function to get the index range along direction Tag for the ArrayIndex-th element of internal_fields. @@ -354,7 +363,7 @@ class DerivFieldMem, NDerivs, MemSpace> */ span_type span_view() { - return *this; + return span_type(*this); } }; diff --git a/src/data_types/vector_field.hpp b/src/data_types/vector_field.hpp index e938bdfe3..21812a26c 100644 --- a/src/data_types/vector_field.hpp +++ b/src/data_types/vector_field.hpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT #pragma once +#include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "vector_field_mem.hpp" @@ -22,6 +23,15 @@ template < inline constexpr bool enable_field< VectorField> = true; +template < + class ElementType, + class IdxRangeType, + class NDTag, + class LayoutStridedPolicy, + class MemorySpace> +inline constexpr bool enable_data_access_methods< + VectorField> = true; + template < class ElementType, class IdxRangeType, diff --git a/src/data_types/vector_field_mem.hpp b/src/data_types/vector_field_mem.hpp index 734b2aeab..1ea90a5de 100644 --- a/src/data_types/vector_field_mem.hpp +++ b/src/data_types/vector_field_mem.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include "ddc_alias_inline_functions.hpp" #include "ddc_aliases.hpp" #include "vector_field_common.hpp" @@ -21,6 +22,14 @@ template inline constexpr bool enable_field> = true; +template +inline constexpr bool enable_data_access_methods< + VectorFieldMem> = true; + +template +inline constexpr bool + enable_mem_type> = true; + /** * @brief Pre-declaration of VectorField. */ diff --git a/src/multipatch/data_types/multipatch_field.hpp b/src/multipatch/data_types/multipatch_field.hpp new file mode 100644 index 000000000..abf19f697 --- /dev/null +++ b/src/multipatch/data_types/multipatch_field.hpp @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: MIT + +#pragma once +#include "multipatch_type.hpp" + + +/** + * @brief A class to store field objects on patches. + * + * On a multipatch domain when we have objects and types defined on different patches, e.g. fields. + * They can be stored in this class and then be accessed by the patch they are defined + * on. + * + * @tparam T The type of the fields/derivative fields/vector fields that are stored on the given patches. + * @tparam Patches The patches of the objects in the same order of the patches + * that the given objects are defined on. + * + * @warning The objects have to be defined on different patches. Otherwise retrieving + * them by their patch is ill-defined. + */ +template