15#include <Kokkos_Core.hpp>
49template <
class ChunkType>
50void display(
double time, ChunkType temp)
52 double const mean_temp
54 / temp.domain().size();
55 std::cout << std::fixed << std::setprecision(3);
56 std::cout <<
"At t = " << time <<
",\n";
57 std::cout <<
" * mean temperature = " << mean_temp <<
"\n";
62 std::cout << std::setw(6) << temp_slice(ix);
64 std::cout <<
" }\n" << std::flush;
68int main(
int argc,
char** argv)
70 Kokkos::ScopeGuard
const kokkos_scope(argc, argv);
75 double const x_start = -1.;
76 double const x_end = 1.;
77 std::size_t
const nb_x_points = 10;
78 double const kx = .01;
81 double const y_start = -1.;
82 double const y_end = 1.;
83 std::size_t
const nb_y_points = 100;
84 double const ky = .002;
87 double const start_time = 0.;
88 double const end_time = 10.;
90 std::ptrdiff_t
const t_output_period = 10;
98 auto const [x_domain, ghosted_x_domain, x_pre_ghost, x_post_ghost]
108 x_post_mirror(x_post_ghost.front() - x_domain.extents(), x_post_ghost.extents());
110 x_pre_mirror(x_pre_ghost.front() + x_domain.extents(), x_pre_ghost.extents());
116 auto const [y_domain, ghosted_y_domain, y_pre_ghost, y_post_ghost]
124 y_post_mirror(y_post_ghost.front() - y_domain.extents(), y_post_ghost.extents());
127 y_pre_mirror(y_pre_ghost.front() + y_domain.extents(), y_pre_ghost.extents());
133 double const invdx2 = 1. / (dx * dx);
134 double const invdy2 = 1. / (dy * dy);
171 ghosted_initial_temp(ixy) = 9.999 * ((x * x + y * y) < 0.25);
193 time_domain.remove_first(
ddc::DiscreteVector<DDimT>(1))) {
199 ghosted_last_temp[x_pre_ghost[ix]][y_domain],
200 ghosted_last_temp[x_pre_mirror[ix]][y_domain]);
204 ghosted_last_temp[x_post_ghost[ix]][y_domain],
205 ghosted_last_temp[x_post_mirror[ix]][y_domain]);
209 ghosted_last_temp[x_domain][y_pre_ghost[iy]],
210 ghosted_last_temp[x_domain][y_pre_mirror[iy]]);
214 ghosted_last_temp[x_domain][y_post_ghost[iy]],
215 ghosted_last_temp[x_domain][y_post_mirror[iy]]);
233 next_temp(ix, iy) = last_temp(ix, iy);
234 next_temp(ix, iy) += kx * dt
235 * (last_temp(ix + 1, iy) - 2.0 * last_temp(ix, iy)
236 + last_temp(ix - 1, iy))
239 next_temp(ix, iy) += ky * dt
240 * (last_temp(ix, iy + 1) - 2.0 * last_temp(ix, iy)
241 + last_temp(ix, iy - 1))
247 if (iter - last_output_iter >= t_output_period) {
248 last_output_iter = iter;
256 std::swap(ghosted_last_temp, ghosted_next_temp);
261 if (last_output_iter < time_domain.
back()) {
KOKKOS_FUNCTION constexpr size_type size() const noexcept
KOKKOS_FUNCTION constexpr span_type span_view() const
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.
The top-level namespace of DDC.
auto parallel_deepcopy(ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
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(Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain in serial.
detail::TaggedVector< CoordinateElement, CDims... > Coordinate
A Coordinate represents a coordinate in the continuous space.
std::ptrdiff_t DiscreteVectorElement
A DiscreteVectorElement is a scalar that represents the difference between two coordinates.
void parallel_for_each(std::string const &label, ExecSpace const &execution_space, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
void for_each(Support const &domain, Functor &&f) noexcept
iterates over a nD domain in serial
auto create_mirror(Space const &space, ChunkSpan< ElementType, Support, Layout, MemorySpace > const &src)