geoschem / geos-chem

GEOS-Chem "Science Codebase" repository. Contains GEOS-Chem science routines, run directory generation scripts, and interface code. This repository is used as a submodule within the GCClassic and GCHP wrappers, as well as in other modeling contexts (external ESMs).
http://geos-chem.org
Other
168 stars 165 forks source link

[BUG/ISSUE] Speed up het rates code by pre-computing species ID's, MWs, and Henry's constants #362

Closed yantosca closed 4 years ago

yantosca commented 4 years ago

Describe the bug:

In the halogens update for GEOS-Chem 12.9.0, the computation of heterogeneous rates was slowed down by several calls to the Ind_() function from within routine SET_HET in KPP/Standard/gckpp_Hetrates.F90. This function is used to translate a species name to its index in the list of species. The Ind_() function incurs a certain amount of overhead on each call, and SET_HET is called on each (I,J,L) iteration. The end result was that the het rates computation was bogged down by inefficient code.

Solution:

Instead of calling the Ind_() function repeatedly from within routine SET_HET, we now have used the defined type object field State_Chm%HetInfo to store precomputed model indices, molecular weights, and Henry's law constants. The State_Chm%HetInfo field only needs to be defined at model initialization, and can be passed into SET_HET on subsequent timesteps.

Furthermore, we were able to improve several internal routines (in which hetchem rates in tropopshereic clouds are computed) in gckpp_Hetrates.F90 by exiting each routine immediately if grid box (I,J,L) corresponded to a location within the stratosphere. Prior to this fix, several needless computations were being performed for stratospheric boxes, where they were not used.

These fixes dramatically decrease the time spent in the computation of the heterogenous chemistry rates. Here are the times in total seconds from several internal 1-month benchmarks:

12.9.0-alpha.2    4863.246
12.9.0-alpha.4   26348.469 
12.9.0-alpha.5    7030.469 
12.9.0-rc.0        441.706

Also, as part of this fix, we have removed multiple inconsistent definitions of parameters (such as molecular weights, Henry's law coefficients, and conversion factors). All molecular weights and Henry's law coefficients now come from the GEOS-Chem species database, and only a single set of unit conversion factors are used. This will cause some minor numerical differences w/r/t the prior code.

yantosca commented 4 years ago

We can now close this issue (which was added for documentation purposes). This issue is resolved by the following commits: https://github.com/geoschem/geos-chem/commit/c860b567bcee0e282b840ac9e177f155947994c2, https://github.com/geoschem/geos-chem/commit/9dd4f63a901c8d1f5574444519eb8d86dc47b2fd, https://github.com/geoschem/geos-chem/commit/83d18521d993ed1a2d98ba280ee3ce9c9c328af7, and https://github.com/geoschem/geos-chem/commit/45741670c518ef0e16e799b92747a7c24b49ecf0.