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

Multidimensional Autoregressive module to generate the correlation for the WL parameterization. More...

Functions/Subroutines

subroutine, public init_mar
 Subroutine to initialise the MAR. More...
 
subroutine, public mar_step (x)
 Routine to generate one step of the MAR. More...
 
subroutine, public mar_step_red (xred)
 Routine to generate one step of the reduce MAR. More...
 
subroutine stoch_vec (dW)
 

Variables

real(kind=8), dimension(:,:), allocatable, public q
 Square root of the noise covariance matrix. More...
 
real(kind=8), dimension(:,:), allocatable, public qred
 Reduce version of Q. More...
 
real(kind=8), dimension(:,:), allocatable, public rred
 Covariance matrix of the noise. More...
 
real(kind=8), dimension(:,:,:), allocatable, public w
 W_i matrix. More...
 
real(kind=8), dimension(:,:,:), allocatable, public wred
 Reduce W_i matrix. More...
 
real(kind=8), dimension(:), allocatable buf_y
 
real(kind=8), dimension(:), allocatable dw
 
integer, public ms
 order of the MAR More...
 

Detailed Description

Multidimensional Autoregressive module to generate the correlation for the WL parameterization.

Remarks
Based on the equation \(y_n = \sum_{i=1}^m y_{n-i} \cdot W_i + Q \cdot \xi_n for an order \)

Function/Subroutine Documentation

subroutine, public mar::init_mar ( )

Subroutine to initialise the MAR.

Definition at line 45 of file MAR.f90.

45  INTEGER :: allocstat,nf,i,info,info2
46  INTEGER, DIMENSION(3) :: s
47 
48  print*, 'Initializing the MAR integrator...'
49 
50  print*, 'Loading the MAR config from files...'
51 
52  OPEN(20,file='MAR_R_params.def',status='old')
53  READ(20,*) nf,ms
54  IF (nf /= n_unres) stop "*** Dimension in files MAR_R_params.def and sf.nml do not correspond ! ***"
55  ALLOCATE(qred(n_unres,n_unres),rred(n_unres,n_unres),wred(ms,n_unres,n_unres), stat=allocstat)
56  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
57  ALLOCATE(q(ndim,ndim),w(ms,ndim,ndim), stat=allocstat)
58  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
59  ALLOCATE(buf_y(0:ndim), dw(ndim), stat=allocstat)
60  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
61  READ(20,*) rred
62  CLOSE(20)
63 
64  OPEN(20,file='MAR_W_params.def',status='old')
65  READ(20,*) nf,ms
66  s=shape(wred)
67  IF (nf /= n_unres) stop "*** Dimension in files MAR_W_params.def and sf.nml do not correspond ! ***"
68  IF (s(1) /= ms) stop "*** MAR order in files MAR_R_params.def and MAR_W_params.def do not correspond ! ***"
69  DO i=1,ms
70  READ(20,*) wred(i,:,:)
71  ENDDO
72  CLOSE(20)
73 
74  CALL init_sqrt
75  CALL sqrtm(rred,qred,info,info2)
76  CALL ireduce(q,qred,n_unres,ind,rind)
77 
78  DO i=1,ms
79  CALL ireduce(w(i,:,:),wred(i,:,:),n_unres,ind,rind)
80  ENDDO
81 
82  ! Kept for internal testing - Uncomment if not needed
83  ! DEALLOCATE(Wred,Rred,Qred, STAT=AllocStat)
84  ! IF (AllocStat /= 0) STOP "*** Deallocation problem ! ***"
85 
86  print*, 'MAR of order',ms,'found!'
87 
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
Statistics accumulators.
Definition: stat.f90:14
subroutine, public mar::mar_step ( real(kind=8), dimension(0:ndim,ms), intent(inout)  x)

Routine to generate one step of the MAR.

Parameters
xState vector of the MAR (store the \(y_i\))

Definition at line 93 of file MAR.f90.

93  REAL(KIND=8), DIMENSION(0:ndim,ms), INTENT(INOUT) :: x
94  INTEGER :: j
95 
96  CALL stoch_vec(dw)
97  buf_y=0.d0
98  buf_y(1:ndim)=matmul(q,dw)
99  DO j=1,ms
100  buf_y(1:ndim)=buf_y(1:ndim)+matmul(x(1:ndim,j),w(j,:,:))
101  ENDDO
102  x=eoshift(x,shift=-1,boundary=buf_y,dim=2)
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
subroutine, public mar::mar_step_red ( real(kind=8), dimension(0:ndim,ms), intent(inout)  xred)

Routine to generate one step of the reduce MAR.

Parameters
xredState vector of the MAR (store the \(y_i\))
Remarks
For debugging purpose only

Definition at line 110 of file MAR.f90.

110  REAL(KIND=8), DIMENSION(0:ndim,ms), INTENT(INOUT) :: xred
111  INTEGER :: j
112 
113  CALL stoch_vec(dw)
114  buf_y=0.d0
115  buf_y(1:n_unres)=matmul(qred,dw(1:n_unres))
116  DO j=1,ms
117  buf_y(1:n_unres)=buf_y(1:n_unres)+matmul(xred(1:n_unres,j),wred(j,:,:))
118  ENDDO
119  xred=eoshift(xred,shift=-1,boundary=buf_y,dim=2)
subroutine mar::stoch_vec ( real(kind=8), dimension(ndim), intent(inout)  dW)
private

Definition at line 125 of file MAR.f90.

125  REAL(KIND=8), DIMENSION(ndim), INTENT(INOUT) :: dw
126  INTEGER :: i
127  DO i=1,ndim
128  dw(i)=gasdev()
129  ENDDO
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85

Variable Documentation

real(kind=8), dimension(:), allocatable mar::buf_y
private

Definition at line 34 of file MAR.f90.

34  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: buf_y,dw
real(kind=8), dimension(:), allocatable mar::dw
private

Definition at line 34 of file MAR.f90.

integer, public mar::ms

order of the MAR

Definition at line 36 of file MAR.f90.

36  INTEGER :: ms !< order of the MAR
real(kind=8), dimension(:,:), allocatable, public mar::q

Square root of the noise covariance matrix.

Definition at line 29 of file MAR.f90.

29  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: q !< Square root of the noise covariance matrix
real(kind=8), dimension(:,:), allocatable, public mar::qred

Reduce version of Q.

Definition at line 30 of file MAR.f90.

30  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: qred !< Reduce version of Q
real(kind=8), dimension(:,:), allocatable, public mar::rred

Covariance matrix of the noise.

Definition at line 31 of file MAR.f90.

31  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: rred !< Covariance matrix of the noise
real(kind=8), dimension(:,:,:), allocatable, public mar::w

W_i matrix.

Definition at line 32 of file MAR.f90.

32  REAL(KIND=8), DIMENSION(:,:,:), ALLOCATABLE :: w !< W_i matrix
real(kind=8), dimension(:,:,:), allocatable, public mar::wred

Reduce W_i matrix.

Definition at line 33 of file MAR.f90.

33  REAL(KIND=8), DIMENSION(:,:,:), ALLOCATABLE :: wred !< Reduce W_i matrix