16#include <Kokkos_Core.hpp>
56template <
class ChunkType>
57void display(
double time, ChunkType temp)
59 double const mean_temp
61 / temp.domain().size();
63 std::cout << std::fixed << std::setprecision(3);
64 std::cout <<
"At t = " << time <<
",\n";
65 std::cout <<
" * mean temperature = " << mean_temp <<
'\n';
66 std::cout <<
" * temperature[y:" << slice_id.value() <<
"] = ";
68 std::cout <<
'\n' << std::flush;
72int main(
int argc,
char** argv)
74 Kokkos::ScopeGuard
const kokkos_scope(argc, argv);
79 double const x_start = -1.;
80 double const x_end = 1.;
81 std::size_t
const nb_x_points = 10;
82 double const kx = .01;
85 double const y_start = -1.;
86 double const y_end = 1.;
87 std::size_t
const nb_y_points = 100;
88 double const ky = .002;
91 double const start_time = 0.;
92 double const end_time = 10.;
94 std::ptrdiff_t
const t_output_period = 10;
102 auto const [x_domain, ghosted_x_domain, x_pre_ghost, x_post_ghost]
112 x_post_mirror(x_post_ghost.front() - x_domain.extents(), x_post_ghost.extents());
114 x_pre_mirror(x_pre_ghost.front() + x_domain.extents(), x_pre_ghost.extents());
120 auto const [y_domain, ghosted_y_domain, y_pre_ghost, y_post_ghost]
128 y_post_mirror(y_post_ghost.front() - y_domain.extents(), y_post_ghost.extents());
131 y_pre_mirror(y_pre_ghost.front() + y_domain.extents(), y_pre_ghost.extents());
137 double const invdx2 = 1. / (dx * dx);
138 double const invdy2 = 1. / (dy * dy);
175 ghosted_initial_temp(ixy) = 9.999 * ((x * x + y * y) < 0.25);
197 time_domain.remove_first(
ddc::DiscreteVector<DDimT>(1))) {
203 ghosted_last_temp[x_pre_ghost[ix]][y_domain],
204 ghosted_last_temp[x_pre_mirror[ix]][y_domain]);
208 ghosted_last_temp[x_post_ghost[ix]][y_domain],
209 ghosted_last_temp[x_post_mirror[ix]][y_domain]);
213 ghosted_last_temp[x_domain][y_pre_ghost[iy]],
214 ghosted_last_temp[x_domain][y_pre_mirror[iy]]);
218 ghosted_last_temp[x_domain][y_post_ghost[iy]],
219 ghosted_last_temp[x_domain][y_post_mirror[iy]]);
237 next_temp(ix, iy) = last_temp(ix, iy);
238 next_temp(ix, iy) += kx * dt
239 * (last_temp(ix + 1, iy) - 2.0 * last_temp(ix, iy)
240 + last_temp(ix - 1, iy))
243 next_temp(ix, iy) += ky * dt
244 * (last_temp(ix, iy + 1) - 2.0 * last_temp(ix, iy)
245 + last_temp(ix, iy - 1))
251 if (iter - last_output_iter >= t_output_period) {
252 last_output_iter = iter;
260 std::swap(ghosted_last_temp, ghosted_next_temp);
265 if (last_output_iter < time_domain.
back()) {
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.
std::ostream & print_content(std::ostream &os, ChunkSpan< ElementType, SupportType, LayoutStridedPolicy, MemorySpace > const &chunk_span)
Print the content of a ChunkSpan.
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 DDims::continuous_dimension_type... > coordinate(DiscreteElement< DDims... > const &c)
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
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)