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 !> 2017 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  ! print*, oi,oj
96  CALL integrate(func_ij,ss)
97  corrint(ind(i),ind(j))=ss
98  END DO
99  END DO
100 
101  OPEN(30,file='corrint.def')
102  WRITE(30,*) corrint
103  CLOSE(30)
104  END SELECT
105 
106 
107  INQUIRE(file='corr2int.def',exist=ex)
108  SELECT CASE (int_corr_mode)
109  CASE ('file')
110  IF (ex) THEN
111  CALL load_tensor4_from_file("corr2int.def",corr2int)
112  ELSE
113  stop "*** File corr2int.def not found ! ***"
114  END IF
115  CASE ('prog')
116  DO i = 1,n_unres
117  n=0
118  DO j= 1,n_unres
119  DO k= 1,n_unres
120  DO l = 1,n_unres
121  oi=i
122  oj=j
123  ok=k
124  ol=l
125 
126  CALL integrate(func_ijkl,ss)
127  IF (abs(ss)>real_eps) n=n+1
128  ENDDO
129  ENDDO
130  ENDDO
131  IF (n/=0) THEN
132  ALLOCATE(corr2int(ind(i))%elems(n), stat=allocstat)
133  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
134 
135  n=0
136  DO j= 1,n_unres
137  DO k= 1,n_unres
138  DO l = 1,n_unres
139  oi=i
140  oj=j
141  ok=k
142  ol=l
143 
144  CALL integrate(func_ijkl,ss)
145  IF (abs(ss)>real_eps) THEN
146  n=n+1
147  corr2int(ind(i))%elems(n)%j=ind(j)
148  corr2int(ind(i))%elems(n)%k=ind(k)
149  corr2int(ind(i))%elems(n)%l=ind(l)
150  corr2int(ind(i))%elems(n)%v=ss
151  END IF
152  ENDDO
153  ENDDO
154  ENDDO
155  corr2int(ind(i))%nelems=n
156  END IF
157  ENDDO
158 
159  CALL write_tensor4_to_file("corr2int.def",corr2int)
160  CASE DEFAULT
161  stop '*** INT_CORR_MODE variable not properly defined in corrmod.nml ***'
162  END SELECT
163 
164  END SUBROUTINE comp_corrint
165 
166 END MODULE int_corr
The stochastic models parameters module.
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:79
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:1181
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:1208
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