Skip to content

Add water tracer consistency checks, and other water tracer work - #497

Merged
billsacks merged 31 commits into
ESCOMP:masterfrom
billsacks:iso_validity_checks_stage1
Sep 12, 2018
Merged

billsacks merged 31 commits into
ESCOMP:masterfrom
billsacks:iso_validity_checks_stage1

Conversation

@billsacks

Copy link
Copy Markdown
Member

Description of changes

  1. Add water tracer consistency checks (@mathewvrothstein )

  2. Breakout of atm2lnd and lnd2atm water variables, needed for water tracers (@mathewvrothstein )

  3. Add some namelist control over the addition of water tracers (@billsacks)

  4. Add a system test that exercises the water tracer consistency checks (@billsacks)

Specific notes

Contributors other than yourself, if any: @mathewvrothstein

CTSM Issues Fixed (include github issue #):

Are answers expected to change (and if so in what way)? No

Any User Interface Changes (namelist or namelist defaults changes)?

  • Adds two new namelist variables: enable_water_tracer_consistency_checks and enable_water_isotopes

Testing performed, if any:

  • Ran much of the aux_clm test suite; will run the rest soon

mathewvrothstein and others added 6 commits August 31, 2018 10:51
closes ESCOMP#479
partially addresses ESCOMP#357
includes fix to ESCOMP#480 that'll be backed out before merging to master
includes testmod for coldStart testing
passes test:
SMS_D_Ld3.f10_f10_musgs.I1850Clm50BgcCrop.cheyenne_intel.clm-coldStart
The main purpose at this point is to allow turning on the tracer
consistency checks via namelist
For now (while we are still working on getting the tracer consistency
check to pass across a whole timestep) a single timestep test is
sufficient. Eventually we want to expand this test and add some other,
similar tests: see ESCOMP#495
@billsacks billsacks self-assigned this Sep 5, 2018
@billsacks

Copy link
Copy Markdown
Member Author

@ekluzek - @mathewvrothstein and I have worked together on this, so I consider this to be sufficiently reviewed, but I'm opening this PR in case you or others want to look at it.

@mathewvrothstein feel free to look at my two most recent commits and comment on them if you'd like.

billsacks and others added 18 commits September 6, 2018 06:38
This is simply so that it runs faster
Previously, it was both doing an endrun and returning a logical (which
would could never be false, because if it was, then the endrun would
have been called). Now we just do an endrun.

I prefer this method because it is less error-prone: If we don't do the
endrun internally but instead rely on passing a logical up the call
stack, then a single instance of accidentally having

wiso_inconsistency = WisoCompareBulkToTracer(...)

instead of

wiso_inconsistency = wiso_inconsistency .or. WisoCompareBulkToTracer(...)

will cause checks to pass when they shouldn't - and this could be really
hard to track down.

Note that the old water isotope branch had a logical controlling whether
to die internally or pass the logical up the call stack, but I feel
that's too much complexity without much benefit.
Output caller location and (if relevant) level. Also output index of
first difference and values at first diff. location.
Previously, 'this' was the bulk. It seems a bit better to make 'this'
the tracer for two reasons:

1. This is more consistent with code we have or will have elsewhere,
   where the bulk is sometimes passed in to the tracer routine.

2. We're going to want to get the tracer's ratio. It seems better to get
   this%info%ratio than tracer%info%ratio.
I didn't like that you needed to remember to add a call to
CompareBulkToTracer for every new variable: it would be easy to forget
this, it would be hard to catch that in a review, and tests wouldn't
catch that omission. This commit adds infrastructure that allows looping
over all water tracer variables for this or other purposes.
With the current usage, the level is embedded in the variable name, so
we don't need to pass it separately.
…nto iso_validity_checks_stage1

Resolved Conflicts:
	src/biogeophys/WaterType.F90
In order to maintain the lower bounds of the data arrays, we need to
either (a) declare 'data' to be a pointer, or (b) pass in the lower
bounds as an argument. For now, since all of our actual variables are
pointers, I'm going with (a). In the future, if we change some variables
to be target, non-pointers, then we should have the caller pass in the
lower bound and change 'data' to:

    real(r8), target, intent(in) :: data(lbound:)
@billsacks

Copy link
Copy Markdown
Member Author

@davidnoone - I thought you'd be interested to know: With some infrastructure I have just added as part of this PR, we automatically ensure that the tracer consistency checks are run on every variable that is added to any of the water types that have instances for each tracer variable. This was driven by my worry that people would add new variables but not realize they needed to call the tracer consistency check on those new variables, and this omission might be hard to notice in a code review.

If you're curious: The infrastructure that enables this is in WaterTracerContainerType.F90; WaterTracerUtils.F90: AllocateVar1d and AllocateVar2d; and WaterType.F90: TracerConsistencyCheck. You can see how it's used in, for example, WaterStateType.F90: InitAllocate. As long as new variables are added with this AllocateVar infrastructure rather than a simple allocate call (which should be relatively easy to spot in a code review, since the new lines would stand out relative to surrounding code), they will automatically have the tracer consistency check run on them.

This reverts commit 2bf5536.

With nag, lower bounds weren't maintained for slices of 2d arrays. I
think that, if I wanted to maintain the lower bounds of those, I would
need to create a temporary pointer in AllocateVar2d that has the correct
lower bounds. It seems like it will be less error-prone to just pass the
lower bounds in. So I'm going to rework the code to work that way.
@davidnoone

Copy link
Copy Markdown

Excellent @billsacks !

@billsacks
billsacks force-pushed the iso_validity_checks_stage1 branch from b626309 to 974162c Compare September 11, 2018 17:39
On second thought, it seems easier and more robust just to pass in the
lower bound of the array.
With the old version, both system tests and unit tests the unit tests
were failing on cheyenne with intel17.0.1, and system tests were failing
on hobart with intel18.0.3.

I looked extensively into the unit test failures. The problem seemed to
be that the vector size turns into garbage in the return from the
constructor: When the test has:

  container = new_water_tracer_container_type()

We get:

 end of clear_vec: vec_size =            0
 end of new_water_tracer_container_type: size =            0
 in test after constructor: size =           97

The problem seems to come in this line:

    container = water_tracer_container_type()

I think this is invoking the copy method, vector_assign_vec, for the
vector component of the derived type.

From inserting some extra prints in this, I see:

  print *,	'in vector_assign_vec: self, other size = ', self%vsize(), other%vsize()
  allocate(temp, source=other)
  print *,	'after allocate: temp size = ',	temp%vsize()
  call self%swap(temp)
  print *,	'after swap: self size = ', self%vsize()

 printing in new_water_tracer_container_type
 in clear_vec
 in resize_vec with new_size, capacity =            0           0
 end of clear_vec: vec_size =            0
 in vector_assign_vec: self, other size =            0           0
 after allocate: temp size =            0
 after swap: self size =            0
 end of new_water_tracer_container_type: size =            0
 in vector_assign_vec: self, other size =            0           0
 after allocate: temp size =           97
 after swap: self size =           97
 in test after constructor: size =           97

Note that the first entry into vector_assign_vec is this line in
new_water_tracer_container_type:

    this%tracer_vec = water_tracer_vector()

whereas the second is this line in the test routine:

    container = water_tracer_container_type()

The first one seems fine, but the second one gives problems.

Changing the water_tracer_container_type constructor to a call to an
init method (thus avoiding the assignment) seems to resolve the problem.
This is needed to avoid floating point exceptions with intel
@billsacks
billsacks force-pushed the iso_validity_checks_stage1 branch from 8ec255b to 3eb60d0 Compare September 11, 2018 21:28
@@ -0,0 +1,127 @@
module test_compare_bulk_to_tracer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mathewvrothstein - I added these unit tests largely for the sake of ensuring that nobody breaks the CompareBulkToTracer routine when it is modified in the future. You may want to take a quick look at these unit tests as a fairly simple example of pfunit-based unit tests, and also because you'll likely need to modify them a bit when you add the ratio argument.

@billsacks
billsacks merged commit d17eadc into ESCOMP:master Sep 12, 2018
@billsacks
billsacks deleted the iso_validity_checks_stage1 branch September 12, 2018 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done (non release/external)

Development

Successfully merging this pull request may close these issues.

3 participants