Skip to content

Add inlined code in the #INLINE F90_RCONST_USE block to the Update_Photo routine#125

Merged
yantosca merged 3 commits intodevfrom
bugfix/f90-rconst-use-in-update-photo
Feb 5, 2025
Merged

Add inlined code in the #INLINE F90_RCONST_USE block to the Update_Photo routine#125
yantosca merged 3 commits intodevfrom
bugfix/f90-rconst-use-in-update-photo

Conversation

@yantosca
Copy link
Copy Markdown
Contributor

@yantosca yantosca commented Jan 27, 2025

This PR fixes a bug that I found when trying to run the C-I tests for the MCM mechanism. The fix does the following:

  1. Added code to the GenerateUpdatePhoto routine in src/gen.c to so that any F90 use statements specified in #INLINE F90_RCONST_USE will be inlined at the top of the Update_PHOTO routine. This will prevent compilation errors.

  2. Moved the USE constants_mcm statement (in examples/mcm/mcm_isoprene.eqn) from #INLINE F90_RCONST to #INLINE F90_RCONST_USE, so that it will be placed at the proper place at the top of the subroutine before any declaration or executable statements.

  3. Edited the ReadTheDocs documentation for F90_RCONST_USE to state that any use statements specified here will be placed into both Update_RCONST and Update_PHOTO.

src/gen.c
- In routine GenerateUpdatePhoto, we also now inline USE statements
  from inline block F90_RCONST_USE into routine Update_Photo.
  This fixes a bug that was found with the MCM mechanism.

examples/mcm/mcm_isoprene.eqn
- Moved "USE constants_mcm" from the F90_RCONST to the F90_RCONST_USE
  inline block.  This will place it properly at the top of the routines.

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <[email protected]>
docs/source/using_kpp/04_input_for_kpp.rst
- Now state that code specified in an #INLINE F90_RCONST_USE section
  will be placed into both Update_RCONST and Update_PHOTO.

Signed-off-by: Bob Yantosca <[email protected]>
@yantosca yantosca added mechanisms Related to chemical mechanisms code / structural Related to structural source code updates bugfix Fixes a bug or a technical issue labels Jan 27, 2025
@yantosca yantosca added this to the 3.2.0 milestone Jan 27, 2025
@yantosca yantosca requested a review from RolfSander January 27, 2025 22:43
@yantosca yantosca self-assigned this Jan 27, 2025
@yantosca
Copy link
Copy Markdown
Contributor Author

With this fix, the C-I test for the MCM mechanism runs to completion:

>>>>>>>> Generating mcm mechanism with KPP <<<<<<<<


This is KPP-3.1.1.

KPP is parsing the equation file.
KPP is computing Jacobian sparsity structure.
KPP is starting the code generation.
KPP is initializing the code generation.
KPP is generating the monitor data:
    - mcm_Monitor
KPP is generating the utility data:
    - mcm_Util
KPP is generating the global declarations:
    - mcm_Main
KPP is generating the ODE function:
    - mcm_Function
KPP is generating the ODE Jacobian:
    - mcm_Jacobian
    - mcm_JacobianSP
KPP is generating the linear algebra routines:
    - mcm_LinearAlgebra
KPP is generating the utility functions:
    - mcm_Util
KPP is generating the rate laws:
    - mcm_Rates
KPP is generating the parameters:
    - mcm_Parameters
KPP is generating the global data:
    - mcm_Global
KPP is generating the driver from ./driver_mcm.f90:
    - mcm_Main
KPP is starting the code post-processing.

KPP has successfully created the model "mcm".

>>>>>>>> Building the mcm test executable <<<<<<<<<

gfortran -cpp -O -g -frecursive  -c mcm_Precision.f90
gfortran -cpp -O -g -frecursive  -c mcm_Parameters.f90
gfortran -cpp -O -g -frecursive  -c mcm_Monitor.f90
gfortran -cpp -O -g -frecursive  -c mcm_Global.f90
gfortran -cpp -O -g -frecursive  -c constants_mcm.f90
gfortran -cpp -O -g -frecursive  -c mcm_Function.f90
gfortran -cpp -O -g -frecursive  -c mcm_JacobianSP.f90
gfortran -cpp -O -g -frecursive  -c mcm_Rates.f90
gfortran -cpp -O -g -frecursive  -c mcm_Initialize.f90
gfortran -cpp -O -g -frecursive  -c mcm_Util.f90
gfortran -cpp -O -g -frecursive  -c mcm_Jacobian.f90
gfortran -cpp -O -g -frecursive  -c mcm_LinearAlgebra.f90
mcm_LinearAlgebra.f90:4446:46:

 4446 |       IF (incX .EQ. incY) IF (incX-1) 5,20,60
      |                                              1
Warning: Fortran 2018 deleted feature: Arithmetic IF statement at (1)
gfortran -cpp -O -g -frecursive  -c mcm_Integrator.f90
gfortran -cpp -O -g -frecursive  -c mcm_Model.f90
gfortran -cpp -O -g -frecursive  -c mcm_Main.f90
gfortran -cpp -O -g -frecursive  mcm_Precision.o    mcm_Parameters.o mcm_Global.o       constants_mcm.o mcm_Function.o mcm_JacobianSP.o mcm_Jacobian.o   mcm_Rates.o   mcm_Util.o   mcm_Monitor.o mcm_LinearAlgebra.o mcm_Main.o          mcm_Initialize.o mcm_Integrator.o    mcm_Model.o  -o mcm.exe

>>>>>>>> Running the mcm test <<<<<<<<


>>>>>>>> mcm test was successful! <<<<<<<<

Copy link
Copy Markdown
Contributor

@RolfSander RolfSander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. UPDATE_PHOTO should be treated in the same way as
UPDATE_RCONST: Both should include the F90_RCONST_USE block.

@yantosca
Copy link
Copy Markdown
Contributor Author

yantosca commented Feb 5, 2025

Thanks @RolfSander. I made note of that in the documentation as well.

@yantosca yantosca merged commit 3c1d962 into dev Feb 5, 2025
@yantosca yantosca deleted the bugfix/f90-rconst-use-in-update-photo branch February 5, 2025 14:52
@yantosca yantosca linked an issue Oct 27, 2025 that may be closed by this pull request
@yantosca yantosca mentioned this pull request Oct 27, 2025
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug or a technical issue code / structural Related to structural source code updates mechanisms Related to chemical mechanisms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Are we using Update_RCONST() correctly?

2 participants