KineticPreProcessor / KPP

The KPP kinetic preprocessor is a software tool that assists the computer simulation of chemical kinetic systems
GNU General Public License v3.0
19 stars 11 forks source link

[BUG/ISSUE] FIX must be the 2nd argument passed to FunTemplate in int/feuler.f90- #60

Closed yantosca closed 1 year ago

yantosca commented 1 year ago

While testing the carboncycle simulation in GEOS-Chem (which uses the Forward-Euler integrator, int/feuler.f90), I was getting negative concentrations that were hard to pin down. Long story short, I traced this to this line of code:

https://github.com/KineticPreProcessor/KPP/blob/d690142f8a7e80e79ecb8ba203b004dbeee63afb/int/feuler.f90#L199-L200

but the generated Fun routine always takes the vector of fixed species concentrations (FIX) as the 2nd argument:

SUBROUTINE Fun ( V, F, RCT, Vdot, Aout, Vdotout )

! V - Concentrations of variable species (local)
  REAL(kind=dp) :: V(NVAR)
! F - Concentrations of fixed species (local)
  REAL(kind=dp) :: F(NFIX)

This led to the F dummy-argument variable being set to a random negative number and propagating negatives through the code.

The fix is just to change

CALL Fun( Y, VAR, RCONST, Ydot ) 

to

CALL Fun( Y, FIX, RCONST, Ydot ) 

in int/feuler.f90. I will submit a PR soon for this for KPP 3.0.0.

yantosca commented 1 year ago

We can close this issue as this has been merged into KPP 3.0.0-rc.4.