A Modular Arbitrary-Order Ocean-Atmosphere Model -- Stochastic implementation
rk2_tl_ad_integrator.f90
Go to the documentation of this file.
1 
2 ! tl_ad_integrator.f90
3 !
4 !> Tangent Linear (TL) and Adjoint (AD) model versions of MAOOAM.
5 !> Integrators module.
6 !
7 !> @copyright
8 !> 2016 Lesley De Cruz & Jonathan Demaeyer.
9 !> See LICENSE.txt for license information.
10 !
11 !---------------------------------------------------------------------------!
12 !
13 !> @remark
14 !> This module actually contains the Heun algorithm routines.
15 !> The user can modify it according to its preferred integration scheme.
16 !> For higher-order schemes, additional buffers will probably have to be defined.
17 !
18 !---------------------------------------------------------------------------
19 
20 
21 
23 
24  USE params, only: ndim
25  USE tl_ad_tensor, only: ad,tl
26  IMPLICIT NONE
27 
28  PRIVATE
29 
30  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: buf_y1 !< Buffer to hold the intermediate position (Heun algorithm) of the tangent linear model
31  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: buf_f0 !< Buffer to hold tendencies at the initial position of the tangent linear model
32  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: buf_f1 !< Buffer to hold tendencies at the intermediate position of the tangent linear model
33 
34 
36 
37 CONTAINS
38 
39  !> Routine to initialise the integration buffers.
40  SUBROUTINE init_tl_ad_integrator
41  INTEGER :: AllocStat
42  ALLOCATE(buf_y1(0:ndim),buf_f0(0:ndim),buf_f1(0:ndim),stat=allocstat)
43  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
44  END SUBROUTINE init_tl_ad_integrator
45 
46 
47 
48  !-----------------------------------------------------!
49  ! !
50  ! Adjoint model integrator !
51  ! !
52  !-----------------------------------------------------!
53 
54  !> Routine to perform an integration step (Heun algorithm) of the adjoint model. The incremented time is returned.
55  !> @param y Initial point.
56  !> @param ystar Adjoint model at the point ystar.
57  !> @param t Actual integration time
58  !> @param dt Integration timestep.
59  !> @param res Final point after the step.
60  SUBROUTINE ad_step(y,ystar,t,dt,res)
61  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: y,ystar
62  REAL(KIND=8), INTENT(INOUT) :: t
63  REAL(KIND=8), INTENT(IN) :: dt
64  REAL(KIND=8), DIMENSION(0:ndim), INTENT(OUT) :: res
65 
66  CALL ad(t,ystar,y,buf_f0)
67  buf_y1 = y+dt*buf_f0
68  CALL ad(t+dt,ystar,buf_y1,buf_f1)
69  res=y+0.5*(buf_f0+buf_f1)*dt
70  t=t+dt
71  END SUBROUTINE ad_step
72 
73  !-----------------------------------------------------!
74  ! !
75  ! Tangent linear model integrator !
76  ! !
77  !-----------------------------------------------------!
78 
79  !> Routine to perform an integration step (Heun algorithm) of the tangent linear model. The incremented time is returned.
80  !> @param y Initial point.
81  !> @param ystar Adjoint model at the point ystar.
82  !> @param t Actual integration time
83  !> @param dt Integration timestep.
84  !> @param res Final point after the step.
85  SUBROUTINE tl_step(y,ystar,t,dt,res)
86  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: y,ystar
87  REAL(KIND=8), INTENT(INOUT) :: t
88  REAL(KIND=8), INTENT(IN) :: dt
89  REAL(KIND=8), DIMENSION(0:ndim), INTENT(OUT) :: res
90 
91  CALL tl(t,ystar,y,buf_f0)
92  buf_y1 = y+dt*buf_f0
93  CALL tl(t+dt,ystar,buf_y1,buf_f1)
94  res=y+0.5*(buf_f0+buf_f1)*dt
95  t=t+dt
96  END SUBROUTINE tl_step
97 
98 
99 END MODULE tl_ad_integrator
real(kind=8), dimension(:), allocatable buf_f1
Buffer to hold tendencies at the intermediate position of the tangent linear model.
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
Statistics accumulators.
Definition: stat.f90:14
Tangent Linear (TL) and Adjoint (AD) model versions of MAOOAM. Integrators module.
subroutine, public ad_step(y, ystar, t, dt, res)
Routine to perform an integration step (Heun algorithm) of the adjoint model. The incremented time is...
subroutine, public ad(t, ystar, deltay, buf)
Tendencies for the AD of MAOOAM in point ystar for perturbation deltay.
subroutine, public tl(t, ystar, deltay, buf)
Tendencies for the TL of MAOOAM in point ystar for perturbation deltay.
The model parameters module.
Definition: params.f90:18
Tangent Linear (TL) and Adjoint (AD) model versions of MAOOAM. Tensors definition module...
real(kind=8), dimension(:), allocatable buf_y1
Buffer to hold the intermediate position (Heun algorithm) of the tangent linear model.
real(kind=8), dimension(:), allocatable buf_f0
Buffer to hold tendencies at the initial position of the tangent linear model.
subroutine, public init_tl_ad_integrator
Routine to initialise the integration buffers.
subroutine, public tl_step(y, ystar, t, dt, res)
Routine to perform an integration step (Heun algorithm) of the tangent linear model. The incremented time is returned.