Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extended diagnostic output from Thompson MP, includes "Add optional scaling to RRTMGP flux adjustment" (#668), fix index bug in m_micro.F90 #679

Merged
merged 40 commits into from
Jul 9, 2021

Conversation

climbfuji
Copy link
Collaborator

@climbfuji climbfuji commented Jun 22, 2021

Description

This PR builds on the work of @ericaligo-NOAA to output a number of diagnostic quantities from Thompson MP using generic aux3d arrays. A dedicated set of arrays and the corresponding logic to allocate them is added in the associated fv3atm PR listed below, and the Thompson microphysics code is updated to populate these based on a runtime configuration flag in input.nml.

Fixes #680.

This PR includes the changes in #668, "Add optional scaling to RRTMGP flux adjustment".

Also: fixes index bug in m_micro.F90.

Testing

See ufs-community/ufs-weather-model#658

Dependencies

#679
NOAA-EMC/fv3atm#331
ufs-community/ufs-weather-model#658

dustinswales and others added 26 commits May 9, 2021 19:32
Merge remote-tracking branch 'origin' into feature/diag
deallocate (nrten1)
deallocate (ncten1)
deallocate (qcten1)
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again.

Copy link
Collaborator

@grantfirl grantfirl 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 fine. It is unquestionably "cleaner" from a code (and metadata) point of view to put these diagnostics in an array. However, this sorta hides what the various diagnostics are. For example, are some of these diagnostics already represented by preexisting variables? Will this lead to hard-to-find duplication at some point down the road? There is a similar array for radiation. The opaqueness of these types of arrays is somewhat against the spirit of the CCPP is all I'm saying, despite being albeit unquestionably cleaner. Another way of looking at this is, what if every CCPP scheme had arrays of opaque/latent/hidden (in terms of metadata) variables?

@climbfuji
Copy link
Collaborator Author

I think it is important to understand that these diagnostics are highly specific to Thompson MP and that only developers who know what they are doing will be using them (e.g. @ericaligo-NOAA who contributed these code changes using the aux3d arrays). We want these diagnostics to be configurable easily without having to worry about how to get them written to disk, defining standard names for them etc. Adding 40+ diagnostic variables to the interface, defining metadata and handling the variable allocation and I/O for something so specialized doesn't seem like the best approach to me. I can imagine that similar requests will be made in the future for other physics schemes.

@ericaligo-NOAA
Copy link
Collaborator

ericaligo-NOAA commented Jun 25, 2021 via email

@grantfirl
Copy link
Collaborator

I get it, it's the easiest implementation for sure, no question. If physics developers really want this functionality (to be able to define an array of diagnostics for which no metadata exists, regardless of whether its contents are represented by pre-existing variables, and "protected" from being molested by other schemes), we probably need to say this in our documentation and carve out an exception in rules or otherwise provide guidance. Some non-trivial fraction of existing diagnostic variables could probably be wrapped up in arrays like this if we were to be consistent across existing CCPP schemes too. If somewhere down the line some scheme wants access to one of the diagnostics (to use as input into their scheme to do something useful with it), then it will just need to be extracted and made an interface variable at that time, I guess. It might be hard for them to discover them without good documentation of what is in the diagnostics array however.

I'm guessing that folks might want to explore this in the CCPP-framework meeting if we haven't done so at some previous point in the past already.

@climbfuji
Copy link
Collaborator Author

climbfuji commented Jun 25, 2021 via email

@grantfirl
Copy link
Collaborator

Other examples falling within the same mold would be all of the scheme-specific diagnostics coming from unified UGWP, MYNN PBL, GF convection, etc.

I'm not talking about this specific PR -- more about the precedent it might create. I'm not asking to change what was done in any way, just thinking how to handle the general case.

How can you be sure that what you consider scheme-specific diagnostic will not be wanted by another developer in the future? This seems subjective.

@climbfuji
Copy link
Collaborator Author

climbfuji commented Jun 25, 2021 via email

@grantfirl
Copy link
Collaborator

Dom, right. That's precisely my point. Other schemes need this kind of functionality, yet up until now, we've been asking for metadata and for the variables to be passed in/out individually, which I think is the case if you look at both of your examples, MYNN PBL and RUC LSM. Perhaps they have these types of variables (that are only allocated and given values when a special flag is set), yet they are passed in/out individually and have metadata, because that's what the CCPP rules say to do. There are exceptions like what is in this PR and the radiation "fluxr" array.

This PR (and other arrays like this) represents a kind of "subversion" of the CCPP rules, but I'm now arguing that it should probably be an officially-sanctioned one. After looking at the list of standard names of variables in the Diag and Interstitial DDTs, there are many that are precisely the type of variable that have been lumped into an array in this PR. If we change the CCPP rules to allow this kind of thing, it saves developers the trouble (and CCPP maintainers longterm) from having to mess with metadata for which no one will use except for those developing/debugging a particular scheme. I think that it could help reduce complexity and increase scheme portability in the longterm. All of this hinges on all of the "hidden" variables truly being scheme-specific and for diagnostic/debugging purposes, though.

Although I do worry about "abuse" of this technique (like I mentioned upthread), the fact that the fluxr array hasn't caused too many problems means that this is probably viable to do (and we should therefore include an exception to the rule in the CCPP docs for this purpose).

@climbfuji
Copy link
Collaborator Author

Dom, right. That's precisely my point. Other schemes need this kind of functionality, yet up until now, we've been asking for metadata and for the variables to be passed in/out individually, which I think is the case if you look at both of your examples, MYNN PBL and RUC LSM. Perhaps they have these types of variables (that are only allocated and given values when a special flag is set), yet they are passed in/out individually and have metadata, because that's what the CCPP rules say to do. There are exceptions like what is in this PR and the radiation "fluxr" array.

This PR (and other arrays like this) represents a kind of "subversion" of the CCPP rules, but I'm now arguing that it should probably be an officially-sanctioned one. After looking at the list of standard names of variables in the Diag and Interstitial DDTs, there are many that are precisely the type of variable that have been lumped into an array in this PR. If we change the CCPP rules to allow this kind of thing, it saves developers the trouble (and CCPP maintainers longterm) from having to mess with metadata for which no one will use except for those developing/debugging a particular scheme. I think that it could help reduce complexity and increase scheme portability in the longterm. All of this hinges on all of the "hidden" variables truly being scheme-specific and for diagnostic/debugging purposes, though.

Although I do worry about "abuse" of this technique (like I mentioned upthread), the fact that the fluxr array hasn't caused too many problems means that this is probably viable to do (and we should therefore include an exception to the rule in the CCPP docs for this purpose).

I couldn't agree more.

@dudhia
Copy link
Collaborator

dudhia commented Jun 25, 2021 via email

Copy link
Collaborator

@gthompsnWRF gthompsnWRF left a comment

Choose a reason for hiding this comment

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

Just a few thoughts added. I think we should just clean up the extra things that were added that really do only care about extended diagnostics but are otherwise added regardless. I don't believe this should be done in the interest of memory footprint or requirement to have just these 3 items in all people running the scheme.

allocate (nrten1(kts:kte))
allocate (ncten1(kts:kte))
allocate (qcten1(kts:kte))
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there are only 3 arrays that overlap out of the total ~35, is it much worry? Also, @ericaligo-NOAA is there a reason we need those 3 (vtsk1, txri1, txrc1) at all in the case without extended diagnostics? I think it's because you started with just 3 arrays and have since expanded. So my bigger concern is taking out those 3 completely in the circumstance of running without that namelist option - making it cleaner overall since some users won't want the overheads of 3 more 3D variables - which is a memory issue when running really big domains.

physics/module_mp_thompson.F90 Show resolved Hide resolved
@@ -3669,6 +4001,8 @@ subroutine mp_thompson (qv1d, qc1d, qi1d, qr1d, qs1d, qg1d, ni1d, &
qiten(k) = qiten(k) - xri*odt
niten(k) = -ni1d(k)*odt
tten(k) = tten(k) - lfus*ocp(k)*xri*odt*(1-IFDRY)
!diag
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you follow my suggestion to take these for ext diag only, then please remember to place these in a IF-statement for the logical namelist check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@gthompsnWRF @ericaligo-NOAA I would like to finish the discussion of this PR today, if possible, because we need to merge it next week and I will be on leave most of next week, too.

Should we remove those three diagnostic fields vtsk1, txri1, txrc1 and not worry about wrapping them in if statements inside do loops?

@@ -3449,6 +3777,7 @@ subroutine mp_thompson (qv1d, qc1d, qi1d, qr1d, qs1d, qg1d, ni1d, &
nstep = 0
do k = kte, kts, -1
vts = 0.
vtsk1(k)=0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ericaligo-NOAA I know why you created a separate array to get a diagnostic output to show for sure where snow terminal velocity is zero when snow is zero, but is it really needed any longer? You know the reason I have vtsk(k) = vtsk(k+1) is to avoid the "accumulation" problem during sedimentation. So the assignment in zero snow is possible here, but you can also just use a post-process mask of something like: WHERE (snow.lt.1.E-9) vtsk(k)=0.0 in output files to achieve the same thing without adding pretty much unneeded variables.

@@ -3758,6 +4094,89 @@ subroutine mp_thompson (qv1d, qc1d, qi1d, qr1d, qs1d, qg1d, ni1d, &
if (qg1d(k) .le. R1) qg1d(k) = 0.0
enddo

! Diagnostics
Copy link
Collaborator

Choose a reason for hiding this comment

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

For this instant, I am going to assume all the terms individually are done right, but I will attempt to come back to this and double-check, thinking it may take me 20-30 minutes to be really thorough.

@climbfuji
Copy link
Collaborator Author

I can explain why three of these arrays are always allocated. For all other extended diagnostics, computation and assignment are isolated to one block of code at the end of the subroutine. The three arrays, however, are computed in various places in the code beforehand and are inside loops over the vertical dimension. I did not want to "pollute" the code and negatively affect performance by adding if statements inside the loops. That's the only reason.

@ericaligo-NOAA
Copy link
Collaborator

ericaligo-NOAA commented Jun 28, 2021 via email

@climbfuji climbfuji force-pushed the thompson_ext_diag_dom branch from 18476ae to 28650fb Compare July 1, 2021 17:00
@ericaligo-NOAA
Copy link
Collaborator

ericaligo-NOAA commented Jul 2, 2021 via email

@climbfuji
Copy link
Collaborator Author

As far as I could tell, - lfusocp(k)xriodt(1-IFDRY), which I assigned to txri, does contribute to a temperature change, and is not duplicate, therefore I would include that in the if statement. There is another diagnostic, txrc, on a different line, related to xrc, which also contributes to a temperature change. Down the road, I do plan on adding all of the fall speeds and approximately 6 other diagnostics for development purposes. Also, I believe what's in the PR now is likely not the final product, unfortunately. Sorry about that. I made some changes that I think were necessary, but I believe cross sections will tell us if my changes are correct. Eric

Ok. Here is my suggestion. For the purpose of getting this PR merged, I will temporarily comment out the three variables vtsk1, txri1, txrc1 to avoid adding more if statements inside the do loops. We can update the diagnostics in a follow-up PR once you have completed your investigation.

@climbfuji
Copy link
Collaborator Author

@ericaligo-NOAA @gthompsnWRF I commented out the three diagnostics vts1, txri, txrc in my latest commit. We can decide what to do with them in a follow-up PR. Please take a look and approve if satisfied. Thanks!

@climbfuji climbfuji changed the title Add extended diagnostic output from Thompson MP Add extended diagnostic output from Thompson MP, includes "Add optional scaling to RRTMGP flux adjustment" (#668) Jul 2, 2021
@climbfuji climbfuji requested a review from dustinswales July 2, 2021 19:28
@climbfuji climbfuji changed the title Add extended diagnostic output from Thompson MP, includes "Add optional scaling to RRTMGP flux adjustment" (#668) Add extended diagnostic output from Thompson MP, includes "Add optional scaling to RRTMGP flux adjustment" (#668), fix index bug in m_micro.F90 Jul 2, 2021
@climbfuji climbfuji requested a review from SMoorthi-emc July 3, 2021 02:03
@grantfirl grantfirl merged commit 275b14c into NCAR:main Jul 9, 2021
@climbfuji climbfuji deleted the thompson_ext_diag_dom branch June 27, 2022 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extended diagnostic output from Thompson MP
7 participants