15#include <Kokkos_Core.hpp>
16#if defined(DDC_EXAMPLE_WITH_PDI)
55template <
class ChunkType>
56void display(
double time, ChunkType temp)
63 / temp.domain().size();
64 std::cout << std::fixed << std::setprecision(3);
65 std::cout <<
"At t = " << time <<
",\n";
66 std::cout <<
" * mean temperature = " << mean_temp <<
"\n";
70 std::cout <<
" * temperature[y:"
75 std::cout << std::setw(6) << temp_slice(ix);
77 std::cout <<
" }\n" << std::flush;
79#if defined(DDC_EXAMPLE_WITH_PDI)
88int main(
int argc,
char** argv)
90#if defined(DDC_EXAMPLE_WITH_PDI)
91 PC_tree_t pdi_conf = PC_parse_string(
"");
94 Kokkos::ScopeGuard
const kokkos_scope(argc, argv);
99 double const x_start = -1.;
100 double const x_end = 1.;
101 std::size_t
const nb_x_points = 10;
102 double const kx = .01;
105 double const y_start = -1.;
106 double const y_end = 1.;
107 std::size_t
const nb_y_points = 100;
108 double const ky = .002;
111 double const start_time = 0.;
112 double const end_time = 10.;
114 std::ptrdiff_t
const t_output_period = 10;
122 auto const [x_domain, ghosted_x_domain, x_pre_ghost, x_post_ghost]
132 x_domain_begin(x_domain.front(), x_post_ghost.extents());
134 x_domain.back() - x_pre_ghost.extents() + 1,
135 x_pre_ghost.extents());
141 auto const [y_domain, ghosted_y_domain, y_pre_ghost, y_post_ghost]
149 y_domain_begin(y_domain.front(), y_post_ghost.extents());
152 y_domain.back() - y_pre_ghost.extents() + 1,
153 y_pre_ghost.extents());
159 double const invdx2 = 1. / (dx * dx);
160 double const invdy2 = 1. / (dy * dy);
167 std::ceil((end_time - start_time) / dt) + .2);
181 DDimY>(ghosted_x_domain, ghosted_y_domain),
188 DDimY>(ghosted_x_domain, ghosted_y_domain),
194 = ghosted_last_temp.span_view();
205 ghosted_initial_temp(ixy)
206 = 9.999 * ((x * x + y * y) < 0.25);
221 ghosted_temp[x_domain][y_domain]);
230 time_domain.remove_first(
ddc::DiscreteVector<DDimT>(1))) {
237 DDimY>(x_pre_ghost, y_domain)],
240 DDimY>(y_domain, x_domain_end)]);
244 DDimY>(y_domain, x_post_ghost)],
247 DDimY>(y_domain, x_domain_begin)]);
251 DDimY>(x_domain, y_pre_ghost)],
254 DDimY>(x_domain, y_domain_end)]);
258 DDimY>(x_domain, y_post_ghost)],
261 DDimY>(x_domain, y_domain_begin)]);
268 DDimY>(x_domain, y_domain)]);
281 next_temp(ix, iy) = last_temp(ix, iy);
282 next_temp(ix, iy) += kx * dt
283 * (last_temp(ix + 1, iy)
284 - 2.0 * last_temp(ix, iy)
285 + last_temp(ix - 1, iy))
288 next_temp(ix, iy) += ky * dt
289 * (last_temp(ix, iy + 1)
290 - 2.0 * last_temp(ix, iy)
291 + last_temp(ix, iy - 1))
297 if (iter - last_output_iter >= t_output_period) {
298 last_output_iter = iter;
303 DDimY>(x_domain, y_domain)]);
308 std::swap(ghosted_last_temp, ghosted_next_temp);
313 if (last_output_iter < time_domain.
back()) {
318 DDimY>(x_domain, y_domain)]);
322#if defined(DDC_EXAMPLE_WITH_PDI)
324 PC_tree_destroy(&pdi_conf);
KOKKOS_FUNCTION constexpr discrete_element_type front() const noexcept
KOKKOS_FUNCTION constexpr discrete_element_type back() const noexcept
A DiscreteElement identifies an element of the discrete dimension.
A DiscreteVector is a vector in the discrete dimension.
PdiEvent & and_with(std::string const &name, T &&t)
PdiEvent & with(std::string const &name, BorrowedChunk &&data)
The top-level namespace of DDC.
auto parallel_deepcopy(ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
void for_each(DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain in serial
KOKKOS_FUNCTION Coordinate< typename DDim::continuous_dimension_type... > coordinate(DiscreteElement< DDim... > const &c)
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
T transform_reduce(DiscreteDomain< DDims... > const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain in serial.
void parallel_for_each(std::string const &label, ExecSpace const &execution_space, DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
detail::TaggedVector< CoordinateElement, CDims... > Coordinate
A Coordinate represents a coordinate in the continuous space.
auto create_mirror(Space const &space, ChunkSpan< ElementType, Support, Layout, MemorySpace > const &src)