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

Module that compute the memory term \(M_3\) of the WL parameterization. More...

Functions/Subroutines

subroutine, public init_memory
 Subroutine to initialise the memory. More...
 
subroutine, public compute_m3 (y, dt, dtn, savey, save_ev, evolve, inter, h_int)
 Compute the integrand of \(M_3\) at each time in the past and integrate to get the memory term. More...
 
subroutine, public test_m3 (y, dt, dtn, h_int)
 Routine to test the #compute_M3 routine. More...
 

Variables

real(kind=8), dimension(:,:), allocatable x
 Array storing the previous state of the system. More...
 
real(kind=8), dimension(:,:), allocatable xs
 Array storing the resolved time evolution of the previous state of the system. More...
 
real(kind=8), dimension(:,:), allocatable zs
 Dummy array to replace Xs in case where the evolution is not stored. More...
 
real(kind=8), dimension(:), allocatable buf_m
 Dummy vector. More...
 
real(kind=8), dimension(:), allocatable buf_m3
 Dummy vector to store the \(M_3\) integrand. More...
 
integer t_index
 Integer storing the time index (current position in the arrays) More...
 
procedure(ss_step), pointer step
 Procedural pointer pointing on the resolved dynamics step routine. More...
 

Detailed Description

Module that compute the memory term \(M_3\) of the WL parameterization.

Remarks

Function/Subroutine Documentation

subroutine, public memory::compute_m3 ( real(kind=8), dimension(0:ndim), intent(in)  y,
real(kind=8), intent(in)  dt,
real(kind=8), intent(in)  dtn,
logical, intent(in)  savey,
logical, intent(in)  save_ev,
logical, intent(in)  evolve,
real(kind=8), intent(in)  inter,
real(kind=8), dimension(0:ndim), intent(out)  h_int 
)

Compute the integrand of \(M_3\) at each time in the past and integrate to get the memory term.

Parameters
ycurrent state
dttimestep
dtnstochastic timestep
saveyset if the state is stored in X at the end
save_evset if the result of the resolved time evolution is stored in Xs at the end
evolveset if the resolved time evolution is performed
interset over which time interval the resolved time evolution must be computed
h_intresult of the integration - give the memory term

Definition at line 86 of file memory.f90.

86  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: y
87  REAL(KIND=8), INTENT(IN) :: dt,dtn
88  LOGICAL, INTENT(IN) :: savey,save_ev,evolve
89  REAL(KIND=8), INTENT(IN) :: inter
90  REAL(KIND=8), DIMENSION(0:ndim), INTENT(OUT) :: h_int
91  REAL(KIND=8) :: t
92  INTEGER :: i,j
93 
94  x(:,t_index)=y
95  IF (b23def) THEN
96  xs(:,t_index)=y
97  zs(:,t_index)=y
98  DO i=1,mems-1
99  j=modulo(t_index+i-1,mems)+1
100  zs(:,j)=xs(:,j)
101  IF (evolve) THEN
102  IF (dt.lt.inter) THEN
103  t=0.d0
104  DO WHILE (t+dt<inter)
105  CALL step(zs(:,j),y,t,dt,dtn,zs(:,j))
106  ENDDO
107  CALL step(zs(:,j),y,t,inter-t,sqrt(inter-t),zs(:,j))
108  ELSE
109  CALL step(zs(:,j),y,t,inter,sqrt(inter),zs(:,j))
110  ENDIF
111  ENDIF
112  IF (save_ev) xs(:,j)=zs(:,j)
113  ENDDO
114  ENDIF
115 
116 
117  ! Computing the integral
118  h_int=0.d0
119 
120  DO i=1,mems
121  j=modulo(t_index+i-2,mems)+1
122  buf_m3=0.d0
123  IF (ldef) THEN
124  CALL sparse_mul3(ltot(:,i),y,x(:,j),buf_m)
125  buf_m3=buf_m3+buf_m
126  ENDIF
127  IF (b14def) THEN
128  CALL sparse_mul3(b14(:,i),x(:,j),x(:,j),buf_m)
129  buf_m3=buf_m3+buf_m
130  ENDIF
131  IF (b23def) THEN
132  CALL sparse_mul3(b23(:,i),x(:,j),zs(:,j),buf_m)
133  buf_m3=buf_m3+buf_m
134  ENDIF
135  IF (mdef) THEN
136  CALL sparse_mul4(mtot(:,i),x(:,j),x(:,j),zs(:,j),buf_m)
137  buf_m3=buf_m3+buf_m
138  ENDIF
139  IF ((i.eq.1).or.(i.eq.mems)) THEN
140  h_int=h_int+0.5*buf_m3
141  ELSE
142  h_int=h_int+buf_m3
143  ENDIF
144  ENDDO
145 
146  h_int=muti*h_int
147  IF (savey) THEN
148  t_index=t_index-1
149  IF (t_index.eq.0) t_index=mems
150  ENDIF
subroutine, public memory::init_memory ( )

