A Modular Arbitrary-Order Ocean-Atmosphere Model -- Stochastic implementation
corr_tensor.f90
Go to the documentation of this file.
1 
2 ! corr_tensor.f90
3 !
4 !> Module to compute the correlations and derivatives used to compute
5 !> the memory term of the WL parameterization
6 !
7 !> @copyright
8 !> 2018 Jonathan Demaeyer.
9 !> See LICENSE.txt for license information.
10 !
11 !---------------------------------------------------------------------------!
12 !
13 !> @remark
14 !
15 !---------------------------------------------------------------------------!
16 
18  USE tensor
19  USE params, only: ndim
20  USE stoch_params, only:mems,muti
22  USE util, only:ireduce,vector_outer
23  USE sf_def, only: n_unres,ind,rind
24  IMPLICIT NONE
25 
26  PRIVATE
27 
28  PUBLIC :: init_corr_tensor
29 
30  TYPE(coolist), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: yy !< Coolist holding the \f$\langle Y \otimes Y^s \rangle\f$ terms
31  TYPE(coolist), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: dy !< Coolist holding the \f$\langle \partial_Y \otimes Y^s \rangle\f$ terms
32  TYPE(coolist), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: ydy !< Coolist holding the \f$\langle Y \otimes \partial_Y \otimes Y^s \rangle\f$ terms
33  TYPE(coolist), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: dyy !< Coolist holding the \f$\langle \partial_Y \otimes Y^s \otimes Y^s \rangle\f$ terms
34  TYPE(coolist4), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: ydyy !< Coolist holding the \f$\langle Y \otimes \partial_Y \otimes Y^s \otimes Y^s \rangle\f$ terms
35 
36  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: dumb_vec !< Dumb vector to be used in the calculation
37  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: dumb_mat1 !< Dumb matrix to be used in the calculation
38  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: dumb_mat2 !< Dumb matrix to be used in the calculation
39  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: expm !< Matrix holding the product inv_corr_i*corr_ij at time \f$s\f$
40 
41 CONTAINS
42 
43  !> Subroutine to initialise the correlations tensors
44  SUBROUTINE init_corr_tensor
45  INTEGER :: i,j,m,AllocStat
46 
47  CALL init_corr
48 
49  print*, 'Computing the time correlation tensors...'
50 
51  ALLOCATE(yy(ndim,mems),dy(ndim,mems), dyy(ndim,mems), stat=allocstat)
52  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
53 
54  ALLOCATE(ydy(ndim,mems), ydyy(ndim,mems), stat=allocstat)
55  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
56 
57  ALLOCATE(dumb_vec(ndim), stat=allocstat)
58  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
59 
60  ALLOCATE(dumb_mat1(ndim,ndim), dumb_mat2(ndim,ndim), stat=allocstat)
61  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
62 
63  ALLOCATE(expm(n_unres,n_unres), stat=allocstat)
64  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
65 
66  DO m=1,mems
67  CALL corrcomp((m-1)*muti)
68 
69  ! YY
71  CALL matc_to_coo(dumb_mat2,yy(:,m))
72 
73  ! dY
74  expm=matmul(inv_corr_i,corr_ij)
76  CALL matc_to_coo(dumb_mat2,dy(:,m))
77 
78  ! YdY
79  DO i=1,n_unres
81  CALL add_matc_to_tensor(ind(i),dumb_mat2,ydy(:,m))
82  ENDDO
83 
84  ! dYY
85  dumb_vec(1:n_unres)=matmul(mean,expm)
86  DO i=1,n_unres
89  CALL add_matc_to_tensor(ind(i),dumb_mat1,dyy(:,m))
90  ENDDO
91 
92  ! YdYY
93  DO i=1,n_unres
94  DO j=1,n_unres
95  CALL vector_outer(corr_ij(i,:),expm(j,:),dumb_mat2(1:n_unres,1:n_unres))
97  CALL add_matc_to_tensor4(ind(i),ind(j),dumb_mat1,ydyy(:,m))
98  ENDDO
99  ENDDO
100  ENDDO
101 
102  DEALLOCATE(dumb_mat1, dumb_mat2, stat=allocstat)
103  IF (allocstat /= 0) stop "*** Problem to deallocate ! ***"
104 
105  DEALLOCATE(dumb_vec, stat=allocstat)
106  IF (allocstat /= 0) stop "*** Problem to deallocate ! ***"
107 
108 
109  END SUBROUTINE init_corr_tensor
110 
111 END MODULE corr_tensor
112 
113 
114 
115 
The stochastic models parameters module.
type(coolist), dimension(:,:), allocatable, public yy
Coolist holding the terms.
Definition: corr_tensor.f90:30
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
subroutine, public add_matc_to_tensor4(i, j, src, dst)
Routine to add a matrix to a rank-4 tensor.
Definition: tensor.f90:537
real(kind=8), dimension(:,:), allocatable, public corr_ij
Matrix holding the correlation matrix at a given time.
Definition: corrmod.f90:32
real(kind=8), dimension(:,:), allocatable expm
Matrix holding the product inv_corr_i*corr_ij at time .
Definition: corr_tensor.f90:39
type(coolist), dimension(:,:), allocatable, public dyy
Coolist holding the terms.
Definition: corr_tensor.f90:33
Utility module.
Definition: util.f90:12
real(kind=8) muti
Memory update time interval.
Statistics accumulators.
Definition: stat.f90:14
type(coolist4), dimension(:,:), allocatable, public ydyy
Coolist holding the terms.
Definition: corr_tensor.f90:34
integer, dimension(:), allocatable, public rind
Unresolved reduction indices.
Definition: sf_def.f90:24
subroutine, public ireduce(A, Ared, n, ind, rind)
Definition: util.f90:314
Tensor utility module.
Definition: tensor.f90:18
subroutine, public init_corr
Subroutine to initialise the computation of the correlation.
Definition: corrmod.f90:46
real(kind=8), dimension(:), allocatable, public mean
Vector holding the mean of the unresolved dynamics (reduced version)
Definition: corrmod.f90:26
subroutine, public vector_outer(u, v, A)
Definition: util.f90:328
subroutine, public add_matc_to_tensor(i, src, dst)
Routine to add a matrix to a rank-3 tensor.
Definition: tensor.f90:474
Coordinate list. Type used to represent the sparse tensor.
Definition: tensor.f90:38
type(coolist), dimension(:,:), allocatable, public dy
Coolist holding the terms.
Definition: corr_tensor.f90:31
type(coolist), dimension(:,:), allocatable, public ydy
Coolist holding the terms.
Definition: corr_tensor.f90:32
subroutine, public init_corr_tensor
Subroutine to initialise the correlations tensors.
Definition: corr_tensor.f90:45
real(kind=8), dimension(:), allocatable dumb_vec
Dumb vector to be used in the calculation.
Definition: corr_tensor.f90:36
integer, public n_unres
Number of unresolved variables.
Definition: sf_def.f90:26
4d coordinate list. Type used to represent the rank-4 sparse tensor.
Definition: tensor.f90:44
subroutine, public matc_to_coo(src, dst)
Routine to convert a matrix to a rank-3 tensor.
Definition: tensor.f90:1244
real(kind=8), dimension(:,:), allocatable dumb_mat2
Dumb matrix to be used in the calculation.
Definition: corr_tensor.f90:38
Module to initialize the correlation matrix of the unresolved variables.
Definition: corrmod.f90:16
real(kind=8), dimension(:,:), allocatable dumb_mat1
Dumb matrix to be used in the calculation.
Definition: corr_tensor.f90:37
integer, dimension(:), allocatable, public ind
Definition: sf_def.f90:24
procedure(corrcomp_from_spline), pointer, public corrcomp
Pointer to the correlation computation routine.
Definition: corrmod.f90:41
The model parameters module.
Definition: params.f90:18
Module to select the resolved-unresolved components.
Definition: sf_def.f90:12
real(kind=8), dimension(:,:), allocatable, public inv_corr_i
Inverse of the covariance matrix of the unresolved variables (reduced version)
Definition: corrmod.f90:31
Module to compute the correlations and derivatives used to compute the memory term of the WL paramete...
Definition: corr_tensor.f90:17
integer mems
Number of steps in the memory kernel integral.