-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create runge_kutta module, begin with simple 2-stage routines
- Loading branch information
1 parent
7968e3e
commit f88f3d4
Showing
3 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
program main | ||
use iso_fortran_env, only: wp => real64 | ||
use misc, only: myfun | ||
use runge_kutta, only: midpoint, heun, ralston | ||
implicit none | ||
|
||
integer :: ii | ||
real(wp) :: t, y, dy | ||
|
||
t = 0_wp | ||
y = 0_wp | ||
! real(wp) :: t, y, dy | ||
! t = 0_wp | ||
! y = 0_wp | ||
! dy = myfun(t, y) | ||
! print *, t, y, dy | ||
|
||
dy = myfun(t, y) | ||
integer, parameter :: N = 2 | ||
real(wp), dimension(N) :: c, b | ||
real(wp), dimension(N,N) :: a | ||
|
||
print *, t, y, dy | ||
call ralston(N, a, b, c) | ||
|
||
print *, c | ||
print *, b | ||
|
||
do ii = 1, N | ||
print *, a(ii, :) | ||
end do | ||
|
||
end program main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module runge_kutta | ||
use iso_fortran_env, only: wp => real64 | ||
implicit none | ||
|
||
contains | ||
|
||
subroutine midpoint(N, a, b, c) | ||
integer, intent(in) :: N | ||
real(wp) :: alpha | ||
real(wp), intent(out), dimension(N) :: c, b | ||
real(wp), intent(out), dimension(N,N) :: a | ||
|
||
alpha = 0.5_wp | ||
call two_stage(N, a, b, c, alpha) | ||
|
||
end subroutine midpoint | ||
|
||
subroutine heun(N, a, b, c) | ||
integer, intent(in) :: N | ||
real(wp) :: alpha | ||
real(wp), intent(out), dimension(N) :: c, b | ||
real(wp), intent(out), dimension(N,N) :: a | ||
|
||
alpha = 1._wp | ||
call two_stage(N, a, b, c, alpha) | ||
|
||
end subroutine heun | ||
|
||
subroutine ralston(N, a, b, c) | ||
integer, intent(in) :: N | ||
real(wp) :: alpha | ||
real(wp), intent(out), dimension(N) :: c, b | ||
real(wp), intent(out), dimension(N,N) :: a | ||
|
||
alpha = 2._wp/3._wp | ||
call two_stage(N, a, b, c, alpha) | ||
|
||
end subroutine ralston | ||
|
||
subroutine two_stage(N, a, b, c, alpha) | ||
integer, intent(in) :: N | ||
real(wp), intent(in) :: alpha | ||
real(wp), intent(out), dimension(N) :: c, b | ||
real(wp), intent(out), dimension(N,N) :: a | ||
|
||
c = [0._wp, alpha] | ||
b = [(1._wp - (1._wp/(2._wp*alpha))), (1._wp/(2._wp*alpha))] | ||
|
||
a = 0._wp | ||
a(2,1) = alpha | ||
|
||
end subroutine two_stage | ||
|
||
end module runge_kutta |