Mercurial > op > rk_sakamoti
annotate rkmod.f90 @ 4:8026ceb4de7a
add Makefile
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Tue, 23 Jul 2024 01:48:31 +0900 |
parents | 2347cff808b0 |
children |
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から呼び出すサブルーチン |
3
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
19 subroutine calc(x, max_i, r) |
2
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 !状態変数 |
3
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
22 integer, intent(in) :: max_i |
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
23 real(kind=dpkind) :: max_t |
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
24 real(kind=dpkind),dimension(max_i, 4),intent(out) :: r |
2
206e90e91191
make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
25 real(kind=dpkind) :: zero = 0 |
3
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
26 integer i |
2
206e90e91191
make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
27 !微分方程式の右辺を計算する関数、解法、時間刻みの指定 |
206e90e91191
make rkmod.f90
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
28 call rktype%setup(rhside,"rk4",1d-5) |
3
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
29 max_t = max_i * 0.01 |
2
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秒としている。 |
3
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
32 r(1, :) = [zero, x] ! 開始点 |
2347cff808b0
chage a parameter of rkmod::calc
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
2
diff
changeset
|
33 do i = 2, max_i |
2
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 |