Skip to content

Commit 7a2ce05

Browse files
authored
worked with radiation. (#2689)
1 parent 7d0c8e9 commit 7a2ce05

File tree

8 files changed

+116
-9
lines changed

8 files changed

+116
-9
lines changed

Source/ERF.H

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ private:
869869

870870
amrex::Vector<std::unique_ptr<IRadiation>> rad; // Radiation model at each level
871871
amrex::Vector<std::unique_ptr<amrex::MultiFab>> qheating_rates; // radiation heating rate source terms (SW, LW)
872-
872+
amrex::Vector<std::unique_ptr<amrex::MultiFab>> rad_fluxes; // radiation fluxes (SW up/dn, LW up/dn)
873873
#ifdef ERF_USE_SHOC
874874
amrex::Vector<std::unique_ptr<SHOCInterface>> shoc_interface; // SHOC model at each level
875875
#endif
@@ -1136,7 +1136,8 @@ private:
11361136
const amrex::Vector<std::string> derived_names_2d {
11371137
"z_surf", "landmask", "mapfac", "lat_m", "lon_m",
11381138
"u_star", "w_star", "t_star", "q_star", "Olen", "pblh",
1139-
"t_surf", "q_surf", "z0"
1139+
"t_surf", "q_surf", "z0", "OLR", "sens_flux", "laten_flux",
1140+
"surf_pres"
11401141
};
11411142

11421143
// algorithm choices

Source/ERF.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ ERF::ERF_shared ()
166166
#endif
167167

168168
qheating_rates.resize(nlevs_max);
169+
rad_fluxes.resize(nlevs_max);
169170
sw_lw_fluxes.resize(nlevs_max);
170171
solar_zenith.resize(nlevs_max);
171172

Source/ERF_MakeNewArrays.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,12 @@ ERF::init_stuff (int lev, const BoxArray& ba, const DistributionMapping& dm,
382382
//*********************************************************
383383
// Radiation heating source terms
384384
//*********************************************************
385-
if (solverChoice.rad_type != RadiationType::None || solverChoice.lsm_type != LandSurfaceType::None)
385+
if (solverChoice.rad_type != RadiationType::None)
386386
{
387-
qheating_rates[lev] = std::make_unique<MultiFab>(ba, dm, 2, ngrow_state);
387+
qheating_rates[lev] = std::make_unique<MultiFab>(ba, dm, 2, 0);
388+
rad_fluxes[lev] = std::make_unique<MultiFab>(ba, dm, 4, 0);
388389
qheating_rates[lev]->setVal(0.);
390+
rad_fluxes[lev]->setVal(0.);
389391
}
390392

391393
//*********************************************************
@@ -407,8 +409,8 @@ ERF::init_stuff (int lev, const BoxArray& ba, const DistributionMapping& dm,
407409
}
408410
BoxArray m_ba(std::move(m_bl));
409411

410-
sw_lw_fluxes[lev] = std::make_unique<MultiFab>(m_ba, dm, 6, ngrow_state); // DIR/DIF VIS/NIR (4), NET SW (1), LW (1)
411-
solar_zenith[lev] = std::make_unique<MultiFab>(m_ba, dm, 1, ngrow_state);
412+
sw_lw_fluxes[lev] = std::make_unique<MultiFab>(m_ba, dm, 6, 0); // DIR/DIF VIS/NIR (4), NET SW (1), LW (1)
413+
solar_zenith[lev] = std::make_unique<MultiFab>(m_ba, dm, 1, 0);
412414

413415
sw_lw_fluxes[lev]->setVal(0.);
414416
solar_zenith[lev]->setVal(0.);

Source/IO/ERF_Plotfile.cpp

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,10 @@ ERF::Write2DPlotFile (int which, PlotFileType plotfile_type, Vector<std::string>
19351935
// Set all components to zero in case they aren't defined below
19361936
mf[lev].setVal(0.0);
19371937

1938+
// Expose domain khi and klo at each level
1939+
int klo = geom[lev].Domain().smallEnd(2);
1940+
int khi = geom[lev].Domain().bigEnd(2);
1941+
19381942
if (containerHasElement(plot_var_names, "z_surf")) {
19391943
#ifdef _OPENMP
19401944
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
@@ -2204,6 +2208,87 @@ ERF::Write2DPlotFile (int which, PlotFileType plotfile_type, Vector<std::string>
22042208
}
22052209
mf_comp++;
22062210
} // z0
2211+
2212+
if (containerHasElement(plot_var_names, "OLR")) {
2213+
#ifdef _OPENMP
2214+
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2215+
#endif
2216+
if (solverChoice.rad_type != RadiationType::None) {
2217+
for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
2218+
{
2219+
const Box& bx = mfi.tilebox();
2220+
const auto& derdat = mf[lev].array(mfi);
2221+
const auto& olr = rad_fluxes[lev]->const_array(mfi);
2222+
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
2223+
derdat(i, j, k, mf_comp) = olr(i, j, khi, 2);
2224+
});
2225+
}
2226+
} else {
2227+
mf[lev].setVal(-999,mf_comp,1,0);
2228+
}
2229+
mf_comp++;
2230+
} // OLR
2231+
2232+
if (containerHasElement(plot_var_names, "sens_flux")) {
2233+
#ifdef _OPENMP
2234+
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2235+
#endif
2236+
if (SFS_hfx3_lev[lev]) {
2237+
for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
2238+
{
2239+
const Box& bx = mfi.tilebox();
2240+
const auto& derdat = mf[lev].array(mfi);
2241+
const auto& hfx_arr = SFS_hfx3_lev[lev]->const_array(mfi);
2242+
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
2243+
derdat(i, j, k, mf_comp) = hfx_arr(i, j, klo);
2244+
});
2245+
}
2246+
} else {
2247+
mf[lev].setVal(-999,mf_comp,1,0);
2248+
}
2249+
mf_comp++;
2250+
} // sens_flux
2251+
2252+
if (containerHasElement(plot_var_names, "laten_flux")) {
2253+
#ifdef _OPENMP
2254+
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2255+
#endif
2256+
if (SFS_hfx3_lev[lev]) {
2257+
for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
2258+
{
2259+
const Box& bx = mfi.tilebox();
2260+
const auto& derdat = mf[lev].array(mfi);
2261+
const auto& qfx_arr = SFS_q1fx3_lev[lev]->const_array(mfi);
2262+
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
2263+
derdat(i, j, k, mf_comp) = qfx_arr(i, j, klo);
2264+
});
2265+
}
2266+
} else {
2267+
mf[lev].setVal(-999,mf_comp,1,0);
2268+
}
2269+
mf_comp++;
2270+
} // laten_flux
2271+
2272+
if (containerHasElement(plot_var_names, "surf_pres")) {
2273+
#ifdef _OPENMP
2274+
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
2275+
#endif
2276+
bool moist = (solverChoice.moisture_type != MoistureType::None);
2277+
for ( MFIter mfi(mf[lev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
2278+
{
2279+
const Box& bx = mfi.tilebox();
2280+
const auto& derdat = mf[lev].array(mfi);
2281+
const auto& cons_arr = vars_new[lev][Vars::cons].const_array(mfi);
2282+
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
2283+
auto rt = cons_arr(i,j,klo,RhoTheta_comp);
2284+
auto qv = (moist) ? cons_arr(i,j,klo,RhoQ1_comp)/cons_arr(i,j,klo,Rho_comp)
2285+
: 0.0;
2286+
derdat(i, j, k, mf_comp) = getPgivenRTh(rt, qv);
2287+
});
2288+
}
2289+
mf_comp++;
2290+
} // surf_pres
2291+
22072292
} // lev
22082293

