Mercurial > op > rk_sakamoti
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:954faa9f6837 | 2:206e90e91191 |
---|---|
1 module rkmod | |
2 use rungekutta !ルンゲクッタ解法をまとめたモジュール | |
3 implicit none | |
4 type(rk) :: rktype !ルンゲクッタ法ソルバに関連する型 | |
5 !======================================== | |
6 contains | |
7 !微分方程式の右辺を定義 | |
8 function rhside(self,time,wk) | |
9 class(rk),intent(inout) :: self !parameter | |
10 real(kind=dpkind) :: time | |
11 real(kind=dpkind),dimension(:) :: wk | |
12 real(kind=dpkind),dimension(size(wk)) :: rhside | |
13 real(kind=dpkind),parameter :: a=10e0,b=28e0,c=8e0/3e0 | |
14 rhside(1)=a*(wk(2)-wk(1)) | |
15 rhside(2)=b*wk(1)-wk(2)-wk(1)*wk(3) | |
16 rhside(3)=wk(1)*wk(2)-c*wk(3) | |
17 end function | |
18 !Rから呼び出すサブルーチン | |
19 subroutine calc(x, max_t, r) | |
20 implicit none | |
21 real(kind=dpkind),dimension(3),intent(in) :: x !状態変数 | |
22 real(kind=dpkind),intent(in) :: max_t | |
23 real(kind=dpkind),allocatable,dimension(:,:),intent(out) :: r | |
24 real(kind=dpkind) :: zero = 0 | |
25 integer i, max_i | |
26 !微分方程式の右辺を計算する関数、解法、時間刻みの指定 | |
27 call rktype%setup(rhside,"rk4",1d-5) | |
28 max_i = int(max_t / 0.01) | |
29 allocate(r(0:max_i, 4)) | |
30 !時刻max_t秒まで、0.01秒毎に配列に記録。 | |
31 !ただし、内部的には刻み幅1e-5秒としている。 | |
32 r(0, :) = [zero, x] ! 開始点 | |
33 do i = 1, max_i | |
34 call rktype%solver(rktype%time+1e-2,x) !積分実行 | |
35 r(i, :) = [rktype%time, x] | |
36 end do | |
37 end subroutine | |
38 end module | |
39 |