A Modular Arbitrary-Order Ocean-Atmosphere Model -- Stochastic implementation
Functions/Subroutines | Variables
tl_ad_tensor Module Reference

Tangent Linear (TL) and Adjoint (AD) model versions of MAOOAM. Tensors definition module. More...

Functions/Subroutines

type(coolist) function, dimension(ndim) jacobian (ystar)
 Compute the Jacobian of MAOOAM in point ystar. More...
 
real(kind=8) function, dimension(ndim, ndim), public jacobian_mat (ystar)
 Compute the Jacobian of MAOOAM in point ystar. More...
 
subroutine, public init_tltensor
 Routine to initialize the TL tensor. More...
 
subroutine compute_tltensor (func)
 Routine to compute the TL tensor from the original MAOOAM one. More...
 
subroutine tl_add_count (i, j, k, v)
 Subroutine used to count the number of TL tensor entries. More...
 
subroutine tl_coeff (i, j, k, v)
 Subroutine used to compute the TL tensor entries. More...
 
subroutine, public init_adtensor
 Routine to initialize the AD tensor. More...
 
subroutine compute_adtensor (func)
 Subroutine to compute the AD tensor from the original MAOOAM one. More...
 
subroutine ad_add_count (i, j, k, v)
 Subroutine used to count the number of AD tensor entries. More...
 
subroutine ad_coeff (i, j, k, v)
 
subroutine, public init_adtensor_ref
 Alternate method to initialize the AD tensor from the TL tensor. More...
 
subroutine compute_adtensor_ref (func)
 Alternate subroutine to compute the AD tensor from the TL one. More...
 
subroutine ad_add_count_ref (i, j, k, v)
 Alternate subroutine used to count the number of AD tensor entries from the TL tensor. More...
 
subroutine ad_coeff_ref (i, j, k, v)
 Alternate subroutine used to compute the AD tensor entries from the TL tensor. More...
 
subroutine, public ad (t, ystar, deltay, buf)
 Tendencies for the AD of MAOOAM in point ystar for perturbation deltay. More...
 
subroutine, public tl (t, ystar, deltay, buf)
 Tendencies for the TL of MAOOAM in point ystar for perturbation deltay. More...
 

Variables

real(kind=8), parameter real_eps = 2.2204460492503131e-16
 Epsilon to test equality with 0. More...
 
integer, dimension(:), allocatable count_elems
 Vector used to count the tensor elements. More...
 
type(coolist), dimension(:), allocatable, public tltensor
 Tensor representation of the Tangent Linear tendencies. More...
 
type(coolist), dimension(:), allocatable, public adtensor
 Tensor representation of the Adjoint tendencies. More...
 

Detailed Description

Tangent Linear (TL) and Adjoint (AD) model versions of MAOOAM. Tensors definition module.

Remarks
The routines of this module should be called only after params::init_params() and aotensor_def::init_aotensor() have been called !

Function/Subroutine Documentation

subroutine, public tl_ad_tensor::ad ( real(kind=8), intent(in)  t,
real(kind=8), dimension(0:ndim), intent(in)  ystar,
real(kind=8), dimension(0:ndim), intent(in)  deltay,
real(kind=8), dimension(0:ndim), intent(out)  buf 
)

Tendencies for the AD of MAOOAM in point ystar for perturbation deltay.

Parameters
ttime
ystarvector with the variables (current point in trajectory)
deltayvector with the perturbation of the variables at time t
bufvector (buffer) to store derivatives.

Definition at line 384 of file tl_ad_tensor.f90.

384  REAL(KIND=8), INTENT(IN) :: t
385  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: ystar,deltay
386  REAL(KIND=8), DIMENSION(0:ndim), INTENT(OUT) :: buf
387  CALL sparse_mul3(adtensor,deltay,ystar,buf)
subroutine tl_ad_tensor::ad_add_count ( integer, intent(in)  i,
integer, intent(in)  j,
integer, intent(in)  k,
real(kind=8), intent(in)  v 
)
private

Subroutine used to count the number of AD tensor entries.

Parameters
itensor \(i\) index
jtensor \(j\) index
ktensor \(k\) index
vvalue that will be added

Definition at line 243 of file tl_ad_tensor.f90.

243  INTEGER, INTENT(IN) :: i,j,k
244  REAL(KIND=8), INTENT(IN) :: v
245  IF ((abs(v) .ge. real_eps).AND.(i /= 0)) THEN
246  IF (k /= 0) count_elems(k)=count_elems(k)+1
247  IF (j /= 0) count_elems(j)=count_elems(j)+1
248  ENDIF
subroutine tl_ad_tensor::ad_add_count_ref ( integer, intent(in)  i,
integer, intent(in)  j,
integer, intent(in)  k,
real(kind=8), intent(in)  v 
)
private

