Let's represent ROMS/TOMS nonlinear model (NLM) as follows:
Code: Select all
d(S)/d(t) = N(S) (1)
Code: Select all
d(s)/d(t) = d{N(S)}/d{t} | s = A s (2)
So
Code: Select all
-d(s')/d(t) = A' s' (3)
Code: Select all
d(S')/d(t) = N(So) + A (S' - So) (4)
The tangent linear and adjoint models are hand-coded using Geiring and Kaminski (1998) recipes. In the following recipes c is a constant and u, v, x, y are time-dependent model state variables.
Code: Select all
Nonlinear Code Tangent Linear Code
--------------------------- -----------------------------
f = c tl_f = 0
f = x tl_f = tl_x
f = c * x tl_f = c * tl_x
f = x * x tl_f = 2 * x * tl_x
f = x ** (n) tl_f = n * x ** (n-1) * tl_x
f = x * y tl_f = tl_x * y + x * tl_y
f = 1 / x tl_f = - f * f * tl_x
f = 1 / SQRT(x) tl_f = - f * f * f * 0.5 * tl_x
f = c / x tl_f = - c * tl_x / (x * x)
= - f * tl_x / x
f = x / y tl_f = (y * tl_x - x * tl_y) / (y * y)
f = 1 / (x + y) tl_f = - f * f * (tl_x + tl_y)
f = 1 / ((x + y)*(u + v)) tl_f = - f * f * (tl_x + tl_y) * (u + v)
- f * f * (x + y) * (tl_u + tl_v)
f = (c + u) / (x + y) tl_f = + tl_u / (x + y)
- f * f * (tl_x + tl_y)
f = MAX(x, y) tl_f = (0.5 + SIGN(0.5, x - y)) * tl_x +
(0.5 - SIGN(0.5, x - y)) * tl_y
f = MAX(x, c) tl_f = (0.5 + SIGN(0.5, x - c)) * tl_x
f = MAX(c, x) tl_f = (0.5 - SIGN(0.5, c - x)) * tl_x
f = MIN(x, y) tl_f = (0.5 + SIGN(0.5, y - x)) * tl_x +
(0.5 - SIGN(0.5, y - x)) * tl_y
f = MIN(x, c) tl_f = (0.5 + SIGN(0.5, c - x)) * tl_x
f = MIN(c, x) tl_f = (0.5 - SIGN(0.5, x - c)) * tl_x
f = AINT(x) tl_f = 0.0
f = ANINT(x) tl_f = 0.0
f = MOD(x,y) tl_f = 0.0
f = ABS(x) tl_f = SIGN(1.0,x) * tl_x
f = SIGN(x,y) tl_f = SIGN(1.0, x) * SIGN(1.0, y) * tl_x + 0.0 * tl_y
= SIGN(1.0, x) * SIGN(1.0, y) * tl_x
f = SIGN(c,x) tl_f = SIGN(1.0, c) * SIGN(1.0, x) * tl_c
= 0.0
f = SQRT(x) tl_f = 0.5 * tl_x / f
f = SQRT(c/x) tl_f = - 0.5 * f * tl_x / x
f = SQRT(x * x + y * y) tl_f = (x * tl_x + y * tl_y) / f
f = LOG(x) tl_f = tl_x / x
f = 1/log(x) tl_f = - f * f * (tl_x / x)
f = EXP(x) tl_f = EXP(x) * tl_x
f = SIN(x) tl_f = COS(x) * tl_x
f = COS(x) tl_f = - SIN(x) * tl_x
f = TAN(x) tl_f = tl_x / (COS(x) * COS(x))
f = TANH(x) tl_f = tl_x / (COSH(x) * COSH(x))
f = SINH(x) tl_f = COSH(x) * tl_x
f = COSH(x) tl_f = - SINH(x) * tl_x
f = ASIN(x) tl_f = tl_x / SQRT(1.0 - x * x)
f = ACOS(x) tl_f = - tl_x / SQRT (1.0 - x * x)
f = ATAN(x) tl_f = tl_x / (1.0 + x * x)
f = ATAN2(x,y) tl_f = (y * tl_x - x * tl_y) / ( x * x + y * y)