Skip to content

Commit

Permalink
Prepare r,theta advection tests for GPU (#110)
Browse files Browse the repository at this point in the history
Simplify r,theta advection tests to help with porting. Unnecessary
inheritance is removed. This inheritance prevents the methods from being
called from GPU. `KOKKOS_FUNCTION` tags are added to allow the test
classes to be used on the GPU for tests
  • Loading branch information
EmilyBourne authored Feb 24, 2025
1 parent 131f624 commit 5399bc4
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 479 deletions.
28 changes: 18 additions & 10 deletions tests/geometryRTheta/advection_2d_rp/advection_all_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ struct SimulationParameters
LogicalToPseudoPhysicalMapping const& pseudo_cart_map,
AnalyticalPhysicalToLogicalMapping const& rev_map,
AnalyticalLogicalToPhysicalMapping const& a_map,
std::string m_name,
std::string dom_name)
std::string const& map_name,
std::string const& dom_name)
: to_physical_mapping_host(map_host)
, to_physical_mapping(map)
, to_logical_mapping(rev_map)
, analytical_to_pseudo_physical_mapping(pseudo_cart_map)
, analytical_to_physical_mapping(a_map)
, mapping_name(m_name)
, mapping_name(map_name)
, domain_name(dom_name)
{
}
Expand All @@ -105,7 +105,7 @@ struct NumericalMethodParameters
TimeStepper time_stepper;
double time_step;
std::string method_name;
NumericalMethodParameters(TimeStepper&& time_stepper, double step, std::string name)
NumericalMethodParameters(TimeStepper&& time_stepper, double step, std::string const& name)
: time_stepper(std::move(time_stepper))
, time_step(step)
, method_name(name)
Expand All @@ -119,7 +119,7 @@ struct NumericalParams
IdxRangeRTheta const grid;
double const dt;

