Introduction

The Weather Research and Forecasting (WRF) Model is an open-source mesoscale numerical meteorological model from NOAA. It has two dynamical cores (NMM designed for atmospheric research and ARW for operational forecasting needs), data assimilation and parallelization capabilites. It covers a wide range of meteorological applications across scales from tens of meters to thousands of kilometers [1].


This brief tutorial refers to WRF-ARW and covers:

Model Overview

WPS (WRF Pre Processing System)
  • configured by namelist.wps
  • geogrid.exe - static domain information
  • ungrib.exe - convert Grib files to a specific binary file (intermediate file format)
  • metgrid.exe - horizontal interpolator of FILEs to domain resolution


WRF model
  • configured by namelist.input
  • real.exe - vertical interpolator
  • wrf.exe - meteorological model


Inputs


WRFWorkflow.png
Figure 1 : WRF model workflow

Compile for Windows

Instruction are also in SVN install.txt

Install cygwin

  • Install cygwin
  • Inside cygwin, install vim, gcc, gfortran, g++, zlib, make, libcurl, diffutils, jasper-devel, png-devel, csh, m4, libglib
  • Edit ~/.bashrc:
   export PATH="/usr/local/bin:/usr/bin"
   export JASPERINC="/usr/include/jasper"
   export JASPERLIB="/usr/lib"
   export CC=gcc 
   export FC=gfortran 
   export F90=gfortran 
   export CXX=g++


Install MPICH2 for Windows 64 bits

  • Uninstall previous version of MPICH2
  • Download MPICH2 from Official Site or SVN
  • Open an admin command prompt by right-clicking on the command prompt icon and selecting "run as administrator"
  • Run msiexec /i mpich2-1.4.1p1-win-x86-64.msi from the admin command prompt to install MPICH2
  • During installation select that MPICH2 be installed for "Everyone" for all users.
  • Register daemon:
   smpd -install
   mpiexec -remove 
   mpiexec -register  (this will ask for user name and password, enter it and confirm it)
   mpiexec -validate (Must return SUCCESS) 
  • Add "C:\Program Files\MPICH2\bin" to system Path and reboot
  • Check smpd using 'smpd -status'. it should return 'smpd running on $hostname$'
  • Test execution environment by running mpiexec -n 2 hostanme

More cross-compatibility tests

  • go to the directory $MPICHROOT\examples and run cpi.exe using: mpiexec -n 4 cpi
  • Check cross-compatibility and go to cygwin and compile hello world application in C (hellow.c) and Fortran (hellow.f)
   gcc hellow.c -o hellow.exe -I/cygdrive/c/Program\ Files/MPICH2/include /cygdrive/c/Program\ Files/MPICH2/lib/libmpi.a
   /cygdrive/c/Program\ Files/MPICH2/bin/mpiexec.exe -n 2 ./hellow.exe
   mpiexec -n 8 hellow.exe
   gfortran hellow.f -o hellowf.exe -I/cygdrive/c/Program\ Files/MPICH2/include /cygdrive/c/Program\ Files/MPICH2/lib/libmpi.a  /cygdrive/c/Program\ Files/MPICH2/lib/libfmpich2g.a
   /cygdrive/c/Program\ Files/MPICH2/bin/mpiexec.exe -n 2 ./hellowf.exe
   mpiexec -n 8 hellowf.exe

Compile Netcdf

Note 1: Not sure if the Windows NetCDF library needs to be installed. Note 2: WRF 3.6.1 is prior to NetCDF 4.

Netcdf in Cygwin

  • Install netcdf libraries with Fortran API:
    • Get 3.6.3 source code from Official page or SVN
    • ./configure --disable-shared --enable-separate-fortran 2>&1 | tee configure.log
    • Check that static libraries (*.a) are in /usr/local/lib and headers are in /usr/local/include
    • Add export NETCDF="/usr/local" to ~/.bashrc

Netcdf in Windows


Compile WRF

  • Code changes to version 3.6.1 to support MPICH2 from Windows:
  LOGICAL mpi_inited          -> integer mpi_inited
  IF( .NOT. mpi_inited ) THEN -> IF ( mpi_inited == 0) THEN

Changed in files:

  $WRFV3/external/RSL_LITE/module_dm.F:SUBROUTINE init_module_dm
  $WRFV3/frame/module_io_quilt.F:SUBROUTINE init_module_wrf_quilt

Compile WPS

  • Compile WPS like normal instructions
  • Replace orog*/con/ with orog*/_con/ in GEOGRID.TBL (con is a reserved Windows folder)

Changes in configure_new.defaults.cygwin

  • Remove "check your compiler" line in configure script
  • Add:
   ARCH_LOCAL = ... -D_WIN32
   CFLAGS_LOCAL= ... -DLANDREAD_STUB
   DM_FC = gfortran -I/cygdrive/c/Program\ Files/MPICH2/include
   DM_CC = gcc -I/cygdrive/c/Program\ Files/MPICH2/include
   LIB_LOCAL = cygdrive/c/Program\ Files/MPICH2/lib/libmpi.a /cygdrive/c/Program\ Files/MPICH2/lib/libfmpich2g.a

Configure a new WRF domain

  1. Copy SVN folder WRF_NewDomain to WRF_MyDomain and cd into it.
  2. Download WRF geographical datasets from our SVN or WRF Portal into geog folder (15.4 GB unpacked).
  3. Add your domain(s) configuration in the &share and &geogrid sections of namelist.wps file. Domains can be build with:
    1. plot_domains.py: python plot_domains.py namelist.wps
    2. WRF Domain Wizard
    3. Note: nest number of grid points must be one greater than a multiple of parent_grid_ratio
  4. Adjust geographical data resolution according to domain resolution (as similar as possible). Possible resolutions include '30s', '2m', '5m', and '10m', corresponding to 30-arc-second data, 2-, 5-, and 10-arc-minute data.
    geog_data_res resolution [km]
    10 min 10*111/60 = 18.5 km
    5 min 5*111/60 = 9.25 km
    2 min 2*111/60 = 3.7 km
    30 sec 30*111/3600 = 0.925 km
  5. Run geogrid.exe to generate files geo_em.d01.nc, geo_em.d02.nc, etc.., one per domain, where domain 1 is the parent, 2, 3,.. are nested domains.
  6. View geo_em.dX.nc in any netcdf viewer tool (example: ncview, ncBrowse)


Example

The following example is for Portugal with 2 domains (max_dom = 2). The parent domain (d01) refers to the first column and nest domain (number 2) refers to the second column. A third, fourth, etc domain could be added by increasing max_dom and adding more columns.

Parent domain (d01):

  • Continental Portugal
  • 9 km horizontal resolution ( dx = dy = 9000.)
  • 61x101 grid points (e_we x e_sn)
  • centered in 8W 40N degrees.

Nest domain (d02):

  • nest of d01 (parent_id = 1)
  • 3 km of horizontal resolution (parent_grid_ratio = 3)
  • 103x199 grid points (e_we x e_sn)
  • lower left corner at grid location (i,j) = (13,12) of the parent grid (i_parent_grid = 13, j_parent_grid = 12)

Note: number of grid points minus 1 are integer multiples of parent_grid_ratio: 102/3 and 198/3.


Namelist.wps for geogrid.exe:

   &share
    wrf_core = 'ARW',
    max_dom = 2,
    io_form_geogrid = 2,
    start_date = '2015-04-29_00:00:00'
    end_date   = '2015-05-08_00:00:00'
    interval_seconds = 10800,
    nocolons = .true.,
   /
   
   &geogrid
    parent_id         =   0,   1
    parent_grid_ratio =   1,   3
    i_parent_start    =   1,   13,
    j_parent_start    =   1,   12,
    e_we              =  61,   103,
    e_sn              =  101,  199,
    geog_data_res     = '2m', '2m'
    dx = 9000,
    dy = 9000,
    map_proj = 'lambert',
    ref_lat   =  40.0,
    ref_lon   = -8.0,
    truelat1  =  30.0,
    truelat2  =  60.0,
    stand_lon = -8.0,
    geog_data_path = 'geog'
    opt_geogrid_tbl_path = '.'
   /

Result of python plot_domains.py namelist.wps 0:

WRF Portugal 3km.png
Figure 2 : Domain extents

Map Projections

WRF model grid is regular in projected coordinates. Possible grid projections are:

map_proj Map projection Projection parameters
lambert Lambert Conformal truelat1, truelat2 (optional), stand_lon
mercator Mercator truelat1
polar Polar stereographic truelat1, stand_lon
lat-lon Regular latitude-longitude, or cylindrical equidistant pole_lat, pole_lon, stand_lon

