概要
大気モデル Weather Research & Forecasting Model (WRF) を用いた実験を行うため、gnuでWRFの初期設定を行ったので、それを記述する。
環境
- OS: CentOS7
- コンパイラ:gnu 11.4.0 (ローカル環境へインストールしたもの。インストールについてはこの記事を参照)
WRFの環境設定
-
インストール先と変数の設定
WRFに必要なライブラリをgnuコンパイラでインストールする。インストール方法は公式を参考にした。intelのコンパイラでインストールする際はこのホームページを参照する。以下、インストール先は${HOME}/local/WRF-gnu とする。$ mkdir ${HOME}/local/WRF-gnu $ DIR=${HOME}/local/WRF-gnu
ライブラリのパスは以下のように設定
$ export NETCDF=$DIR/netcdf $ export LD_LIBRARY_PATH=$NETCDF/lib:$DIR/grib2/lib${LD_LIBRARY_PATH} $ export PATH=$NETCDF/bin:$DIR/mpich/bin:${PATH} $ export JASPERLIB=$DIR/grib2/lib $ export JASPERINC=$DIR/grib2/include
コンパイラとそのオプションは以下のように設定
$ export CC=gcc $ export CXX=g++ $ export FC=gfortran $ export FCFLAGS="-m64 -fallow-argument-mismatch" $ export F77=gfortran $ export FFLAGS="-m64 -fallow-argument-mismatch" $ export LDFLAGS="-L$NETCDF/lib -L$DIR/grib2-gcc/lib" $ export CPPFLAGS="-I$NETCDF/include -I$DIR/grib2-gcc/include -fcommon"
-
Zlibのインストール(hdf5のビルドに必要。)
$ wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.11.tar.gz $ tar xzvf zlib-1.2.11.tar.gz $ cd zlib-1.2.11 $ ./configure --prefix=$DIR/grib2 $ make -j 4 $ make install $ cd .. $ rm -rf zlib*
-
HDF5のインストール(netcdfのビルドに必要。)
$ wget https://github.com/HDFGroup/hdf5/archive/hdf5-1_10_5.tar.gz $ tar xzvf hdf5-1.10.5.tar.gz $ cd hdf5-1.10.5 $ ./configure --prefix=$DIR/netcdf-gcc --with-zlib=$DIR/grib2 --with-szlib=$DIR/grib2 --enable-fortran --enable-shared $ make -j 4 $ make install $ cd .. $ rm -rf hdf5*
-
netcdf-cのインストール
$ wget https://github.com/Unidata/netcdf-c/archive/v4.7.2.tar.gz $ tar xzvf v4.7.2.tar.gz $ cd netcdf-c-4.7.2 $ ./configure --prefix=$DIR/netcdf --disable-dap --enable-netcdf4 --enable-hdf5 --enable-shared $ make -j 4 $ make install $ cd .. $ rm -rf v4.7.2.tar.gz netcdf-c*
-
netcdf-fortranのインストール
$ export LIBS=”-lnetcdf -lz” $ wget https://github.com/Unidata/netcdf-fortran/archive/v4.5.2.tar.gz $ tar xzvf v4.5.2.tar.gz $ cd netcdf-fortran-4.5.2 $ ./configure --prefix=$DIR/netcdf --disable-hdf5 --enable-shared $ make -j 4 $ make install $ cd .. $ rm -rf netcdf-fortran* v4.5.2.tar.gz
-
mpichのインストール
$ wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/mpich-3.0.4.tar.gz $ tar xzvf mpich-3.0.4.tar.gz $ cd mpich-3.0.4 $ ./configure --prefix=$DIR/mpich $ make -j 4 2>&1 $ make install $ cd .. $ rm -rf mpich*
-
libgpngのインストール(wgribに必要)
$ wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz $ tar xzvf libpng-1.2.50.tar.gz $ cd libpng-1.2.50 $ ./configure --prefix=$DIR/grib2 $ make -j 4 $ make install $ cd .. $ rm -rf libpng*
-
jasperのインストール(wgribに必要)
$ wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz $ tar xzvf jasper-1.900.1.tar.gz $ cd jasper-1.900.1 $ ./configure --prefix=$DIR/grib2 $ make -j 4 $ make install $ cd .. $ rm -rf jasper*
-
WRFで実験する際の変数を~/.bashrcに追記。
~/.bashrcDIR=${HOME}/local/WRF-gnu export NETCDF=$DIR/netcdf export LD_LIBRARY_PATH=$NETCDF/lib:$DIR/grib2/lib export PATH=$NETCDF/bin:$DIR/mpich/bin:${PATH} export JASPERLIB=$DIR/grib2/lib export JASPERINC=$DIR/grib2/include
bashの内容を反映させる。
$ source .bashrc
参考URL
https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php
https://forum.mmm.ucar.edu/threads/full-wrf-and-wps-installation-example-gnu.12385/
https://forum.mmm.ucar.edu/threads/full-wrf-and-wps-installation-example-intel.15229/
https://qiita.com/jsasaki/items/00bc30207e9ad7f81532
https://estuarine.jp/2020/05/ubuntu-intel-netcdf/
https://www.hysk.sakura.ne.jp/Linux_tips/GRIBwgribInfo
WRFのダウンロード
-
WRFのユーザー登録
WRFの公式サイトでユーザー登録
-
gitでソースをダウンロード
以下では、WrfFamilyディレクトリにWRFを入れることとする。$ WRFDIR=${PWD}/WrfFamily $ mkdir WrfFamily $ cd WrfFamily $ git clone --recurse-submodules https://github.com/wrf-model/WRF $ git clone https://github.com/wrf-model/WPS
-
地形データのダウンロード
以下では、WrfFamilyディレクトリの GEOG/ 以下にデータを格納することとする。$ mkdir GEOG $ wget https://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz $ tar xvzf geog_high_res_mandatory.tar.gz $ rm geog_high_res_mandatory.tar.gz $ cd ..
参考URL
https://www2.mmm.ucar.edu/wrf/users/download/get_source.html
https://forum.mmm.ucar.edu/threads/full-wrf-and-wps-installation-example-gnu.12385/
https://www2.mmm.ucar.edu/wrf/users/download/get_sources_wps_geog.html
現実設定実験の環境の設定
-
netcdfのパスの設定
~/.bachrcに以下が書かれていることを確認。~/.bashrcDIR=${HOME}/local/WRF-gnu export NETCDF=$DIR/netcdf export LD_LIBRARY_PATH=$NETCDF/lib:$DIR/grib2/lib export PATH=$NETCDF/bin:$DIR/mpich/bin:${PATH} export JASPERLIB=$DIR/grib2/lib export JASPERINC=$DIR/grib2/include
-
WRFのコンパイル
$ cd ${WRFDIR} $ cd WRF $ ./configure
使用コンパイラはgnuのMPI並列で34(openMPと併用の場合は35)。
Compile for nestingは1。
コンパイルは以下のようにする。$ ./compile em_real >& log.compile
コンパイルが上手くいったかはndow.exe, tc.exe, wrf.exeの容量がゼロでないことから確認する。
$ du -sh main/*.exe
再設定したい場合には以下のようにする。
$ ./clean -a $ ./configure $ ./compile em_real >& log.compile
-
WPS(WRF実行時の境界条件データ等を作成する)の設定
$ cd ${WRFDIR} $ cd WRF $ ./configure
設定番号はgnuのMPI並列で3番(WPSの処理においてはMPI並列の必要性は低いので、1番でも十分?)
コンパイルは以下のようにする。$ ./compile >& compile.log
コンパイルが上手くいったかはgeogrid/src/geogrid.exe、ungrib/src/ungrib.exe, metgrid/src/metgrid.exeの容量がゼロでないことから確認する。
$ du -sh geogrid/src/geogrid.exe $ du -sh ungrib/src/ungrib.exe $ du -sh metgrid/src/metgrid.exe
参考URL
https://www2.mmm.ucar.edu/wrf/OnLineTutorial/Compile/wrf_compile2.php
https://www2.mmm.ucar.edu/wrf/OnLineTutorial/Compile/wps_compile2.php