Wednesday, February 17, 2010

Weather Research and Forecasting Model Explained (Part 3) - System Architecture and Parallelism

WRF ,as mentioned in part 1 and part2, is a system designed for both operational and research purposes, and to run on systems from conventional laptops to super computers. The design of such a versatile system is a real challenge.
In this post we will explore some of the WRF's Software Framework design and explain the functionality of the different layers of the system. Also we'll discuss how the system handles parallelism in different hardware environments.
Software Framework Architecture[1][2]:
(The following functionalities doesn't include parallelism handling)

 Figure1: Hierarchical WRF Software Design
As it appears in Figure 1, the system design has 3 layers:
The Driver Layer:
It defines and allocates domains and associates them in a nest hierarchy. It also manages the flow of a system run as it's responsible for stepping the time for the loop mentioned in part1. And it's responsible for I/O operations. 
The Mediation Layer:
It interfaces between the two other layers. For example the driver layer uses Fortran 90's derived data-types while the model layer deals with scalar arrays only. The mediation layer is responsible for dereferencing the scalar arrays from the derived data types.
The Model Layer:
It performs the actual weather prediction computations like physics calculations and time integration.

Parallelism (Two Level decomposition):

Due to the versatileness of the system mentioned before, parallel systems including shared memory and distributed memory architectures. Two level decomposition addresses that problem by decomposing domains in patches and decomposing patches into tiles. With patches being "a section of a model domain allocated to a single memory address space" and tiles being "the amount of a patch that is allocated to a one thread of execution and every cell of a patch that requires computation must fall into some tile"[2].
The driver layer is responsible for distributed and shared memory allocation. Also it handles the decomposition of domains into patches and patches into tiles. While the model layer handles only tiles. This part reflects one of the best design features of the WRF Software Framework; Model layer is meant to be programmed by meteorological scientists not computer scientists, so handling parallelism issues (i.e. synchronization, memory allocation, communication, etc) was made part of the driver layer leaving the model layer to have only "meteorological calculators"-tiles callable subroutines.

[1] John G. Michalakes, Michael McAtee and Jerry Wegiel, SOFTWARE INFRASTRUCTURE FOR THE WEATHER RESEARCH AND FORECAST MODEL
[2] Weather Research and Forecast Model 1.2: Software Design and Implementation

Friday, February 12, 2010

Weather Research and Forecasting Model Explained (Part 2) - Nesting and System Components

In the part 1 we introduced WRF and discussed the meteorological basics of Advanced Research WRF. In this part we discuss the concept of nesting and explain different system parts of WRF. But first we'll define two basic terms.
Grid: Raw atmospheric data layed out as a discrete grid for an area of the map.
Figure 1 [1] Grid examples
Domian: A model created by processing grid information and making it ready for processing by WRF Model.
Nesting:
Nesting is a way of getting high resolution data from low resolution data.That's achieved by introducing more grid or grids to the initial state. Those finer grain grids force the need for more high resolution data. That data is obtained by interpolating data from coarse grain grids or could be user input.
Figure 2 [1] Nested grid
WRF System Components:

Figure3 [1] WRF system components
As it appears in figure 1, the system has 3 main components: Preprocessor (WPS), the WRF Model and Post Processor.
The WPS is responsible for preparing the input (initial conditions and lateral boundary conditions) to ARW for real-data simulations by [2]
  1. Defining simulation domain and nested domains.
  2. Computing latitude, longitude, map scale factors for every grid point
  3. Interpolates time-invariant terrestrial data to simulation grids (e.g., terrain height and soil type)
  4. Interpolates meteorological fields from another model onto simulation domains
The WRF Software Framework is the core engine of the system, it has the Dynamics solver, physics package and WRF-Chem and the interfacing between them. That core has all the equations mentioned in part 1.
The Post Processor, it processes the output of the WRF WRF Software Framework and converts it to GRIB format. For more information check [3] and [4].

[1] A Description of the Advanced Research WRF Version 3, http://www.mmm.ucar.edu/wrf/users/docs/arw_v3.pdf
[2] WPS Basics, http://www.mmm.ucar.edu/people/duda/files/wps_files/WPS-basics.pdf
[3] NCEP WRF Post Processor User Guide, http://www.emc.ncep.noaa.gov/mmb/papers/chuang/2/wrfpost.txt
[4] User's Guide for the NMM Core of the Weather Research and Forecast (WRF) Modeling System Version 3, Chapter 7: Post Processing Utilities.

Thursday, February 4, 2010

Weather Research and Forecasting Model Explained (Part 1) - Weather Prediction Basics

My goal here is to give a simple overview of the WRF for computer science students.
The Weather Resarch and Forecasting (WRF, pronounced "worf") model is an open-source numerical weather prediction (NWP) and atmospheric simulation system designed for both research and operational applications [1]. This system was developed as joint effort between National Center of Atmospheric Research, National Oceanic and Atmospheric Administration (NOAA), Air Force Weather Agency and others. In this post ,and the posts to follow, I'll try to explain the WRF from two different perspectives, the first being Meteorology and the second being Computer Science.
I am here concerned with the Advanced Research WRF (ARW) subset of WRF.
Weather Prediction Basics:
Weather Prediction means to predict the state of the atmosphere in terms of (pressure, temperature, speed of wind, etc). Our atmosphere is controlled by flow and the conditions of the air across the planet and by predicting that flow we can predict the weather conditions in the area of interest. The prediction is done by providing a system with information about the current state of the area of interest. Then the system uses that information as the parameters for its equations (usually difference equations) to produce future conditions for that area.
Euler's Equations:
Advanced Research WRF's dynamics engine integrates Euler's Equations to predict air flow.
Euler's equations are defined as a set of differential equations used in fluid dynamics to govern invscid flow (Wikipedia).
Being continuous equations, Euler's equations are discretized. Both temporal and spacial discretization are needed. So the surface of the earth is mapped as a grid ,based on the projection method used to project the spheric shape of earth, where all variable are defined on that grid.
Figure 1 Spacial discretization
(V,U,W are wind velocities, θ is the potential temperature)
For temporal discretization, the Euler's equations are integrated using a time-split integration scheme called Runge-Kutta method.

The following loop is used to integrate the equations and this loop is the main loop in the system (i.e. all other components are used to provide this loop with the information needed to compute the current time step)

Begin Time Step
Begin RK3 Loop:
Solve the equations
End RK3 Loop
Compute non-RK3 physics
End Time Step
Note: This is a very simple version of the loop for the complete version reference [1].

Initial and lateral boundary conditions:
For the system to be able to predict the weather for a certain area it doesn't only need its initial conditions but it also needs a way to know its boundary conditions as of course adjacent areas affect the area of interest. To solve this problem, several methods of generating lateral boundary data are used including periodic generating in which the lateral boundary conditions are repeated along the x-axis or y-axis or both.

[1] A Description of the Advanced Research WRF Version 3