Skip to content

Commit d782df2

Browse files
committed
fix gas_washout, indexing issues in sethet
1 parent 5353070 commit d782df2

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

src/mam4xx/mo_sethet.hpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ void calc_het_rates(const Real satf, // saturation fraction in cloud //in
6060
//=================================================================================
6161
KOKKOS_INLINE_FUNCTION
6262
void calc_precip_rescale(
63-
const ColumnView cmfdqr, // dq/dt for convection [kg/kg/s] //in
64-
const ColumnView nrain, // stratoform precip [kg/kg/s] //in
65-
const ColumnView nevapr, // evaporation [kg/kg/s] // in
66-
const ColumnView precip) { // precipitation [kg/kg/s] // out
63+
const ColumnView &cmfdqr, // dq/dt for convection [kg/kg/s] //in
64+
const ColumnView &nrain, // stratoform precip [kg/kg/s] //in
65+
const ColumnView &nevapr, // evaporation [kg/kg/s] // in
66+
const ColumnView &precip) { // precipitation [kg/kg/s] // out
6767
// -----------------------------------------------------------------------
6868
// calculate precipitation rate at each grid
6969
// this is added to rescale the variable precip (which can only be positive)
@@ -103,12 +103,12 @@ void gas_washout(
103103
const int plev, // calculate from this level below //in
104104
const Real xkgm, // mass flux on rain drop //in
105105
const Real xliq_ik, // liquid rain water content [gm/m^3] // in
106-
const ColumnView xhen_i, // henry's law constant
107-
const ColumnView tfld_i, // temperature [K]
108-
const ColumnView delz_i, // layer depth about interfaces [cm] // in
109-
const ColumnView xeqca, // internal variable
110-
const ColumnView xca, // internal variable
111-
const ColumnView xgas) { // gas concentration // inout
106+
const ColumnView &xhen_i, // henry's law constant
107+
const ColumnView &tfld_i, // temperature [K]
108+
const ColumnView &delz_i, // layer depth about interfaces [cm] // in
109+
const ColumnView &xeqca, // internal variable
110+
const ColumnView &xca, // internal variable
111+
const ColumnView &xgas) { // gas concentration // inout
112112
//------------------------------------------------------------------------
113113
// calculate gas washout by cloud if not saturated
114114
//------------------------------------------------------------------------
@@ -141,7 +141,7 @@ void gas_washout(
141141
// otherwise
142142
// hno3(gas)_new = hno3(gas)_old
143143
//-----------------------------------------------------------------
144-
for (int kk = 0; kk < plev; kk++) {
144+
for (int kk = plev; kk < pver; kk++) {
145145
allca += xca(kk);
146146
if (allca < xeqca(kk)) {
147147
xgas(kk) = haero::max(xgas(kk) - xca(kk), 0.0);
@@ -153,7 +153,7 @@ void gas_washout(
153153
KOKKOS_INLINE_FUNCTION
154154
void find_ktop(
155155
Real rlat, // latitude in radians for columns
156-
ColumnView press, // pressure [Pa] // in
156+
const ColumnView &press, // pressure [Pa] // in
157157
int &ktop) { // index that only calculate het_rates above this level //out
158158
//---------------------------------------------------------------------------
159159
// -------- find the top level that het_rates are set as 0 above it ---------
@@ -183,32 +183,32 @@ void sethet(
183183
const ColumnView
184184
het_rates[gas_pcnst], //[pver][gas_pcnst], rainout rates [1/s] //out
185185
const Real rlat, // latitude in radians for columns
186-
const ColumnView press, // pressure [pascals] //in
187-
const ColumnView zmid, // midpoint geopot [km] //in
186+
const ColumnView &press, // pressure [pascals] //in
187+
const ColumnView &zmid, // midpoint geopot [km] //in
188188
const Real phis, // surf geopotential //in
189-
const ColumnView tfld, // temperature [K] //in
190-
const ColumnView cmfdqr, // dq/dt for convection [kg/kg/s] //in
191-
const ColumnView nrain, // stratoform precip [kg/kg/s] //in
192-
const ColumnView nevapr, // evaporation [kg/kg/s] //in
189+
const ColumnView &tfld, // temperature [K] //in
190+
const ColumnView &cmfdqr, // dq/dt for convection [kg/kg/s] //in
191+
const ColumnView &nrain, // stratoform precip [kg/kg/s] //in
192+
const ColumnView &nevapr, // evaporation [kg/kg/s] //in
193193
const Real delt, // time step [s] //in
194-
const ColumnView xhnm, // total atms density [cm^-3] //in
194+
const ColumnView &xhnm, // total atms density [cm^-3] //in
195195
const ColumnView qin[gas_pcnst], // xported species [vmr] //in
196196
// working variables
197-
const ColumnView xeqca, // var for gas_washout
198-
const ColumnView xca, // var for gas_washout
197+
const ColumnView &xeqca, // var for gas_washout
198+
const ColumnView &xca, // var for gas_washout
199199
const ColumnView
200-
xgas2, // gas phase species for h2o2 (2) and so2 (3) [molecules/cm^3]
200+
&xgas2, // gas phase species for h2o2 (2) and so2 (3) [molecules/cm^3]
201201
const ColumnView
202-
xgas3, // gas phase species for h2o2 (2) and so2 (3) [molecules/cm^3]
203-
const ColumnView delz, // layer depth about interfaces [cm]
204-
const ColumnView xh2o2, // h2o2 concentration [molecules/cm^3]
205-
const ColumnView xso2, // so2 concentration [molecules/cm^3]
206-
const ColumnView xliq, // liquid rain water content in a grid cell [gm/m^3]
207-
const ColumnView rain, // precipitation (rain) rate [molecules/cm^3/s]
208-
const ColumnView precip, // precipitation rate [kg/kg/s]
209-
const ColumnView xhen_h2o2, // henry law constants
210-
const ColumnView xhen_hno3, // henry law constants
211-
const ColumnView xhen_so2, // henry law constants
202+
&xgas3, // gas phase species for h2o2 (2) and so2 (3) [molecules/cm^3]
203+
const ColumnView &delz, // layer depth about interfaces [cm]
204+
const ColumnView &xh2o2, // h2o2 concentration [molecules/cm^3]
205+
const ColumnView &xso2, // so2 concentration [molecules/cm^3]
206+
const ColumnView &xliq, // liquid rain water content in a grid cell [gm/m^3]
207+
const ColumnView &rain, // precipitation (rain) rate [molecules/cm^3/s]
208+
const ColumnView &precip, // precipitation rate [kg/kg/s]
209+
const ColumnView &xhen_h2o2, // henry law constants
210+
const ColumnView &xhen_hno3, // henry law constants
211+
const ColumnView &xhen_so2, // henry law constants
212212
const ColumnView tmp_hetrates[gas_pcnst], const int spc_h2o2_ndx,
213213
const int spc_so2_ndx, const int h2o2_ndx, const int so2_ndx,
214214
const int h2so4_ndx, const int gas_wetdep_cnt, const int wetdep_map[3]) {
@@ -432,22 +432,22 @@ void sethet(
432432
work1 = avo2 * xliq(kk);
433433
work2 = const0 * tfld(kk);
434434

435-
if (h2o2_ndx > 0) {
435+
if (h2o2_ndx >= 0) {
436436
calc_het_rates(satf_h2o2, rain(kk), xhen_h2o2(kk), // in
437437
tmp_hetrates[1](kk), work1, work2, // in
438438
het_rates[h2o2_ndx](kk)); // out
439439
}
440440

441441
// if ( prog_modal_aero .and.
442-
if (so2_ndx > 0 && h2o2_ndx > 0) {
442+
if (so2_ndx >= 0 && h2o2_ndx >= 0) {
443443
het_rates[so2_ndx](kk) = het_rates[h2o2_ndx](kk);
444-
} else if (so2_ndx > 0) {
444+
} else if (so2_ndx >= 0) {
445445
calc_het_rates(satf_so2, rain(kk), xhen_so2(kk), // in
446446
tmp_hetrates[2](kk), work1, work2, // in
447447
het_rates[so2_ndx](kk)); // out
448448
}
449449

450-
if (h2so4_ndx > 0) {
450+
if (h2so4_ndx >= 0) {
451451
calc_het_rates(satf_hno3, rain(kk), xhen_hno3(kk), // in
452452
tmp_hetrates[0](kk), work1, work2, // in
453453
het_rates[h2so4_ndx](kk)); // out

src/validation/mo_sethet/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ set(ERROR_THRESHOLDS
4444
9e-8 # calc_het_rates, this is due to using a more specific value for mass_h2o
4545
${DEFAULT_TOL} # calc_precip_rescale
4646
${DEFAULT_TOL} # find_ktop, output is an int
47-
9e-3 # gas_washout
48-
9e-2 # sethet
47+
9e-8 # gas_washout
48+
9e-8 # sethet
4949
)
5050
foreach(input tol IN ZIP_LISTS TEST_LIST ERROR_THRESHOLDS)
5151
# copy the baseline file into place.

src/validation/mo_sethet/sethet.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ void sethet(Ensemble *ensemble) {
2222
constexpr int gas_pcnst = mam4::gas_chemistry::gas_pcnst;
2323

2424
// non-ColumnView input values
25-
// const Real rlat = input.get_array("rlat")[0]; //need
26-
const Real rlat = -.2320924702;
25+
const Real rlat = input.get_array("rlat")[0]; //need
26+
//const Real rlat = -.2320924702;
2727
const Real phis = input.get_array("phis")[0];
2828
const Real delt = input.get_array("delt")[0];
2929

30-
const int spc_h2o2_ndx = input.get_array("spc_h2o2_ndx")[0];
31-
const int spc_so2_ndx = input.get_array("spc_so2_ndx")[0];
32-
const int h2o2_ndx = input.get_array("h2o2_ndx")[0];
33-
const int so2_ndx = input.get_array("so2_ndx")[0];
34-
const int h2so4_ndx = input.get_array("h2so4_ndx")[0];
30+
const int spc_h2o2_ndx = input.get_array("spc_h2o2_ndx")[0] - 1;
31+
const int spc_so2_ndx = input.get_array("spc_so2_ndx")[0] - 1;
32+
const int h2o2_ndx = input.get_array("h2o2_ndx")[0] - 1;
33+
const int so2_ndx = input.get_array("so2_ndx")[0] - 1;
34+
const int h2so4_ndx = input.get_array("h2so4_ndx")[0] - 1;
3535
const int gas_wetdep_cnt = input.get_array("gas_wetdep_cnt")[0];
3636

3737
int wetdep_map[3];
3838
const auto wetdep_map_in = input.get_array("wetdep_map");
39-
wetdep_map[0] = wetdep_map_in[0];
40-
wetdep_map[1] = wetdep_map_in[1];
41-
wetdep_map[2] = wetdep_map_in[2];
39+
wetdep_map[0] = wetdep_map_in[0] - 1;
40+
wetdep_map[1] = wetdep_map_in[1] - 1;
41+
wetdep_map[2] = wetdep_map_in[2] - 1;
4242

4343
const auto press_in = input.get_array("press");
4444
const auto zmid_in = input.get_array("zmid");

0 commit comments

Comments
 (0)