# HG changeset patch # User "uncorrelated zombie" # Date 1721501809 -32400 # Node ID 206e90e911912cc4816c882449890c052571d249 # Parent 954faa9f6837e1daea2ae73b3d907ec4122dca90 make rkmod.f90 diff -r 954faa9f6837 -r 206e90e91191 rkmain.f90 --- a/rkmain.f90 Sun Jul 21 02:08:58 2024 +0900 +++ b/rkmain.f90 Sun Jul 21 03:56:49 2024 +0900 @@ -1,49 +1,13 @@ program rkmain - use rungekutta !ルンゲクッタ解法をまとめたモジュール + use rkmod implicit none - real(kind=dpkind),dimension(3) :: x !状態変数 - type(rk) :: rktype !ルンゲクッタ法ソルバに関連する型 - real(kind=dpkind),allocatable,dimension(:,:) :: r + real(kind=dpkind),dimension(3) :: x real(kind=dpkind) :: max_t - - !初期値の指定 - x = [0.5e0,0.5e0,0.5e0] - max_t = 5e1 - call calc(x, max_t, r) - print *, r; + real(kind=dpkind),allocatable,dimension(:,:) :: r - !======================================== - contains - !微分方程式の右辺を定義 - function rhside(self,time,wk) - class(rk),intent(inout) :: self !parameter - real(kind=dpkind) :: time - real(kind=dpkind),dimension(:) :: wk - real(kind=dpkind),dimension(size(wk)) :: rhside - real(kind=dpkind),parameter :: a=10e0,b=28e0,c=8e0/3e0 - rhside(1)=a*(wk(2)-wk(1)) - rhside(2)=b*wk(1)-wk(2)-wk(1)*wk(3) - rhside(3)=wk(1)*wk(2)-c*wk(3) - end function - !Rから呼び出すサブルーチン - subroutine calc(x, max_t, r) - implicit none - real(kind=dpkind),dimension(3),intent(in) :: x - real(kind=dpkind),intent(in) :: max_t - real(kind=dpkind),allocatable,dimension(:,:),intent(out) :: r - real(kind=dpkind) :: zero = 0 - integer i, max_i - !微分方程式の右辺を計算する関数、解法、時間刻みの指定 - call rktype%setup(rhside,"rk4",1d-5) - max_i = int(max_t / 0.01) - allocate(r(0:max_i, 4)) - !時刻max_t秒まで、0.01秒毎に配列に記録。 - !ただし、内部的には刻み幅1e-5秒としている。 - r(0, :) = [zero, x] ! 開始点 - do i = 1, max_i - call rktype%solver(rktype%time+1e-2,x) !積分実行 - r(i, :) = [rktype%time, x] - end do - end subroutine + x = [0.5d0,0.5d0,0.5d0] + max_t = 5d1 + call calc(x, max_t, r) + print *, r end program diff -r 954faa9f6837 -r 206e90e91191 rkmod.f90 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rkmod.f90 Sun Jul 21 03:56:49 2024 +0900 @@ -0,0 +1,39 @@ +module rkmod + use rungekutta !繝ォ繝ウ繧イ繧ッ繝繧ソ隗」豕輔r縺セ縺ィ繧√◆繝「繧ク繝・繝シ繝ォ + implicit none + type(rk) :: rktype !繝ォ繝ウ繧イ繧ッ繝繧ソ豕輔た繝ォ繝舌↓髢「騾」縺吶k蝙 + !======================================== + contains + !蠕ョ蛻譁ケ遞句シ上ョ蜿ウ霎コ繧貞ョ夂セゥ + function rhside(self,time,wk) + class(rk),intent(inout) :: self !parameter + real(kind=dpkind) :: time + real(kind=dpkind),dimension(:) :: wk + real(kind=dpkind),dimension(size(wk)) :: rhside + real(kind=dpkind),parameter :: a=10e0,b=28e0,c=8e0/3e0 + rhside(1)=a*(wk(2)-wk(1)) + rhside(2)=b*wk(1)-wk(2)-wk(1)*wk(3) + rhside(3)=wk(1)*wk(2)-c*wk(3) + end function + !R縺九i蜻シ縺ウ蜃コ縺吶し繝悶Ν繝シ繝√Φ + subroutine calc(x, max_t, r) + implicit none + real(kind=dpkind),dimension(3),intent(in) :: x !迥カ諷句、画焚 + real(kind=dpkind),intent(in) :: max_t + real(kind=dpkind),allocatable,dimension(:,:),intent(out) :: r + real(kind=dpkind) :: zero = 0 + integer i, max_i + !蠕ョ蛻譁ケ遞句シ上ョ蜿ウ霎コ繧定ィ育ョ励☆繧矩未謨ー縲∬ァ」豕輔∵凾髢灘綾縺ソ縺ョ謖螳 + call rktype%setup(rhside,"rk4",1d-5) + max_i = int(max_t / 0.01) + allocate(r(0:max_i, 4)) + !譎ょ綾max_t遘偵∪縺ァ縲0.01遘呈ッ弱↓驟榊励↓險倬鹸縲 + !縺溘□縺励∝驛ィ逧縺ォ縺ッ蛻サ縺ソ蟷1e-5遘偵→縺励※縺繧九 + r(0, :) = [zero, x] ! 髢句ァ狗せ + do i = 1, max_i + call rktype%solver(rktype%time+1e-2,x) !遨榊螳溯。 + r(i, :) = [rktype%time, x] + end do + end subroutine +end module +