Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scarpma committed Feb 10, 2020
0 parents commit b7f7369
Show file tree
Hide file tree
Showing 10 changed files with 538 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

FC = gfortran
FLAGS = -O3 # -fbounds-check
TARGET = test

SOURCES = $(wildcard *.f90)
OBJS = $(SOURCES:.f90=.o)

%.o: %.f90
$(FC) $(FLAGS) -c $<

all: $(OBJS)
$(FC) -o $(TARGET) $(OBJS) $(LIBS)

clean:
rm *.o *.mod $(TARGET)

include make.dep
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ode
69 changes: 69 additions & 0 deletions caotic_pendulum.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module caotic_pendulum
use precision
use functions
use solvers
implicit none

real(dp), parameter :: pi = 3.14159265358979323846264338327_dp
real(dp), parameter :: eps = 1.d-10

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

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

81 changes: 81 additions & 0 deletions functions.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module functions
use precision
implicit none
private

public :: ff
public :: pendolo
public :: harmonic

real(dp), public :: k1
real(dp), public :: k2
real(dp), public :: Q
real(dp), public :: A
real(dp), public :: w

contains

subroutine fsub(t,u,up)
real(dp), intent(in) :: t
real(dp), intent(in) :: u(:)
real(dp), intent(out) :: up(:)

up(1) = u(2)
up(2) = k1*u(1) + k2*u(2)

end subroutine fsub

function f1(t,u) result(up)
real(dp), intent(in) :: t
real(dp), intent(in) :: u(:)
real(dp), allocatable :: up(:)

allocate(up(size(u)))

up(1) = k1*u(1)

end function f1


function ff(t,u) result(up)
real(dp), intent(in) :: t
real(dp), intent(in) :: u(:)
real(dp), allocatable :: up(:)

allocate(up(size(u)))

up(1) = u(2)
up(2) = k1*u(1) + k2*u(2)

end function ff

function pendolo(t,u) result(up)
real(dp), intent(in) :: t
real(dp), intent(in) :: u(:)
real(dp), allocatable :: up(:)

allocate(up(size(u)))

up(1) = u(2)
up(2) = -sin(u(1)) - u(2)/Q + A*cos(w*t)

end function pendolo

function harmonic(t,u) result(up)
real(dp), intent(in) :: t
real(dp), intent(in) :: u(:)
real(dp), allocatable :: up(:)

allocate(up(size(u)))

up(1) = u(2)
up(2) = -u(1) - u(2)/Q + A*cos(w*t)

end function harmonic




end module functions


26 changes: 26 additions & 0 deletions job
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash


echo ./test 0.01 100 rk2
./test 0.01 100 rk2
echo ./test 0.01 100 rk4
./test 0.01 100 rk4
echo ./test 0.01 100 dp54
./test 0.01 100 dp54
echo ./test 0.01 100 dp87
./test 0.01 100 dp87


echo ./test 0.001 1000 rk2
./test 0.001 1000 rk2
echo ./test 0.001 1000 rk4
./test 0.001 1000 rk4
echo ./test 0.001 1000 dp54
./test 0.001 1000 dp54
echo ./test 0.001 1000 dp87
./test 0.001 1000 dp87

echo ./test 0.001 100000 dp54
./test 0.001 100000 dp54
echo ./test 0.001 100000 dp87
./test 0.001 100000 dp87
9 changes: 9 additions & 0 deletions make.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
caotic_pendulum.o: precision.o
caotic_pendulum.o: functions.o
caotic_pendulum.o: solvers.o
functions.o: precision.o
solvers.o: precision.o
solvers.o: precision.o
test.o: precision.o
test.o: functions.o
test.o: solvers.o
5 changes: 5 additions & 0 deletions makedep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

grep use *.f90 | awk '{print gensub(".f90:",".o:",1,$1), $3".o"}'


6 changes: 6 additions & 0 deletions precision.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module precision
! Double precision
integer, parameter, public :: dp = selected_real_kind(14)
! Quadrupole precision
!integer, parameter, public :: dp = selected_real_kind(30)
end module precision
Loading

0 comments on commit b7f7369

Please sign in to comment.