#author("2023-08-04T17:50:14+09:00","default:Miyashita","Miyashita")
#author("2023-08-04T17:58:37+09:00","default:Miyashita","Miyashita")
*setrun.py Memorandums [#m87b0cbc]
#contents
特に重要な変数を書き出してみる.~
~

**clawdata [#ec21a730]
-clawdata.lower (list of float)~
計算領域の端点の設定.~
clawdata.lower[0] は西端の x (または lon), ~
clawdata.lower[1] は南端の y (または lat). ~
~

-clawdata.upper (list of float)~
計算領域の端点の設定.~
clawdata.upper[0] は東端の x (または lon), ~
clawdata.upper[1] は北端の y (または lat). ~
~

-clawdata.num_cells  (list of int)~
~

-clawdata.capa_index (int)
直交座標系か緯度経度かで異なる.~
example を見ると直交座標系のときは 0 で緯度経度の時は 2.~
amrdata.aux_type も参照.~
~


-clawdata.bc_lower, clawdata.bc_upper~
境界条件の設定.~
名前とリストが意味するものはそれぞれ以下の通り.
#codeprettify{{
# Choice of BCs at xlower and xupper:
#   0 => user specified (must modify bcN.f to use this option)
#   1 => extrapolation (non-reflecting outflow)
#   2 => periodic (must specify this at both boundaries)
#   3 => solid wall for systems where q(2) is normal velocity
clawdata.bc_lower[0] = 'extrap' # Western,  x-direction
clawdata.bc_upper[0] = 'extrap' # Eastern,  x-direction
clawdata.bc_lower[1] = 'extrap' # Southern, y-direction
clawdata.bc_upper[1] = 'extrap' # Northern, y-direction
}}
入力値は数値でもテキストでもOKで,以下のように対応している.
 1 <-> "extrap"   
 2 <-> "periodic" 
 3 <-> "wall"     
~

-clawdata.t0 (float)~
計算開始時の時刻設定.~
基本的には 0.0 で良いが,storm-surge の計算でハリケーン上陸時刻を 0.0 という基準にすると,計算開始時の時刻はマイナスになる.~
ike の examples を参照.~
~

-clawdata.tfinal (float)~
計算終了時刻.ただし,下にある clawdata.output_times の方が優先される.~
リストで指定した clawdata.output_times の最後の出力時刻が clawdata.tfinal より早ければ,clawdata.output_times の最後の時刻をもって計算が終わる.~
~

-clawdata.output_t0 (boolean)~
True なら計算開始時のファイルを出力する.~
~

-clawdata.num_output_times (int)~
計算開始から計算終了までに出力を行う回数.~
計算時間を指定した値で等分割した間隔で出力される.
#codeprettify{{
# Output nout frames at equally spaced times up to tfinal:
clawdata.num_output_times = 36
}}
~
~

-clawdata.output_times (list of float)~
出力の回数を指定するのではなく,出力する時間をリストで指定する.~
等間隔でなくても良い.
#codeprettify{{
# Specify a list of output times.
clawdata.output_times = [0.5, 1.0, 2.0]
}}
~
~

-clawdata.output_step_interval (int)~
出力の回数や時刻を指定するのではなく,出力するステップ数を指定する.~
AMR では相性がよろしくなくあまり使わないような気がする(debug 時には便利).~
#codeprettify{{
# Output every iout timesteps with a total of ntot time steps:
clawdata.output_step_interval = 1
}}
~
上記の3つの変数
 clawdata.num_output_times (int)
 clawdata.output_times  (list of float)
 clawdata.output_step_interval (int)
はいずれか一つを指定すればよい.重複しないように.~
~

-clawdata.dt_variable~
#codeprettify{{
clawdata.dt_variable = True # variable time steps used based on cfl_desired
}}
~

-clawdata.dt_initial~
~

-clawdata.dt_max~
~

-clawdata.cfl_desired~
~

-clawdata.cfl_max~
~

-clawdata.steps_max~
~
~