NumericalParams(IdxRangeRTheta grid, double dt) : grid(grid), dt(dt) {};
NumericalParams(IdxRangeRTheta grid, double dt) : grid(grid), dt(dt) {}
NumericalParams(NumericalParams&& params) = default;
NumericalParams(NumericalParams& params) = default;
};
Expand Down Expand Up @@ -215,17 +215,25 @@ void run_simulations_with_methods(
<< to_lower(num.method_name) << "-";
std::string output_stem = output_stream.str();

simulate_the_3_simulations(
SplinePolarFootFinder const foot_finder(
num.time_stepper,
sim.to_physical_mapping,
sim.analytical_to_pseudo_physical_mapping,
params.advection_builder,
params.advection_evaluator);

BslAdvectionRTheta
advection_operator(params.interpolator, foot_finder, sim.to_physical_mapping);

run_simulations(
sim.to_physical_mapping_host,
sim.to_physical_mapping,
sim.to_logical_mapping,
sim.analytical_to_pseudo_physical_mapping,
sim.analytical_to_physical_mapping,
params.grid,
num.time_stepper,
params.interpolator,
params.advection_builder,
params.advection_evaluator,
foot_finder,
advection_operator,
params.final_time,
num.time_step,
params.if_save_curves,
Expand Down
22 changes: 15 additions & 7 deletions tests/geometryRTheta/advection_2d_rp/advection_selected_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,18 @@ int main(int argc, char** argv)

// SELECTION OF THE SIMULATION.
#if defined(TRANSLATION_SIMULATION)
TranslationSimulation simulation(to_physical_mapping_host, rmin, rmax);
AdvectionSimulation simulation
= get_translation_simulation(to_physical_mapping_host, rmin, rmax);
std::string const simu_type = "TRANSLATION";
key += "Translation";

#elif defined(ROTATION_SIMULATION)
RotationSimulation simulation(to_physical_mapping_host, rmin, rmax);
AdvectionSimulation simulation = get_rotation_simulation(to_physical_mapping_host, rmin, rmax);
std::string const simu_type = "ROTATION";
key += "Rotation";

#elif defined(DECENTRED_ROTATION_SIMULATION)
DecentredRotationSimulation simulation(to_physical_mapping_host);
AdvectionSimulation simulation = get_decentred_rotation_simulation(to_physical_mapping_host);
std::string const simu_type = "DECENTRED ROTATION";
key += "Decentred_rotation";
#endif
Expand All @@ -288,6 +289,15 @@ int main(int argc, char** argv)
fs::create_directory(output_folder);
}

SplinePolarFootFinder const foot_finder(
time_stepper,
to_physical_mapping,
logical_to_pseudo_cart_mapping,
builder,
spline_evaluator_extrapol);

BslAdvectionRTheta advection_operator(interpolator, foot_finder, to_physical_mapping);

std::cout << mapping_name << " MAPPING - " << adv_domain_name << " DOMAIN - " << method_name
<< " - " << simu_type << " : " << std::endl;
simulate(
Expand All @@ -297,11 +307,9 @@ int main(int argc, char** argv)
logical_to_pseudo_cart_mapping,
to_physical_analytical_mapping,
grid,
time_stepper,
foot_finder,
advection_operator,
simulation,
interpolator,
builder,
spline_evaluator_extrapol,
final_time,
dt,
save_curves,
Expand Down
97 changes: 38 additions & 59 deletions tests/geometryRTheta/advection_2d_rp/advection_simulation_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ template <
class PhysicalToLogicalMapping,
class LogicalToPseudoPhysicalMapping,
class AnalyticalLogicalToPhysicalMapping,
class TimeStepper,
class PolarFootFinder,
class AdvectionOperator,
class Simulation>
void simulate(
LogicalToPhysicalMappingHost const& to_physical_mapping_host,
Expand All @@ -339,32 +340,15 @@ void simulate(
LogicalToPseudoPhysicalMapping const& analytical_to_pseudo_physical_mapping,
AnalyticalLogicalToPhysicalMapping const& analytical_to_physical_mapping,
IdxRangeRTheta const& grid,
TimeStepper const& time_stepper,
PolarFootFinder const& foot_finder,
AdvectionOperator const& advection_operator,
Simulation& simulation,
PreallocatableSplineInterpolatorRTheta<ddc::NullExtrapolationRule> const&
function_interpolator,
SplineRThetaBuilder const& advection_builder,
SplineRThetaEvaluatorConstBound& advection_evaluator,
double const final_time,
double const dt,
bool save_curves,
bool save_feet,
std::string const& output_folder)
{
SplinePolarFootFinder const foot_finder(
time_stepper,
to_physical_mapping,
analytical_to_pseudo_physical_mapping,
advection_builder,
advection_evaluator);

BslAdvectionRTheta
advection_operator(function_interpolator, foot_finder, to_physical_mapping_host);
auto function_to_be_advected_test = simulation.get_test_function();
auto advection_field_test = simulation.get_advection_field();



// TO CLOCK THE SIMULATION ------------------------------------------------------------------
std::chrono::time_point<std::chrono::system_clock> start_simulation;
std::chrono::time_point<std::chrono::system_clock> end_simulation;
Expand All @@ -391,7 +375,7 @@ void simulate(
if (ddc::get<R>(coord) <= 1e-15) {
ddc::get<Theta>(coord) = 0;
}
allfdistribu_test(irp) = function_to_be_advected_test(coord);
allfdistribu_test(irp) = simulation.advected_function(coord);
});


Expand All @@ -400,7 +384,7 @@ void simulate(
ddc::for_each(grid, [&](IdxRTheta const irp) {
// Moving the coordinates in the physical domain:
CoordXY const coord_xy = to_physical_mapping_host(ddc::coordinate(irp));
CoordXY const advection_field = advection_field_test(coord_xy, 0.);
CoordXY const advection_field = simulation.advection_field(coord_xy, 0.);

// Define the advection field on the physical domain:
ddcHelper::get<X>(advection_field_test_vec_host)(irp) = ddc::get<X>(advection_field);
Expand Down Expand Up @@ -433,13 +417,13 @@ void simulate(
grid,
analytical_to_physical_mapping,
to_logical_mapping,
advection_field_test,
simulation.advection_field,
end_time);
feet_coords_rp_dt = compute_exact_feet_rp(
grid,
analytical_to_physical_mapping,
to_logical_mapping,
advection_field_test,
simulation.advection_field,
dt);


Expand All @@ -448,7 +432,7 @@ void simulate(
ddc::for_each(grid, [&](IdxRTheta const irp) {
double const err
= fabs(allfdistribu_advected_test(irp)
- function_to_be_advected_test(feet_coords_rp_end_time(irp)));
- simulation.advected_function(feet_coords_rp_end_time(irp)));
max_err = max_err > err ? max_err : err;
});

Expand All @@ -464,7 +448,7 @@ void simulate(
to_physical_mapping_host,
grid,
allfdistribu_advected_test,
function_to_be_advected_test,
simulation.advected_function,
get_field(feet_coords_rp_end_time))
<< std::endl;

Expand Down Expand Up @@ -502,10 +486,10 @@ void simulate(
host_t<DFieldMemRTheta> initial_function(grid);
host_t<DFieldMemRTheta> end_function(grid);
ddc::for_each(grid, [&](const IdxRTheta irp) {
initial_function(irp) = function_to_be_advected_test(ddc::coordinate(irp));
initial_function(irp) = simulation.advected_function(ddc::coordinate(irp));

// Exact final state
end_function(irp) = function_to_be_advected_test(feet_coords_rp_end_time(irp));
end_function(irp) = simulation.advected_function(feet_coords_rp_end_time(irp));
});
saving_computed(to_physical_mapping_host, get_field(initial_function), name_0);
saving_computed(to_physical_mapping_host, get_field(end_function), name_1);
Expand Down Expand Up @@ -578,19 +562,17 @@ template <
class PhysicalToLogicalMapping,
class LogicalToPseudoPhysicalMapping,
class AnalyticalLogicalToPhysicalMapping,
class TimeStepper>
void simulate_the_3_simulations(
class PolarFootFinder,
class AdvectionOperator>
void run_simulations(
LogicalToPhysicalMappingHost const& to_physical_mapping_host,
LogicalToPhysicalMapping const& to_physical_mapping,
PhysicalToLogicalMapping const& to_logical_mapping,
LogicalToPseudoPhysicalMapping const& analytical_to_pseudo_physical_mapping,
AnalyticalLogicalToPhysicalMapping const& analytical_to_physical_mapping,
IdxRangeRTheta const& grid,
TimeStepper& time_stepper,
PreallocatableSplineInterpolatorRTheta<ddc::NullExtrapolationRule> const&
function_interpolator,
SplineRThetaBuilder const& advection_builder,
SplineRThetaEvaluatorConstBound& advection_evaluator,
PolarFootFinder const& foot_finder,
AdvectionOperator const& advection_operator,
double const final_time,
double const dt,
bool const& save_curves,
Expand All @@ -602,31 +584,32 @@ void simulate_the_3_simulations(
double const rmin = ddc::coordinate(r_idx_range.front());
double const rmax = ddc::coordinate(r_idx_range.back());

TranslationSimulation simulation_1(to_physical_mapping, rmin, rmax);
RotationSimulation simulation_2(to_physical_mapping, rmin, rmax);
DecentredRotationSimulation simulation_3(to_physical_mapping);
AdvectionSimulation simulation_translation
= get_translation_simulation(to_physical_mapping, rmin, rmax);
AdvectionSimulation simulation_rotation
= get_rotation_simulation(to_physical_mapping, rmin, rmax);
AdvectionSimulation simulation_decentred_rotation
= get_decentred_rotation_simulation(to_physical_mapping);

std::string const title_simu_1 = " TRANSLATION : ";
std::string const title_simu_2 = " ROTATION : ";
std::string const title_simu_3 = " DECENTRED ROTATION : ";
std::string const title_simu_translation = " TRANSLATION : ";
std::string const title_simu_rotation = " ROTATION : ";
std::string const title_simu_decentred_rotation = " DECENTRED ROTATION : ";

std::string output_folder = output_stem + "Translation_output";
if (save_curves or save_feet) {
fs::create_directory(output_folder);
}
std::cout << title + title_simu_1 << std::endl;
std::cout << title + title_simu_translation << std::endl;
simulate(
to_physical_mapping_host,
to_physical_mapping,
to_logical_mapping,
analytical_to_pseudo_physical_mapping,
analytical_to_physical_mapping,
grid,
time_stepper,
simulation_1,
function_interpolator,
advection_builder,
advection_evaluator,
foot_finder,
advection_operator,
simulation_translation,
final_time,
dt,
save_curves,
Expand All @@ -637,19 +620,17 @@ void simulate_the_3_simulations(
if (save_curves or save_feet) {
fs::create_directory(output_folder);
}
std::cout << title + title_simu_2 << std::endl;
std::cout << title + title_simu_rotation << std::endl;
simulate(
to_physical_mapping_host,
to_physical_mapping,
to_logical_mapping,
analytical_to_pseudo_physical_mapping,
analytical_to_physical_mapping,
grid,
time_stepper,
simulation_2,
function_interpolator,
advection_builder,
advection_evaluator,
foot_finder,
advection_operator,
simulation_rotation,
final_time,
dt,
save_curves,
Expand All @@ -660,19 +641,17 @@ void simulate_the_3_simulations(
if (save_curves or save_feet) {
fs::create_directory(output_folder);
}
std::cout << title + title_simu_3 << std::endl;
std::cout << title + title_simu_decentred_rotation << std::endl;
simulate(
to_physical_mapping_host,
to_physical_mapping,
to_logical_mapping,
analytical_to_pseudo_physical_mapping,
analytical_to_physical_mapping,
grid,
time_stepper,
simulation_3,
function_interpolator,
advection_builder,
advection_evaluator,
foot_finder,
advection_operator,
simulation_decentred_rotation,
final_time,
dt,
save_curves,
Expand Down
Loading

0 comments on commit 5399bc4

Please sign in to comment.