Alternate subroutine used to count the number of AD tensor entries from the TL tensor.

Parameters
itensor \(i\) index
jtensor \(j\) index
ktensor \(k\) index
vvalue that will be added

Definition at line 346 of file tl_ad_tensor.f90.

346  INTEGER, INTENT(IN) :: i,j,k
347  REAL(KIND=8), INTENT(IN) :: v
348  IF ((abs(v) .ge. real_eps).AND.(j /= 0)) count_elems(j)=count_elems(j)+1
subroutine tl_ad_tensor::ad_coeff ( integer, intent(in)  i,
integer, intent(in)  j,
integer, intent(in)  k,
real(kind=8), intent(in)  v 
)
private
Parameters
itensor \(i\) index
jtensor \(j\) index
ktensor \(k\) index
vvalue to add

Definition at line 257 of file tl_ad_tensor.f90.

257  INTEGER, INTENT(IN) :: i,j,k
258  REAL(KIND=8), INTENT(IN) :: v
259  INTEGER :: n
260  IF (.NOT. ALLOCATED(adtensor)) stop "*** ad_coeff routine : tensor not yet allocated ***"
261  IF ((abs(v) .ge. real_eps).AND.(i /=0)) THEN
262  IF (k /=0) THEN
263  IF (.NOT. ALLOCATED(adtensor(k)%elems)) stop "*** ad_coeff routine : tensor not yet allocated ***"
264  n=(adtensor(k)%nelems)+1
265  adtensor(k)%elems(n)%j=i
266  adtensor(k)%elems(n)%k=j
267  adtensor(k)%elems(n)%v=v
268  adtensor(k)%nelems=n
269  END IF
270  IF (j /=0) THEN
271  IF (.NOT. ALLOCATED(adtensor(j)%elems)) stop "*** ad_coeff routine : tensor not yet allocated ***"
272  n=(adtensor(j)%nelems)+1
273  adtensor(j)%elems(n)%j=i
274  adtensor(j)%elems(n)%k=k
275  adtensor(j)%elems(n)%v=v
276  adtensor(j)%nelems=n
277  END IF
278  END IF
subroutine tl_ad_tensor::ad_coeff_ref ( integer, intent(in)  i,
integer, intent(in)  j,
integer, intent(in)  k,
real(kind=8), intent(in)  v 
)
private

Alternate subroutine used to compute the AD tensor entries from the TL tensor.

Parameters
itensor \(i\) index
jtensor \(j\) index
ktensor \(k\) index
vvalue to add

Definition at line 358 of file tl_ad_tensor.f90.

358  INTEGER, INTENT(IN) :: i,j,k
359  REAL(KIND=8), INTENT(IN) :: v
360  INTEGER :: n
361  IF (.NOT. ALLOCATED(adtensor)) stop "*** ad_coeff_ref routine : tensor not yet allocated ***"
362  IF ((abs(v) .ge. real_eps).AND.(j /=0)) THEN
363  IF (.NOT. ALLOCATED(adtensor(j)%elems)) stop "*** ad_coeff_ref routine : tensor not yet allocated ***"
364  n=(adtensor(j)%nelems)+1
365  adtensor(j)%elems(n)%j=i
366  adtensor(j)%elems(n)%k=k
367  adtensor(j)%elems(n)%v=v
368  adtensor(j)%nelems=n
369  END IF
subroutine tl_ad_tensor::compute_adtensor ( external  func)
private

Subroutine to compute the AD tensor from the original MAOOAM one.

Parameters
funcsubroutine used to do the computation

Definition at line 217 of file tl_ad_tensor.f90.

subroutine tl_ad_tensor::compute_adtensor_ref ( external  func)
private

Alternate subroutine to compute the AD tensor from the TL one.

Parameters
funcsubroutine used to do the computation

Definition at line 318 of file tl_ad_tensor.f90.

subroutine tl_ad_tensor::compute_tltensor ( external  func)
private

Routine to compute the TL tensor from the original MAOOAM one.

Parameters
funcsubroutine used to do the computation

Definition at line 121 of file tl_ad_tensor.f90.

subroutine, public tl_ad_tensor::init_adtensor ( )

Routine to initialize the AD tensor.

Definition at line 193 of file tl_ad_tensor.f90.

