Create variables to track non-passive species, so that they can be excluded from the Rosenbrock error norm (in int/rosenbrock*.f90 integrators only)#154
Conversation
|
It's good to see that there is now a possibility to exclude dummy With the current implementation, you can use the optional argument only My suggestion is that we put NonDummySpc_Count into ICNTRL(19). The Would that work? |
|
Thanks @RolfSander, I think that's a good idea. I'll try it. |
|
@RolfSander: I just noticed that there is the |
Yes, we should avoid confusion. Unfortunately,
Here is yet another idea: During the discussion, @obin1 used the name |
|
I like If we are looking for something more general, would |
|
Thanks @RolfSander. I think |
ac46cd9 to
d8b35b8
Compare
code_f90.c
- In function F90_Decl:
- Modified the ELM case block to write a F90 scalar argument with the
OPTIONAL attribute when ATTR_F90_OPT is specified
- Updated comments (cosmetic changes)
- Added F90_FunctionBeginNoArgDecl, which is similar to F90_FunctionBegin
except that it doesn't automatically write the F90 function args
immediately below the subroutine header.
- In routine Use_F90:
- Point FunctionBeginNoArgDecl to F90_FunctionBeginNoArgDecl
src/code.c
- Added function prototype for FunctionBeginNoArgDecl
src/code.h
- Added macro DefElmO, which writes an OPTIONAL F90 scalar variable
- Added an extern function prototype for FunctionBeginNoArgDecl
src/code_c.c
src/code_f77.c
src/code_matlab.c
- Point FunctionBeginNoArgDecl to NULL in order to avoid
uninitialized-variable compiler warnings
CHANGELOG.md
- Updated accordingly
Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
src/gen.c
- In routine InitGen:
- Added variables NON_PASV_SPC_CT and NON_PASV_SPC_IND, which will
be used to write F90 variables (NonPassiveSpc_Count and
NonPassiveSpc_indices) to keep track of non-passive species
- Updated comments for clarity + other cosmetic changes
- In routine GenerateUpdateRconst
- Now use FunctionBeginNoArgsDecl to write the subroutine interface
for UPDATE_RCONST with YIN as optional input argument
- Updated comments
- In routine GenerateGlobalHeader
- Write NonPassiveSpc_Count and NonPassiveSpc_Indices to ROOT_Global
(for F90 only)
- Now write the autoreduction variables following the non-THREADPRIVATE
variables
- Updated comments, cosmetic changes
- In routine GenerateInitialize
- Use FunctionBeginNoArgsDecl to write the ROOT_Initialize subroutine
header with PassiveSpc_ATOL_Threshold optional variable
- Write the PassiveSpc_ATOL_Threshold variable declaration
following all F90 USE statements
- For F90 only, add inlined code that initializes the variables
NonPassiveSpc_Count and NonPassiveSpc_Indices by testing which
species have ATOL < PassiveSpc_ATOL_Threshold
- Updated comments for clarity
int/rosenbrock.f90
int/rosenbrock_adj.f90
int/rosenbrock_autoreduce.f90
int/rosenbrock_tlm.f90
- Rewrote the ros_ErrorNorm function to use NonPassiveSpc_Count and
NonPassiveSpc_Indices so that passive species won't influence
the Rosenbrock error norm
- Use separate loops for vector tolerance and scalar tolerance,
to faciltate vectorization
Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
d8b35b8 to
66c2796
Compare
Overview
This is the companion PR to #66 and #144. In this PR we allow optional arguments to be passed to Rosenbrock F90 integrators so that we can exclude dummy species (i.e. those added to chemical reactions for the purpose of obtaining diagnostic information) from the Rosenbrock error norm computation. This should prevent the issue where integration results are changed depending on the number of dummy species in the mechanism (cf geoschem/geos-chem#3175).
Technical description
Two optional arguments are passed to the top-level INTEGRATE functions in the
int/rosenbrock.f90,int/rosenbrock_autoreduce.f90,int/rosenbrock_adj.f90andint/rosenbrock_tlm.f90integrators. These are:NonDummySpc_Count: The number of non-dummy speciesNonDummySpc_Indices: The KPP species indices for non-dummy speciesThese optional variables can be defined outside of KPP by using a simple test of absolute tolerance, such as:
This only has to be done once, e.g. at model initialization. Then these can be passed to the Rosenbrock integrator:
CALL Integrate( TIN, TOUT, ICNTRL, RCNTRL, ISTATUS, RSTATE, IERR, & NonDummySpc_Count, NonDummySpc_Indices )We have also updated the algorithm in the
Ros_ErrorNormfunction (in each of theint/rosenbrock*.f90 files)to compute the error norm on the basis of non-dummy species when the optional arguments are passed. If they are not passed, it will fall back to the default behavior (using all species to compute the error norm). Also we have optimized the function to facilitate vectorization and to remove unnecessary ELSE blocks, which can be a bottleneck:Related GitHub issues
Tagging @RolfSander @msl3v @jimmielin @obin1 @fsolmon @ujongebloed @mje1398