Code Examples
This is a page in progress! It offers shortcuts to examples of ESMF usage to examine and copy. If there is an example you would like to see on this page, or you have a code snippet you think would help others, please write esmf_support@ucar.edu.
Using System Tests as Examples
There are many ESMF system tests which are runnable examples of how to set up multi-component ESMF applications. These are bundled with the ESMF source code, in esmf/src/system_tests. Click here for a complete listing.Steps to ESMF Adoption: PARSE
Before examining the examples in more detail, it's useful to understand the steps needed to adopt ESMF.
- Prepare user code. Split user code into initialize, run and finalize methods and decide on components, coupling fields, and control flow.
- Adapt data structures. Wrap native data structures either as:
- ESMF Arrays (index space only) - Regrid via user-supplied weights + sparse matrix multiply
- ESMF Field objects (coordinates and metadata) - Regrid via on-line weight generation
- Register user methods. Attach user code initialize, run and finalize methods to ESMF Components through registration calls.
- Schedule, synchronize, and send data between components. Write couplers using ESMF redistribution, sparse matrix multiply, regridding, or user-specified transformations.
- Execute the application. Run components using an ESMF driver.
Adapt Data Structures - Using ESMF Arrays
ESMF Array creation, from an existing Fortran array, includes picture.Version: 3.1.0p1
Type: Reference Manual example
Code is in: esmf/src/Infrastructure/Array/examples/ESMF_ArrayFarrayEx.F90.
ESMF Array creation, with memory allocation, includes picture.
Version: 3.1.0p1
Type: Reference Manual example
Code is in: esmf/src/Infrastructure/Array/examples/ESMF_ArrayEx.F90.
An example of how to set up Arrays with arbitrary distribution. This is how to represent unstructured meshes at the Array level. The example shows the use of these Arrays in a sparse matrix multiply operation. This operation could be used to implement regridding, with user-supplied interpolation weights.
Version: 3.1.0rp1
Type: Unit test
Code is in: esmf/src/Infrastructure/Array/tests/ESMF_ArrayArbIdxSMMUTest.F90
Schedule, Synchronize and Send Data Between Components
A very simple example of using Arrays and sparse matrix multiply for transferring data between components. Instead of interpolation weights, it takes in the identity matrix and effectively does a redistribution.Version: 3.1.0p1
Type: System test
Code is in: esmf/src/system_tests/ESMF_ArraySparseMatMul/
Note: This is also a good example to look at if you're doing a redistribution of data - replace the Array sparse matrix multiply with the Array redistribution operation.
A more realistic example of using Arrays and sparse matrix multiply to transfer data between components. This takes in SCRIP-generated interpolation weights.
Version: 3.1.0p1
Type: Use test case
Code is in: Not in the main ESMF source distribution! To get the use test case code, follow the checkout instructions on this page.
