Skip to content

Commit

Permalink
add option to turn off 2stream
Browse files Browse the repository at this point in the history
  • Loading branch information
magpowell committed Nov 6, 2024
1 parent cfbf07c commit 7a4c798
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 49 deletions.
1 change: 1 addition & 0 deletions include_test/Radiation_solver_rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Radiation_solver_shortwave
#ifdef __CUDACC__
void solve_gpu(
const bool switch_fluxes,
const bool switch_disable_2s,
const bool switch_raytracing,
const bool switch_independent_column,
const bool switch_cloud_optics,
Expand Down
20 changes: 12 additions & 8 deletions src_test/Radiation_solver_rt.cu
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ void Radiation_solver_shortwave::load_mie_tables(

void Radiation_solver_shortwave::solve_gpu(
const bool switch_fluxes,
const bool switch_disable_2s,
const bool switch_raytracing,
const bool switch_independent_column,
const bool switch_cloud_optics,
Expand Down Expand Up @@ -636,10 +637,10 @@ void Radiation_solver_shortwave::solve_gpu(

if (switch_fluxes)
{
Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_up.ptr());
Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_dn.ptr());
Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_dn_dir.ptr());
Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_net.ptr());
// Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_up.ptr());
// Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_dn.ptr());
// Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_dn_dir.ptr());
// Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(n_lev, grid_cells.y, grid_cells.x, sw_flux_net.ptr());
if (switch_raytracing)
{
Gas_optics_rrtmgp_kernels_cuda_rt::zero_array(grid_cells.y, grid_cells.x, rt_flux_tod_up.ptr());
Expand Down Expand Up @@ -837,10 +838,13 @@ void Radiation_solver_shortwave::solve_gpu(

(*fluxes).net_flux();

Gpt_combine_kernels_cuda_rt::add_from_gpoint(
n_col, n_lev, sw_flux_up.ptr(), sw_flux_dn.ptr(), sw_flux_dn_dir.ptr(), sw_flux_net.ptr(),
(*fluxes).get_flux_up().ptr(), (*fluxes).get_flux_dn().ptr(), (*fluxes).get_flux_dn_dir().ptr(), (*fluxes).get_flux_net().ptr());

if(!switch_disable_2s)
{
Gpt_combine_kernels_cuda_rt::add_from_gpoint(
n_col, n_lev, sw_flux_up.ptr(), sw_flux_dn.ptr(), sw_flux_dn_dir.ptr(), sw_flux_net.ptr(),
(*fluxes).get_flux_up().ptr(), (*fluxes).get_flux_dn().ptr(), (*fluxes).get_flux_dn_dir().ptr(), (*fluxes).get_flux_net().ptr());
}

if (switch_raytracing)
{
Gpt_combine_kernels_cuda_rt::add_from_gpoint(
Expand Down
99 changes: 58 additions & 41 deletions src_test/test_rte_rrtmgp_rt.cu
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ void solve_radiation(int argc, char** argv)
{"shortwave" , { true, "Enable computation of shortwave radiation."}},
{"longwave" , { false, "Enable computation of longwave radiation." }},
{"fluxes" , { true, "Enable computation of fluxes." }},
{"disable-2s" , { false, "use raytracing onlu for flux computation. must be passed with raytracing" }},
{"raytracing" , { true, "Use raytracing for flux computation. '--raytracing 256': use 256 rays per pixel" }},
{"independent-column", { false, "run raytracer in independent column mode"}},
{"cloud-optics" , { false, "Enable cloud optics." }},
Expand All @@ -249,6 +250,7 @@ void solve_radiation(int argc, char** argv)
const bool switch_shortwave = command_line_switches.at("shortwave" ).first;
const bool switch_longwave = command_line_switches.at("longwave" ).first;
const bool switch_fluxes = command_line_switches.at("fluxes" ).first;
const bool switch_disable_2s = command_line_switches.at("disable-2s").first;
const bool switch_raytracing = command_line_switches.at("raytracing" ).first;
const bool switch_independent_column= command_line_switches.at("independent-column").first;
const bool switch_cloud_optics = command_line_switches.at("cloud-optics" ).first;
Expand All @@ -275,6 +277,11 @@ void solve_radiation(int argc, char** argv)
throw std::runtime_error(error);
}

if (switch_disable_2s && !switch_raytracing) {
std::string error = "cannot disable two-stream for flux calc without turning ray tracing on";
throw std::runtime_error(error);
}

if (switch_liq_cloud_optics && switch_ice_cloud_optics) {
std::string error = "Both liquid-only and ice-only cloud optics cannot be enabled simultaneously";
throw std::runtime_error(error);
Expand Down Expand Up @@ -716,10 +723,13 @@ void solve_radiation(int argc, char** argv)

if (switch_fluxes)
{
sw_flux_up .set_dims({n_col, n_lev});
sw_flux_dn .set_dims({n_col, n_lev});
sw_flux_dn_dir.set_dims({n_col, n_lev});
sw_flux_net .set_dims({n_col, n_lev});
if(!switch_disable_2s)
{
sw_flux_up .set_dims({n_col, n_lev});
sw_flux_dn .set_dims({n_col, n_lev});
sw_flux_dn_dir.set_dims({n_col, n_lev});
sw_flux_net .set_dims({n_col, n_lev});
}

if (switch_raytracing)
{
Expand Down Expand Up @@ -780,6 +790,7 @@ void solve_radiation(int argc, char** argv)

rad_sw.solve_gpu(
switch_fluxes,
switch_disable_2s,
switch_raytracing,
switch_independent_column,
switch_cloud_optics,
Expand Down Expand Up @@ -917,27 +928,30 @@ void solve_radiation(int argc, char** argv)

if (switch_fluxes)
{
auto nc_sw_flux_up = output_nc.add_variable<Float>("sw_flux_up" , {"lev", "y", "x"});
auto nc_sw_flux_dn = output_nc.add_variable<Float>("sw_flux_dn" , {"lev", "y", "x"});
auto nc_sw_flux_dn_dir = output_nc.add_variable<Float>("sw_flux_dn_dir", {"lev", "y", "x"});
auto nc_sw_flux_net = output_nc.add_variable<Float>("sw_flux_net" , {"lev", "y", "x"});
if(!switch_disable_2s)
{
auto nc_sw_flux_up = output_nc.add_variable<Float>("sw_flux_up" , {"lev", "y", "x"});
auto nc_sw_flux_dn = output_nc.add_variable<Float>("sw_flux_dn" , {"lev", "y", "x"});
auto nc_sw_flux_dn_dir = output_nc.add_variable<Float>("sw_flux_dn_dir", {"lev", "y", "x"});
auto nc_sw_flux_net = output_nc.add_variable<Float>("sw_flux_net" , {"lev", "y", "x"});

nc_sw_flux_up .insert(sw_flux_up_cpu .v(), {0, 0, 0});
nc_sw_flux_dn .insert(sw_flux_dn_cpu .v(), {0, 0, 0});
nc_sw_flux_dn_dir.insert(sw_flux_dn_dir_cpu.v(), {0, 0, 0});
nc_sw_flux_net .insert(sw_flux_net_cpu .v(), {0, 0, 0});
nc_sw_flux_up .insert(sw_flux_up_cpu .v(), {0, 0, 0});
nc_sw_flux_dn .insert(sw_flux_dn_cpu .v(), {0, 0, 0});
nc_sw_flux_dn_dir.insert(sw_flux_dn_dir_cpu.v(), {0, 0, 0});
nc_sw_flux_net .insert(sw_flux_net_cpu .v(), {0, 0, 0});

nc_sw_flux_up.add_attribute("long_name","Upwelling shortwave fluxes (TwoStream solver)");
nc_sw_flux_up.add_attribute("units","W m-2");
nc_sw_flux_up.add_attribute("long_name","Upwelling shortwave fluxes (TwoStream solver)");
nc_sw_flux_up.add_attribute("units","W m-2");

nc_sw_flux_dn.add_attribute("long_name","Downwelling shortwave fluxes (TwoStream solver)");
nc_sw_flux_dn.add_attribute("units","W m-2");
nc_sw_flux_dn.add_attribute("long_name","Downwelling shortwave fluxes (TwoStream solver)");
nc_sw_flux_dn.add_attribute("units","W m-2");

nc_sw_flux_dn_dir.add_attribute("long_name","Downwelling direct shortwave fluxes (TwoStream solver)");
nc_sw_flux_dn_dir.add_attribute("units","W m-2");
nc_sw_flux_dn_dir.add_attribute("long_name","Downwelling direct shortwave fluxes (TwoStream solver)");
nc_sw_flux_dn_dir.add_attribute("units","W m-2");

nc_sw_flux_net.add_attribute("long_name","Net shortwave fluxes (TwoStream solver)");
nc_sw_flux_net.add_attribute("units","W m-2");
nc_sw_flux_net.add_attribute("long_name","Net shortwave fluxes (TwoStream solver)");
nc_sw_flux_net.add_attribute("units","W m-2");
}

if (switch_raytracing)
{
Expand Down Expand Up @@ -979,27 +993,30 @@ void solve_radiation(int argc, char** argv)

if (switch_single_gpt)
{
auto nc_sw_gpt_flux_up = output_nc.add_variable<Float>("sw_gpt_flux_up" , {"lev", "y", "x"});
auto nc_sw_gpt_flux_dn = output_nc.add_variable<Float>("sw_gpt_flux_dn" , {"lev", "y", "x"});
auto nc_sw_gpt_flux_dn_dir = output_nc.add_variable<Float>("sw_gpt_flux_dn_dir", {"lev", "y", "x"});
auto nc_sw_gpt_flux_net = output_nc.add_variable<Float>("sw_gpt_flux_net" , {"lev", "y", "x"});

nc_sw_gpt_flux_up .insert(sw_gpt_flux_up_cpu .v(), {0, 0, 0});
nc_sw_gpt_flux_dn .insert(sw_gpt_flux_dn_cpu .v(), {0, 0, 0});
nc_sw_gpt_flux_dn_dir.insert(sw_gpt_flux_dn_dir_cpu.v(), {0, 0, 0});
nc_sw_gpt_flux_net .insert(sw_gpt_flux_net_cpu .v(), {0, 0, 0});

nc_sw_gpt_flux_up.add_attribute("long_name","Upwelling shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_up.add_attribute("units","W m-2");

nc_sw_gpt_flux_dn.add_attribute("long_name","Downwelling shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_dn.add_attribute("units","W m-2");

nc_sw_gpt_flux_dn_dir.add_attribute("long_name","Downwelling direct shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_dn_dir.add_attribute("units","W m-2");

nc_sw_gpt_flux_net.add_attribute("long_name","Net shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_net.add_attribute("units","W m-2");
if(!switch_disable_2s)
{
auto nc_sw_gpt_flux_up = output_nc.add_variable<Float>("sw_gpt_flux_up" , {"lev", "y", "x"});
auto nc_sw_gpt_flux_dn = output_nc.add_variable<Float>("sw_gpt_flux_dn" , {"lev", "y", "x"});
auto nc_sw_gpt_flux_dn_dir = output_nc.add_variable<Float>("sw_gpt_flux_dn_dir", {"lev", "y", "x"});
auto nc_sw_gpt_flux_net = output_nc.add_variable<Float>("sw_gpt_flux_net" , {"lev", "y", "x"});

nc_sw_gpt_flux_up .insert(sw_gpt_flux_up_cpu .v(), {0, 0, 0});
nc_sw_gpt_flux_dn .insert(sw_gpt_flux_dn_cpu .v(), {0, 0, 0});
nc_sw_gpt_flux_dn_dir.insert(sw_gpt_flux_dn_dir_cpu.v(), {0, 0, 0});
nc_sw_gpt_flux_net .insert(sw_gpt_flux_net_cpu .v(), {0, 0, 0});

nc_sw_gpt_flux_up.add_attribute("long_name","Upwelling shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_up.add_attribute("units","W m-2");

nc_sw_gpt_flux_dn.add_attribute("long_name","Downwelling shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_dn.add_attribute("units","W m-2");

nc_sw_gpt_flux_dn_dir.add_attribute("long_name","Downwelling direct shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_dn_dir.add_attribute("units","W m-2");

nc_sw_gpt_flux_net.add_attribute("long_name","Net shortwave fluxes for g-point "+std::to_string(single_gpt)+" (TwoStream solver)");
nc_sw_gpt_flux_net.add_attribute("units","W m-2");
}
}
}
}
Expand Down

0 comments on commit 7a4c798

Please sign in to comment.