banner
NEWS LETTER

WRF基础 | WRF的运行

Scroll down

WRF的运行

WRF运行流程图

地形准备

下载网址:WRF静态地形数据

完整运行步骤

Step 1: FNL准备

  1. 初始和强迫场文件用的是FNL文件,FNL文件可在官方网站:https://rda.ucar.edu/datasets/ds083.2/(需要注册),或使用python下载文件

  2. WPS文件夹内需要有Vtable文件,一般用的是Vtable.GFS,复制到WPS文件下改为Vtable,该文件位置在WPS/ungrib/Variable_Tables/。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
"""
Python script to download selected files from rda.ucar.edu.
After you save the file, don't forget to make it executable
i.e. - "chmod 755 <name_of_script>"
"""
import sys, os
from urllib.request import build_opener
import datetime
import pandas as pd

opener = build_opener()

dates = pd.date_range('2007-12-7 06:00:00', '2007-12-8 12:00:00', freq='6H')
for idate in dates:
year = str(idate.year)
month = str(idate.month)
day = str(idate.day)
hour=str(idate.hour)

month = month.zfill(2)
day = day.zfill(2)
hour=hour.zfill(2)

file = "https://data.rda.ucar.edu/ds083.2/grib2/"+year+"/"+year+'.'+month+"/fnl_"+year+month+day+"_"+hour+"_"+"00"+".grib2"

ofile = os.path.basename(file)
sys.stdout.write("downloading " + ofile + " ... ")
sys.stdout.flush()
infile = opener.open(file)
outfile = open(ofile, "wb")
outfile.write(infile.read())
outfile.close()
sys.stdout.write("done\n")

Step 2: 文件的修改

运行之前需要更改两份文件的内容,一个是namelist.wps,另一个是namelist.input。

namelist.wps:

namelist.input:

Step 3: WPS运行

1
2
3
4
5
6
7
8
9
10
11
# 定义模拟域,并将各种地面数据集插入模型网格
./geogrid.exe

# 链接FNL数据
./link_grib.csh path_to_data

# 读取 GRIB 文件,"degribs"数据,并以称为中间格式的简单格式写入数据
./ungrib.exe

# 将 ungrib 程序提取的中间格式气象数据水平插值到 geogrid 程序定义的模拟域中
./metgrid.exe

Step 4: WRF运行

1
2
3
4
5
6
7
8
9
# 链接WPS处理的文件
ln -sf ../../WPS/met_em.d* .

# 产生初始场文件和边界场文件
./real.exe

# 运行
# 注意:这里使用的是单核运行,如有需要可多核多线程
./wrf.exe

简单运行步骤

