forked from comp-phys-uniroma2/ode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaotic_pendulum.f90
70 lines (52 loc) · 1.39 KB
/
caotic_pendulum.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
module caotic_pendulum
use precision
use constants
use functions
use solvers
implicit none
contains
subroutine solve(Nstep, Nperiods, x0, v0)
integer, intent(in) :: Nstep, Nperiods
real(dp), intent(in) :: x0, v0
real(dp) :: t, tfin, ttrans, dt, err
real(dp), allocatable :: u(:), u0(:), uex(:)
integer :: Ntot, Ntrans, id, id2
integer :: i
! w0 = 1
! dt = 0.01
dt = 2.0_dp*pi/(w*real(Nstep, dp))
Ntot = Nstep*Nperiods
tfin = Ntot*dt
Ntrans = int(Nperiods*0.0)
ttrans = Nstep*Ntrans*dt
write(*,*) 'dt=',dt
allocate(u0(2))
allocate(uex(2))
u0 = (/x0, v0/)
u = u0
t = 0.0_dp
do while (t<ttrans)
call dopri54(pendolo, t, dt, u0, u, err)
!call rk4(pendolo, t, dt, u0, u)
t = t + dt
u0 = u
end do
open(newunit=id, file='sol.dat')
!open(newunit=id2, file='poincare.dat', position='APPEND')
i = 0
do while (t<tfin)
write(id,'(F20.8,4(ES20.8))') t, u, u(2)*u(2)/2.0_dp + 1.0_dp - cos(u(1)), err
write(*,'(F20.8,3(ES20.8))') t, u, err
!if (mod(i,Nstep) == 0 ) then
! write(id2,*) Q, u(2)
!end if
call dopri54(pendolo, t, dt, u0, u, err)
!call rk4(pendolo, t, dt, u0, u)
t = t + dt
i = i + 1
u0 = u
end do
close(id)
!close(id2)
end subroutine solve
end module caotic_pendulum