8#include "multipatch_field.hpp"
9#include "multipatch_field_mem.hpp"
21 class ExecSpace = Kokkos::DefaultExecutionSpace>
25 (ddc::is_chunk_v<FieldMem>) or (is_vector_field_v<FieldMem>)
26 or (is_multipatch_field_mem_v<FieldMem>));
28 (ddc::is_chunk_v<DerivFieldMem>) or (is_vector_field_v<DerivFieldMem>)
29 or (is_multipatch_field_mem_v<DerivFieldMem>));
33 typename FieldMem::discrete_domain_type,
34 typename DerivFieldMem::discrete_domain_type>)
35 || (is_multipatch_field_mem_v<FieldMem> && is_multipatch_field_mem_v<DerivFieldMem>));
38 Kokkos::SpaceAccessibility<ExecSpace, typename FieldMem::memory_space>::accessible,
39 "MemorySpace has to be accessible for ExecutionSpace.");
41 Kokkos::SpaceAccessibility<ExecSpace, typename DerivFieldMem::memory_space>::accessible,
42 "MemorySpace has to be accessible for ExecutionSpace.");
46 using IdxRange =
typename FieldMem::discrete_domain_type;
81 update(ExecSpace(), y, dt, dy_calculator);
103 ExecSpace
const& exec_space,
108 static_assert(ddc::is_chunk_v<FieldMem>);
109 using Idx =
typename IdxRange::discrete_element_type;
111 ddc::parallel_for_each(
114 KOKKOS_LAMBDA(Idx
const idx) { y(idx) = y(idx) + dy(idx) * dt; });
134 ExecSpace
const& exec_space,
149 if constexpr (ddc::is_chunk_v<ValField>) {
150 ddc::parallel_deepcopy(copy_to, copy_from);
152 ddcHelper::deepcopy(copy_to, copy_from);
163 template <
class DerivFieldType,
class Idx,
class... DDims>
164 KOKKOS_FUNCTION
static void fill_k_total(DerivFieldType k_total, Idx i, Coord<DDims...> new_val)
167 (std::is_same_v<DerivField, DerivFieldType>)
168 || (is_multipatch_field_v<DerivField>));
169 ((ddcHelper::get<DDims>(k_total)(i) = ddc::get<DDims>(new_val)), ...);
181 template <
class FuncType,
class...
T>
185 static_assert(std::conjunction_v<std::is_same<T, DerivField>...>);
186 std::size_t
constexpr n_args =
sizeof...(T);
187 using element_type =
typename DerivField::element_type;
189 std::is_invocable_r_v<element_type, FuncType, std::array<element_type, n_args>>);
190 std::array<DerivField, n_args> k_arr({k...});
191 if constexpr (is_vector_field_v<DerivField>) {
193 }
else if constexpr (is_multipatch_field_v<DerivField>) {
194 assemble_multipatch_field_k_total(exec_space, k_total, func, k_arr);
210 template <
class FieldType,
class FuncType, std::
size_t n_args>
212 ExecSpace
const& exec_space,
215 std::array<FieldType, n_args> k_arr)
const
217 static_assert(ddc::is_chunk_v<FieldType>);
218 using Idx =
typename FieldType::discrete_domain_type::discrete_element_type;
219 ddc::parallel_for_each(
221 get_idx_range(k_total),
222 KOKKOS_LAMBDA(Idx
const i) {
223 std::array<double, n_args> k_elems;
224 for (
int j(0); j < n_args; ++j) {
225 k_elems[j] = k_arr[j](i);
227 k_total(i) = func(k_elems);
240 template <
class FieldType,
class FuncType, std::
size_t n_args>
242 ExecSpace
const& exec_space,
245 std::array<FieldType, n_args> k_arr)
const
247 static_assert(is_vector_field_v<FieldType>);
248 using element_type =
typename FieldType::element_type;
249 using Idx =
typename FieldType::discrete_domain_type::discrete_element_type;
250 ddc::parallel_for_each(
252 get_idx_range(k_total),
253 KOKKOS_LAMBDA(Idx
const i) {
254 std::array<element_type, n_args> k_elems;
255 for (
int j(0); j < n_args; ++j) {
256 k_elems[j] = k_arr[j](i);
273 template <
typename P>
278 void assemble_multipatch_field_k_total_on_patch(
279 ExecSpace
const& exec_space,
285 static_assert((ddc::is_chunk_v<FieldType>) or (is_vector_field_v<FieldType>));
286 std::array<FieldType, n_args> k_arr_on_patch;
287 FieldType k_total_on_patch = k_total.template get<Patch>();
288 for (std::size_t i(0); i < n_args; ++i) {
289 k_arr_on_patch[i] = k_arr[i].template get<Patch>();
291 if constexpr (is_vector_field_v<FieldType>) {
307 template <
typename P>
312 void assemble_multipatch_field_k_total(
313 ExecSpace
const& exec_space,
318 ((assemble_multipatch_field_k_total_on_patch<Patches>(exec_space, k_total, func, k_arr)),
See DerivFieldMemImplementation.
Definition derivative_field.hpp:10
See DerivFieldImplementation.
Definition derivative_field.hpp:20
The superclass from which all timestepping methods inherit.
Definition itimestepper.hpp:23
typename FieldMem::discrete_domain_type IdxRange
The type of the index range on which the values of the function are defined.
Definition itimestepper.hpp:46
void assemble_vector_field_k_total(ExecSpace const &exec_space, FieldType k_total, FuncType func, std::array< FieldType, n_args > k_arr) const
Calculate func(k_arr[0], k_arr[1], ...) when FieldType is a VectorField.
Definition itimestepper.hpp:241
void assemble_k_total(ExecSpace const &exec_space, DerivField k_total, FuncType func, T... k) const
A method to assemble multiple derivative fields into one.
Definition itimestepper.hpp:182
typename DerivFieldMem::view_type DerivConstField
The constant type of the derivatives values of the function being evolved.
Definition itimestepper.hpp:59
void update(ExecSpace const &exec_space, ValField y, double dt, std::function< void(DerivField, ValConstField)> dy_calculator) const
Carry out one step of the timestepping scheme.
Definition itimestepper.hpp:102
virtual void update(ExecSpace const &exec_space, ValField y, double dt, std::function< void(DerivField, ValConstField)> dy_calculator, std::function< void(ValField, DerivConstField, double)> y_update) const =0
Carry out one step of the timestepping scheme.
typename FieldMem::span_type ValField
The type of the values of the function being evolved.
Definition itimestepper.hpp:50
void update(ValField y, double dt, std::function< void(DerivField, ValConstField)> dy_calculator) const
Carry out one step of the timestepping scheme.
Definition itimestepper.hpp:78
void copy(ValField copy_to, ValConstField copy_from) const
Make a copy of the values of the function being evolved.
Definition itimestepper.hpp:147
void assemble_field_k_total(ExecSpace const &exec_space, FieldType k_total, FuncType func, std::array< FieldType, n_args > k_arr) const
Calculate func(k_arr[0], k_arr[1], ...) when FieldType is a Field (ddc::ChunkSpan).
Definition itimestepper.hpp:211
typename FieldMem::view_type ValConstField
The constant type of the values of the function being evolved.
Definition itimestepper.hpp:53
static KOKKOS_FUNCTION void fill_k_total(DerivFieldType k_total, Idx i, Coord< DDims... > new_val)
A method to fill an element of a vector field.
Definition itimestepper.hpp:164
A class to store field objects on patches.
Definition multipatch_field.hpp:30
Base tag for a patch.
Definition patch.hpp:14
A class which describes the real space in the temporal direction.
Definition geometry.hpp:44