Skip to content

Commit

Permalink
Merge pull request #230 from eagles-project/oscar/mo_photo_2
Browse files Browse the repository at this point in the history
Oscar/mo photo 2
  • Loading branch information
odiazib authored Aug 25, 2023
2 parents 403291a + 94103ba commit ca8274d
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 2 deletions.
123 changes: 123 additions & 0 deletions src/mam4xx/mo_photo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ constexpr int pverm = pver - 1;
using View5D = Kokkos::View<Real *****>;
using View4D = Kokkos::View<Real ****>;
using View2D = DeviceType::view_2d<Real>;
using View1D = DeviceType::view_1d<Real>;
using ViewInt1D = DeviceType::view_1d<int>;

KOKKOS_INLINE_FUNCTION
void cloud_mod(const Real zen_angle, const Real *clouds, const Real *lwc,
Expand Down Expand Up @@ -318,6 +320,7 @@ void interpolate_rsf(const Real *alb_in, const Real sza_in, const Real *p_in,
if (p_in[kk] > press[0]) {
pind = 1;
wght1 = one;

// Fortran to C++ indexing
} else if (p_in[kk] <= press[nump - 1]) {
// Fortran to C++ indexing
Expand Down Expand Up @@ -547,6 +550,126 @@ void jlong(const Real sza_in, const Real *alb_in, const Real *p_in,
} // end kk

} // jlong
const Real phtcnt = 1; // number of photolysis reactions
KOKKOS_INLINE_FUNCTION
void table_photo(const View2D &photo, // out
const ColumnView &pmid, const ColumnView &pdel,
const ColumnView &temper, // in
const ColumnView &colo3_in, const Real zen_angle,
const Real srf_alb, const ColumnView &lwc,
const ColumnView &clouds, // in
const Real esfact, const View4D &xsqy, const View1D &sza,
const View1D &del_sza, const View1D &alb, const View1D &press,
const View1D &del_p, const View1D &colo3, const View1D &o3rat,
const View1D &del_alb, const View1D &del_o3rat,
const View1D &etfphot, const View5D &rsf_tab,
const View1D &prs, const View1D &dprs, const int nw,
const int nump, const int numsza, const int numcolo3,
const int numalb, const int np_xs, const int numj,
const View1D &pht_alias_mult_1, const ViewInt1D &lng_indexer,
// work arrays
const View2D &lng_prates, const View2D &rsf,
const View2D &xswk, const View1D &psum_l,
const View1D &psum_u) {
/*-----------------------------------------------------------------
... table photorates for wavelengths > 200nm
-----------------------------------------------------------------*/

//@param[in] photos_icol (pver,phtcnt) photodissociation rates at icol
//[1/s]
//@param[in] pmid(pver) midpoint pressure [Pa]
//@param[in] pdel(pver) pressure delta about midpoint [Pa]
//@param[in] temper(pver) midpoint temperature [K]
//@param[in] colo3_in(pver) col_dens(icol,pver,0) ! column densities
//[molecules/cm^2]
//@param[in] zen_angle(icol) solar zenith angle [radians]
//@param[in] srf_alb(icols) surface albedo
//@param[in] lwc(icol,pver) liquid water content [kg/kg]
//@param[in] clouds(icol,pver) cloud fraction
//@param[in] esfact earth sun distance factor
// @param[in] xsqy
// @param[in] sza
// @param[in] del_sza
// @param[in] alb
// @param[in] press
// @param[in] del_p
// @param[in] colo3
// @param[in] o3rat
// @param[in] del_alb
// @param[in] del_o3rat
// @param[in] etfphot
// @param[in] rsf_tab
// @param[in] prs
// @param[in] dprs
// @param[in] nw wavelengths >200nm
// @param[in] nump number of altitudes in rsf
// @param[in] numsza number of zen angles in rsf
// @param[in] numcolo3 number of o3 columns in rsf
// @param[in] numalb number of albedos in rsf
// @param[in] np_xs number of pressure levels in xsection table
// @param[in] numj number of photorates in xsqy, rsf
// @param[out] j_long(:,:) photo rates [1/s]

if (phtcnt < 1) {
return;
}

constexpr Real zero = 0;

constexpr Real Pa2mb = 1.e-2; // pascals to mb
constexpr Real r2d = 180.0 / haero::Constants::pi; // degrees to radians
// BAD CONSTANT
constexpr Real max_zen_angle = 88.85; // degrees

// vertical pressure array [hPa]
Real parg[pver] = {};
Real eff_alb[pver] = {};
Real cld_mult[pver] = {};

/*-----------------------------------------------------------------
... zero all photorates
-----------------------------------------------------------------*/
const Real sza_in = zen_angle * r2d;
// daylight
if (sza_in >= zero && sza_in < max_zen_angle) {
/*-----------------------------------------------------------------
... compute eff_alb and cld_mult -- needs to be before jlong
-----------------------------------------------------------------*/
cloud_mod(zen_angle, clouds.data(), lwc.data(), pdel.data(),
srf_alb, // in
eff_alb, cld_mult);

for (int kk = 0; kk < pver; ++kk) {
parg[kk] = pmid(kk) * Pa2mb;
cld_mult[kk] *= esfact;
} // kk
/*-----------------------------------------------------------------
... long wave length component
-----------------------------------------------------------------*/

jlong(sza_in, eff_alb, parg, temper.data(), colo3_in.data(), xsqy,
sza.data(), del_sza.data(), alb.data(), press.data(), del_p.data(),
colo3.data(), o3rat.data(), del_alb.data(), del_o3rat.data(),
etfphot.data(),
rsf_tab, // in
prs.data(), dprs.data(), nw, nump, numsza, numcolo3, numalb, np_xs,
numj,
lng_prates, // output
// work arrays
rsf, xswk, psum_l.data(), psum_u.data());

for (int mm = 0; mm < phtcnt; ++mm) {
if (lng_indexer(mm) > -1) {
for (int kk = 0; kk < pver; ++kk) {
photo(kk, mm) = cld_mult[kk] *
(photo(kk, mm) + pht_alias_mult_1(mm) *
lng_prates(lng_indexer(mm), kk));
} // end kk
} // end if
} // end mm
}
// } // end col_loop
}

} // namespace mo_photo
} // end namespace mam4
Expand Down
3 changes: 2 additions & 1 deletion src/validation/convproc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ foreach (input
compute_activation_tend_do_act_false
compute_updraft_mixing_ratio
ma_convproc_tend
ma_convproc_dp_intr
# FIXME; this test fails because we change compare_mam4xx_mam4.py
#ma_convproc_dp_intr
compute_tendencies
)

