River forcing LtracerSrc and setting temp to 0 ?!

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
User avatar
jivica
Posts: 172
Joined: Mon May 05, 2003 2:41 pm
Location: The University of Western Australia, Perth, Australia
Contact:

River forcing LtracerSrc and setting temp to 0 ?!

#1 Unread post by jivica »

Think there is a "feature" introduced in the recent ROMS related to river source temperature set to 0C even you chose not the alter ocean ambient temperature.
What I am doing is simulating only fresh water inflow using river forcing and setting source salinity but do not want to change ocean temperature.

If you set in the ocean.in that you have only 2 active tracers (temp, salt) NAT = 2 and no passive tracer NPT = 0 and then later in activate this:
LuvSrc == T
and
LtracerSrc == F T ! just use salinity and not temperature

It is still setting tracer temperature to ini_value which is 0 and introducing cold water into the ocean.

To be sure I am not outdated just svn to the latest version 904, recompiled and got the same thing/problem.
From INFO I can see it is NOT reading river_temp from the river.nc forcing file as I would expect, so that is fine.
Later in the code it sets it to 0 which it shouldn't.

Then I pulled back my old workhorse version 3.4 and changed .h *bry definition inside* and ocean.in,
used the same setup and bingo, it is just using salinity as should and not changing ambient temperature in the ocean.

Does anybody else bumped on the same bug?

Cheers
Ivica

User avatar
kate
Posts: 4092
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: River forcing LtracerSrc and setting temp to 0 ?!

#2 Unread post by kate »

No, but I know that if you ask for inflow without providing tracer values, you can get an unstable downwind advection scheme. My last battle with this went for six months before blowing up - I had accidentally turned off all my bio tracer river sources.

User avatar
jivica
Posts: 172
Joined: Mon May 05, 2003 2:41 pm
Location: The University of Western Australia, Perth, Australia
Contact:

Re: River forcing LtracerSrc and setting temp to 0 ?!

#3 Unread post by jivica »

Hi Kate
I am using MPDATA in old 3.4 and the latest code
And with old all is as should be... looking into the code
to figure what/when went wrong
Cheers Ivica

User avatar
jivica
Posts: 172
Joined: Mon May 05, 2003 2:41 pm
Location: The University of Western Australia, Perth, Australia
Contact:

Re: River forcing LtracerSrc and setting temp to 0 ?!

#4 Unread post by jivica »

I think I've fixed it.
It is working now as I would expect (MP_DATA) and the problem was in step3d_t.F and pre_step3d.F
(note that "_original" is current version in roms trunk)
Shortly, indexing was (I think) wrong in the step3d_t.F and in pre_step3d.F part with source direction == 1 was missing etc..

Code: Select all

diff step3d_t.F step3d_t.F_original 
527,528c527,528
<                 IF (((IstrUm2.le.Isrc).and.(Isrc.le.Iendp2)).and.       &
<      &              ((JstrVm2.le.Jsrc).and.(Jsrc.le.Jendp2))) THEN
---
>                 IF (((IstrUm2.le.Isrc).and.(Isrc.le.Iendp3)).and.       &
>      &              ((JstrVm2.le.Jsrc).and.(Jsrc.le.Jendp2i))) THEN
552,553c552,553
<                 IF (((IstrUm2.le.Isrc).and.(Isrc.le.Iendp2)).and.      &
<      &              ((JstrVm2.le.Jsrc).and.(Jsrc.le.Jendp2))) THEN
---
>                 IF (((IstrUm2.le.Isrc).and.(Isrc.le.Iendp2i)).and.      &
>      &              ((JstrVm2.le.Jsrc).and.(Jsrc.le.Jendp3))) THEN

Code: Select all

