Skip to content

Commit

Permalink
Add missing ddc namespace on for_each in geometryRTheta
Browse files Browse the repository at this point in the history
Closes #195

See merge request gysela-developpers/gyselalibxx!418

--------------------------------------------

Co-authored-by: Pauline Vidal <[email protected]>
  • Loading branch information
EmilyBourne and PaulineVidal committed Mar 25, 2024
1 parent 0604ad9 commit 1c3b003
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion simulations/geometryRTheta/diocotron/diocotron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int main(int argc, char** argv)
DFieldRP rho_eq(grid);

// Initialize rho and rho equilibrium ****************************
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
rho(irp) = exact_rho.initialisation(coords(irp));
rho_eq(irp) = exact_rho.equilibrium(coords(irp));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class VortexMergerEquilibria
DFieldRP sigma_0(grid);
DFieldRP phi_eq(grid);
const double sig = 0.3;
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
const CoordRP coord_rp(ddc::coordinate(irp));
const CoordXY coord_xy(m_mapping(coord_rp));
const double x = ddc::get<RDimX>(coord_xy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class VortexMergerDensitySolution
IDomainRP grid = ddc::get_domain<IDimR, IDimP>(rho_init);

// Initialisation:
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
const CoordRP coord_rp(ddc::coordinate(irp));
const CoordXY coord_xy(m_mapping(coord_rp));
const double x = ddc::get<RDimX>(coord_xy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Interpolation_on_random_coord(

// Evaluation of the function on the grid. -----------------------------------------------
DFieldRP function_evaluated(grid);
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
CoordRP coord(coordinate(ddc::select<IDimR>(irp)), coordinate(ddc::select<IDimP>(irp)));
function_evaluated(irp) = exact_function(coord);
});
Expand All @@ -75,7 +75,7 @@ void Interpolation_on_random_coord(
int number_p(0);
double random_factor_r;
double random_factor_p;
for_each(random_grid, [&](IndexRP const irp) {
ddc::for_each(random_grid, [&](IndexRP const irp) {
CoordR coord_r(coordinate(ddc::select<IDimR>(irp)));
CoordP coord_p(coordinate(ddc::select<IDimP>(irp)));

Expand Down Expand Up @@ -132,7 +132,7 @@ void Interpolation_on_random_coord(

// Compare the obtained values with the exact function. ----------------------------------
double max_err(0.0);
for_each(random_coords.domain(), [&](IndexRP const irp) {
ddc::for_each(random_coords.domain(), [&](IndexRP const irp) {
double err = fabs(function_interpolated(irp) - exact_function(random_coords(irp)));
max_err = max_err > err ? max_err : err;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void saving_computed(Mapping const& mapping, DSpanRP function, std::string const
std::ofstream out_file(name, std::ofstream::out);
out_file << std::fixed << std::setprecision(16);

for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
IDomainP p_dom = ddc::select<IDimP>(grid);

IndexR const ir(ddc::select<IDimR>(irp));
Expand Down Expand Up @@ -380,7 +380,7 @@ void simulate(
start_simulation = std::chrono::system_clock::now();

// Initialization of the advected function:
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
CoordRP coord = coordinate(irp);
if (ddc::get<RDimR>(coord) <= 1e-15) {
ddc::get<RDimP>(coord) = 0;
Expand All @@ -391,7 +391,7 @@ void simulate(


// Definition of advection field:
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
// Moving the coordinates in the physical domain:
CoordXY const coord_xy = mapping(ddc::coordinate(irp));
CoordXY const advection_field = advection_field_test(coord_xy, 0.);
Expand Down Expand Up @@ -428,7 +428,7 @@ void simulate(

// Compute the maximal absolute error on the space at the end of the simulation:
double max_err = 0.;
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
double const err
= fabs(allfdistribu_advected_test(irp)
- function_to_be_advected_test(feet_coords_rp_end_time(irp)));
Expand Down Expand Up @@ -463,7 +463,7 @@ void simulate(
// Save the computed characteristic feet:
if (if_save_feet) {
FieldRP<CoordRP> feet(grid);
for_each(grid, [&](const IndexRP irp) { feet(irp) = ddc::coordinate(irp); });
ddc::for_each(grid, [&](const IndexRP irp) { feet(irp) = ddc::coordinate(irp); });
foot_finder(feet.span_view(), advection_field_test_vec, dt);
std::string const name = output_folder + "/feet_computed.txt";
save_feet(mapping, grid, feet.span_view(), name);
Expand All @@ -477,7 +477,7 @@ void simulate(

DFieldRP initial_function(grid);
DFieldRP end_function(grid);
for_each(grid, [&](const IndexRP irp) {
ddc::for_each(grid, [&](const IndexRP irp) {
initial_function(irp) = function_to_be_advected_test(ddc::coordinate(irp));

// Exact final state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ TEST(AdvectionFieldRPComputation, TestAdvectionFieldFinder)
auto function = simulation.get_test_function();
auto phi_function = simulation.get_electrostatique_potential();
auto advection_field = simulation.get_advection_field();
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
CoordRP const coord_rp(ddc::coordinate(irp));
CoordXY const coord_xy(mapping(coord_rp));

Expand All @@ -224,7 +224,7 @@ TEST(AdvectionFieldRPComputation, TestAdvectionFieldFinder)
// Compare advection fields ---
VectorDFieldRP<RDimX, RDimY> difference_between_fields_exact_and_xy(grid);
// > Compare the advection field computed on XY to the exact advection field
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
ddcHelper::get<RDimX>(difference_between_fields_exact_and_xy)(irp)
= ddcHelper::get<RDimX>(advection_field_exact)(irp)
- ddcHelper::get<RDimX>(advection_field_xy)(irp);
Expand All @@ -236,7 +236,7 @@ TEST(AdvectionFieldRPComputation, TestAdvectionFieldFinder)

// > Compare the advection field computed on RP to the advection field computed on XY
VectorDFieldRP<RDimX, RDimY> difference_between_fields_xy_and_rp(grid);
for_each(grid_without_Opoint, [&](IndexRP const irp) {
ddc::for_each(grid_without_Opoint, [&](IndexRP const irp) {
CoordRP const coord_rp(ddc::coordinate(irp));

std::array<std::array<double, 2>, 2> J; // Jacobian matrix
Expand All @@ -261,7 +261,7 @@ TEST(AdvectionFieldRPComputation, TestAdvectionFieldFinder)
- ddcHelper::get<RDimY>(advection_field_xy)(irp);
});

for_each(Opoint_grid, [&](IndexRP const irp) {
ddc::for_each(Opoint_grid, [&](IndexRP const irp) {
// computation made in BslAdvectionRP operator:
ddcHelper::get<RDimX>(advection_field_xy_from_rp)(irp) = CoordX(advection_field_xy_center);
ddcHelper::get<RDimY>(advection_field_xy_from_rp)(irp) = CoordY(advection_field_xy_center);
Expand All @@ -276,7 +276,7 @@ TEST(AdvectionFieldRPComputation, TestAdvectionFieldFinder)
});

// --- Check the difference on advection fields --------------------------------------------------
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
EXPECT_LE(abs(ddcHelper::get<RDimX>(difference_between_fields_exact_and_xy)(irp)), 1e-5);
EXPECT_LE(abs(ddcHelper::get<RDimY>(difference_between_fields_exact_and_xy)(irp)), 1e-5);

Expand All @@ -293,7 +293,7 @@ TEST(AdvectionFieldRPComputation, TestAdvectionFieldFinder)
advection_operator(allfdistribu_xy, advection_field_xy, dt);

// Check the advected functions ---
for_each(grid, [&](IndexRP const irp) {
ddc::for_each(grid, [&](IndexRP const irp) {
EXPECT_NEAR(allfdistribu_rp(irp), allfdistribu_xy(irp), 1e-13);
});
}
Expand Down
8 changes: 4 additions & 4 deletions tests/timestepper/crank_nicolson_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ TEST(CrankNicolsonFixture, CrankNicolsonOrder)
DChunkX result(dom);

double exp_val = exp(5.0 * dt * Nt);
for_each(dom, [&](IndexX ix) {
ddc::for_each(dom, [&](IndexX ix) {
double const C = (double(ix.uid()) - 0.6);
result(ix) = C * exp_val + 0.6;
});

for (int j(0); j < Ntests; ++j) {
for_each(dom, [&](IndexX ix) { vals(ix) = double(ix.uid()); });
ddc::for_each(dom, [&](IndexX ix) { vals(ix) = double(ix.uid()); });

for (int i(0); i < Nt; ++i) {
crank_nicolson
.update(vals,
dt,
[&](ChunkSpan<double, IDomainX> dy,
ChunkSpan<double const, IDomainX> y) {
for_each(dom, [&](IndexX ix) { dy(ix) = 5.0 * y(ix) - 3.0; });
ddc::for_each(dom, [&](IndexX ix) { dy(ix) = 5.0 * y(ix) - 3.0; });
});
}

double linf_err = 0.0;
for_each(dom, [&](IndexX ix) {
ddc::for_each(dom, [&](IndexX ix) {
double const err = abs(result(ix) - vals(ix));
linf_err = err > linf_err ? err : linf_err;
});
Expand Down
10 changes: 5 additions & 5 deletions tests/timestepper/crank_nicolson_2d_mixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST(CrankNicolson2DFixtureMixedTypes, CrankNicolson2DOrderMixedTypes)

double cos_val = std::cos(omega * dt * Nt);
double sin_val = std::sin(omega * dt * Nt);
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
double const dist_x = (coordinate(select<IDimX>(ixy)) - xc);
double const dist_y = (coordinate(select<IDimY>(ixy)) - yc);

Expand All @@ -95,26 +95,26 @@ TEST(CrankNicolson2DFixtureMixedTypes, CrankNicolson2DOrderMixedTypes)
});

for (int j(0); j < Ntests; ++j) {
for_each(dom, [&](IndexXY ixy) { vals(ixy) = coordinate(ixy); });
ddc::for_each(dom, [&](IndexXY ixy) { vals(ixy) = coordinate(ixy); });

for (int i(0); i < Nt; ++i) {
crank_nicolson.update(
Kokkos::DefaultHostExecutionSpace(),
vals,
dt,
[yc, xc, &dom, omega](AdvectionFieldSpan dy, ChunkView<CoordXY, IDomainXY> y) {
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
ddcHelper::get<RDimX>(dy)(ixy) = omega * (yc - ddc::get<RDimY>(y(ixy)));
ddcHelper::get<RDimY>(dy)(ixy) = omega * (ddc::get<RDimX>(y(ixy)) - xc);
});
},
[&dom](ChunkSpan<CoordXY, IDomainXY> y, AdvectionFieldView dy, double dt) {
for_each(dom, [&](IndexXY ixy) { y(ixy) += dt * dy(ixy); });
ddc::for_each(dom, [&](IndexXY ixy) { y(ixy) += dt * dy(ixy); });
});
}

double linf_err = 0.0;
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
double const err_x = ddc::get<RDimX>(result(ixy) - vals(ixy));
double const err_y = ddc::get<RDimY>(result(ixy) - vals(ixy));
double const err = std::sqrt(err_x * err_x + err_y * err_y);
Expand Down
8 changes: 4 additions & 4 deletions tests/timestepper/euler_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ TEST(EulerFixture, EulerOrder)
DChunkX result(dom);

double exp_val = exp(5.0 * dt * Nt);
for_each(dom, [&](IndexX ix) {
ddc::for_each(dom, [&](IndexX ix) {
double const C = (double(ix.uid()) - 0.6);
result(ix) = C * exp_val + 0.6;
});

for (int j(0); j < Ntests; ++j) {
for_each(dom, [&](IndexX ix) { vals(ix) = double(ix.uid()); });
ddc::for_each(dom, [&](IndexX ix) { vals(ix) = double(ix.uid()); });

for (int i(0); i < Nt; ++i) {
euler
.update(vals,
dt,
[&](ChunkSpan<double, IDomainX> dy,
ChunkSpan<double const, IDomainX> y) {
for_each(dom, [&](IndexX ix) { dy(ix) = 5.0 * y(ix) - 3.0; });
ddc::for_each(dom, [&](IndexX ix) { dy(ix) = 5.0 * y(ix) - 3.0; });
});
}

double linf_err = 0.0;
for_each(dom, [&](IndexX ix) {
ddc::for_each(dom, [&](IndexX ix) {
double const err = abs(result(ix) - vals(ix));
linf_err = err > linf_err ? err : linf_err;
});
Expand Down
10 changes: 5 additions & 5 deletions tests/timestepper/euler_2d_mixed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST(Euler2DFixtureMixedTypes, Euler2DOrderMixedTypes)

double cos_val = std::cos(omega * dt * Nt);
double sin_val = std::sin(omega * dt * Nt);
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
double const dist_x = (coordinate(select<IDimX>(ixy)) - xc);
double const dist_y = (coordinate(select<IDimY>(ixy)) - yc);

Expand All @@ -95,26 +95,26 @@ TEST(Euler2DFixtureMixedTypes, Euler2DOrderMixedTypes)
});

for (int j(0); j < Ntests; ++j) {
for_each(dom, [&](IndexXY ixy) { vals(ixy) = coordinate(ixy); });
ddc::for_each(dom, [&](IndexXY ixy) { vals(ixy) = coordinate(ixy); });

for (int i(0); i < Nt; ++i) {
euler.update(
Kokkos::DefaultHostExecutionSpace(),
vals,
dt,
[yc, xc, &dom, omega](AdvectionFieldSpan dy, ChunkView<CoordXY, IDomainXY> y) {
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
ddcHelper::get<RDimX>(dy)(ixy) = omega * (yc - ddc::get<RDimY>(y(ixy)));
ddcHelper::get<RDimY>(dy)(ixy) = omega * (ddc::get<RDimX>(y(ixy)) - xc);
});
},
[&dom](ChunkSpan<CoordXY, IDomainXY> y, AdvectionFieldView dy, double dt) {
for_each(dom, [&](IndexXY ixy) { y(ixy) += dt * dy(ixy); });
ddc::for_each(dom, [&](IndexXY ixy) { y(ixy) += dt * dy(ixy); });
});
}

double linf_err = 0.0;
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
double const err_x = ddc::get<RDimX>(result(ixy) - vals(ixy));
double const err_y = ddc::get<RDimY>(result(ixy) - vals(ixy));
double const err = std::sqrt(err_x * err_x + err_y * err_y);
Expand Down
8 changes: 4 additions & 4 deletions tests/timestepper/runge_kutta_1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ TYPED_TEST(RungeKuttaFixture, RungeKuttaOrder)
DChunkX result(dom);

double exp_val = exp(5.0 * dt * Nt);
for_each(dom, [&](IndexX ix) {
ddc::for_each(dom, [&](IndexX ix) {
double const C = (double(ix.uid()) - 0.6);
result(ix) = C * exp_val + 0.6;
});

for (int j(0); j < Ntests; ++j) {
for_each(dom, [&](IndexX ix) { vals(ix) = double(ix.uid()); });
ddc::for_each(dom, [&](IndexX ix) { vals(ix) = double(ix.uid()); });

for (int i(0); i < Nt; ++i) {
runge_kutta
.update(vals,
dt,
[&](ChunkSpan<double, IDomainX> dy,
ChunkSpan<double const, IDomainX> y) {
for_each(dom, [&](IndexX ix) { dy(ix) = 5.0 * y(ix) - 3.0; });
ddc::for_each(dom, [&](IndexX ix) { dy(ix) = 5.0 * y(ix) - 3.0; });
});
}

double linf_err = 0.0;
for_each(dom, [&](IndexX ix) {
ddc::for_each(dom, [&](IndexX ix) {
double const err = abs(result(ix) - vals(ix));
linf_err = err > linf_err ? err : linf_err;
});
Expand Down
10 changes: 5 additions & 5 deletions tests/timestepper/runge_kutta_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ TYPED_TEST(RungeKutta2DFixture, RungeKutta2DOrder)

double cos_val = std::cos(omega * dt * Nt);
double sin_val = std::sin(omega * dt * Nt);
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
double const dist_x = (coordinate(select<IDimX>(ixy)) - xc);
double const dist_y = (coordinate(select<IDimY>(ixy)) - yc);

Expand All @@ -132,7 +132,7 @@ TYPED_TEST(RungeKutta2DFixture, RungeKutta2DOrder)
});

for (int j(0); j < Ntests; ++j) {
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
ddcHelper::get<RDimX>(vals)(ixy) = coordinate(select<IDimX>(ixy));
ddcHelper::get<RDimY>(vals)(ixy) = coordinate(select<IDimY>(ixy));
});
Expand All @@ -143,23 +143,23 @@ TYPED_TEST(RungeKutta2DFixture, RungeKutta2DOrder)
vals,
dt,
[yc, xc, &dom, omega](AdvectionFieldSpan dy, AdvectionFieldView y) {
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
ddcHelper::get<RDimX>(dy)(ixy)
= omega * (yc - ddcHelper::get<RDimY>(y)(ixy));
ddcHelper::get<RDimY>(dy)(ixy)
= omega * (ddcHelper::get<RDimX>(y)(ixy) - xc);
});
},
[&dom](AdvectionFieldSpan y, AdvectionFieldView dy, double dt) {
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
ddcHelper::get<RDimX>(y)(ixy) += ddcHelper::get<RDimX>(dy)(ixy) * dt;
ddcHelper::get<RDimY>(y)(ixy) += ddcHelper::get<RDimY>(dy)(ixy) * dt;
});
});
}

double linf_err = 0.0;
for_each(dom, [&](IndexXY ixy) {
ddc::for_each(dom, [&](IndexXY ixy) {
double const err_x
= ddcHelper::get<RDimX>(result)(ixy) - ddcHelper::get<RDimX>(vals)(ixy);
double const err_y
Expand Down
Loading

0 comments on commit 1c3b003

Please sign in to comment.