Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#384 closed bug (Fixed)

Incorrectly coded option UV_PSOURCE in step2d_LF_AM3.h

Reported by: arango Owned by: arango
Priority: major Milestone: Adjoint Based Algorithms
Component: Adjoint Version: 3.3
Keywords: Cc:

Description (last modified by arango)

I have been hunting for an adjoint bug in tl_step2d_LF_AM3.h and ad_step2d_LF_AM3.h for two days. It occurs when the mass point sources UV_PSOURCE option is activated. It turns out the the bug was in the nonlinear code step2d_LF_AM3.h:

      DO is=1,Nsrc
        i=Isrc(is)
        j=Jsrc(is)
        IF (((IstrR.le.i).and.(i.le.IendR)).and.                        &
     &      ((JstrR.le.j).and.(j.le.JendR))) THEN
          IF (INT(Dsrc(is)).eq.0) THEN
            cff=1.0_r8/(on_u(i,j)*                                      &
     &                  0.5_r8*(zeta(i-1,j,knew)+h(i-1,j)+              &
     &                          zeta(i  ,j,knew)+h(i  ,j)))
            ubar(i,j,knew)=Qbar(is)*cff
#  ifdef SOLVE3D
            DU_avg1(i,j)=Qbar(is)
#  endif
          ELSE
            cff=1.0_r8/(om_v(i,j)*                                      &
     &                  0.5_r8*(zeta(i,j-1,knew)+h(i,j-1)+              &
     &                          zeta(i,j  ,knew)+h(i,j  )))
            vbar(i,j,knew)=Qbar(is)*cff
#  ifdef SOLVE3D
            DV_avg1(i,j)=Qbar(is)
#  endif
          END IF
        END IF
      END DO

The override of variables DU_av1 and DV_avg1 is completely incorrect here and should be done separately after all the barotropic time-steps have been carry-out. That is, when

      IF ((iif(ng).eq.(nfast(ng)+1)).and.PREDICTOR_2D_STEP(ng)) THEN
#  ifdef UV_PSOURCE
        DO is=1,Nsrc
          i=Isrc(is)
          j=Jsrc(is)
          IF (((IstrR.le.i).and.(i.le.IendR)).and.                      &
     &        ((JstrR.le.j).and.(j.le.JendR))) THEN
            IF (INT(Dsrc(is)).eq.0) THEN
              DU_avg1(i,j)=Qbar(is)
            ELSE
              DV_avg1(i,j)=Qbar(is)
            END IF
          END IF
        END DO
#  endif
        ...
      END IF

This generated a nasty bug in the adjoint codes. There cannot be redundant operations in the adjoint model... This bug have been in the adjoint codes since the beginning. In the nonlinear model is it a minor correction and not identical results can be achived after this update.

I actually think that the override of DU_avg1 and DV_avg1 for the mass point-sources is not needed at all when UV_PSOURCE is activated. The barotropic time filtering is carried out in terms of ubar and vbar (which already have point source information) when the local arrays Duon and Dvom are computed at each barotropic time-step. Noticed that it is Duon and Dvom that are used to compute the time filtered (accumulation) arrays DU_avg1, DU_avg2, DV_avg1, and DV_avg2. I may eliminate this in the future after more thinking and testing.

Change History (2)

comment:1 by arango, 14 years ago

Resolution: Fixed
Status: newclosed

I also updated get_state.F and corrected a typo in def_mod.F.

comment:2 by arango, 14 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.