Subroutine to initialise the memory.

Definition at line 45 of file memory.f90.

45  INTEGER :: allocstat
46 
47  t_index=mems
48 
49  ALLOCATE(x(0:ndim,mems), stat=allocstat)
50  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
51 
52  x=0.d0
53 
54  IF (b23def) THEN
55  ALLOCATE(xs(0:ndim,mems), zs(0:ndim,mems), stat=allocstat)
56  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
57 
58  xs=0.d0
59  ENDIF
60 
61  ALLOCATE(buf_m3(0:ndim), buf_m(0:ndim), stat=allocstat)
62  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
63 
64  SELECT CASE (x_int_mode)
65  CASE('reso')
66  step => ss_step
67  CASE('tang')
68  step => ss_tl_step
69  CASE DEFAULT
70  stop '*** X_INT_MODE variable not properly defined in stoch_params.nml ***'
71  END SELECT
72 
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
Statistics accumulators.
Definition: stat.f90:14
subroutine, public memory::test_m3 ( real(kind=8), dimension(0:ndim), intent(in)  y,
real(kind=8), intent(in)  dt,
real(kind=8), intent(in)  dtn,
real(kind=8), dimension(0:ndim), intent(out)  h_int 
)

Routine to test the #compute_M3 routine.

Parameters
ycurrent state
dttimestep
dtnstochastic timestep
h_intresult of the integration - give the memory term

Definition at line 159 of file memory.f90.

159  REAL(KIND=8), DIMENSION(0:ndim), INTENT(IN) :: y
160  REAL(KIND=8), INTENT(IN) :: dt,dtn
161  REAL(KIND=8), DIMENSION(0:ndim), INTENT(OUT) :: h_int
162  INTEGER :: i,j
163 
164  CALL compute_m3(y,dt,dtn,.true.,.true.,.true.,muti,h_int)
165  print*, t_index
166  print*, 'X'
167  DO i=1,mems
168  j=modulo(t_index+i-1,mems)+1
169  print*, i,j,x(1,j)
170  ENDDO
171 
172  IF (b23def) THEN
173  print*, 'Xs'
174  DO i=1,mems
175  j=modulo(t_index+i-1,mems)+1
176  print*, i,j,xs(1,j)
177  ENDDO
178  ENDIF
179  print*, 'h_int',h_int

Variable Documentation

real(kind=8), dimension(:), allocatable memory::buf_m
private

Dummy vector.

Definition at line 31 of file memory.f90.

31  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: buf_m !< Dummy vector
real(kind=8), dimension(:), allocatable memory::buf_m3
private

Dummy vector to store the \(M_3\) integrand.

Definition at line 32 of file memory.f90.

32  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: buf_m3 !< Dummy vector to store the \f$M_3\f$ integrand
procedure(ss_step), pointer memory::step
private

Procedural pointer pointing on the resolved dynamics step routine.

Definition at line 36 of file memory.f90.

36  PROCEDURE(ss_step), POINTER :: step !< Procedural pointer pointing on the resolved dynamics step routine
integer memory::t_index
private

Integer storing the time index (current position in the arrays)

Definition at line 34 of file memory.f90.

34  INTEGER :: t_index !< Integer storing the time index (current position in the arrays)
real(kind=8), dimension(:,:), allocatable memory::x
private

Array storing the previous state of the system.

Definition at line 28 of file memory.f90.

28  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: x !< Array storing the previous state of the system
real(kind=8), dimension(:,:), allocatable memory::xs
private

Array storing the resolved time evolution of the previous state of the system.

Definition at line 29 of file memory.f90.

29  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: xs !< Array storing the resolved time evolution of the previous state of the system
real(kind=8), dimension(:,:), allocatable memory::zs
private

Dummy array to replace Xs in case where the evolution is not stored.

Definition at line 30 of file memory.f90.

30  REAL(KIND=8), DIMENSION(:,:), ALLOCATABLE :: zs !< Dummy array to replace Xs in case where the evolution is not stored