Bug in output time step in DEF_DIAGS after restart

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
fgrosse
Posts: 6
Joined: Tue Jun 06, 2017 1:54 pm
Location: Dalhousie University

Bug in output time step in DEF_DIAGS after restart

#1 Post by fgrosse » Wed Oct 04, 2017 4:36 pm

Hello,

There seems to be a bug in the DEF_DIAGS at the point where the output time step for the diagnostics file is determined after a restart of ROMS. In my code (which is from August this year) lines 721-734 read as:

Code: Select all

!
!  Set unlimited time record dimension to the appropriate value.
!
        IF (nRST(ng).eq.nDIA(ng)) THEN
          IF (ndefDIA(ng).gt.0) THEN
            DIA(ng)%Rindex=((ntstart(ng)-1)-                            &
     &                      ndefDIA(ng)*((ntstart(ng)-1)/ndefDIA(ng)))/ &
     &                     nDIA(ng)
          ELSE
            DIA(ng)%Rindex=(ntstart(ng)-1)/nDIA(ng)
          END IF
        ELSE
          DIA(ng)%Rindex=rec_size
        END IF
In case nRST does not equal nDIA and the last written restart time stamp is before the last one in the diagnostics file, the old data in the diagnostics file are not overwritten at the correct position but the newly calculated data are appended to the file. I suppose changing the logic in DEF_DIAGS analogous to that of DEF_HIS should solve this issue.

Best,
Fabian

fgrosse
Posts: 6
Joined: Tue Jun 06, 2017 1:54 pm
Location: Dalhousie University

Re: Bug in output time step in DEF_DIAGS after restart

#2 Post by fgrosse » Thu Nov 16, 2017 12:07 am

It seems the DEF_HIS logic for determining the output record (see below) also has a flaw.

Code: Select all

!
!  Set unlimited time record dimension to the appropriate value.
!
        IF (ndefHIS(ng).gt.0) THEN
          HIS(ng)%Rindex=((ntstart(ng)-1)-                              &
     &                    ndefHIS(ng)*((ntstart(ng)-1)/ndefHIS(ng)))/   &
     &                   nHIS(ng)
        ELSE
          HIS(ng)%Rindex=(ntstart(ng)-1)/nHIS(ng)
        END IF
        HIS(ng)%Rindex=MIN(HIS(ng)%Rindex,rec_size)
Today I had to restart a simulation with daily HIS (and RST) output after 3 days of simulated time with the first HIS file still being the correct output file. However, the first call of WRT_HIS in the re-started job (initialised at day 4 midnight) did not write to the 5th record but to the 4th, i.e., the last record from the previous job was overwritten incorrectly (and subsequent output also was written to the wrong records).

I replaced the code as follows and now it works correctly:

Code: Select all

!
!  Set unlimited time record dimension to the appropriate value.
!
        IF (ndefHIS(ng).gt.0) THEN
          IF ((ntstart(ng)-1).lt.ndefHIS(ng)) THEN
            HIS(ng)%Rindex=1+((ntstart(ng)-1)- ndefHIS(ng)*            &
     &                        ((ntstart(ng)-1)/ndefHIS(ng)))/nHIS(ng)
          ELSE
            HIS(ng)%Rindex=  ((ntstart(ng)-1)- ndefHIS(ng)*            &
     &                        ((ntstart(ng)-1)/ndefHIS(ng)))/nHIS(ng)
          END IF
        ELSE
          HIS(ng)%Rindex=(ntstart(ng)-1)/nHIS(ng)
        END IF
        HIS(ng)%Rindex=MIN(HIS(ng)%Rindex,rec_size)
Best,
Fabian

User avatar
arango
Site Admin
Posts: 1128
Joined: Wed Feb 26, 2003 4:41 pm
Location: IMCS, Rutgers University
Contact:

Re: Bug in output time step in DEF_DIAGS after restart

#3 Post by arango » Fri Nov 17, 2017 6:26 pm

Well, this logic has worked for us for years. Your problem is that NAVG and NDIA are inconsistent with NRST. If you have AVERAGES and DIAGNOSTICS_TS and/or DIAGNOSTICS_UV activated, you need to set NAVG=NDIA. It doesn't make any sense to have different values because if you are going to compute balances and fluxes, you need data from both average and diagnostic NetCDF files. Since the ROMS data are time-averaged, you need to set NRST=NAVG=NDIA, if you want to restart your application. In this way, there is always a robust way to restart the summation for the time averages and have a continous solution.

fgrosse
Posts: 6
Joined: Tue Jun 06, 2017 1:54 pm
Location: Dalhousie University

Re: Bug in output time step in DEF_DIAGS after restart

#4 Post by fgrosse » Tue Nov 21, 2017 6:16 pm

This reply only partly applies to my setup. Indeed, my NAVG=0 (=> no output) differs from my NRST=1440 (=> daily restart writing). However, AVERAGES is switched off and DIAGNOSTICS_TS and DIAGNOSTICS_BIO are switched on, though, with NDIA=NRST=1440. Hence, I would expect that the diagnostics output should not be affected by what you described above.

I agree that NDIA must not be larger than NRST in order to allow for correct averaged values. However, identical (and also smaller) values should be fine, conceptually and technically, following your explanation.

In addition, I set NHIS=NRST=1440 for my history output. To my understanding, this should not cause the writing into a wrong history file record after restart if the actual output step is still smaller than or equal to NDEFHIS+1 ("+1" because of initial values written to record 1 for first history file of new simulation).

User avatar
arango
Site Admin
Posts: 1128
Joined: Wed Feb 26, 2003 4:41 pm
Location: IMCS, Rutgers University
Contact:

Re: Bug in output time step in DEF_DIAGS after restart

#5 Post by arango » Tue Nov 21, 2017 6:32 pm

Smaller values of NDIA are possible but its value needs to be an exact factor of NRST, say NDIA=NRST/2 should give you an integer. The time window (in seconds) should be exactly divided by DT.

fgrosse
Posts: 6
Joined: Tue Jun 06, 2017 1:54 pm
Location: Dalhousie University

Re: Bug in output time step in DEF_DIAGS after restart

#6 Post by fgrosse » Tue Nov 21, 2017 7:49 pm

Both is the case as NDIA=NRST and NDIA is defined anyway as an integer factor applied to DT.

Post Reply