E3SM-Project / v3atm

Fork of E3SM for testing v3 atm changes
Other
0 stars 5 forks source link

fixed the shape of dummy array pdeldry in lin_strat_chem.F90 #28

Closed wlin7 closed 1 year ago

wlin7 commented 1 year ago

The caller passes in the array in the shape of (pcols,pver) while the shape of the dummy array in the subroutine is (ncol,pver) and used as such inside subroutine linv3_strat_chem_solve.

When pcols > ncol, undefined values would be used in the calculations for do3_linoz_du and do3_linoz_psc_du.

While this will fix rin with debug mode, it has no impact on simulation results as the array involved, pdeldry, is only used for computing several diagnostic variables do3_linoz_du and do3_linoz_psc_du, which are not output by default.

[BFB]

wlin7 commented 1 year ago

Both array shapes of (ncol,pver) and (pcols,pver) are used throughout the chemUCI codes. Continue looking to see if any similar bugs.

tangq commented 1 year ago

I noticed pcols and ncol are used in the code interchangeably before. What is the difference between these two variables?

wlin7 commented 1 year ago

pcols and ncol are used in the code interchangeably before. What is the difference between these two variables?

They can often be different. PCOLS is set via macro during compilation as the maximum # of columns per chunk. The value is usually optimized for performance. ncol is the actual # of columns for a chunk during runtime. Based on grid and pe-layout, the decomposition of the domain often has chunks not filling up to the max value of pcols. To reference the array safely, the explicit upper bound of ncol is often used.

keziming commented 1 year ago

The caller passes in the array in the shape of (pcols,pver) while the shape of the dummy array in the subroutine is (ncol,pver) and used as such inside subroutine linv3_strat_chem_solve.

When pcols > ncol, undefined values would be used in the calculations for do3_linoz_du and do3_linoz_psc_du.

[NBFB]

If this ncol/pcols inconsistency shows up at other places, which one we should choose? As you explained that pcols >= ncol, using pcols here to replace ncol can avoid inconsistency but still can cause empty (or non-realistic) column to be calculated. Am I right @wlin7 ?

wlin7 commented 1 year ago

If this ncol/pcols inconsistency shows up at other places, which one we should choose? As you explained that pcols >= ncol, using pcols here to replace ncol can avoid inconsistency but still can cause empty (or non-realistic) column to be calculated. Am I right @wlin7 ?

Ziming, for this particular case, inside the subroutine linv3_strat_chem_solve, it always uses the form of pdeldry(:ncol,:) correctly in actual calculation. Undefined values in pdeldry(ncol+1:pcols,:) are never used.

However, when the dummy array is declared as pdeldry(ncol,pver), and the actual array passed from the caller is pdeldry(pcols,pver), the undefined values would be spread to the dummy array in active columns. For example undefined value of pdeldry(ncol+1,1) from the caller would end up in the dummy array at pdeldry(1,2), and so on. Note the discussion here is applicable only when ncol < pcols.

wlin7 commented 1 year ago

The standard tests appear to be not affected by this bug fix, which is great (and a bit puzzling). The bug was exposed when performing PET test in debug mode.