annotate rkmain.f90 @ 1:954faa9f6837

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