11 #include <Kokkos_Core.hpp>
45 template <
class ChunkType>
46 void display(
double time, ChunkType temp)
53 / temp.domain().size();
54 std::cout << std::fixed << std::setprecision(3);
55 std::cout <<
"At t = " << time <<
",\n";
56 std::cout <<
" * mean temperature = " << mean_temp <<
"\n";
59 = temp[ddc::get_domain<DDimY>(temp).front()
60 + ddc::get_domain<DDimY>(temp).size() / 2];
61 std::cout <<
" * temperature[y:"
62 << ddc::get_domain<DDimY>(temp).size() / 2 <<
"] = {";
65 ddc::get_domain<DDimX>(temp),
67 std::cout << std::setw(6) << temp_slice(ix);
69 std::cout <<
" }" << std::endl;
75 int main(
int argc,
char** argv)
84 double const x_start = -1.;
86 double const x_end = 1.;
88 size_t const nb_x_points = 10;
90 double const kx = .01;
92 double const y_start = -1.;
94 double const y_end = 1.;
96 size_t const nb_y_points = 100;
98 double const ky = .002;
100 double const start_time = 0.;
102 double const end_time = 10.;
104 size_t const t_output_period = 10;
116 auto const [x_domain, ghosted_x_domain, x_pre_ghost, x_post_ghost]
128 x_domain_begin(x_domain.front(), x_post_ghost.extents());
132 x_domain.back() - x_pre_ghost.extents() + 1,
133 x_pre_ghost.extents());
142 auto const [y_domain, ghosted_y_domain, y_pre_ghost, y_post_ghost]
152 y_domain_begin(y_domain.front(), y_post_ghost.extents());
156 y_domain.back() - y_pre_ghost.extents() + 1,
157 y_pre_ghost.extents());
180 .5 / (kx * invdx2_max + ky * invdy2_max)};
184 std::ceil((end_time - start_time) / max_dt) + .2};
202 DDimY>(ghosted_x_domain, ghosted_y_domain),
209 DDimY>(ghosted_x_domain, ghosted_y_domain),
215 = ghosted_last_temp.span_view();
221 double const x =
coordinate(ddc::select<DDimX>(ixy));
222 double const y =
coordinate(ddc::select<DDimY>(ixy));
223 ghosted_initial_temp(ixy)
224 = 9.999 * ((x * x + y * y) < 0.25);
231 DDimY>(ghosted_x_domain, ghosted_y_domain),
239 ghosted_temp[x_domain][y_domain]);
245 for (
auto const iter :
252 ghosted_last_temp[x_pre_ghost][y_domain],
253 ghosted_last_temp[y_domain][x_domain_end]);
255 ghosted_last_temp[y_domain][x_post_ghost],
256 ghosted_last_temp[y_domain][x_domain_begin]);
258 ghosted_last_temp[x_domain][y_pre_ghost],
259 ghosted_last_temp[x_domain][y_domain_end]);
261 ghosted_last_temp[x_domain][y_post_ghost],
262 ghosted_last_temp[x_domain][y_domain_begin]);
269 ghosted_next_temp[x_domain][y_domain]};
282 = ddc::select<DDimX>(ixy);
284 = ddc::select<DDimY>(ixy);
287 double const dx_m = 0.5 * (dx_l + dx_r);
290 double const dy_m = 0.5 * (dy_l + dy_r);
291 next_temp(ix, iy) = last_temp(ix, iy);
294 * (dx_l * last_temp(ix + 1, iy)
295 - 2.0 * dx_m * last_temp(ix, iy)
296 + dx_r * last_temp(ix - 1, iy))
297 / (dx_l * dx_m * dx_r);
300 * (dy_l * last_temp(ix, iy + 1)
301 - 2.0 * dy_m * last_temp(ix, iy)
302 + dy_r * last_temp(ix, iy - 1))
303 / (dy_l * dy_m * dy_r);
308 if (iter - last_output >= t_output_period) {
311 display(
coordinate(iter), ghosted_temp[x_domain][y_domain]);
317 std::swap(ghosted_last_temp, ghosted_next_temp);
322 if (last_output < time_domain.
back()) {
325 ghosted_temp[x_domain][y_domain]);
Definition: discrete_domain.hpp:24
constexpr discrete_element_type back() const noexcept
Definition: discrete_domain.hpp:132
constexpr discrete_element_type front() const noexcept
Definition: discrete_domain.hpp:127
constexpr DiscreteDomain remove_first(mlength_type n) const
Definition: discrete_domain.hpp:147
A DiscreteElement identifies an element of the discrete dimension.
Definition: discrete_element.hpp:124
A DiscreteVector is a vector in the discrete dimension.
Definition: discrete_vector.hpp:208
Definition: kokkos_allocator.hpp:14
Definition: scope_guard.hpp:14
constexpr parallel_device_policy parallel_device
Definition: for_each.hpp:173
constexpr serial_host_policy serial_host
Definition: for_each.hpp:171
T transform_reduce([[maybe_unused]] serial_host_policy policy, DiscreteDomain< DDims... > const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain using the Serial execution policy.
Definition: transform_reduce.hpp:231
ddc::Coordinate< QueryDDims... > coordinate(DiscreteDomain< DDims... > const &domain, DiscreteElement< QueryDDims... > const &icoord) noexcept
Definition: discrete_domain.hpp:261
DDC_INLINE_FUNCTION Coordinate< CDim > distance_at_left(DiscreteElement< NonUniformPointSampling< CDim >> i)
Definition: non_uniform_point_sampling.hpp:144
auto deepcopy(ChunkDst &&dst, ChunkSrc &&src)
Copy the content of a borrowed chunk into another.
Definition: deepcopy.hpp:19
void init_discrete_space(Args &&... args)
Initialize (emplace) a global singleton discrete space.
Definition: discrete_space.hpp:109
DDC_INLINE_FUNCTION Coordinate< CDim > distance_at_right(DiscreteElement< NonUniformPointSampling< CDim >> i)
Definition: non_uniform_point_sampling.hpp:151
void for_each(serial_host_policy, DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using the serial execution policy
Definition: for_each.hpp:101
ddc_detail::TaggedVector< CoordinateElement, CDims... > Coordinate
A Coordinate represents a coordinate in the continuous space.
Definition: coordinate.hpp:19
Definition: chunk_span.hpp:26
Definition: reducer.hpp:96
Definition: reducer.hpp:10