16#include <Kokkos_Core.hpp>
50template <
class ChunkType>
51void display(
double time, ChunkType temp)
53 double const mean_temp
55 / temp.domain().size();
56 std::cout << std::fixed << std::setprecision(3);
57 std::cout <<
"At t = " << time <<
",\n";
58 std::cout <<
" * mean temperature = " << mean_temp <<
"\n";
63 std::cout << std::setw(6) << temp_slice(ix);
65 std::cout <<
" }\n" << std::flush;
69int main(
int argc,
char** argv)
71 Kokkos::ScopeGuard
const kokkos_scope(argc, argv);
76 double const x_start = -1.;
77 double const x_end = 1.;
78 std::size_t
const nb_x_points = 10;
79 double const kx = .01;
82 double const y_start = -1.;
83 double const y_end = 1.;
84 std::size_t
const nb_y_points = 100;
85 double const ky = .002;
88 double const start_time = 0.;
89 double const end_time = 10.;
91 std::ptrdiff_t
const t_output_period = 10;
99 auto const [x_domain, ghosted_x_domain, x_pre_ghost, x_post_ghost]
109 x_post_mirror(x_post_ghost.front() - x_domain.extents(), x_post_ghost.extents());
111 x_pre_mirror(x_pre_ghost.front() + x_domain.extents(), x_pre_ghost.extents());
117 auto const [y_domain, ghosted_y_domain, y_pre_ghost, y_post_ghost]
125 y_post_mirror(y_post_ghost.front() - y_domain.extents(), y_post_ghost.extents());
128 y_pre_mirror(y_pre_ghost.front() + y_domain.extents(), y_pre_ghost.extents());
134 double const invdx2 = 1. / (dx * dx);
135 double const invdy2 = 1. / (dy * dy);
172 ghosted_initial_temp(ixy) = 9.999 * ((x * x + y * y) < 0.25);
194 time_domain.remove_first(
ddc::DiscreteVector<DDimT>(1))) {
200 ghosted_last_temp[x_pre_ghost[ix]][y_domain],
201 ghosted_last_temp[x_pre_mirror[ix]][y_domain]);
205 ghosted_last_temp[x_post_ghost[ix]][y_domain],
206 ghosted_last_temp[x_post_mirror[ix]][y_domain]);
210 ghosted_last_temp[x_domain][y_pre_ghost[iy]],
211 ghosted_last_temp[x_domain][y_pre_mirror[iy]]);
215 ghosted_last_temp[x_domain][y_post_ghost[iy]],
216 ghosted_last_temp[x_domain][y_post_mirror[iy]]);
234 next_temp(ix, iy) = last_temp(ix, iy);
235 next_temp(ix, iy) += kx * dt
236 * (last_temp(ix + 1, iy) - 2.0 * last_temp(ix, iy)
237 + last_temp(ix - 1, iy))
240 next_temp(ix, iy) += ky * dt
241 * (last_temp(ix, iy + 1) - 2.0 * last_temp(ix, iy)
242 + last_temp(ix, iy - 1))
248 if (iter - last_output_iter >= t_output_period) {
249 last_output_iter = iter;
257 std::swap(ghosted_last_temp, ghosted_next_temp);
262 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.
T host_transform_reduce(Support const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction 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.
void host_for_each(Support const &domain, Functor &&f) noexcept
iterates 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
auto create_mirror(Space const &space, ChunkSpan< ElementType, Support, Layout, MemorySpace > const &src)