時刻、計算結果の出力処理の記述¶
時刻、計算結果の出力処理を記述します。
時間依存の方程式を解くソルバーの場合、タイムステップの数だけ時刻、 計算結果の出力を繰り返します。
また、時刻、計算結果の出力のたびにユーザがソルバーの実行を中止していないか確認し、 中止していたら実行を中止します。
なお、ソルバーが出力する計算結果についてはソルバー定義ファイルには記述しませんので、 ソルバー定義ファイルとの対応関係を気にせず記述できます。
時刻、計算結果の出力処理を追記したソースコードを リスト 9 に示します。強調して示したのが追記した部分です。
1 ! (略)
2 integer:: isize, jsize
3 double precision, dimension(:,:), allocatable:: grid_x, grid_y
4 double precision, dimension(:,:), allocatable:: elevation
5 integer, dimension(:,:), allocatable:: obstacle
6 double precision:: time
7 integer:: iteration
8 integer:: canceled
9 integer:: locked
10 double precision, dimension(:,:), allocatable:: velocity_x, velocity_y
11 double precision, dimension(:,:), allocatable:: depth
12 integer, dimension(:,:), allocatable:: wetflag
13 double precision:: convergence
14
15 ! (略)
16
17 ! 属性を読み込む
18 call cg_iric_read_grid_real_node_f("Elevation", elevation, ier)
19 call cg_iric_read_grid_integer_cell_f("Obstacle", obstacle, ier)
20
21 allocate(velocity_x(isize,jsize), velocity_y(isize,jsize), depth(isize,jsize), wetflag(isize,jsize))
22 iteration = 0
23 time = 0
24 do
25 time = time + timestep
26 ! (ここで計算を実行。格子の形状も変化)
27
28 call iric_check_cancel_f(canceled)
29 if (canceled == 1) exit
30 call iric_check_lock_f(condFile, locked)
31 do while (locked == 1)
32 sleep(1)
33 call iric_check_lock_f(condFile, locked)
34 end do
35 call iric_write_sol_start_f(condFile, ier)
36 call cg_iric_write_sol_time_f(time, ier)
37 ! 格子を出力
38 call cg_iric_write_sol_gridcoord2d_f (grid_x, grid_y, ier)
39 ! 計算結果を出力
40 call cg_iric_write_sol_real_f ('VelocityX', velocity_x, ier)
41 call cg_iric_write_sol_real_f ('VelocityY', velocity_y, ier)
42 call cg_iric_write_sol_real_f ('Depth', depth, ier)
43 call cg_iric_write_sol_integer_f ('Wet', wetflag, ier)
44 call cg_iric_write_sol_baseiterative_real_f ('Convergence', convergence, ier)
45 call cg_iric_flush_f(condFile, fin, ier)
46 call iric_write_sol_end_f(condFile, ier)
47 iteration = iteration + 1
48 if (iteration > maxiterations) exit
49 end do
50
51 ! 計算データファイルを閉じる
52 call cg_close_f(fin, ier)
53 stop
54end program SampleProgram
時刻、計算結果の出力に使う関数の詳細については、 時刻 (もしくはループ回数) の出力, 計算結果の出力 を参照してください。 計算実行中に格子形状が変化する場合、 計算格子の出力 (計算開始後の格子) で説明する関数を使用してください。
計算結果については、iRIC では特別な名前が定義されており、 特定の目的で使用される結果ではその名前を使用する必要があります。 特別な計算結果の名前については 計算結果 を参照してください。