22092294
std::string plotfilename;

Source/PhysicsInterfaces/Radiation/ERF_Radiation.H

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,15 @@ public:
9999
amrex::Vector<amrex::MultiFab*>& lsm_input_ptrs,
100100
amrex::Vector<amrex::MultiFab*>& lsm_output_ptrs,
101101
amrex::MultiFab* qheating_rates,
102+
amrex::MultiFab* rad_fluxes,
102103
amrex::MultiFab* z_phys,
103104
amrex::MultiFab* lat_ptr,
104105
amrex::MultiFab* lon_ptr) override
105106
{
106107
set_grids(level, step, time, dt, ba, geom,
107108
cons_in, lsm_fluxes, lsm_zenith,
108109
lsm_input_ptrs, qheating_rates,
109-
z_phys, lat_ptr, lon_ptr);
110+
rad_fluxes, z_phys, lat_ptr, lon_ptr);
110111
rad_run_impl(lsm_output_ptrs);
111112
}
112113

@@ -123,6 +124,7 @@ public:
123124
amrex::MultiFab* lsm_zenith,
124125
amrex::Vector<amrex::MultiFab*>& lsm_input_ptrs,
125126
amrex::MultiFab* qheating_rates,
127+
amrex::MultiFab* rad_fluxes,
126128
amrex::MultiFab* z_phys,
127129
amrex::MultiFab* lat,
128130
amrex::MultiFab* lon);
@@ -253,6 +255,9 @@ private:
253255
// Pointer to the radiation source terms
254256
amrex::MultiFab* m_qheating_rates = nullptr;
255257

