Skip to content

Commit 9c2de6e

Browse files
Merge pull request #447 from eagles-project/singhbalwinder/exit-optics-if-neg-dryvol
Adds logic to avoid very small numbers for dryvol
2 parents eca4a54 + 60c6c3c commit 9c2de6e

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/mam4xx/modal_aer_opt.hpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ constexpr int prefi = 10;
4242

4343
// BAD CONSTANT
4444
constexpr Real small_value_40 = 1.e-40;
45+
constexpr Real neg_small_value_16 = -1.e-16;
4546

4647
// Density of liquid water (STP)
4748
constexpr Real rhoh2o = haero::Constants::density_h2o;
@@ -368,12 +369,10 @@ also output wetvol and watervol
368369
dryvol += specvol[i];
369370
crefin += specvol[i] * specrefindex(i, ilwsw);
370371
}
371-
// printf("qaerwat_kk %e rhoh2o %e \n", qaerwat_kk, rhoh2o);
372372

373373
watervol = qaerwat_kk / rhoh2o;
374374
wetvol = watervol + dryvol;
375-
// printf("wetvol %e watervol %e dryvol %e \n ", wetvol, watervol,dryvol);
376-
if (watervol < zero && lwsw == 0) // lwsw=='lw'
375+
if (watervol < zero) // lwsw=='lw'
377376
{
378377
// BAD CONSTANT
379378
// FIXME
@@ -405,7 +404,7 @@ also output wetvol and watervol
405404
} // lwsw=='lw'
406405
// FIXME
407406
refr = crefin.real();
408-
refi = crefin.imag();
407+
refi = haero::abs(crefin.imag());
409408

410409
} // calc_refin_complex
411410

@@ -643,6 +642,25 @@ KOKKOS_INLINE_FUNCTION void modal_aero_sw_wo_diagnostics_k(
643642

644643
// lw =0 and sw =1
645644
Real dryvol, wetvol, watervol = {};
645+
// NOTE: The following logic exists only in MAM4xx,
646+
// it doesn't exists in Fortan MAM4. This logic is added
647+
// to deal with very small (essentially zero)
648+
// negative values for dryvol
649+
dryvol = zero;
650+
for (int ispec = 0; ispec < nspec; ++ispec) {
651+
dryvol += specvol[ispec];
652+
}
653+
if (dryvol < zero && dryvol > neg_small_value_16) {
654+
// if dryvol is negative and a very small number,
655+
// set all optical properties to zero
656+
// and continue to next iteration
657+
tauxar(mm, isw) = zero;
658+
wa(mm, isw) = zero;
659+
ga(mm, isw) = zero;
660+
fa(mm, isw) = zero;
661+
continue; // continue to next isw
662+
}
663+
646664
Kokkos::complex<Real> crefin = {};
647665
Real refr, refi = {};
648666

@@ -718,8 +736,8 @@ KOKKOS_INLINE_FUNCTION void modal_aero_sw_wo_diagnostics_k(
718736
fa(mm, isw) = dopaer * palb * pasm * pasm;
719737

720738
} // isw
721-
} // k
722-
} // k
739+
} // mm
740+
} // modal_aero_sw_wo_diagnostics_k ends
723741

724742
inline int get_work_len_aerosol_optics() {
725743
// tauxar, wa, ga, fa

0 commit comments

Comments
 (0)