A Modular Arbitrary-Order Ocean-Atmosphere Model -- Stochastic implementation
int_corr.f90
Go to the documentation of this file.
1 
2 ! int_corr.f90
3 !
4 !> Module to compute or load the integrals of the correlation matrices
5 !
6 !> @copyright
7 !> 2018 Jonathan Demaeyer.
8 !> See LICENSE.txt for license information.
9 !
10 !---------------------------------------------------------------------------!
11 !
12 !> @remark
13 !
14 !---------------------------------------------------------------------------!
15 
16 MODULE int_corr
17  USE params, only: ndim
18  USE sf_def, only: n_unres,ind
20  USE int_comp, only: integrate
22  USE stoch_params, only: int_corr_mode
23 
24  PRIVATE
25 
26  INTEGER :: oi,oj,ok,ol !< Integers that specify the matrices and tensor component considered as a function of time
27  REAL(KIND=8), PARAMETER :: real_eps = 2.2204460492503131e-16 !< Small epsilon constant to determine equality with zero
28 
29  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE, PUBLIC :: corrint !< Matrix holding the integral of the correlation matrix
30  TYPE(coolist4), DIMENSION(:), ALLOCATABLE, PUBLIC :: corr2int !< Tensor holding the integral of the correlation outer product with itself
31 
32  PUBLIC :: init_corrint,comp_corrint
33 
34 CONTAINS
35 
36  !> Subroutine to initialise the integrated matrices and tensors
37  SUBROUTINE init_corrint
38  INTEGER :: AllocStat
39 
40  ALLOCATE(corrint(ndim,ndim), stat=allocstat)
41  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
42 
43  ALLOCATE(corr2int(ndim), stat=allocstat)
44  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
45 
46  CALL init_corr ! Initialize the correlation matrix function
47 
48  corrint=0.d0
49 
50  END SUBROUTINE init_corrint
51 
52  !> Function that returns the component oi and oj of the correlation matrix at time s
53  !> @param s time at which the function is evaluated
54  FUNCTION func_ij(s)
55  IMPLICIT NONE
56  REAL(KIND=8) :: s,func_ij
57  CALL corrcomp(s)
58  func_ij=corr_ij(oi,oj)
59  RETURN
60  END FUNCTION func_ij
61 
62  !> Function that returns the component oi,oj,ok and ol of the outer product of the
63  !> correlation matrix with itself at time s
64  !> @param s time at which the function is evaluated
65  FUNCTION func_ijkl(s)
66  IMPLICIT NONE
67  REAL(KIND=8) :: s,func_ijkl
68  CALL corrcomp(s)
69  func_ijkl=corr_ij(oi,oj)*corr_ij(ok,ol)
70  RETURN
71  END FUNCTION func_ijkl
72 
73  !> Routine that actually compute or load the integrals
74  SUBROUTINE comp_corrint
75  IMPLICIT NONE
76  INTEGER :: i,j,k,l,n,AllocStat
77  REAL(KIND=8) :: ss
78  LOGICAL :: ex
79 
80  INQUIRE(file='corrint.def',exist=ex)
81  SELECT CASE (int_corr_mode)
82  CASE ('file')
83  IF (ex) THEN
84  OPEN(30,file='corrint.def',status='old')
85  READ(30,*) corrint
86  CLOSE(30)
87  ELSE
88  stop "*** File corrint.def not found ! ***"
89  END IF
90  CASE ('prog')
91  DO i = 1,n_unres
92  DO j= 1,n_unres
93  oi=i
94  oj=j
95  CALL integrate(func_ij,ss)
96  corrint(ind(i),ind(j))=ss
97  END DO
98  END DO
99 
100  OPEN(30,file='corrint.def')
101  WRITE(30,*) corrint
102  CLOSE(30)
103  END SELECT
104 
105 
106  INQUIRE(file='corr2int.def',exist=ex)
107  SELECT CASE (int_corr_mode)
108  CASE ('file')
109  IF (ex) THEN
110  CALL load_tensor4_from_file("corr2int.def",corr2int)
111  ELSE
112  stop "*** File corr2int.def not found ! ***"
113  END IF
114  CASE ('prog')
115  DO i = 1,n_unres
116  n=0
117  DO j= 1,n_unres
118  DO k= 1,n_unres
119  DO l = 1,n_unres
120  oi=i
121  oj=j
122  ok=k
123  ol=l
124 
125  CALL integrate(func_ijkl,ss)
126  IF (abs(ss)>real_eps) n=n+1
127  ENDDO
128  ENDDO
129  ENDDO
130  IF (n/=0) THEN
131  ALLOCATE(corr2int(ind(i))%elems(n), stat=allocstat)
132  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
133 
134  n=0
135  DO j= 1,n_unres
136  DO k= 1,n_unres
137  DO l = 1,n_unres
138  oi=i
139  oj=j
140  ok=k
141  ol=l
142 
143  CALL integrate(func_ijkl,ss)
144  IF (abs(ss)>real_eps) THEN
145  n=n+1
146  corr2int(ind(i))%elems(n)%j=ind(j)
147  corr2int(ind(i))%elems(n)%k=ind(k)
148  corr2int(ind(i))%elems(n)%l=ind(l)
149  corr2int(ind(i))%elems(n)%v=ss
150  END IF
151  ENDDO
152  ENDDO
153  ENDDO
154  corr2int(ind(i))%nelems=n
155  END IF
156  ENDDO
157 
158  CALL write_tensor4_to_file("corr2int.def",corr2int)
159  CASE DEFAULT
160  stop '*** INT_CORR_MODE variable not properly defined in corrmod.nml ***'
161  END SELECT
162 
163  END SUBROUTINE comp_corrint
164 
165 END MODULE int_corr
The stochastic models parameters module.
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
real(kind=8), dimension(:,:), allocatable, public corr_ij
Matrix holding the correlation matrix at a given time.
Definition: corrmod.f90:32
subroutine, public comp_corrint
Routine that actually compute or load the integrals.
Definition: int_corr.f90:75
real(kind=8) function func_ijkl(s)
Function that returns the component oi,oj,ok and ol of the outer product of the correlation matrix wi...
Definition: int_corr.f90:66
real(kind=8), dimension(:,:), allocatable, public corrint
Matrix holding the integral of the correlation matrix.
Definition: int_corr.f90:29
Statistics accumulators.
Definition: stat.f90:14
Utility module containing the routines to perform the integration of functions.
Definition: int_comp.f90:17
subroutine, public load_tensor4_from_file(s, t)
Load a rank-4 tensor coolist from a file definition.
Definition: tensor.f90:1322
integer oi
Definition: int_corr.f90:26
Tensor utility module.
Definition: tensor.f90:18
subroutine, public init_corr
Subroutine to initialise the computation of the correlation.
Definition: corrmod.f90:46
character(len=4) int_corr_mode
Correlation integration mode.
type(coolist4), dimension(:), allocatable, public corr2int
Tensor holding the integral of the correlation outer product with itself.
Definition: int_corr.f90:30
subroutine, public init_corrint
Subroutine to initialise the integrated matrices and tensors.
Definition: int_corr.f90:38
subroutine, public write_tensor4_to_file(s, t)
Load a rank-4 tensor coolist from a file definition.
Definition: tensor.f90:1349
real(kind=8) function func_ij(s)
Function that returns the component oi and oj of the correlation matrix at time s.
Definition: int_corr.f90:55
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
real(kind=8), parameter real_eps
Small epsilon constant to determine equality with zero.
Definition: int_corr.f90:27
Module to initialize the correlation matrix of the unresolved variables.
Definition: corrmod.f90:16
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
subroutine, public integrate(func, ss)
Routine to compute integrals of function from O to #maxint.
Definition: int_comp.f90:30
integer oj
Definition: int_corr.f90:26
integer ol
Integers that specify the matrices and tensor component considered as a function of time...
Definition: int_corr.f90:26
Module to select the resolved-unresolved components.
Definition: sf_def.f90:12
integer ok
Definition: int_corr.f90:26
Module to compute or load the integrals of the correlation matrices.
Definition: int_corr.f90:16