annotate rkmod.f90 @ 2:206e90e91191

make rkmod.f90
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Sun, 21 Jul 2024 03:56:49 +0900
parents
children 2347cff808b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
1 module rkmod
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
2 use rungekutta !ルンゲクッタ解法をまとめたモジュール
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
3 implicit none
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
4 type(rk) :: rktype !ルンゲクッタ法ソルバに関連する型
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
5 !========================================
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
6 contains
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
7 !微分方程式の右辺を定義
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
8 function rhside(self,time,wk)
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
9 class(rk),intent(inout) :: self !parameter
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
10 real(kind=dpkind) :: time
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
11 real(kind=dpkind),dimension(:) :: wk
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
12 real(kind=dpkind),dimension(size(wk)) :: rhside
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
13 real(kind=dpkind),parameter :: a=10e0,b=28e0,c=8e0/3e0
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
14 rhside(1)=a*(wk(2)-wk(1))
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
15 rhside(2)=b*wk(1)-wk(2)-wk(1)*wk(3)
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
16 rhside(3)=wk(1)*wk(2)-c*wk(3)
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
17 end function
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
18 !Rから呼び出すサブルーチン
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
19 subroutine calc(x, max_t, r)
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
20 implicit none
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
21 real(kind=dpkind),dimension(3),intent(in) :: x !状態変数
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
22 real(kind=dpkind),intent(in) :: max_t
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
23 real(kind=dpkind),allocatable,dimension(:,:),intent(out) :: r
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
24 real(kind=dpkind) :: zero = 0
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
25 integer i, max_i
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
26 !微分方程式の右辺を計算する関数、解法、時間刻みの指定
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
27 call rktype%setup(rhside,"rk4",1d-5)
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
28 max_i = int(max_t / 0.01)
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
29 allocate(r(0:max_i, 4))
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
30 !時刻max_t秒まで、0.01秒毎に配列に記録。
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
31 !ただし、内部的には刻み幅1e-5秒としている。
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
32 r(0, :) = [zero, x] ! 開始点
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
33 do i = 1, max_i
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
34 call rktype%solver(rktype%time+1e-2,x) !積分実行
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
35 r(i, :) = [rktype%time, x]
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
36 end do
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
37 end subroutine
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
38 end module
206e90e91191 make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff changeset
39