6 #include "ddc_aliases.hpp"
7 #include "derivative_field_common.hpp"
9 template <
class,
class,
int,
class>
18 class MemorySpace = Kokkos::HostSpace,
19 class LayoutStridedPolicy = std::experimental::layout_right>
22 template <
class ElementType,
class SupportType,
class MemorySpace,
class LayoutStr
idedPolicy>
23 inline constexpr
bool enable_deriv_field<
26 template <
class ElementType,
class SupportType,
class MemorySpace,
class LayoutStr
idedPolicy>
27 inline constexpr
bool enable_borrowed_deriv_field<
30 template <
class ElementType,
class SupportType,
class MemorySpace,
class LayoutStr
idedPolicy>
31 inline constexpr
bool enable_data_access_methods<
46 is_borrowed_deriv_field_v<FieldDst> && is_borrowed_deriv_field_v<FieldSrc>,
48 auto deepcopy(FieldDst&& dst, FieldSrc&& src)
50 assert(dst.get_values_field().domain().extents() == src.get_values_field().domain().extents());
55 dst_field.deepcopy(src_field);
67 template <
class ExecSpace,
class FieldDst,
class FieldSrc>
68 auto deepcopy(ExecSpace
const& execution_space, FieldDst&& dst, FieldSrc&& src)
70 static_assert(is_borrowed_deriv_field_v<FieldDst>);
71 static_assert(is_borrowed_deriv_field_v<FieldSrc>);
73 assert(dst.get_values_field().idx_range().extents()
74 == src.get_values_field().idx_range().extents());
79 dst_field.deepcopy(execution_space, src_field);
102 template <
class ElementType,
class... DDims,
class MemorySpace,
class LayoutStridedPolicy>
103 class DerivField<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>
105 Field<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>,
111 Field<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>,
162 =
DerivField<ElementType
const, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>;
166 using discrete_deriv_idx_range_type =
typename base_type::discrete_deriv_idx_range_type;
171 using discrete_deriv_index_type =
typename base_type::discrete_deriv_index_type;
174 using reference =
typename chunk_type::reference;
177 using base_type::n_fields;
183 template <std::
size_t ArrayIndex,
class Tag>
184 KOKKOS_FUNCTION constexpr Idx<Tag> get_chunk_subidx_range_1d_idx()
187 if constexpr (ddc::in_tags_v<Tag, deriv_tags>) {
189 if constexpr (ArrayIndex & (1 << ddc::type_seq_rank_v<Tag, deriv_tags>)) {
203 template <std::
size_t ArrayIndex>
204 KOKKOS_FUNCTION constexpr discrete_deriv_index_type get_chunk_subidx_range_idx()
206 return discrete_deriv_index_type(get_chunk_subidx_range_1d_idx<ArrayIndex, DDims>()...);
210 template <
class Field, std::size_t... ArrayIndex>
211 KOKKOS_FUNCTION constexpr
void initialise_fields(
213 std::index_sequence<ArrayIndex...>)
215 ((base_type::internal_fields[ArrayIndex] = chunks.internal_fields[chunks.get_array_index(
216 get_chunk_subidx_range_idx<ArrayIndex>())]),
220 auto get_kokkos_view_from_internal_chunk(
int index)
222 typename base_type::internal_mdspan_type field = base_type::internal_fields[index];
223 auto kokkos_layout = ddc::detail::build_kokkos_layout(
226 std::make_index_sequence<
sizeof...(DDims)> {});
228 ddc::detail::mdspan_to_kokkos_element_t<ElementType,
sizeof...(DDims)>,
229 decltype(kokkos_layout),
230 MemorySpace>(field.data_handle(), kokkos_layout);
257 class = std::enable_if_t<std::is_same_v<typename Allocator::memory_space, MemorySpace>>>
261 field.m_physical_idx_range,
262 field.m_deriv_idx_range,
263 field.m_cross_derivative_idx_range)
265 initialise_fields(field, std::make_integer_sequence<std::size_t, n_fields> {});
276 class SFINAEElementType = ElementType,
277 class = std::enable_if_t<std::is_const_v<SFINAEElementType>>,
280 class = std::enable_if_t<std::is_same_v<typename Allocator::memory_space, MemorySpace>>>
284 field.m_physical_idx_range,
285 field.m_deriv_idx_range,
286 field.m_cross_derivative_idx_range)
288 initialise_fields(field, std::make_integer_sequence<std::size_t, n_fields> {});
297 template <
class OElementType>
302 field.m_physical_idx_range,
303 field.m_deriv_idx_range,
304 field.m_cross_derivative_idx_range)
306 initialise_fields(field, std::make_integer_sequence<std::size_t, n_fields> {});
309 KOKKOS_DEFAULTED_FUNCTION ~
DerivField() =
default;
328 template <
class OElementType,
class OLayoutStr
idedPolicy,
class OMemorySpace>
332 for (
int i(0); i < n_fields; ++i) {
333 auto kokkos_span = get_kokkos_view_from_internal_chunk(i);
334 auto src_kokkos_span = src.get_kokkos_view_from_internal_chunk(i);
335 Kokkos::deep_copy(kokkos_span, src_kokkos_span);
345 template <
class ExecSpace,
class OElementType,
class OMemorySpace,
class OLayoutStr
idedPolicy>
347 ExecSpace
const& execution_space,
350 for (
int i(0); i < n_fields; ++i) {
351 auto kokkos_span = get_kokkos_view_from_internal_chunk(i);
352 auto src_kokkos_span = src.get_kokkos_view_from_internal_chunk(i);
353 Kokkos::deep_copy(execution_space, kokkos_span, src_kokkos_span);
366 template <
class... DElem>
367 KOKKOS_FUNCTION constexpr reference
operator()(DElem... elems)
const noexcept
369 static_assert((ddc::is_discrete_element_v<DElem> && ...));
370 using full_index_type = detail::combine_t<DElem...>;
371 full_index_type elem(elems...);
372 return base_type::get_internal_field(elem)();
405 class MemorySpace = Kokkos::HostSpace,
406 class LayoutStridedPolicy = std::experimental::layout_right>
412 class NewMemorySpace,
417 struct OnMemorySpace<NewMemorySpace,
DerivField<ElementType, SupportType, MemorySpace, Layout>>
Definition: derivative_field_common.hpp:31
See DerivFieldMemImplementation.
Definition: derivative_field.hpp:10
A class which holds references to chunks of memory describing a field and its derivatives.
Definition: derivative_field.hpp:107
typename base_type::element_type element_type
The type of the elements in the chunks.
Definition: derivative_field.hpp:116
constexpr KOKKOS_DEFAULTED_FUNCTION DerivField & operator=(DerivField &&other)=default
Move-assigns a new value to this DerivField.
typename detail::strip_deriv_t< deriv_tags > physical_deriv_grids
A type sequence containing all grid types for which derivatives are present in this object.
Definition: derivative_field.hpp:140
constexpr KOKKOS_DEFAULTED_FUNCTION DerivField(DerivField const &other)=default
Copy-construct a DerivField.
constexpr KOKKOS_FUNCTION reference operator()(DElem... elems) const noexcept
Get an element from a constant field.
Definition: derivative_field.hpp:367
typename base_type::deriv_tags deriv_tags
A type sequence containing all derivatives present in this object.
Definition: derivative_field.hpp:137
constexpr KOKKOS_DEFAULTED_FUNCTION DerivField & operator=(DerivField const &other)=default
Copy-assigns a new value to this DerivField, yields a new view to the same data.
constexpr KOKKOS_DEFAULTED_FUNCTION DerivField(DerivField &&other)=default
Move-construct a DerivField.
void deepcopy(ExecSpace const &execution_space, DerivField< OElementType, index_range_type, OMemorySpace, OLayoutStridedPolicy > src)
Copy the source DerivField into this DerivField using Kokkos::deep_copy.
Definition: derivative_field.hpp:346
void deepcopy(DerivField< OElementType, index_range_type, OMemorySpace, OLayoutStridedPolicy > src)
Copy the source DerivField into this DerivField using Kokkos::deep_copy.
Definition: derivative_field.hpp:329
typename base_type::chunk_type chunk_type
The type of the field stored in the array.
Definition: derivative_field.hpp:155
typename base_type::index_range_type index_range_type
The IdxRange on which the fields in this object are defined.
Definition: derivative_field.hpp:126
typename base_type::discrete_domain_type discrete_domain_type
The IdxRange on which the chunks in this object are defined.
Definition: derivative_field.hpp:124
typename base_type::physical_idx_range_type physical_idx_range_type
The physical index range on which the field is defined.
Definition: derivative_field.hpp:146
constexpr KOKKOS_FUNCTION view_type span_cview() const
Get a constant DerivField of this field.
Definition: derivative_field.hpp:383
typename base_type::discrete_element_type discrete_element_type
The Idx which can be used to index this object.
Definition: derivative_field.hpp:134
constexpr DerivField(DerivFieldMem< OElementType, index_range_type, NDerivs, Allocator > &field)
Constructs a new DerivField containing a modifiable view on the data in a DerivFieldMem.
Definition: derivative_field.hpp:258
typename base_type::physical_grids physical_grids
A type sequence containing all the grids on which the fields are defined.
Definition: derivative_field.hpp:143
constexpr DerivField(DerivFieldMem< OElementType, index_range_type, NDerivs, Allocator > const &field)
Constructs a new DerivField containing a constant view on the data in a DerivFieldMem.
Definition: derivative_field.hpp:281
constexpr KOKKOS_FUNCTION DerivField(DerivField< OElementType, index_range_type, MemorySpace, LayoutStridedPolicy > const &field)
Copy construct a DerivField.
Definition: derivative_field.hpp:298
constexpr KOKKOS_FUNCTION span_type span_view() const
Get a modifiable DerivField of this field.
Definition: derivative_field.hpp:396
See DerivFieldImplementation.
Definition: derivative_field.hpp:20