258+
// Pointer to the radiation fluxes
259+
amrex::MultiFab* m_rad_fluxes = nullptr;
260+
256261
// Pointer to the terrain heights
257262
amrex::MultiFab* m_z_phys = nullptr;
258263

Source/PhysicsInterfaces/Radiation/ERF_Radiation.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Radiation::set_grids (int& level,
142142
MultiFab* lsm_zenith,
143143
Vector<MultiFab*>& lsm_input_ptrs,
144144
MultiFab* qheating_rates,
145+
MultiFab* rad_fluxes,
145146
MultiFab* z_phys,
146147
MultiFab* lat,
147148
MultiFab* lon)
@@ -157,6 +158,7 @@ Radiation::set_grids (int& level,
157158
m_lsm_fluxes = lsm_fluxes;
158159
m_lsm_zenith = lsm_zenith;
159160
m_qheating_rates = qheating_rates;
161+
m_rad_fluxes = rad_fluxes;
160162
m_z_phys = z_phys;
161163
m_lat = lat;
162164
m_lon = lon;
@@ -614,6 +616,9 @@ Radiation::kokkos_buffers_to_mf (Vector<MultiFab*>& lsm_output_ptrs)
614616
auto sfc_flux_dir_nir_d = sfc_flux_dir_nir;
615617
auto sfc_flux_dif_vis_d = sfc_flux_dif_vis;
616618
auto sfc_flux_dif_nir_d = sfc_flux_dif_nir;
619+
auto sw_flux_up_d = sw_flux_up;
620+
auto sw_flux_dn_d = sw_flux_dn;
621+
auto lw_flux_up_d = lw_flux_up;
617622
auto lw_flux_dn_d = lw_flux_dn;
618623
auto mu0_d = mu0;
619624

@@ -625,6 +630,7 @@ Radiation::kokkos_buffers_to_mf (Vector<MultiFab*>& lsm_output_ptrs)
625630
const int jmin = vbx.smallEnd(1);
626631
const int offset = m_col_offsets[mfi.index()];
627632
const Array4<Real>& q_arr = m_qheating_rates->array(mfi);
633+
const Array4<Real>& f_arr = m_rad_fluxes->array(mfi);
628634
ParallelFor(vbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
629635
{
630636
// map [i,j,k] 0-based to [icol, ilay] 0-based
@@ -639,6 +645,12 @@ Radiation::kokkos_buffers_to_mf (Vector<MultiFab*>& lsm_output_ptrs)
639645
Real iexner = 1./getExnergivenP(Real(p_lay_d(icol,ilay)), R_d/Cp_d);
640646
q_arr(i,j,k,0) *= iexner;
641647
q_arr(i,j,k,1) *= iexner;
648+
649+
// Populate the fluxes
650+
f_arr(i,j,k,0) = sw_flux_up_d(icol,ilay);
651+
f_arr(i,j,k,1) = sw_flux_dn_d(icol,ilay);
652+
f_arr(i,j,k,2) = lw_flux_up_d(icol,ilay);
653+
f_arr(i,j,k,3) = lw_flux_dn_d(icol,ilay);
642654
});
643655
if (m_lsm_fluxes) {
644656
const Array4<Real>& lsm_arr = m_lsm_fluxes->array(mfi);

Source/PhysicsInterfaces/Radiation/ERF_RadiationInterface.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public:
3535
amrex::Vector<amrex::MultiFab*>& lsm_input_ptrs,
3636
amrex::Vector<amrex::MultiFab*>& lsm_output_ptrs,
3737
amrex::MultiFab* qheating_rates,
38+
amrex::MultiFab* rad_fluxes,
3839
amrex::MultiFab* z_phys,
3940
amrex::MultiFab* lat,
4041
amrex::MultiFab* lon) = 0;

Source/TimeIntegration/ERF_AdvanceRadiation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void ERF::advance_radiation (int lev,
3636
cons.boxArray(), geom[lev], &(cons),
3737
sw_lw_fluxes[lev].get(), solar_zenith[lev].get(),
3838
lsm_input_ptrs, lsm_output_ptrs,
39-
qheating_rates[lev].get(), z_phys_nd[lev].get() ,
40-
lat_ptr, lon_ptr);
39+
qheating_rates[lev].get(), rad_fluxes[lev].get(),
40+
z_phys_nd[lev].get() , lat_ptr, lon_ptr);
4141
}
4242
}

0 commit comments

Comments
 (0)