Skip to content

Use Y instead of C in Update_RCONST#106

Merged
yantosca merged 5 commits intodevfrom
issue93
Jul 25, 2024
Merged

Use Y instead of C in Update_RCONST#106
yantosca merged 5 commits intodevfrom
issue93

Conversation

@srosanka
Copy link
Copy Markdown
Collaborator

This pull request includes the necessary changes such that in Update_RCONST variable concentrations for rate constants that depend on species concentrations are used. To ensure backwards compatibility, YIN is an optional input. If YIN is not passed to Update_RCONST, concentrations from the global C array are used instead.

Closes #93

Update_RCONST now uses variable concentrations for rate constants that
depend on species concentrations. To ensure backwards compatibility, YIN
is an optional input. If YIN is not passed to Update_RCONST,
concentrations from the global C array are used instead.
@srosanka srosanka added the integrators Related to numerical integrators label Jul 12, 2024
@srosanka srosanka added this to the 3.2.0 milestone Jul 12, 2024
@srosanka srosanka requested a review from yantosca July 12, 2024 17:27
@srosanka
Copy link
Copy Markdown
Collaborator Author

@yantosca Should I add something to the documentation that Y should be used now instead of C when declaring reaction rates?

@yantosca yantosca self-assigned this Jul 15, 2024
@yantosca yantosca added the feature New feature or request label Jul 15, 2024
Copy link
Copy Markdown
Contributor

@yantosca yantosca left a comment

Choose a reason for hiding this comment

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

@srosanka @RolfSander: I ran the C-I tests on the issue93 branch. I found a couple of issues:

  1. We get a bunch of compile warnings in the C-language tests, that Y is an unused variable. It may be due to the fact that C doesn't allow for optional variables like F90 does.:
> C_rk_Rates.c: In function ‘Update_RCONST’:
> C_rk_Rates.c:166:8: warning: unused variable ‘Y’ [-Wunused-variable]
>   166 | double Y[NSPEC];                         /* Concentrations of species (local) */
>       |        ^
430a435,438
> C_rosadj_Rates.c: In function ‘Update_RCONST’:
> C_rosadj_Rates.c:166:8: warning: unused variable ‘Y’ [-Wunused-variable]
>   166 | double Y[NSPEC];                         /* Concentrations of species (local) */
>       |        ^
527a536,539
> C_sd_Rates.c: In function ‘Update_RCONST’:
> C_sd_Rates.c:166:8: warning: unused variable ‘Y’ [-Wunused-variable]
>   166 | double Y[NSPEC];                         /* Concentrations of species (local) */
>       |        ^
888a901,904
> C_sdadj_Rates.c: In function ‘Update_RCONST’:
> C_sdadj_Rates.c:166:8: warning: unused variable ‘Y’ [-Wunused-variable]
>   166 | double Y[NSPEC];                         /* Concentrations of species (local) */
>       |        ^
978a995,998
> C_small_strato_Rates.c: In function ‘Update_RCONST’:
> C_small_strato_Rates.c:166:8: warning: unused variable ‘Y’ [-Wunused-variable]
>   166 | double Y[NSPEC];                         /* Concentrations of species (local) */
  1. The mcm example fails, but this is fixed in the h211b branch.
mcm_Rates.f90:431:19:

  431 |   USE constants_mcm
      |                   1
Error: Unexpected USE statement at (1)
make: *** [Makefile_mcm:238: mcm_Rates.o] Error 1
make: *** Waiting for unfinished jobs....

On the Azure Dev Pipelines we don't run the MCM example as that takes too much memory. So we can live with this until we merge in the h211b branch, I think.

Any thoughts about the warning when generating C-language code? We don't have a lot of C users for KPP but we probably should fix this for reliability's sake.

@RolfSander
Copy link
Copy Markdown
Contributor

I was not able to reproduce the "unused variable" warning on my
computer. @yantosca: Maybe you are using a different C compiler version,
or maybe just a different warning level?

Anyway, maybe we can make the changes F90-specific and leave the code in
C and the other languages untouched. Something like this could work:

if ( useLang==F90_LANG )
    FunctionBegin( UPDATE_RCONST, YIN );
    Y = DefvElm( "Y", real, -NSPEC, "Concentrations of species (local)" );
    Declare(Y);
    NewLines(1);
else
    FunctionBegin( UPDATE_RCONST );

(note that I just typed this code here on github in pseudo-syntax)

@yantosca
Copy link
Copy Markdown
Contributor

@srosanka: That would be great if you could add some documentation about using Y instead of C.