Run WRF

After the domain is configured and geo_em.dX.nc files are generated for each domain, namelist.wps and namelist.input files must be edited.

  1. Add new domain(s), vertical resolution and nesting options (one-way or two-way) to &domain section of namelist.input: Note: WRF bug - here, dx and dy are needed for all domains. &domains time_step = 54,  ! time step of each domain (recommended 6*dx in km for a typical case) time_step_fract_num = 0, time_step_fract_den = 1, max_dom = 1, e_we = 51, e_sn = 71, e_vert = 30,  ! number of grid points in z-direction (bottom-top) p_top_requested = 5000,  ! pressure at top [Pa] num_metgrid_levels = 27,  ! number of vertical levels in metgrid files num_metgrid_soil_levels = 4,  ! number of soil levels in metgrid files dx = 9000, dy = 9000, grid_id = 1  ! id of each grid parent_id = 0 i_parent_start = 1 j_parent_start = 1 parent_grid_ratio = 1 parent_time_step_ratio = 1  ! ratio = parent/nest feedback = 1,  ! 0 - one-way nesting, 1 - two-way nesting smooth_option = 0  ! if feedback is on. /
  2. Add &metgrid and &ungrib sections to namelist.wps (if they are not there already): &ungrib out_format = 'WPS',  ! intermediate file format (binary WPS specific) prefix = 'FILE',  ! prefix name of intermediate files / &metgrid fg_name = 'FILE'  ! prefix name of intermediate files io_form_metgrid = 2,  ! Use netcdf format for IO opt_metgrid_tbl_path = '.'  ! path for METGRID.TBL opt_output_from_metgrid_path = '.'  ! path to write output netcdf files (met_em.dX) /
  3. >Adapt time parameters in both namelist files (&share in namelist.wps and &time in namelist.input): namelist.wps: &share wrf_core = 'ARW', max_dom = 2, io_form_geogrid = 2, start_date = '2015-04-29_00:00:00' end_date = '2015-05-08_00:00:00' interval_seconds = 10800,  ! interval between each GFS file [seconds] nocolons = .true., / namelist.input: &time_control run_days = 0, run_hours = 36, run_minutes = 0, run_seconds = 0, start_year = 2015, 2015, 2015, start_month = 05, 03, 03, start_day = 27, 21, 21, start_hour = 00, 00, 00, start_minute = 00, 00, 00, start_second = 00, 00, 00, end_year = 2015, 2015, 2015, end_month = 05, 03, 03, end_day = 28, 21, 21, end_hour = 12, 06, 06, end_minute = 00, 00, 00, end_second = 00, 00, 00, interval_seconds = 10800 input_from_file = .true.,.true.,.true., history_interval = 60, 60, 60, frames_per_outfile = 1000, 1000, 1000, restart = .false., restart_interval = 5000, io_form_history = 2 io_form_restart = 2 io_form_input = 2 io_form_boundary = 2 debug_level = 1 iofields_filename = "iofields.txt" ignore_iofields_warning = .true. /
  4. Copy GFS grib2 files to the current directory under the name GRIBFILE.AAA, GRIBFILE.AAB, using script link_grib.bat.
  5. Run ungrib.exe to convert GFS files into intermediate format files with names FILE_yyyy-MM-DD_HH
  6. Run metgrid.exe to interpolate GFS FILEs to the domain resolution, generating met_em.dX.yyyy-MM-DD_HH.nc files.
  7. Run real.exe to interpolate metgrid necdf files to the chosen number of vertical layers, generating wrfst and wrfini files (netcdf)
  8. Run wrf.exe [or mpiexec -n X wrf.exe] to run WRF model, generating wrfout_dX.yyyy-MM-DD_HH for each domain.

References

  1. WRF Model: http://www.wrf-model.org
  2. Geographical datasets: http://www2.mmm.ucar.edu/wrf/users/download/get_sources_wps_geog.html
  3. WRF-ARW Page: http://www2.mmm.ucar.edu/wrf/users
  4. GFS model: http://www.nco.ncep.noaa.gov/pmb/products/gfs/

Links

Action Server WRF Runner Plugin

WRF User Guide

Geographical datasets

Description of namelist.wps

Description of namelist.input