diff pre_step3d.F pre_step3d.F_original 
369,370c369,370
<           DO j=JstrVm2,Jendp2i
<             DO i=IstrUm2,Iendp3
---
>           DO j=Jstr,Jend
>             DO i=Istr,Iend+1
377,378c377,378
<           DO j=JstrVm2,Jendp3
<             DO i=IstrUm2,Iendp2i
---
>           DO j=Jstr,Jend+1
>             DO i=Istr,Iend
525,563c525,537
<               IF (INT(SOURCES(ng)%Dsrc(is)).eq.0) THEN
<                 IF (((IstrUm2.le.Isrc).and.(Isrc.le.Iendp2)).and.       &
<      &              ((JstrVm2.le.Jsrc).and.(Jsrc.le.Jendp2))) THEN
<                   IF (LtracerSrc(itrc,ng)) THEN
<                     FX(Isrc,Jsrc)=Huon(Isrc,Jsrc,k)*                    &
<      &                            SOURCES(ng)%Tsrc(is,k,itrc)
<                   ELSE
<                     IF ((rmask(Isrc  ,Jsrc).eq.0.0_r8).and.             &
<      &                  (rmask(Isrc-1,Jsrc).eq.1.0_r8)) THEN
<                       FX(Isrc,Jsrc)=Huon(Isrc,Jsrc,k)*                  &
<      &                              t(Isrc-1,Jsrc,k,3,itrc)
<                     ELSE IF ((rmask(Isrc  ,Jsrc).eq.1.0_r8).and.        &
<      &                       (rmask(Isrc-1,Jsrc).eq.0.0_r8)) THEN
<                       FX(Isrc,Jsrc)=Huon(Isrc,Jsrc,k)*                  &
<      &                              t(Isrc  ,Jsrc,k,3,itrc)
<                     END IF
<                   END IF  
<                 END IF    
<               ELSE IF (INT(SOURCES(ng)%Dsrc(is)).eq.1) THEN
<                 IF (((IstrUm2.le.Isrc).and.(Isrc.le.Iendp2)).and.      &
<      &              ((JstrVm2.le.Jsrc).and.(Jsrc.le.Jendp2))) THEN
<                   IF (LtracerSrc(itrc,ng)) THEN
<                     FE(Isrc,Jsrc)=Hvom(Isrc,Jsrc,k)*                    &
<      &                            SOURCES(ng)%Tsrc(is,k,itrc)
<                   ELSE
<                     IF ((rmask(Isrc,Jsrc  ).eq.0.0_r8).and.             &
<      &                  (rmask(Isrc,Jsrc-1).eq.1.0_r8)) THEN
<                       FE(Isrc,Jsrc)=Hvom(Isrc,Jsrc,k)*                  &
<      &                              t(Isrc,Jsrc-1,k,3,itrc)
<                     ELSE IF ((rmask(Isrc,Jsrc  ).eq.1.0_r8).and.        &
<      &                       (rmask(Isrc,Jsrc-1).eq.0.0_r8)) THEN
<                       FE(Isrc,Jsrc)=Hvom(Isrc,Jsrc,k)*                  &
<      &                              t(Isrc,Jsrc  ,k,3,itrc)
<                     END IF
<                   END IF  
<                 END IF    
<               END IF      
<             END DO        
<           END IF          
---
>               IF (LtracerSrc(itrc,ng).and.                              &
>      &            ((Istr.le.Isrc).and.(Isrc.le.Iend+1)).and.            &
>      &            ((Jstr.le.Jsrc).and.(Jsrc.le.Jend+1))) THEN
>                 IF (INT(SOURCES(ng)%Dsrc(is)).eq.0) THEN
>                   FX(Isrc,Jsrc)=Huon(Isrc,Jsrc,k)*                      &
>      &                          SOURCES(ng)%Tsrc(is,k,itrc)
>                 ELSE
>                   FE(Isrc,Jsrc)=Hvom(Isrc,Jsrc,k)*                      &
>      &                          SOURCES(ng)%Tsrc(is,k,itrc)
>                 END IF
>               END IF
>             END DO
>           END IF

zduvims
Posts: 7
Joined: Fri Feb 10, 2023 4:06 pm
Location: Virginia Institute of Marine Science

Re: River forcing LtracerSrc and setting temp to 0 ?!

#5 Unread post by zduvims »

Screenshot 2025-06-04 at 07.22.37.png
I ran into same issue with low temperature when I define LwSrc, and the model crashed. The temperature field is wrong because I run this model for summer in the tropical area. I have checked my boundary/climatology/atmospheric inputs, and they are fine. I set my river_temp = 28, but the model seems not read it.



In pre_step3d.F, it says:

Code: Select all

!  Apply tracers point sources to the horizontal advection terms,
!  if any.
!
!    Dsrc(is) = 0,  flow across grid cell u-face (positive or negative)
!    Dsrc(is) = 1,  flow across grid cell v-face (positive or negative)
!
          IF (LuvSrc(ng)) THEN
            DO is=1,Nsrc(ng)
              Isrc=SOURCES(ng)%Isrc(is)
              Jsrc=SOURCES(ng)%Jsrc(is)
              IF (((Istr.le.Isrc).and.(Isrc.le.Iend+1)).and.            &
     &            ((Jstr.le.Jsrc).and.(Jsrc.le.Jend+1))) THEN
                IF (INT(SOURCES(ng)%Dsrc(is)).eq.0) THEN
                  IF (LtracerSrc(itrc,ng)) THEN
                    FX(Isrc,Jsrc)=Huon(Isrc,Jsrc,k)*                    &
     &                            SOURCES(ng)%Tsrc(is,k,itrc)
                  ELSE
                    FX(Isrc,Jsrc)=0.0_r8
                  END IF
                ELSE IF (INT(SOURCES(ng)%Dsrc(is)).eq.1) THEN
                  IF (LtracerSrc(itrc,ng)) THEN
                    FE(Isrc,Jsrc)=Hvom(Isrc,Jsrc,k)*                    &
     &                            SOURCES(ng)%Tsrc(is,k,itrc)
                  ELSE
                     FE(Isrc,Jsrc)=0.0_r8
                  END IF
                END IF
              END IF
            END DO
          END IF
It seems this only works for LuvSrc, and I did not find LwSrc. Is it a possible bug?

Let say if I want to apply the river_temp for LwSrc, can I change "IF (LuvSrc(ng)) THEN" to "IF (LuvSrc(ng)) .or. IF(LwSrc(ng)) THEN"? But then how about the FE and FX? They points to u/v masks, while LwSrc should use rho_mask?
I am not sure how to simply make it work.

User avatar
wilkin
Posts: 935
Joined: Mon Apr 28, 2003 5:44 pm
Location: Rutgers University
Contact:

Re: River forcing LtracerSrc and setting temp to 0 ?!

#6 Unread post by wilkin »

For LuvSrc the volume flux through the cell faces modifies FX and FE in pre_step3d.F. The tracer enters when, subsequently, in step3d_t.F we take the divergence of those fluxes. For LwSrc the divergence of tracer simply appears directly in step3d_t.F. Look in step3d_t.F for "LwSrc" to see where this is done. The code is correct.

The LuvSrc and LwSrc logical flags in roms.in indicate whether any such sources exist. You can have just one of these T, or both of them T(rue). Whether an individual source is to be treated as Luv or Lw is determined by the values of river_direction in the river netcdf file for each river. If all your sources are to be LwSrc, all river_direction must equal 2.

river_direction carries over to SOURCES(ng)%Dsrc in the code snippet you posted. The change you suggest would do nothing because in that part of the code it only treats Dsrc = 0 and Dsrc = 1 (the river_direction values for flow through the cell faces).

Check your values of LtracerSrc in roms.in. The first value must be T to use the river_temp inputs. If you don't want to use river_temp and just have ROMS preserve the temperature of the inflow cell, set this to F. In your logfile you should see that switching the LtracerSrc flag changes whether river-temp is read, or not, from the rivers file.

If you chop and change between LuvSrc and LwSrc by changing river_direction in the river input file, be mindful of the change in interpretation of river_Xposition,river_Eposition from the u,v index to rho index of the receiving cell. You may inadvertently place your source in the land. See https://www.myroms.org/wiki/River_Runoff
John Wilkin: DMCS Rutgers University
71 Dudley Rd, New Brunswick, NJ 08901-8521, USA. ph: 609-630-0559 jwilkin@rutgers.edu

zduvims
Posts: 7
Joined: Fri Feb 10, 2023 4:06 pm
Location: Virginia Institute of Marine Science

Re: River forcing LtracerSrc and setting temp to 0 ?!

#7 Unread post by zduvims »

wilkin wrote: Wed Jun 04, 2025 2:50 pm For LuvSrc the volume flux through the cell faces modifies FX and FE in pre_step3d.F. The tracer enters when, subsequently, in step3d_t.F we take the divergence of those fluxes. For LwSrc the divergence of tracer simply appears directly in step3d_t.F. Look in step3d_t.F for "LwSrc" to see where this is done. The code is correct.

The LuvSrc and LwSrc logical flags in roms.in indicate whether any such sources exist. You can have just one of these T, or both of them T(rue). Whether an individual source is to be treated as Luv or Lw is determined by the values of river_direction in the river netcdf file for each river. If all your sources are to be LwSrc, all river_direction must equal 2.

river_direction carries over to SOURCES(ng)%Dsrc in the code snippet you posted. The change you suggest would do nothing because in that part of the code it only treats Dsrc = 0 and Dsrc = 1 (the river_direction values for flow through the cell faces).

Check your values of LtracerSrc in roms.in. The first value must be T to use the river_temp inputs. If you don't want to use river_temp and just have ROMS preserve the temperature of the inflow cell, set this to F. In your logfile you should see that switching the LtracerSrc flag changes whether river-temp is read, or not, from the rivers file.

If you chop and change between LuvSrc and LwSrc by changing river_direction in the river input file, be mindful of the change in interpretation of river_Xposition,river_Eposition from the u,v index to rho index of the receiving cell. You may inadvertently place your source in the land. See https://www.myroms.org/wiki/River_Runoff
Hi,

Thank you very much for your reply! I just tested using two different river temp values. Yes, the code will read the temp.

I think my issue may be due to the mixing. I change TNU2 from 10 to zero, now it’s looks better, while the temperature still has a decreasing trend.

Another issue may be due to the point source location? I did not put them at the very landward part of the river channel. Instead, i put them near the ocean so I can make sure the sediment load all enter the ocean. Otherwise some sediment will be trapped in the channel. It could be the gradient of temperature between the landward part, the source point, and the seaward part that cause the problem?

I will try to turn off tracer’s temp to see what will happen. I didn’t do that because the roms.in suggested turn on temp and salt for rivers.

Post Reply