-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_lorenz63_lv.f90
130 lines (103 loc) · 3.07 KB
/
mod_lorenz63_lv.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
!===============================================================================
! program name: m_lv
!
! programmer: da,cheng org: umd ([email protected]) date: 2018-03-23
!
! Description:
! a module related to Lyapunov vector calculations
!
!-------------------------------------------------------------------------------
module mod_lorenz63_lv
use mod_math, only : eye, qr
implicit none
private
integer,parameter :: r_kind = kind(0.d0)
public :: le_blv, le_flv
contains
!
! Lyapunov exponents calculated from backward Lyapunov vectors
!
subroutine le_blv(nx,nt,dt,M,LE,Q0)
implicit none
integer,intent(in) :: nx
integer,intent(in) :: nt
real(r_kind),intent(in) :: dt
real(r_kind),intent(in) :: M(nx,nx,nt) ! M(:,:,1)
real(r_kind),intent(out) :: LE(nx)
real(r_kind),intent(in),optional :: Q0(nx,nx)
real(r_kind) :: Q(nx,nx,nt), R(nx,nx,nt)
integer :: n
call eye(nx,Q(:,:,1))
if(present(Q0)) Q(:,:,1) = Q0
call fwd_qr(nx,nt,M,Q,R,Q0=Q(:,:,1))
do n = 1, nx
LE(n) = sum(log(abs( R(n,n,1:nt) )))
enddo
LE(:)=LE(:)/(nt*dt)
endsubroutine
!
! Lyapunov exponents calculated from forward Lyapunov vectors
!
subroutine le_flv(nx,nt,dt,Mt,LE,Qn)
implicit none
integer,intent(in) :: nx
integer,intent(in) :: nt
real(r_kind),intent(in) :: dt
real(r_kind),intent(in) :: Mt(nx,nx,nt) ! M(:,:,i) for TLM from step i to step i+1
real(r_kind),intent(out) :: LE(nx)
real(r_kind),intent(in),optional :: Qn(nx,nx)
real(r_kind) :: Q(nx,nx,nt) ! Q(:,:,i) for step i
real(r_kind) :: R(nx,nx,nt) ! R(:,:,i) from step i to step i+1
real(r_kind) :: bufQ(nx,nx)
integer :: n
call eye(nx,bufQ)
if(present(Qn)) bufQ = Qn
call bwd_qr(nx,nt,Mt,Q,R,Qn=bufQ)
do n = 1, nx
LE(n) = sum(log(abs( R(n,n,1:nt) )))
enddo
LE(:)=LE(:)/(nt*dt)
endsubroutine
!
!
!
subroutine fwd_qr(nx,nt,M,Q,R,Q0)
implicit none
integer,intent(in) :: nx
integer,intent(in) :: nt
real(r_kind),intent(in) :: M(nx,nx,nt)
real(r_kind),intent(out) :: Q(nx,nx,nt)
real(r_kind),intent(out) :: R(nx,nx,nt)
real(r_kind),intent(in),optional :: Q0(nx,nx)
real(r_kind) :: bufQ(nx,nx), bufM(nx,nx)
integer :: n
call eye(nx,Q(:,:,1)) ! identiy matrix
if (present(Q0)) Q(:,:,1)=Q0
do n = 1, nt
bufM = matmul(M(:,:,n),Q(:,:,n)) ! evolve from step i -> step i+1
call qr(nx,bufM,bufQ,R(:,:,n)) ! get Q at step i+1, & R from step i->step i+1
if (n<nt) Q(:,:,n+1) = bufQ
enddo
endsubroutine
!
!
!
subroutine bwd_qr(nx,nt,Mt,Q,R,Qn)
implicit none
integer,intent(in) :: nx
integer,intent(in) :: nt
real(r_kind),intent(in) :: Mt(nx,nx,nt)
real(r_kind),intent(out) :: Q(nx,nx,nt)
real(r_kind),intent(out) :: R(nx,nx,nt)
real(r_kind),intent(in),optional :: Qn(nx,nx)
real(r_kind) :: bufQ(nx,nx), bufMt(nx,nx)
integer :: n
call eye(nx,bufQ) ! identiy matrix
if (present(Qn)) bufQ=Qn
do n = nt, 1, -1
bufMt = matmul(Mt(:,:,n),bufQ) ! evolve from step i+1 -> step i
call qr(nx,bufMt,bufQ,R(:,:,n)) ! get Q at step i, & R from step i+1 ->step i
Q(:,:,n) = bufQ
enddo
endsubroutine
endmodule