Mercurial > op > rk_sakamoti
comparison rkmain.f90 @ 0:5bd0f2a15d2a
import from https://qiita.com/sakamoti/items/de851e0d07aeef5be310
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Tue, 23 Jul 2024 02:30:57 +0900 |
parents | |
children | 954faa9f6837 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5bd0f2a15d2a |
---|---|
1 program rkmain | |
2 use rungekutta !ルンゲクッタ解法をまとめたモジュール | |
3 implicit none | |
4 real(kind=dpkind),dimension(3) :: x !状態変数 | |
5 type(rk) :: rktype !ルンゲクッタ法ソルバに関連する型 | |
6 | |
7 !微分方程式の右辺を計算する関数、解法、時間刻みの指定 | |
8 call rktype%setup(rhside,"rk4",1d-5) | |
9 !初期値の指定 | |
10 x=[0.5e0,0.5e0,0.5e0] | |
11 !時刻0?50秒まで、0.01秒毎に標準出力へ書き出し。 | |
12 !ただし、内部的には刻み幅1e-5秒としている。 | |
13 do | |
14 if(rktype%time>5e1)exit | |
15 call rktype%solver(rktype%time+1e-2,x) !積分実行 | |
16 print*,rktype%time,x | |
17 enddo | |
18 !======================================== | |
19 contains | |
20 !微分方程式の右辺を定義 | |
21 function rhside(self,time,wk) | |
22 class(rk),intent(inout) :: self !parameter | |
23 real(kind=dpkind) :: time | |
24 real(kind=dpkind),dimension(:) :: wk | |
25 real(kind=dpkind),dimension(size(wk)) :: rhside | |
26 real(kind=dpkind),parameter :: a=10e0,b=28e0,c=8e0/3e0 | |
27 rhside(1)=a*(wk(2)-wk(1)) | |
28 rhside(2)=b*wk(1)-wk(2)-wk(1)*wk(3) | |
29 rhside(3)=wk(1)*wk(2)-c*wk(3) | |
30 end function | |
31 end program |