**amrdata [#q824883c]
-amrdata.amr_levels_max~
分割するレベルの数.Level 1 を一番粗いレベルとして,Level 4 までの 4種類のメッシュサイズとする場合は 4 を入れる.~
~

-amrdata.refinement_ratios_x~
Level k から Level k+1 となる時の, x 方向のメッシュサイズの比.\( \frac{\Delta x_{k+1}}{\Delta x_{k}} \)のこと.~
したがって,Level 1 から 4 まである場合は 3要素のリストになる.~
\( \frac{\Delta x_{2}}{\Delta x_{1}}, ~ \frac{\Delta x_{3}}{\Delta x_{2}}, ~ \frac{\Delta x_{4}}{\Delta x_{3}}, ~ \dots \) の順番で書く.~
~

-amrdata.refinement_ratios_y~
上に同じで,y 方向のレベル間のメッシュサイズ比. \( \frac{\Delta y_{k+1}}{\Delta y_{k}} \)のこと.~
~

-amrdata.refinement_ratios_t~
上に同じで,\( \frac{\Delta t_{k+1}}{\Delta t_{k}} \)のこと.~
クーラン数を考慮すると,一般的には上の2変数と同一の値にするのが無難.~

~
例えば 2430m → 810m → 270m → 90m という分割をしたい場合は以下のようになる.
#codeprettify{{
# ---------------
# AMR parameters:
# ---------------
amrdata = rundata.amrdata

# max number of refinement levels:
amrdata.amr_levels_max = 4

# List of refinement ratios at each level (length at least mxnest-1)
amrdata.refinement_ratios_x = [3,3,3]
amrdata.refinement_ratios_y = [3,3,3]
amrdata.refinement_ratios_t = [3,3,3]
}}
~

-amrdata.aux_type
リストの要素の数は clawdata.num_aux の値と一致している必要がある.

#codeprettify{{
# Specify type of each aux variable in amrdata.auxtype.
# This must be a list of length maux, each element of which is one of:
#   'center',  'capacity', 'xleft', or 'yleft'  (see documentation).

amrdata.aux_type = ['center','center','yleft'] # if x,y-coordinates
#amrdata.aux_type = ['center','capacity','yleft'] # if lonlat
}}
~
~

**geo_data [#u625663a]
-geo_data.coodinate_system~
座標系の指定.X,Y で計算するか lon, lat で計算するか.~
ここを変更する場合は併せてコリオリの設定を変更する必要がある.
#codeprettify(lang-python){{
geo_data.coodinate_system = 1 # for Cartesian x-y in meters
geo_data.coodinate_system = 2 # for latitude-longitude on the sphere
}}
~
~

**topo_data [#tfa16dc1]
-topo_data.topofiles (list of lists)
#codeprettify(lang-python){{
# topotype: format style
# fname: filename of the topography
topo_data.topofiles.append([topotype, minlevel, maxlevel, t1, t2, fname])
}}
topotype=2 は header 6行,7行目から (my*mx)行 1列で配列したファイル形式.~
topotype=3 は header 6行,7行目から my行 mx列.~
1は古い形式らしく,4は NetCDF.~
dtopo の topotype も同じ.~
~
~

**dtopo_data [#vec3d296]
-dtopo_data.dtopofiles (list of lists)
#codeprettify{{
# topotype: format style
# fname: filename of the topography
dtopo_data.dtopofiles.append([topotype, minlevel, maxlevel, fname])
}}
~
-dtopo_data.dt_max_dtopo (float)~
dtopo の input をしている間の dt の最大値.通常の clawdata.dt_max とは別で指定できる.~
dtopo によって地形が変化している間,時間刻みの最大は dtopo_data.dt_max_dtopo と clawdata.dt_max の小さい方を優先する.
#codeprettify{{
dtopo_data.dt_max_dtopo = 0.5
}}
~
~
**region [#ddf48699]
topo を複数入力してそれぞれの範囲内で解像度の制限をかけたかったら.
#codeprettify{{
    # ---------------
    # Regions:
    # ---------------
    regions = rundata.regiondata.regions
    # to specify regions of refinement append lines of the form
    #  [minlevel,maxlevel,t1,t2,x1,x2,y1,y2]
    ## Level 1
    regions.append([1, 1, clawdata.t0, clawdata.tfinal, clawdata.lower[0], clawdata.upper[0], clawdata.lower[1], clawdata.upper[1]])
    ## Level 2+
    topo_file = topotools.Topography('topofile.asc', topo_type=3)
    regions.append([1, 2, clawdata.t0, clawdata.tfinal, topo_file.x[0], topo_file.x[-1], topo_file.y[0], topo_file.y[-1]])
}}
~
~
**gauge [#j008f956]
時系列データ出力地点指定.~
setrun.py の中で地点指定をすると,数が増えたり変更のときに煩雑になる.~
事前に地点を入れた外部ファイルを用意しておいて,そのファイルを setrun.py の中で読ませるのが管理上健全.
#codeprettify{{
    # ---------------
    # Gauges:
    # ---------------
    gauges = rundata.gaugedata.gauges
    # for gauges append lines of the form  [gaugeno, x, y, t1, t2]
    dat = np.genfromtxt('gaugesetfile.txt', delimiter=',',  skip_header=0, dtype='float')
    [gauges.append(dat[i]) for i in range(0,dat.shape[0])]
}}
~
~