```shell

!/bin/bash

WRF和WPS文件夹所在位置

wrf_dir=/home/deepin/data/Daimu/Daimu-wudong/WRF/WRF4.0v2/

FNL文件夹所在,此处用了两个方法,一个是使用本地下好的FNL文件,另一个是在线下载。

fnl_dir=/home/deepin/FNL/

运行所在文件夹

run_dir=/home/deepin/data/Daimu/Daimu-wudong/WRF/Project/

项目名称

project_name=test_WRF

参数修改有三个地方,一个是下面,另外两个是namelist.wps和namelist.input

start_time=2011-09-28_06:00:00
end_time=2011-09-28_12:00:00
lon_e=105
lon_w=125
lat_n=24
lat_s=12
dx=9000
dy=9000

run_days=0
run_hours=6
run_minutes=0
run_seconds=0

——————————————————————————make project folder———————————————————————————-

if [ ! -d “${run_dir}${project_name}” ];then
mkdir ${run_dir}${project_name}
else
rm -rf ${run_dir}${project_name}
mkdir ${run_dir}${project_name}
fi

——————————————————————————make fnl folder—————————————————————————————-

mkdir ${rundir}${project_name}/FNL
cd ${wrf_dir}
echo “————————————————————————download fnl———————————————————————————————-“
read -p “you want to choose? 1.download fnl; 2.Local file “ input
if [ $input = “1” ];then
cp download_new.py ${run_dir}${project_name}/FNL
cd ${run_dir}${project_name}/FNL
sed -i “s|2007-12-7 06:00:00|${start_time/
/ }|” downloadnew.py
sed -i “s|2007-12-8 12:00:00|${end_time/
/ }|” download_new.py

conda activate fnl
python ./download_new.py
else
cd ${run_dir}${project_name}/FNL
deal_time=$start_time
t1=date -d ${deal_time:0:4}${deal_time:5:2}${deal_time:8:2}" "${deal_time:11:8} +%s
t2=date -d ${end_time:0:4}${end_time:5:2}${end_time:8:2}" "${end_time:11:8} +%s

cp ${fnldir}/“GRIB”${deal_time:0:4}/“fnl“${dealtime:0:4}${deal_time:5:2}${deal_time:8:2}”“${deal_time:11:2}”_00.grib2” ./
deal_time=${deal_time:0:4}${deal_time:5:2}${deal_time:8:2}${deal_time:11:2}

while [ $t1 -lt $t2 ]; do
dealtime=date -d ${deal_time:0:4}${deal_time:4:2}${deal_time:6:2}" "${deal_time:8:2}" 6 hour" +"%Y%m%d%H"
cp ${fnl_dir}/“GRIB”${deal_time:0:4}/“fnl
“${dealtime:0:4}${deal_time:4:2}${deal_time:6:2}”“${deal_time:8:2}”_00.grib2” ./
t1=date -d ${deal_time:0:4}${deal_time:4:2}${deal_time:6:2}" "${deal_time:8:8} +%s
done
fi

——————————————————————————-copy WPS———————————————————————————————-

cd ${wrf_dir}
cp -r ./WPS ${run_dir}${project_name}
source libraries.sh

cd ${run_dir}${project_name}/WPS

lon_num=$[(lon_w-lon_e)111000/dx+10]
lat_num=$[(lat_n-lat_s)
111000/dy+10]
lat_ns=$[(lat_n+lat_s)/2]
lon_we=$[(lon_w+lon_e)/2]

create namelist.wps

touch namelist.wps

cat > namelist.wps << EOF
&share
wrf_core = ‘ARW’,
max_dom = 1,
start_date = ${start_time},’2006-08-16_12:00:00’,
end_date = ${end_time},’2006-08-16_12:00:00’,
interval_seconds = 21600
io_form_geogrid = 2,
/

&geogrid
parent_id = 1, 1,
parent_grid_ratio = 1, 3,
i_parent_start = 1, 31,
j_parent_start = 1, 17,
e_we = ${lon_num}, 112,
e_sn = ${lat_num}, 97,
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!
! The default datasets used to produce the MAXSNOALB and ALBEDO12M
! fields have changed in WPS v4.0. These fields are now interpolated
! from MODIS-based datasets.
!
! To match the output given by the default namelist.wps in WPS v3.9.1,
! the following setting for geog_data_res may be used:
!
! geog_data_res = ‘maxsnowalb_ncep+albedo_ncep+default’, ‘maxsnowalb_ncep+albedo_ncep+default’,
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
geog_data_res = ‘10m’,’2m’,
dx = ${dx},
dy = ${dy},
map_proj = ‘lambert’,
ref_lat = ${lat_ns},
ref_lon = ${lon_we},
truelat1 = ${lat_s},
truelat2 = ${lat_n},
stand_lon = ${lon_we},
geog_data_path = ‘/home/deepin/geog’
/

&ungrib
out_format = ‘WPS’,
prefix = ‘FILE’,
/

&metgrid
fg_name = ‘FILE’
io_form_metgrid = 2,
/

EOF

echo “—————————————————————-run geogrid——————————————————————“
./geogrid.exe
echo “—————————————————————-run link———————————————————————-“
./link_grib.csh ../FNL/fnl*
echo “—————————————————————-run ungrib——————————————————————-“
./ungrib.exe
echo “—————————————————————run metgrid——————————————————————-“
./metgrid.exe

————————————————————————————-WRF—————————————————————————————————————-

link constant files

#
mkdir ${run_dir}${project_name}/WRF
cd ${run_dir}${project_name}/WRF

ln -fs ${wrf_dir}WRF/run/RRTM_DATA ./RRTM_DATA
ln -fs ${wrf_dir}WRF/run/RRTMG_LW_DATA ./RRTMG_LW_DATA
ln -fs ${wrf_dir}WRF/run/RRTMG_SW_DATA ./RRTMG_SW_DATA
ln -fs ${wrf_dir}WRF/run/RRTM_DATA_DBL ./RRTM_DATA
ln -fs ${wrf_dir}WRF/run/.TBL .
ln -fs ${wrf_dir}WRF/run/ozone
.

ln -sf ${run_dir}${project_name}/WPS/met_em.d* .

ln -fs ${wrf_dir}WRF/main/wrf.exe .
ln -fs ${wrf_dir}WRF/main/real.exe .

create namelist.input

touch namelist.input

cat > namelist.input << EOF
&time_control
run_days = ${run_days},
run_hours = ${run_hours},
run_minutes = ${run_minutes},
run_seconds = ${run_seconds},
start_year = ${start_time:0:4}, 2000, 2000,
start_month = ${start_time:5:2}, 01, 01,
start_day = ${start_time:8:2}, 24, 24,
start_hour = ${start_time:11:2}, 12, 12,
end_year = ${end_time:0:4}, 2000, 2000,
end_month = ${end_time:5:2}, 01, 01,
end_day = ${end_time:8:2}, 25, 25,
end_hour = ${end_time:11:2}, 12, 12,
interval_seconds = 21600
input_from_file = .true.,.true.,.true.,
history_interval = 180, 60, 60,
frames_per_outfile = 1, 1000, 1000,
restart = .false.,
restart_interval = 7200,
io_form_history = 2
io_form_restart = 2
io_form_input = 2
io_form_boundary = 2
/

&domains
time_step = 30,
time_step_fract_num = 0,
time_step_fract_den = 1,
max_dom = 1,
e_we = ${lon_num}, 112, 94,
e_sn = ${lat_num}, 97, 91,
e_vert = 33, 33, 33,
p_top_requested = 5000,
num_metgrid_levels = 27,
num_metgrid_soil_levels = 4,
dx = ${dx}, 10000, 3333.33,
dy = ${dy}, 10000, 3333.33,
grid_id = 1, 2, 3,
parent_id = 0, 1, 2,
i_parent_start = 1, 31, 30,
j_parent_start = 1, 17, 30,
parent_grid_ratio = 1, 3, 3,
parent_time_step_ratio = 1, 3, 3,
feedback = 1,
smooth_option = 0
/

&physics
mp_physics = 3, 3, 3,
ra_lw_physics = 1, 1, 1,
ra_sw_physics = 1, 1, 1,
radt = 30, 30, 30,
sf_sfclay_physics = 1, 1, 1,
sf_surface_physics = 2, 2, 2,
bl_pbl_physics = 1, 1, 1,
bldt = 0, 0, 0,
cu_physics = 1, 1, 0,
cudt = 5, 5, 5,
isfflx = 1,
ifsnow = 1,
icloud = 1,
surface_input_source = 1,
num_soil_layers = 4,
sf_urban_physics = 0, 0, 0,
/

&fdda
/

&dynamics
hybrid_opt = 2,
w_damping = 0,
diff_opt = 1, 1, 1,
km_opt = 4, 4, 4,
diff_6th_opt = 0, 0, 0,
diff_6th_factor = 0.12, 0.12, 0.12,
base_temp = 290.
damp_opt = 3,
zdamp = 5000., 5000., 5000.,
dampcoef = 0.2, 0.2, 0.2
khdif = 0, 0, 0,
kvdif = 0, 0, 0,
non_hydrostatic = .true., .true., .true.,
moist_adv_opt = 1, 1, 1,
scalar_adv_opt = 1, 1, 1,
gwd_opt = 1,
/

&bdy_control
spec_bdy_width = 5,
specified = .true.
/

&grib2
/

&namelist_quilt
nio_tasks_per_group = 0,
nio_groups = 1,
/

EOF

echo “——————————————————————-run real—————————————————————-“
./real.exe

echo “——————————————————————-run wrf——————————————————————“
mpirun -np 40 ./wrf.exe

result=tail -n 1 rsl.out.0000
if [[ $result =~ “SUCCESS COMPLETE WRF” ]];then
echo “SUCCESS COMPLETE WRF”
cp ./wrfout* ${run_dir}${project_name}/
rm -rf ${run_dir}${project_name}/WPS
rm -rf ${run_dir}${project_name}/WRF
rm -rf ${run_dir}${project_name}/FNL

else
echo “出错啦”
fi

cd ${run_dir}

其他文章