@RolfSander: I used gcc 10.2.0 and 11.4.0 in my tests. I can add the IF block around the code as you said.

@RolfSander
Copy link
Copy Markdown
Contributor

I used gcc 10.2.0 and 11.4.0 in my tests.

I've used gcc 11.4.0, and I'm getting the warning now as well. I really
don't understand why I got no warning in my first try.

I can add the IF block around the code as you said.

Thanks!

@yantosca
Copy link
Copy Markdown
Contributor

@RolfSander -- I can also update the C-I script to print the compiler version

@RolfSander
Copy link
Copy Markdown
Contributor

Printing the compiler version is always a good idea when debugging (even though in this case, I don't think it can explain why I didn't see a warning initially).

yantosca added 2 commits July 17, 2024 10:44
src/gen.c
- Wrap the code to declare UPDATE_RCONST with YIN in an if block that
  only executes when useLang==F90
- Place code to declare UPDATE_RCONST without any variables in the
  else block.

Signed-off-by: Bob Yantosca <[email protected]>
.ci-pipelinoes/ci-common.defs.sh
- Add a function "print_compiler_versions" to print the gcc and
  gfortran compiler versions that are used to run the tests.

.ci-pipelines/ci-testing-script.sh
- Call "print_compiler_versions" function before running tests.
  This will print the compiler versions at the top of stdout output.

CHANGELOG.md
- Updated accordingly

Signed-off-by: Bob Yantosca <[email protected]>
@yantosca yantosca self-requested a review July 17, 2024 14:55
@yantosca
Copy link
Copy Markdown
Contributor

@RolfSander @srosanka: I pushed a fix that should only declare Update_Rconst with Y for F90.

Also the C-I tests now print at the top of stdout:

###########################################################################
         KPP CONTINUOUS INTEGRATION TESTS, USING THESE COMPILERS:

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

###########################################################################

@RolfSander
Copy link
Copy Markdown
Contributor

I pushed a fix that should only declare Update_Rconst with Y for F90.

Thanks, this looks good.

Also the C-I tests now print at the top of stdout

Thanks, this can be very helpful for future debugging!

@srosanka
Copy link
Copy Markdown
Collaborator Author

@yantosca and @RolfSander: thanks for spotting this issue and implementing the necessary changes to the code.

@yantosca: Great. I will then make some additions to the documentation.

@srosanka
Copy link
Copy Markdown
Collaborator Author

@yantosca I updated the documentation related to this issue. Please let me know if further adjustments are necessary.

@RolfSander
Copy link
Copy Markdown
Contributor

Thanks, @srosanka, for writing the documentation!

However, there is one thing I don't understand. Why should the user
change C to Y in their *.eqn file? I thought that UPDATE_RCONST
now automatically gets the correct value for Y, and the user doesn't
have to change anything.

Maybe the new documentation should be moved from the explanation of the #EQUATIONS section to the
description of ICNTRL(15)?

@yantosca
Copy link
Copy Markdown
Contributor

Thanks, @srosanka, for writing the documentation!

However, there is one thing I don't understand. Why should the user change C to Y in their *.eqn file? I thought that UPDATE_RCONST now automatically gets the correct value for Y, and the user doesn't have to change anything.

Maybe the new documentation should be moved from the explanation of the #EQUATIONS section to the description of ICNTRL(15)?

Thanks @srosanka and @RolfSander. I agree, I don't think we need to explicitly add Y to the rate constant. In the function template we have something like this:

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SUBROUTINE FunTemplate( T, Y, Ydot, P_VAR, D_VAR )
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!  Template for the ODE function call.
!  Updates the rate coefficients (and possibly the fixed species) at each call
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
   IF ( Do_Update_RCONST ) CALL Update_RCONST( Y )
...
END SUBROUTINE FunTemplate

so Y is already passed as an argument to the function that will be integrated.

@RolfSander
Copy link
Copy Markdown
Contributor

I've adjusted the documentation. Is it ok now?

Copy link
Copy Markdown
Contributor

@yantosca yantosca left a comment

Choose a reason for hiding this comment

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

Thanks @RolfSander! This is good to merge now.

@yantosca yantosca merged commit f1d6ef1 into dev Jul 25, 2024
@yantosca yantosca deleted the issue93 branch July 25, 2024 13:37
@srosanka
Copy link
Copy Markdown
Collaborator Author

Thanks, @RolfSander and @yantosca for making the necessary adjustments to the documentation and for merging the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request integrators Related to numerical integrators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants