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

Clean up diagnostic variables in WW3 for Langmuir turbulence parameterization #4

Closed
wants to merge 11 commits into from

Conversation

qingli411
Copy link

@qingli411 qingli411 commented May 7, 2022

Pull Request Summary

This PR cleans up the calculation of Stokes drift and other diagnostics variables in WW3 for Langmuir turbulence parameterization in CESM.

Description

  • Clean up the calculations of the surface Stokes drift (USSX and USSY) and surface layer averaged Stokes drift (USSHX and USSHY). The calculation of surface layer averaged Stokes drift and the tail contributions to both versions of Stokes drift are activated when W3_CESMCOUPLED is defined.
  • Change the input field of mixed layer depth HML to a more general surface layer depth HSL. This depth is used to calculate the surface layer averaged Stokes drift. When used in CESM, the surface layer depth is defined as 1/5 of the mixed layer depth. Now this 1/5 factor is applied to the mixed layer depth when importing the fields in the cap.
  • Clean up the diagnostic variables for Langmuir turbulence parameterization. Some variables are intermediate quantities and are not used in the parameterization. These variables are now deleted. The key variable diagnosed in WW3 is the surface layer averaged Stokes drift (USSHX and USSHY). The Langmuir enhancement factor (LAMULT) and the surface layer averaged Langmuir number (LASL) are now calculated when they are exported in the cap. LASL is needed for the Langmuir induced entrainment parameterization in CVMix but was not there in the cap code. So it is now added following the way LAMULT is defined.
  • This PR only changes the diagnostic variables in WW3 and shouldn't change the answers of WW3. Ideally, this PR shouldn't change the diagnostic variables to be used in CESM (LAMULT, LASL) as well. But given that the calculation of these variables are moved to the cap, and the way division by zero and physically invalid values (both should be rare) are handled, small changes to these variables are expected.
  • Labels: enhancement?
  • Suggestions for a reviewers: @alperaltuntas @DeniseWorthen @mvertens

Issue(s) addressed

This PR partially addresses the following issues.

Commit Message

Clean up the calculation of Stokes drift and other diagnostic variables for Langmuir turbulence parameterization.

Check list

Testing

  • How were these changes tested?
  • Are the changes covered by regression tests? (If not, why? Do new tests need to be added?)
  • Have the matrix regression tests been run (if yes, please note HPC and compiler)?
  • Please provide the summary output of matrix.comp (matrix.Diff.txt, matrixCompFull.txt and matrixCompSummary.txt):
  • Please indicate the expected changes in the regression test output (Note the known list of non-identical tests).
  • Please provide the summary output of matrix.comp (matrix.Diff.txt, matrixCompFull.txt and matrixCompSummary.txt):

This PR has not been tested yet.

Todo

I think there are still a few things to do in this PR. But I'm not sure what's the best way to proceed so I listed them here for discussion. Any suggestions? @alperaltuntas @DeniseWorthen @mvertens

  • I didn’t include any new ifdefs to control whether or not to include the high frequency tail contributions to the Stokes drift or whether or not we should output the surface layer averaged Stokes drift. We may need some new ifdefs for better control of such features for non-CESM users as described in Add optional high frequency tail to USSX, USSY NOAA-EMC/WW3#669.
  • The output of the surface layer averaged Stokes drift (USSHX, USSHY) needs additional lines in w3iogomd.F90 that depend on the indices of the flag array FLOGRD. I’m not sure what’s the best way to combine the flags in FLOGRD and ifdefs so I didn’t add them. Right now USSHX and USSHY should be calculated and used in the cap when W3_CESMCOUPLED is defined but they are not in the WW3 output.
  • I think we also need corresponding lines for USSHX and USSHY in w3initmd.F90 and w3iorsmd.F90 for initialization and restart? Again they depend on the indices in the arrays of the flags.
  • In the calculations of LAMULT and LASL (now in wav_import_export.F90), we may need better ways to check division by zero. I also put some arbitrary limits to avoid unphysical behavior (e.g., LASL should default to a large number which corresponds to LAMULT=1 and USSX=USSY=0, and LASL should be greater than zero). I think we should make sure these are consistent with other part of the code.

qingli411 added 4 commits May 7, 2022 08:58
1. Remove redundant temporary variables (ETUSSX, ETUSSY, ETUSSXH, ETUSSYH)
   and lines for calculating the surface Stokes drift and surface layer
   averaged Stokes drift.
2. Calculation of surface layer averaged Stokes drift and the tail
   contribution to both surface and surface layer averaged Stokes drift
   are activated when W3_CESMCOUPLED is defined.
Replace the mixed layer depth by a surface layer depth for the depth
averaged Stokes drift and define it to be 1/5 of the mixed layer depth
when importing the field.
1. Remove unnecessary diagnostic variables for Langmuir turbulence
   parameterization in CESM.
2. Move the calculations of Langmuir enhancement factor (lamult) and
   surface layer averaged Langmuir number (lasl) to the cap-code.
3. Add a new variable (lasl) to be exported for Langmuir turbulence
   parameterization in CESM.
@DeniseWorthen
Copy link

DeniseWorthen commented May 9, 2022

@qingli411 it looks like you are removing LANGMT as a variable output from WW3. Do you want to be able to retain this variable in WW3 output? I've been working on getting a cesm-like case set up for UFS and we discovered that the LANGMT variable is not getting written to the ww3 history file right now. I've fixed a couple of issues and I am now getting LANGMT in the netcdf file, but it is all undefined.

@qingli411
Copy link
Author

@DeniseWorthen LANGMT can be diagnosed from the surface Stokes drift USSX and USSY and surface friction velocity so I don't think it is critical to retain this variable in WW3 output (I realized that I didn't remove those lines that define LANGMT and I will do that in a new commit). Instead, I think it is helpful to save the surface layer averaged Stokes drift in WW3 output. So I will do the following.

  1. Remove LANGMT from WW3 output
  2. Add the surface layer averaged Stokes drift to WW3 output (currently it is calculated but not saved in the output). I will put it in the same wave-ocean layer group as the surface Stokes drift.

@qingli411
Copy link
Author

@alperaltuntas Do you have any suggestions on which branch of CESM I should use or start from to test the changes here?

@alperaltuntas
Copy link
Member

@qingli411 , For testing, I suggest you use the newly created cesm2_3_alpha09b tag, but make sure to switch to main_0.0.4 and dev/unified_0.0.4 tags for WW3_interface and WW3, respectively.

@qingli411
Copy link
Author

OK. I will try that. Thanks! @alperaltuntas

ALLOCATE ( WADATS(IMOD)%XLANGMT(NXXX), STAT=ISTAT )
ALLOCATE ( WADATS(IMOD)%XUSSHX(NXXX), STAT=ISTAT )
CHECK_ALLOC_STATUS ( ISTAT )
ALLOCATE ( WADATS(IMOD)%XUSSY(NXXX), STAT=ISTAT )
Copy link
Member

Choose a reason for hiding this comment

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

I believe, you mean to allocate XUSSHY here, and not ``XUSSY`.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

ALLOCATE ( WADATS(IMOD)%XLANGMT(1), STAT=ISTAT )
ALLOCATE ( WADATS(IMOD)%XUSSHX(1), STAT=ISTAT )
CHECK_ALLOC_STATUS ( ISTAT )
ALLOCATE ( WADATS(IMOD)%XUSSY(1), STAT=ISTAT )
Copy link
Member

Choose a reason for hiding this comment

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

Again, I believe you mean to allocate XUSSHY here, and not ``XUSSY`.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

#ifdef W3_CESMCOUPLED
USE W3ADATMD, ONLY: LANGMT
#endif
#ifdef W3_CESMCOUPLED
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the whitespaces before ifdefs.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -225,7 +225,8 @@ subroutine initialize_gridout
varatts( "USP ", "USSPY ", "Partitioned surface Stokes drift y ", "m s-1 ", "p ", .false.) , &
varatts( "TWC ", "TAUOCX ", "Total wave to ocean stress x ", "Pa ", " ", .false.) , &
varatts( "TWC ", "TAUOCY ", "Total wave to ocean stress y ", "Pa ", " ", .false.) , &
varatts( "LAN ", "LANGMT ", "Turbulent Langmuir number (La_t) ", "nd ", " ", .false.) &
varatts( "USSH ", "USSHX ", "Surface layer averaged Stokes drift x ", "m s-1 ", " ", .false.) , &
varatts( "USSH ", "USSHY ", "Surface layer averaged Stokes drift y ", "m s-1 ", " ", .false.) , &
Copy link
Member

Choose a reason for hiding this comment

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

You need to remove the comma at the end here (before ampersand).

Copy link
Author

Choose a reason for hiding this comment

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

Done

alphal = atan( sin(sww) / ( &
2.5 * UST(isea)*ASF(isea)*sqrt(dair/dwat) &
/ max(1.e-14, sqrt(USSX(jsea)**2+USSY(jsea)**2)) &
* log(max(1.0, abs(1.25*HSL(ix,iy)/HS(jsea)))) &
Copy link
Member

Choose a reason for hiding this comment

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

Here, we get a floating point error when HS is zero. It is unclear to me why HS becomes exactly zero at a sea point, but regardless, it looks like this expression should be refactored to ensure numerical stability for cells where denominators are very small.

Copy link
Author

Choose a reason for hiding this comment

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

I think we need to set sw_lamult to 1 when HS=0. So I add this condition in the if statement on Line 673.

@qingli411
Copy link
Author

Thanks, @alperaltuntas, for reviewing this PR! And sorry for my delay. In addition to fixing these, I also added a switch W3_SDTAIL in w3iogomd.F90 to control if we want to include the contribution of a high frequency tail to the Stokes drift, trying to address the question in NOAA-EMC#764. But I'm not sure if we need additional steps for this new switch?

@alperaltuntas
Copy link
Member

I am closing this PR in favor of the updated version #8

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.

3 participants