# bug when using option 31 or 32 for momentum viscosity

Reported by:reporter: Owned by:owner: The author of the ticket. Person in charge for handling clem systeam high LDF release-4.0 major

#### Analysis

There is a bug when using options 30 and 31 for momentum viscosity that makes the model crash at the first time step.
The problem is 2 fold:
1) ahmt and ahmf coefficients are not initialized to 0
2) indices start at 2 when calculating ahmf while it should start at 1 (F-points)

#### Fix

In ldfdyn.F90 ⇒

Initialize the coefficients during init

```         ahmt(:,:,:) = 0._wp
ahmf(:,:,:) = 0._wp
```

And replace this loop:

```              DO jj = 2, jpjm1
DO ji = fs_2, fs_jpim1
zu2pv2_ij_p1 = ub(ji  ,jj+1,jk) * ub(ji  ,jj+1,jk) + vb(ji+1,jj  ,jk) * vb(ji+1,jj  ,jk)
zu2pv2_ij    = ub(ji  ,jj  ,jk) * ub(ji  ,jj  ,jk) + vb(ji  ,jj  ,jk) * vb(ji  ,jj  ,jk)
zu2pv2_ij_m1 = ub(ji-1,jj  ,jk) * ub(ji-1,jj  ,jk) + vb(ji  ,jj-1,jk) * vb(ji  ,jj-1,jk)
zetmax = MAX( e1t(ji,jj) , e2t(ji,jj) )
zefmax = MAX( e1f(ji,jj) , e2f(ji,jj) )
ahmt(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * r1_288 ) * zetmax * tmask(ji,jj,jk)      ! 288= 12*12 * 2
ahmf(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * r1_288 ) * zefmax * fmask(ji,jj,jk)
END DO
END DO
```

by these ones:

```               DO jj = 2, jpjm1
DO ji = fs_2, fs_jpim1
zu2pv2_ij    = ub(ji  ,jj  ,jk) * ub(ji  ,jj  ,jk) + vb(ji  ,jj  ,jk) * vb(ji  ,jj  ,jk)
zu2pv2_ij_m1 = ub(ji-1,jj  ,jk) * ub(ji-1,jj  ,jk) + vb(ji  ,jj-1,jk) * vb(ji  ,jj-1,jk)
zetmax = MAX( e1t(ji,jj) , e2t(ji,jj) )
ahmt(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_m1) * r1_288 ) * zetmax * tmask(ji,jj,jk)      ! 288= 12*12 * 2
END DO
END DO
DO jj = 1, jpjm1
DO ji = 1, fs_jpim1
zu2pv2_ij_p1 = ub(ji  ,jj+1,jk) * ub(ji  ,jj+1,jk) + vb(ji+1,jj  ,jk) * vb(ji+1,jj  ,jk)
zu2pv2_ij    = ub(ji  ,jj  ,jk) * ub(ji  ,jj  ,jk) + vb(ji  ,jj  ,jk) * vb(ji  ,jj  ,jk)
zefmax = MAX( e1f(ji,jj) , e2f(ji,jj) )
ahmf(ji,jj,jk) = SQRT( (zu2pv2_ij + zu2pv2_ij_p1) * r1_288 ) * zefmax * fmask(ji,jj,jk)
END DO
END DO
```

### Commit History (2)

ChangesetTimeChangeLog
10784clem2019-03-20T19:36:44+01:00

solve ticket #2261

10783clem2019-03-20T19:36:26+01:00

solve ticket #2261

### comment:1 Changed 19 months ago by nicolasmartin

• Description modified (diff)

### comment:2 Changed 18 months ago by clem

In 10783:

solve ticket #2261

### comment:3 Changed 18 months ago by clem

In 10784:

solve ticket #2261

### comment:4 Changed 18 months ago by clem

• Resolution set to fixed
• Status changed from new to closed

solved at r10784

Note: See TracTickets for help on using tickets.