193  INTEGER :: i
194  INTEGER :: allocstat
195  ALLOCATE(adtensor(ndim),count_elems(ndim), stat=allocstat)
196  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
197  count_elems=0
198  CALL compute_adtensor(ad_add_count)
199 
200  DO i=1,ndim
201  ALLOCATE(adtensor(i)%elems(count_elems(i)), stat=allocstat)
202  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
203  END DO
204 
205  DEALLOCATE(count_elems, stat=allocstat)
206  IF (allocstat /= 0) stop "*** Deallocation problem ! ***"
207 
208  CALL compute_adtensor(ad_coeff)
209 
210  CALL simplify(adtensor)
211 
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
Statistics accumulators.
Definition: stat.f90:14
subroutine, public tl_ad_tensor::init_adtensor_ref ( )

Alternate method to initialize the AD tensor from the TL tensor.

Remarks
The tltensor must be initialised before using this method.

Definition at line 294 of file tl_ad_tensor.f90.

294  INTEGER :: i
295  INTEGER :: allocstat
296  ALLOCATE(adtensor(ndim),count_elems(ndim), stat=allocstat)
297  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
298  count_elems=0
299  CALL compute_adtensor_ref(ad_add_count_ref)
300 
301  DO i=1,ndim
302  ALLOCATE(adtensor(i)%elems(count_elems(i)), stat=allocstat)
303  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
304  END DO
305 
306  DEALLOCATE(count_elems, stat=allocstat)
307  IF (allocstat /= 0) stop "*** Deallocation problem ! ***"
308 
309  CALL compute_adtensor_ref(ad_coeff_ref)
310 
311  CALL simplify(adtensor)
312 
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
Statistics accumulators.
Definition: stat.f90:14
subroutine, public tl_ad_tensor::init_tltensor ( )

Routine to initialize the TL tensor.

Definition at line 97 of file tl_ad_tensor.f90.

97  INTEGER :: i
98  INTEGER :: allocstat
99  ALLOCATE(tltensor(ndim),count_elems(ndim), stat=allocstat)
100  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
101  count_elems=0
102  CALL compute_tltensor(tl_add_count)
103 
104  DO i=1,ndim
105  ALLOCATE(tltensor(i)%elems(count_elems(i)), stat=allocstat)
106  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
107  END DO
108 
109  DEALLOCATE(count_elems, stat=allocstat)
110  IF (allocstat /= 0) stop "*** Deallocation problem ! ***"
111 
112  CALL compute_tltensor(tl_coeff)
113 
114  CALL simplify(tltensor)
115 
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
Statistics accumulators.
Definition: stat.f90:14
type(coolist), dimension(:), allocatable, public tltensor
Tensor representation of the Tangent Linear tendencies.
type(coolist) function, dimension(ndim) tl_ad_tensor::jacobian ( real(kind=8), dimension(0:ndim), intent(in)  ystar)
private

Compute the Jacobian of MAOOAM in point ystar.

Parameters
ystararray with variables in which the jacobian should be evaluated.
Returns
Jacobian in coolist-form (table of tuples {i,j,0,value})

Definition at line 75 of file tl_ad_tensor.f90.

75  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: ystar
76  TYPE(coolist), DIMENSION(ndim) :: jacobian
77  CALL jsparse_mul(aotensor,ystar,jacobian)
Coordinate list. Type used to represent the sparse tensor.
Definition: tensor.f90:38
type(coolist), dimension(:), allocatable, public aotensor
- Tensor representation of the tendencies.
real(kind=8) function, dimension(ndim,ndim), public tl_ad_tensor::jacobian_mat ( real(kind=8), dimension(0:ndim), intent(in)  ystar)

Compute the Jacobian of MAOOAM in point ystar.

Parameters
ystararray with variables in which the jacobian should be evaluated.
Returns
Jacobian in matrix form

Definition at line 84 of file tl_ad_tensor.f90.

84  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: ystar
85  REAL(KIND=8), DIMENSION(ndim,ndim) :: jacobian_mat
86  CALL jsparse_mul_mat(aotensor,ystar,jacobian_mat)
type(coolist), dimension(:), allocatable, public aotensor
- Tensor representation of the tendencies.
subroutine, public tl_ad_tensor::tl ( real(kind=8), intent(in)  t,
real(kind=8), dimension(0:ndim), intent(in)  ystar,
real(kind=8), dimension(0:ndim), intent(in)  deltay,
real(kind=8), dimension(0:ndim), intent(out)  buf 
)