Expand Down
3 changes: 3 additions & 0 deletions src/validation/mo_photo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_executable(mo_photo_driver
calc_sum_wght.cpp
interpolate_rsf.cpp
jlong.cpp
table_photo.cpp
)

target_link_libraries(mo_photo_driver skywalker;validation;${HAERO_LIBRARIES})
Expand All @@ -37,6 +38,7 @@ set(TEST_LIST
stand_synthetic_calc_sum_wght_ts_355
stand_synthetic_interpolate_rsf_ts_355
stand_synthetic_jlong_ts_355
stand_synthetic_table_photo_ts_355
)
# # matching the tests and errors, just for convenience

Expand All @@ -48,6 +50,7 @@ set(ERROR_THRESHOLDS
6e-8
6e-6
8e-6
2e-6
)
foreach(input tol IN ZIP_LISTS TEST_LIST ERROR_THRESHOLDS)
# copy the baseline file into place.
Expand Down
3 changes: 3 additions & 0 deletions src/validation/mo_photo/mo_photo_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void find_index(Ensemble *ensemble);
void interpolate_rsf(Ensemble *ensemble);
void jlong(Ensemble *ensemble);
void calc_sum_wght(Ensemble *ensemble);
void table_photo(Ensemble *ensemble);
int main(int argc, char **argv) {
if (argc == 1) {
usage();
Expand Down Expand Up @@ -59,6 +60,8 @@ int main(int argc, char **argv) {
jlong(ensemble);
} else if (func_name == "calc_sum_wght") {
calc_sum_wght(ensemble);
} else if (func_name == "table_photo") {
table_photo(ensemble);
} else {
std::cerr << "Error: Function name '" << func_name
<< "' does not have an implemented test!" << std::endl;
Expand Down
Loading

0 comments on commit ca8274d

Please sign in to comment.