.. role:: underline
:class: underline
==========================
WRF Software & Computation
==========================
|
|
WRF Build Mechanism
===================
The WRF build mechanism standardizes the WRF code building process for different types of computing environments/platforms. Its components and functions are described below. For instructions on building WRF, `see Compiling <./compiling.html>`_.
|
|
|
Build Components
----------------
The build mechanism's primary components consist of the following. Read below for details.
* :ref:`Scripts`
* :ref:`Programs`
* :ref:`Makefiles`
* :ref:`Configuration Files`
* :ref:`Registry1`
* :ref:`Environment Variables`
|
|
.. _Scripts:
Scripts
+++++++
The top-level *WRF/* directory contains three user-executable scripts:
1. configure (which relies on the Perl script *WRF/arch/Config_new.pl*)
2. compile
3. clean
|
|
.. _Programs:
Programs
++++++++
A substantial portion of WRF code is automatically generated during the build. This is done by the *tools/registry* file.
|
|
.. _Makefiles:
Makefiles
+++++++++
Much of the WRF code is written in the C and C++ programming language. These languages utilize a command called "make," which, when executed, performs the actions listed in a file called a *Makefile*. WRF contains a primary *Makefile* in its top-level directory (*WRF/*), and additional makefiles in various subdirectories. When WRF is built/compiled, *make* is called recursively over the directory structure.
|
|
.. _Configuration Files:
Configuration Files
+++++++++++++++++++
Prior to building/compiling WRF, a *configure* script is run. This script generates a *configure.wrf* file, which contains details about the compiler, linker, build settings, rules, and macro definitions used by the "make" utility. It is read by WRF Makefiles (except Makefiles in the *WRF/tools* and *WRF/external* directories). *configure.wrf* is deleted when the code system is cleaned by the user-issued *clean* script. Thus, *configure.wrf* can be modified for temporary changes, such as optimization levels and compiling with debugging. Permanent changes should be made in *arch/configure_new.defaults*. The *configure.wrf* file is composed by the following three files:
* **arch/configure_new.defaults** : contains lists of compiler options for all supported platforms and configurations; changes made to this file are permanent
* **arch/preamble_new** : constitutes the generic parts (non-architecture-specific) of the *configure.wrf* file; *See the file for details.**
* **arch/postamble_new** : similar to *arch/preamble_new*. *See the file for details.*
|
|
.. _Registry1:
Registry
++++++++
A :ref:`Registry2` file contains defining aspects of variables used in the model, which are read and accounted for during a WRF code build/compile. Registry files are found in the *WRF/Registry* directory. The files are named *Registry.x* (or *registry.x*), where *x* is a specific application (e.g., *Registry.EM_CHEM* includes variables specific to the WRF Chemistry model). For a basic WRF build/compile, the file used is *Registry.EM_COMMON*, which contains shared entries for all applications.
As part of the WRF build/compile process, *WRF/tools/registry\** files look for a file named "*Registry*" to read as input. Prior to compiling the code, the *configure* script is run to incorporate user-specified applications. Based on these specifications, *configure* copies the appropriate *Registry.x* file to the expected file name *Registry*.
|
.. important::
Because the *Registry* file is created during the build/compile, if any modifications are made to it, they will be lost during the compile. Modifications should be made to the *Registry.x* files.
|
|
.. _Environment Variables:
Environment Variables
+++++++++++++++++++++
An environment variable is user-defined (or defined by the user's computing environment), and determines computation specifics. For WRF *configure* and *compile* processes, environment variables determine the following:
* Location of the netCDF library and Perl command
* Which WRF dynamic core to compile
* Machine-specific features
* Optional build libraries (such as Grib Edition 2, HDF, and parallel netCDF)
|
In addition to WRF-related environment settings, there may also be settings specific to particular compilers or libraries. For e.g., local installations may require setting a variable like *MPICH_F90* to ensure the correct instance of the Fortran 90 compiler is used by the ``mpif90`` command.
|
|
|
|
WRF Build Mechanics
-------------------
The two steps in the WRF build process are **configuration** and **compilation**.
|
|
Configuration
+++++++++++++
The *configure* script (in the top-level *WRF* directory) configures the model to determine information about the user's computing environment prior to compilation, and it steps through the following processes:
#. Tries to locate mandatory and optional libraries (e.g., netCDF or HDF) and tools (e.g., Perl); it checks for these in standard paths, or paths from the user's shell environment settings
#. Calls the UNIX "*uname*" command to determine the user's platform
#. The Perl script *arch/Config_new.pl* is executed, displaying a list of available machine configurations for the user to choose from
#. The user-selected set of options is then used to generate the *configure.wrf* file in the top-level directory
|
.. note::
Each time the *clean* script is used, the *configure.wrf* file is overwritted, but is saved as *configure.wrf.backup*.
|
|
Compilation
+++++++++++
The *compile* script (located in the top-level *WRF* directory) steps through the processes to build/compile the WRF code after it has been configured. It performs checks, creates an argument list, copies the appropriate *Registry.X* file to *Registry/Registry* (see :ref:`Registry1`). The script then issues the UNIX "*make*" command, using the *Makefile* in the top-level *WRF/* directory, along with recursive invocations of "*make*" in the *WRF* subdirectories, and *configure.wrf's* settings to build the WRF code. The order of a complete build is as follows:
#. ``make`` is issued from the *WRF/external* directory
* ``make`` is issued from *WRF/external/io_{grib1,grib_share,int,netcdf}* for Grib Edition 1, binary, and netCDF implementations of I/O API
* ``make`` is issued from *WRF/external/RSL_LITE* to build the communications layer (distributed-memory/dmpar builds only)
* ``make`` is issued from *WRF/external/esmf_time_f90* to build the ESMF time manager library
* ``make`` is issued from *WRF/external/fftpack* to build the FFT library for the global filters
* ``make`` is issued from other *WRF/external* directories, as specified by the "*external:*" target in *configure.wrf*
|
#. ``make`` is issued from the *WRF/tools* directory to build the program that reads the *WRF/Registry/Registry* file and auto-generate files in the *WRF/inc* directory
#. ``make`` is issued from the *WRF/frame* directory to build the WRF framework-specific modules
#. ``make`` is issued from the *WRF/share* directory to build the mediation layer routines, including WRF I/O modules that call the I/O API
#. ``make`` is issued from the *WRF/phys* directory to build the WRF model layer routines for physics
#. ``make`` is issued from the *WRF/dyn_em* directory to build mediation-layer and model-layer subroutines
#. ``make`` is issued from the *WRF/main* directory to build the WRF's *main* programs, which are symbolically linked to a location based on the build case argument to the *compile* script (e.g., for a real-data case, the executables are linked to *WRF/test/em_real*)
* Source files (*\*.F* or *\*.F90* files) are preprocessed to produce *\*.f90* files, which are input to the compiler. Registry-generated files from the *WRF/inc* directory may be included.
* *\*.f90* files are compiled, which creates object files (*\*.o*) that are added to the library *WRF/main/libwrflib.a*. Most *WRF/external/\** directories generate their own library file.
* Executables are generated - depending whether an idealized or real-data case is chosen in the case argument to the ``compile`` command, the following are built:
* **Idealized Case**
* *wrf.exe* (the WRF model executable)
* *ideal.exe* (a preprocessor for idealized cases)
|
* **Real-data Case**
* *wrf.exe* (the WRF model executable)
* *real.exe* (a preprocessor for real-data cases)
* *ndown.exe* (for one-way nesting)
* *tc.exe* (for tropical storm addition or removal)
|
.. note::
The *\*.o* files and *\*.f90* files created during the compile are kept until the *WRF/clean* script is used. When runtime errors refer to line numbers, or when using debugging tools (e.g., *dbx* or *gbd*), the line numbers are specific to the *\*.f90*. However, code changes should be made to the *\*.F* files.
|
|
|
|
|
.. _Registry2:
Registry
========
.. container:: row m-0 p-0
.. container:: col-md-12 pl-0 pr-3 py-3 m-0
.. container:: card px-0 h-100
.. rst-class:: card-header-def
.. rubric:: Registry
.. container:: card-body-def
A system that includes a Registry program that builds WRF code according to the Registry file, which contains a text-based table that lists and describes state fields and their attributes.
|
The WRF code is largely generated from the *Registry*, which provides a high-level, single-point of control over the fundamental structure of the model data. The Registry consists of two components:
#. Registry file (in *WRF/Registry*)
#. Registry program (in *WRF/tools*).
|
The *WRF/Registry* directory contains the following files:
.. csv-table::
:widths: 20, 40
:header: "File Name","Type of WRF Build"
Registry.EM_COMMON,Standard/Basic WRF; containing variables common to all applications
Registry.EM_COMMON.var, Minimal subset of Registry.EM_COMMON required for a WRFDA compile
Registry.EM_CHEM,WRF Chemistry (WRF-Chem)
Registry.wrfvar,WRF Data Assimilation (WRFDA)
Registry.wrfchemvar,WRF-Chem + WRFDA
Registry.tladj,WRFPLUS
|
|
The *Registry.X* files define:
* Variables
* Input or output fields
* Fields required for parallel communication
* Fields associated with a specific physics package
* Fields that provide tendencies to multiple physics or dynamics routines
* Communication
* Namelist options
|
|
The following attributes are declared for each state variable listed in the *Registry.X* file:
* Variable name
* Dimensionality
* WRF I/O behavior and streams
* Horizontal and vertical staggering
* Feedback and nesting interpolation requirements
|
The Registry file provides input to generate communications for distributed memory processing (halo exchanges between patches, support for periodic lateral boundaries, and array transposes for FFTs to be run in the X, Y, or Z directions). The Registry associates various fields with particular physics packages, preventing over-allocation.
|
|
|
|
Registry Mechanics
------------------
When a WRF build is initiated, the appropriate *Registry.X* file is copied to a file named *Registry*. The Registry program/executable (written in *C* and found in *WRF/tools*) uses the contents of the *Registry* file to generate files in the *WRF/inc* directory. These "include" files are used by the WRF Fortran source files during compilation. The Registry is used to build all model executables. Refer to the below image for details:
.. image:: ../images/users_guide/wrf_software_registry_mechanics.jpg
:alt: "An image that shows when the user compiles WRF, the Registry Program reads Registry/Registry, producing auto-generated sections of code that are stored in files in the inc directory. These are included into WRF using the CPP preprocessor and the Fortran compiler."
|
|
|
|
Registry Entries
----------------
The following entry types are used in the WRF *Registry.X* file:
.. csv-table::
:widths: 20, 40
**Dimspec**, Dimensions used to define arrays in the model
**State**, State variables and arrays in the domain structure
**i1**, Local variables and arrays in WRF's "solve" routine (*WRF/dyn_em/solve_em.F*)
**Typedef**, Derived types that are subtypes of the domain structure
**Rconfig**, Represents namelist variables or arrays
**Package**, Packaged attributes (e.g. for a specific physics package)
**Halo**, Halo update interprocessor communications
**Period**, Communications for periodic boundary updates
**Xpose**, Communications for parallel matrix transposes
**include**, Similar to a CPP *#include* file
|
|
Dimspec
+++++++
.. container:: row m-0 p-0
.. container:: col-md-12 pl-0 pr-3 py-3 m-0
.. container:: card px-0 h-100
.. rst-class:: card-header-def
.. rubric:: Dimspec
.. container:: card-body-def
*Registry* file entries that consist of dimension specifications of WRF fields.
|
The below example assigns dimension names to the *i, j*, and *k* dimensions:
.. code-block::
dimspec i 1 standard_domain x west_east
dimspec j 3 standard_domain y south_north
dimspec k 2 standard_domain z bottom_top
|
.. tip::
Use the ``ncdump -h`` command to list the variables found in a WRF output/history file. For each variable, the three directional dimensions appear as *west_east, south_north*, and *bottom_top*.
|
Miscellaneous Dimspec Notes:
* Because WRF uses horizontal and vertical staggering, dimension names include a *_stag* suffix, representing staggered sizes.
* The list of names in the ** column may either be a single/unique character, or a string with no embedded spaces (e.g., *my_dim*).
* When this dimension is used within the *Registry* for :ref:`State and I1 Variables`, it must be surrounded by curly braces (e.g., *{my_dim}*).
* The ** variable is not case specific.
* To keep the WRF system consistent between build types, a unified *registry.dimspec* file is used (located in the *Registry* directory), and is included in each *Registry.\** file.
|
|
.. _State and I1 Variables:
State and I1 Variables
++++++++++++++++++++++
.. container:: row m-0 p-0
.. container:: col-md-12 pl-0 pr-3 py-3 m-0
.. container:: card px-0 h-100
.. rst-class:: card-header-def
.. rubric:: state Variable
.. container:: card-body-def
A field eligible for input/output (I/O) and communications, and exists for the duration of the model forecast.
.. container:: col-md-12 pl-0 pr-3 py-3 m-0
.. container:: card px-0 h-100
.. rst-class:: card-header-def
.. rubric:: i1 Variable
.. container:: card-body-def
"Intermediate level one" fields - typically tendency terms computed during a single model time-step, and then discarded prior to the next time-step.
|
.. note::
For i1 variables, space allocation and de-allocation is automatic (part of the model's "solver" stack).
|
Below are the columns (in order from left to right) used for state and i1 variables in the *Registry* file.
|
.. csv-table::
:header: Column Heading, Description, Type
:escape: \
**Table**, either *state* or *i1*, string
**Type**, type of variable or array, real\, double\, integer\, logical\, character\, or derived
**Sym**, symbolic name inside WRF, string; not case-sensitive
**Dims**, dimensionality of the array, string; use hyphen *(-)* when dimensionless
**Use**, denotes association with the solver (*dyn_em*)\, or 4D scalar array, string; if not specific\, declared *misc*
**NumTLev**, number of time levels, integer for arrays; use hyphen *(-)* for variables
**Stagger**, indicates staggered dimensions, string; X\,Y\,Z\, or hyphen *(-)* if not staggered
**IO**, whether and how it is subject to I/O and nesting, string; use hyphen *(-)* when no specification
**Dname**, metadata name, string; in quotes
**Descrip**, metadata description, string; in quotes
**Units**, metadata units, string; in quotes
|
.. code-block::