Tendencies for the TL of MAOOAM in point ystar for perturbation deltay.

Parameters
ttime
ystarvector with the variables (current point in trajectory)
deltayvector with the perturbation of the variables at time t
bufvector (buffer) to store derivatives.

Definition at line 396 of file tl_ad_tensor.f90.

396  REAL(KIND=8), INTENT(IN) :: t
397  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: ystar,deltay
398  REAL(KIND=8), DIMENSION(0:ndim), INTENT(OUT) :: buf
399  CALL sparse_mul3(tltensor,deltay,ystar,buf)
type(coolist), dimension(:), allocatable, public tltensor
Tensor representation of the Tangent Linear tendencies.
subroutine tl_ad_tensor::tl_add_count ( integer, intent(in)  i,
integer, intent(in)  j,
integer, intent(in)  k,
real(kind=8), intent(in)  v 
)
private

Subroutine used to count the number of TL tensor entries.

Parameters
itensor \(i\) index
jtensor \(j\) index
ktensor \(k\) index
vvalue that will be added

Definition at line 147 of file tl_ad_tensor.f90.

147  INTEGER, INTENT(IN) :: i,j,k
148  REAL(KIND=8), INTENT(IN) :: v
149  IF (abs(v) .ge. real_eps) THEN
150  IF (j /= 0) count_elems(i)=count_elems(i)+1
151  IF (k /= 0) count_elems(i)=count_elems(i)+1
152  ENDIF
subroutine tl_ad_tensor::tl_coeff ( integer, intent(in)  i,
integer, intent(in)  j,
integer, intent(in)  k,
real(kind=8), intent(in)  v 
)
private

Subroutine used to compute the TL tensor entries.

Parameters
itensor \(i\) index
jtensor \(j\) index
ktensor \(k\) index
vvalue to add

Definition at line 161 of file tl_ad_tensor.f90.

161  INTEGER, INTENT(IN) :: i,j,k
162  REAL(KIND=8), INTENT(IN) :: v
163  INTEGER :: n
164  IF (.NOT. ALLOCATED(tltensor)) stop "*** tl_coeff routine : tensor not yet allocated ***"
165  IF (.NOT. ALLOCATED(tltensor(i)%elems)) stop "*** tl_coeff routine : tensor not yet allocated ***"
166  IF (abs(v) .ge. real_eps) THEN
167  IF (j /=0) THEN
168  n=(tltensor(i)%nelems)+1
169  tltensor(i)%elems(n)%j=j
170  tltensor(i)%elems(n)%k=k
171  tltensor(i)%elems(n)%v=v
172  tltensor(i)%nelems=n
173  END IF
174  IF (k /=0) THEN
175  n=(tltensor(i)%nelems)+1
176  tltensor(i)%elems(n)%j=k
177  tltensor(i)%elems(n)%k=j
178  tltensor(i)%elems(n)%v=v
179  tltensor(i)%nelems=n
180  END IF
181  END IF
type(coolist), dimension(:), allocatable, public tltensor
Tensor representation of the Tangent Linear tendencies.

Variable Documentation

type(coolist), dimension(:), allocatable, public tl_ad_tensor::adtensor

Tensor representation of the Adjoint tendencies.

Definition at line 44 of file tl_ad_tensor.f90.

44  TYPE(coolist), DIMENSION(:), ALLOCATABLE, PUBLIC :: adtensor
Coordinate list. Type used to represent the sparse tensor.
Definition: tensor.f90:38
integer, dimension(:), allocatable tl_ad_tensor::count_elems
private

Vector used to count the tensor elements.

Definition at line 38 of file tl_ad_tensor.f90.

38  INTEGER, DIMENSION(:), ALLOCATABLE :: count_elems
real(kind=8), parameter tl_ad_tensor::real_eps = 2.2204460492503131e-16
private

Epsilon to test equality with 0.

Definition at line 35 of file tl_ad_tensor.f90.

35  REAL(KIND=8), PARAMETER :: real_eps = 2.2204460492503131e-16
type(coolist), dimension(:), allocatable, public tl_ad_tensor::tltensor

Tensor representation of the Tangent Linear tendencies.

Definition at line 41 of file tl_ad_tensor.f90.

41  TYPE(coolist), DIMENSION(:), ALLOCATABLE, PUBLIC :: tltensor
Coordinate list. Type used to represent the sparse tensor.
Definition: tensor.f90:38
type(coolist), dimension(:), allocatable, public tltensor
Tensor representation of the Tangent Linear tendencies.