**fgmax [#xdf37bc2]
topo ファイルごとに fgmax (fixed_grid max) を出したければ.
#codeprettify{{
    fgmax_files = rundata.fgmax_data.fgmax_files
    # == fgmax.data values ==
    # Domain 1
    topo_file = topotools.Topography('topofile.asc', topo_type=3)
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # uniform rectangular x-y grid
    fg.dx = topo_file.delta[0]        # desired resolution of fgmax grid
    fg.x1 = topo_file.x[0]
    fg.x2 = topo_file.x[-1]
    fg.y1 = topo_file.y[0]
    fg.y2 = topo_file.y[-1]
    fg.min_level_check = 1 # which levels to monitor max on
    fg.arrival_tol = 1.0e-1
    fg.tstart_max = 0.0    # just before wave arrives
    fg.tend_max = 1.e10    # when to stop monitoring max values
    fg.dt_check = 1.0     # how often to update max values
    fg.interp_method = 0   # 0 ==> pw const in cells, recommended
    rundata.fgmax_data.fgmax_grids.append(fg)  # written to fgmax_grids.data

  rundata.fgmax_data.num_fgmax_val = 5
}}
~
~

**fixed_grids [#ucc9d435]
v5.9.0 からは非推奨になった.
特定の領域だけAMRを使わずに,ずっと同じ解像度で解いてしまおう,というもの.~
#codeprettify{{
    # == setfixedgrids.data values ==
    fixedgrids = rundata.fixed_grid_data.fixedgrids
    # for fixed grids append lines of the form
    # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\
    #  ioutarrivaltimes,ioutsurfacemax]
    topo_file = topotools.Topography(os.path.join(topodir, 'fileA.asc'))
    fixedgrids.append([0.0, 21600.0, 361, topo_file.x[0], topo_file.x[-1], topo_file.y[0], topo_file.y[-1], topo_file.Z.shape[1], topo_file.Z.shape[0], 0, 0])
    topo_file = topotools.Topography(os.path.join(topodir, 'fileB.asc'))
    fixedgrids.append([0.0, 21600.0, 361, topo_file.x[0], topo_file.x[-1], topo_file.y[0], topo_file.y[-1], topo_file.Z.shape[1], topo_file.Z.shape[0], 0, 0])
}}
この場合では t1,t2,noutput がそれぞれ 0.0, 21600.0,361 となっているので,~
ファイル出力間隔が 60 秒,計 361 回(0〜6 時間)の出力になる.~
当然ながら計算負荷も上がるし, AMR のパッチ出力より容量が大きくなるので注意.~
ioutsurfacemax を 1 にすると最大水位の列が出力されるようになる.fgmaxより変なパターン出現しなくて便利かも.~
~
~


**fgout [#r1a3ee71]
#codeprettify{{
    topo_file = topotools.Topography(os.path.join(topodir, topofile), topo_type=3) # 何かのtopographyを基準に

    fgout = fgout_tools.FGoutGrid()
    fgout.fgno = 3
    fgout.output_format = 'ascii'
    fgout.x1 = topo_file.x[0]
    fgout.x2 = topo_file.x[-1]
    fgout.y1 = topo_file.y[0]
    fgout.y2 = topo_file.y[-1]
    fgout.nx = topo_file.Z.shape[1]
    fgout.ny = topo_file.Z.shape[0]
    fgout.tstart = 3600.0*5.0
    fgout.tend = clawdata.tfinal
    fgout.nout = int((fgout.tend - fgout.tstart)/3600.0) * 60 + 1
    fgout_grids.append(fgout)
}}


Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes