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

separate diagnostic fill of total tend from passing of total tend to pkg/layers #720

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

antnguyen13
Copy link
Collaborator

@antnguyen13 antnguyen13 commented Apr 6, 2023

What changes does this PR introduce?

Enable users to calculate the total tendencies of theta and salt and pass to pkg/layers independent of whether diagnostics TOTTTEND and TOTSTEND are filled or not.

What is the current behaviour?

The calculation of total tendencies for theta/salt and passing of these to pkg/layers will be non-zeroes only if the diagnostics to TOT[T,S]TEND are filled. If not, zeros are passed to pkg/layers, variable layers_tottend is filled with zeros inside subroutine layers_fill inside layers_save.F and diagnostics LTto[1SLT,2TH,3RHO] and LSto[1SLT,2TH,3RHO] are all zeros.

What is the new behaviour

Separate the if/def block for filling the diagnostics from the calculation of tendencies, such that non-zeros tendencies can be passed to pkg/layers independent of whether the diagnostics are filled.

Does this PR introduce a breaking change?

None.

Other information:

Suggested addition to tag-index

(To avoid unnecessary merge conflicts, please don't update tag-index. One of the admins will do that when merging your pull request.)

The values for tottend[T,S] are calculated when
(1) diagnostics of tottend[T,S] are requested outside of pkg/layers
AND/OR
(2) diagnostics of tottend[T,S] are requested INSIDE pkg/layers.
In case of (2) inside pkg/layers, prior to being diagnosed, the
tottend variables are being passed around as input arguments for
subroutines layers_calc.F and layers_fluxcalc.F, prior to the final
diagnostic call. Here, we introduce (a) option LAYERS_DIAG_TOTTEND
in LAYERS_OPTIONS.h (default to #define) to strip all array definitions,
subroutine arguments, and related calculations, thus saving memory
and computed time, and (b) logical "layers_diag_tottendTS" (default
to .TRUE.) to allow the filling of the layers diagnotics.
@antnguyen13
Copy link
Collaborator Author

@jm-c I made some changes, as you will see, by introducing two new things:

  1. an option to allow bypassing defining of large arrays and calculations of these arrays (if undef) in the case we dont care to diagnose layers tottend
  2. a logical to finally determine if we really write out layers diagnostics.

The reason for 1 is explained above: even if we don't want to diagnose, we're still passing around very large arrays and computing things that are all zeros.

The reason for 2, instead of just using diagnostic_is_on , is that the names of the diagnostics are not fixed, with a number "1" or "2" floating around depending on order of T/S (although it might have been hardcoded 1=T, 2=S, or the other way around... but I dont want to make a mess in diagnostics_fill_state.F to determine this string, which requiring several other pkg/layers variables.. so i make it easier by defining the associated/accompanied logical.

Due to the way tottend variables are being used, defined, calculated,
and subsequently diagnosed within pkg/layers, the best approach is
to wrap it around the ifdef block as now done with previously
defined LAYERS_DIAG_TOTTEND compiling option without the need of
accompanied complexity of another logical.

Now, outside of pkg/layers, if uselayers is true, the tottend
is being computed and a call is done to pass it into pkg/layers.
However, inside pkg/layers, only within #ifdef LAYERS_DIAG_TOTTEND
block will any calculations and diagnostics relevant to tottend
will be done.
@antnguyen13
Copy link
Collaborator Author

antnguyen13 commented May 9, 2023

@jm-c after looking more carefully at the way tottend variables are used in pkg/layers and how to call this from outside, i've simplified the problem by

a. doing as you suggested in diagnostics_fill_state.F: simply hook in the additional check for useLayers. Even though this variable is defined outside of pkg/layers, a subsequent call to routine layers_fill requires the additional wrap "#ifdef ALLOW_LAYERS" .
b. now, inside pkg/layers, everything related to tottend will only be defined, used, computed, and diagnosed if the new option LAYERS_DIAG_TOTTEND is defined.

Edit: the failed readthedoc is not due to any of my changes i believe.

@jm-c
Copy link
Member

jm-c commented Jul 6, 2023

@antnguyen13 I tried to run "testreport -devel" using gfortran but got this error when running cfc_example:

At line 6739 of file layers_fluxcalc.f
Fortran runtime error: Index '0' of dimension 1 of array 'mybylo' below lower bound of 1

Could you check ?

@antnguyen13
Copy link
Collaborator Author

antnguyen13 commented Jul 7, 2023

@jm-c eeks, i'm appalled by my sloppiness.. now should be ok!

ps- I will ask for your help at the next devel meeting on which tot[T,S]tend to diagnose, as it turns out the one I'm trying to get correct here is useless for nlfs, and so even when pkg/layers is compiled, the tot[T,S]tend being passed in are not useful at all for closing budgets. What i'm hoping to diagnose is the tot[T,S]tend that accounts for the changing hFac such that when diagnosed at THIS timestep it is equivalent to snap shots of NEXT time-step minus THIS timestep (the type we use for closing offline budgets).

@jm-c
Copy link
Member

jm-c commented Aug 30, 2023

2 comments:

  1. I really think it would be useful to open a new issue to list the problems related to LAYERS_THERMODYNAMICS code.
  2. If we want to refine what you added in this PR: I took a quick look at this "total-tendency" layers bits but it's also output outside pkg/diagnostics, so it's not enough to check if the pkg/layers corresponding diagnostics is used. I might cook something simple and push it here.

- Register the use of Layers-Thermodynamics code by setting new switch "layers_useThermo",
  set at compile time (CPP option LAYERS_THERMODYNAMICS) since, currently, there is no
  run-time params for this ;
- Add a stop if Layers-Thermodynamics code is use without pkg/diagnostics (since all
  the calls are within "IF ( useDiagnostics )" ;
Note: put new switch in (new) dedicated header file "LAYERS_SWITCH.h" to facilitate
      access from outside pkg/layers (no need to include LAYERS_OPTIONS.h)
using the (new) "layers_useThermo" switch (instead of "useLayers") allow to refine
the condition and only call pkg/layers S/R when Layers-Thermodynamics code is used

also some minor changes that minimize differences with original version
@jm-c
Copy link
Member

jm-c commented Aug 30, 2023

@antnguyen13 I pushed my little changes. If you don't like these we could revert the 2 commits.

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.

None yet

3 participants