MODULE model_mod (CLM)

DART project logo

Jump to DART Documentation Main Index
version information for this file:
$Id: model_mod.html 6420 2013-08-22 23:44:03Z thoar $

NAMELIST / INTERFACES / FILES / REFERENCES / ERRORS / PLANS / PRIVATE COMPONENTS / TERMS OF USE

Overview

This is the DART interface to the Community Land Model (CLM). It is run as part of the Community Earth System Model (CESM) framework. It is strongly recommended that you become familiar with running a multi-instance experiment in CESM before you try to run DART/CLM. The DART/CLM facility uses language and concepts that should be familiar to CESM users. The DART/CLM capability is entirely dependent on the multi-instance capability of CESM, first supported in its entirety in CESM1.1.1. Consequently, this version or newer is required to run CLM/DART. The CLM User's Guide is an excellent reference for CLM.

DART uses the multi-instance capability of CESM, which means that DART is not responsible for advancing the model. This GREATLY simplifies the traditional DART workflow, but it means CESM has to stop and write out a restart file every time an assimilation is required. The multi-instance capability is very new to CESM and we are in close collaboration with the CESM developers to make using DART with CESM as easy as possible. While we strive to keep DART requirements out of the model code, there are a few SourceMods needed to run DART from within CESM. The SourceMods are available at http://www.image.ucar.edu/pub/DART/CESM/DART_SourceMods_cesm1_1_1.tar and should be unpacked into your HOME directory. They will create a ~/cesm_1_1_1 directory with the appropriate SourceMods structure. The ensuing scripts require these SourceMods and expect them to be in your HOME directory.

Our notes on how to set up, configure, build, and run CESM for an assimilation experiment evolved into scripts. These scripts are not intended to be a 'black box'; you will have to read and understand them and modify them to your own purpose. They are heavily commented -- in keeping with their origins as a set of notes. If you would like to offer suggestions on how to improve those notes - please send them to dart@ucar.edu - we'd love to hear them.

Script Description
CESM1_1_1_pmo_setup runs a single instance of CLM to harvest synthetic observations for an OSSE or "perfect model" experiment. It requires a single CLM state from a previous experiment and uses a specified DATM stream for forcing. This parallels an assimilation experiment in that in the multi-instance setting each CLM instance may use (should use?) a unique DATM forcing. This script has almost nothing to do with DART. There is one (trivial) section that records some configuration information in the DART setup script, but that's about it. This script should initially be run without DART to ensure a working CESM environment.
CESM1_1_1_hybrid_initial runs a multi-instance CLM experiment and can be used to perform a free run or 'open loop' experiment. By default, each CLM instance uses a unique DATM forcing. This script also has almost nothing to do with DART. There is one (trivial) section that records some configuration information in the DART setup script, but that's about it. This script should initially be run without DART to ensure a working CESM.
CESM_DART_config augments a CESM case with the bits and pieces required to run DART. When either CESM1_1_1_pmo_setup or CESM1_1_1_hybrid_initial gets executed, CESM_DART_config gets copied to the CESM "caseroot" directory. It is designed such that you can execute it at any time during a CESM experiment. When you do execute it, it will build the DART executables and copy them into the CESM "bld" directory, stage the run-time configurable input.nml in the "caseroot" directory, etc. and also modifies the CESM case.run script to call the DART scripts for assimilation or to harvest synthetic observations.

In addition to the script above, there are a couple scripts that will either perform an assimilation (assimilate.csh) or harvest observations for a perfect model experiment (perfect_model.csh). These scripts are designed to work on several compute platforms although they require configuration, mainly to indicate the location of the DART observation sequence files on your system.

Pertinent details of the CLM gridcell.

CLM gridcell breakdown "The land surface is represented by 5 primary sub-grid land cover types (landunits: glacier, lake, wetland, urban, vegetated) in each grid cell. The vegetated portion of a grid cell is further divided into patches of plant functional types, each with its own leaf and stem area index and canopy height. Each subgrid land cover type and PFT patch is a separate column for energy and water calculations." -- CLM documentation.

The only location information available is at the gridcell level. All landunits, columns, and PFTs in that gridcell have the same location. This has ramifications for the forward observation operators. If the observation metadata has information about land use/land cover, it can be used to select only those patches that are appropriate. Otherwise, an area-weighted average of ALL patches in the gridcell is used to calculate the observation value for that location.

A word about forward observation operators.

"Simple" observations like snowcover fraction come directly from the DART state. It is possible to configure the CLM history files to contain the CLM estimates of some quantities (mostly flux tower observations e.g, net ecosystem production, sensible heat flux, latent heat flux) that are very complicated combinations of portions of the CLM state. The forward observation operators for these flux tower observations read these quantities from the CLM .h1. history file. The smaller the CLM gridcell, the more likely it seems that these values will agree with point observations.

The prior and posterior values for these will naturally be identical as the history file is unchanged by the assimilation. Configuring the CLM user_nl_clm files to output the desired quantities must be done at the first execution of CLM. As soon as CONTINUE_RUN=TRUE, the namelist values for history file generation are ignored. Because the history file creation is very flexible, some additional information must be passed to DART to construct the filename of the .h1. history file needed for any particular time.

[top]

NAMELIST

These namelists are read from the file input.nml. Namelists start with an ampersand '&' and terminate with a slash '/'. Character strings that contain a '/' must be enclosed in quotes to prevent them from prematurely terminating the namelist.

&model_nml 
  clm_restart_filename         = 'clm_restart.nc',
  clm_history_filename         = 'clm_history.nc',
  output_state_vector          = .false.,
  assimilation_period_days     = 2,
  assimilation_period_seconds  = 0,
  model_perturbation_amplitude = 0.2,
  calendar                     = 'Gregorian',
  debug                        = 0
  clm_state_variables          = 'frac_sno',    'KIND_SNOWCOVER_FRAC',
                                 'H2OSNO',      'KIND_SNOW_WATER',
                                 'H2OSOI_LIQ',  'KIND_SOIL_MOISTURE',
                                 'H2OSOI_ICE',  'KIND_ICE',
                                 'T_SOISNO',    'KIND_SOIL_TEMPERATURE',
                                 'cpool',       'KIND_CARBON',
                                 'frootc',      'KIND_ROOT_CARBON',
                                 'leafc',       'KIND_LEAF_CARBON',
                                 'leafn',       'KIND_LEAF_NITROGEN',
   /
Item Type Description
clm_restart_filename character(len=256) this is the filename of the CLM restart file. The DART scripts resolve linking the specific CLM restart file to this generic name. This file provides the elements used to make up the DART state vector. The variables are in their original landunit, column, and PFT-based representations.
clm_history_filename character(len=256) this is the filename of the CLM .h0. history file. The DART scripts resolve linking the specific CLM history file to this generic name. Some of the metadata needed for the DART/CLM interfaces is contained only in this history file, so it is needed for all DART routines.
output_state_vector logical If .true. write state vector as a 1D array to the DART diagnostic output files. If .false. break state vector up into variables before writing to the output files.
assimilation_period_days,
assimilation_period_seconds
integer Combined, these specify the width of the assimilation window. The current model time is used as the center time of the assimilation window. All observations in the assimilation window are assimilated. BEWARE: if you put observations that occur before the beginning of the assimilation_period, DART will error out because it cannot move the model 'back in time' to process these observations.
model_perturbation_amplitude integer Required by the DART interfaces, but not used by CLM.
calendar character(len=32) string specifying the calendar to use with DART. The CLM dates will be interpreted with this same calendar. For assimilations with real observations, this should be 'Gregorian'.
debug integer Set to 0 (zero) for minimal output. Successively higher values generate successively more output. Not all values are important, however. It seems I've only used values [3,6,7,8]. Go figure.
clm_state_variables character(:,2) Pairs of strings that identify the CLM variables and their DART kind. Only CLM variable names in the CLM restart file are valid. The DART kind must be one found in the DART/obs_kind/obs_kind_mod.f90 AFTER it gets built by preprocess. Most of the land observation kinds are specified by DART/obs_def/obs_def_tower_mod.f90, so it should be specified in the preprocess_nml:input_files variable.


&obs_def_tower_nml
   casename    = '../clm_dart',
   hist_nhtfrq = -24,
   debug       = .false.
   /
Item Type Description
casename character(len=256) this is the name of the CESM case. It is used by the forward observation operators to help construct the filename of the CLM .h1. history files for the flux tower observations. When the input.nml gets staged in the CASEROOT directory by CESM_DART_config, the appropriate value should automatically be inserted.
hist_nhtfrq integer this is the same value as in the CLM documentation. A negative value indicates the number of hours contained in the .h1. file. This value is needed to constuct the right .h1. filename. When the input.nml gets staged in the CASEROOT directory by CESM_DART_config, the appropriate value should automatically be inserted. Due to the large number of ways of specifying the CLM history file information, the correct value here is very dependent on how the case was configured. You would be wise to check it.
debug logical Set to .false. for minimal output.

[top]

OTHER MODULES USED (directly)

types_mod
time_manager_mod
threed_sphere/location_mod
utilities_mod
obs_kind_mod
obs_def_tower_mod
random_seq_mod
[top]

PUBLIC INTERFACES - Required

use model_mod, only : get_model_size
 adv_1step
 get_state_meta_data
 model_interpolate
 get_model_time_step
 static_init_model
 end_model
 init_time
 init_conditions
 nc_write_model_atts
 nc_write_model_vars
 pert_model_state
 get_close_maxdist_init
 get_close_obs_init
 get_close_obs
 ens_mean_for_model

A note about documentation style. Optional arguments are enclosed in brackets [like this].


model_size = get_model_size( )
integer :: get_model_size

Returns the length of the model state vector.

model_size The length of the model state vector.


call adv_1step(x, time)
real(r8), dimension(:), intent(inout) :: x
type(time_type),        intent(in)    :: time

Advances the model for a single time step. The time associated with the initial model state is also input although it is not used for the computation.

x State vector of length model_size.
time    Specifies time of the initial model state.


call get_state_meta_data (index_in, location, [, var_type] )
integer,             intent(in)  :: index_in
type(location_type), intent(out) :: location
integer, optional,   intent(out) ::  var_type 

Returns metadata about a given element, indexed by index_in, in the model state vector. The location defines where the state variable is located.

index_in    Index of state vector element about which information is requested.
location The location of state variable element.
var_type Returns the type (always 1) of the indexed state variable as an optional argument.


call model_interpolate(x, location, itype, obs_val, istatus)
real(r8), dimension(:), intent(in)  :: x
type(location_type),    intent(in)  :: location
integer,                intent(in)  :: itype
real(r8),               intent(out) :: obs_val
integer,                intent(out) :: istatus

Given model state, returns the value interpolated to a given location.

x A model state vector.
location    Location to which to interpolate.
itype Not used.
obs_val The interpolated value from the model.
istatus Quality control information, always returned 0.


var = get_model_time_step()
type(time_type) :: get_model_time_step

Returns the time step (forecast length) of the model;

var    Smallest time step of model.


call static_init_model()

Used for runtime initialization of model; reads namelist, initializes model parameters, etc. This is the first call made to the model by any DART-compliant assimilation routine.



call end_model()

A stub.



call init_time(time)
type(time_type), intent(out) :: time

Returns the time at which the model will start if no input initial conditions are to be used. This is used to spin-up the model from rest.

time    Initial model time.


call init_conditions(x)
real(r8), dimension(:), intent(out) :: x

Returns default initial conditions for the model; generally used for spinning up initial model states.

x    Initial conditions for state vector.


ierr = nc_write_model_atts(ncFileID)
integer             :: nc_write_model_atts
integer, intent(in) :: ncFileID

Function to write model specific attributes to a netCDF file. At present, DART is using the NetCDF format to output diagnostic information. This is not a requirement, and models could choose to provide output in other formats. This function writes the metadata associated with the model to a NetCDF file opened to a file identified by ncFileID.

ncFileID    Integer file descriptor to previously-opened netCDF file.
ierr Returns a 0 for successful completion.


ierr = nc_write_model_vars(ncFileID, statevec, copyindex, timeindex)
integer                            :: nc_write_model_vars
integer,                intent(in) :: ncFileID
real(r8), dimension(:), intent(in) :: statevec
integer,                intent(in) :: copyindex
integer,                intent(in) :: timeindex

Writes a copy of the state variables to a netCDF file. Multiple copies of the state for a given time are supported, allowing, for instance, a single file to include multiple ensemble estimates of the state.

ncFileID file descriptor to previously-opened netCDF file.
statevec A model state vector.
copyindex    Integer index of copy to be written.
timeindex The timestep counter for the given state.
ierr Returns 0 for normal completion.


call pert_model_state(state, pert_state, interf_provided)
real(r8), dimension(:), intent(in)  :: state
real(r8), dimension(:), intent(out) :: pert_state
logical,                intent(out) :: interf_provided

Given a model state, produces a perturbed model state.

state State vector to be perturbed.
pert_state Perturbed state vector: NOT returned.
interf_provided    Returned false; interface is not implemented.


call get_close_maxdist_init(gc, maxdist)
type(get_close_type), intent(inout) :: gc
real(r8),             intent(in)    :: maxdist

Pass-through to the 3D Sphere locations module. See get_close_maxdist_init() for the documentation of this subroutine.



call get_close_obs_init(gc, num, obs)
type(get_close_type), intent(inout) :: gc
integer,              intent(in)    :: num
type(location_type),  intent(in)    :: obs(num)

Pass-through to the 3D Sphere locations module. See get_close_obs_init() for the documentation of this subroutine.



call get_close_obs(gc, base_obs_loc, base_obs_kind, obs, obs_kind, num_close, close_ind [, dist])
type(get_close_type), intent(in)  :: gc
type(location_type),  intent(in)  :: base_obs_loc
integer,              intent(in)  :: base_obs_kind
type(location_type),  intent(in)  :: obs(:)
integer,              intent(in)  :: obs_kind(:)
integer,              intent(out) :: num_close
integer,              intent(out) :: close_ind(:)
real(r8), optional,   intent(out) :: dist(:)

Pass-through to the 3D Sphere locations module. See get_close_obs() for the documentation of this subroutine.



call ens_mean_for_model(ens_mean)
real(r8), dimension(:), intent(in) :: ens_mean

A NULL INTERFACE in this model.

ens_mean    State vector containing the ensemble mean.

[top]

PUBLIC INTERFACES - Optional

use model_mod, only : get_gridsize
 restart_file_to_sv
 sv_to_restart_file
 get_clm_restart_filename
 get_state_time
 get_grid_vertval
 compute_gridcell_value
 find_gridcell_Npft
 DART_get_var
 get_model_time

call get_gridsize(num_lon, num_lat, num_lev)
integer, intent(out) :: num_lon, num_lat, num_lev

Returns the number of longitudes, latitudes, and total number of levels in the CLM state.

num_lon The number of longitude grid cells in the CLM state. This comes from the CLM history file.
num_lat The number of latitude grid cells in the CLM state. This comes from the CLM history file.
num_lev The number of levels grid cells in the CLM state. This comes from 'nlevtot' in the CLM restart file.


call restart_file_to_sv(filename, state_vector, restart_time )
character(len=*), intent(in)    :: filename
real(r8),         intent(inout) :: state_vector(:)
type(time_type),  intent(out)   :: restart_time

Reads the current time and state variables from a CLM restart file and packs them into a DART state vector. This MUST happen in the same fashion as the metadata arrays are built. The variables specified in the model_nml:clm_state_variables are the ones read from the CLM restart file to create the DART state vector.

filename The name of the CLM restart file.
state_vector The DART state vector.
restart_time The valid time of the CLM state.


call sv_to_restart_file(state_vector, filename, dart_time)
real(r8),         intent(in) :: state_vector(:)
character(len=*), intent(in) :: filename
type(time_type),  intent(in) :: dart_time

This routine updates the CLM restart file with the posterior state from the assimilation. Some CLM variables that are useful to include in the DART state (frac_sno, for example) are diagnostic quantities and are not used for subsequent model advances. The known diagnostic variables are NOT updated. If the values created by the assimilation are outside physical bounds, or if the original CLM value was 'missing', the vector_to_prog_var() subroutine ensures that the values in the original CLM restart file are not updated.

state_vector The DART state vector containing the state modified by the assimilation.
filename The name of the CLM restart file. The contents of some of the variables will be overwritten with new values.
dart_time The valid time of the DART state. This has to match the time in the CLM restart file.


call get_clm_restart_filename( filename )
character(len=*), intent(out) :: filename

provides access to the name of the CLM restart file to routines outside the scope of this module.

filename The name of the CLM restart file.


time = get_state_time(file_handle)
integer,          intent(in) :: file_handle 
character(len=*), intent(in) :: file_handle 
type(time_type)              :: get_state_time

This routine has two interfaces - one for an integer input, one for a filename. They both return the valid time of the model state contained in the file. The file referenced is the CLM restart file in netCDF format.

file_handle If specified as an integer, it must be the netCDF file identifier from nf90_open(). If specified as a filename, the name of the netCDF file.
time A DART time-type that contains the valid time of the model state in the CLM restart file.


call get_grid_vertval(x, location, varstring, interp_val, istatus)
real(r8),            intent(in)  :: x(:)
type(location_type), intent(in)  :: location
character(len=*),    intent(in)  :: varstring
real(r8),            intent(out) :: interp_val
integer,             intent(out) :: istatus

Calculate the value of quantity at depth. The gridcell value at the levels above and below the depth of interest are calculated and then the value for the desired depth is linearly interpolated. Each gridcell value is an area-weighted value of an unknown number of column- or pft-based quantities. This is one of the workhorse routines for model_interpolate().

x The DART state vector.
location The location of the desired quantity.
varstring The CLM variable of interest - this must be part of the DART state. e.g, T_SOISNO, H2OSOI_LIQ, H2OSOI_ICE ...
interp_val The quantity at the location of interest.
istatus error code. 0 (zero) indicates a successful interpolation.


call compute_gridcell_value(x, location, varstring, interp_val, istatus)
real(r8),            intent(in)  :: x(:)
type(location_type), intent(in)  :: location
character(len=*),    intent(in)  :: varstring
real(r8),            intent(out) :: interp_val
integer,             intent(out) :: istatus

Calculate the value of a CLM variable in the DART state vector given a location. Since the CLM location information is only available at the gridcell level, all the columns in a gridcell are area-weighted to derive the value for the location. This is one of the workhorse routines for model_interpolate(), and only select CLM variables are currently supported. Only CLM variables that have no vertical levels may use this routine.

x The DART state vector.
location The location of the desired quantity.
varstring The CLM variable of interest - this must be part of the DART state. e.g, frac_sno, leafc, ZWT ...
interp_val The quantity at the location of interest.
istatus error code. 0 (zero) indicates a successful interpolation.


call find_gridcell_Npft(varstring)
character(len=*), intent(in) :: varstring

This is a utility routine that helps identify how many land units,columns, or PFTs are in each gridcell for a particular variable. Helps answer exploratory questions about which gridcells are appropriate to test code. The CLM variable is read from the CLM restart file.

varstring The CLM variable name of interest.


call DART_get_var(ncid, varname, datmat)
integer,                  intent(in)  :: ncid
character(len=*),         intent(in)  :: varname
real(r8), dimension(:),   intent(out) :: datmat
real(r8), dimension(:,:), intent(out) :: datmat

Reads a 1D or 2D variable of 'any' type from a netCDF file and processes and applies the offset/scale/FillValue attributes correctly.

ncid The netCDF file identifier to an open file. ncid is the output from a nf90_open() call.
varname The name of the netCDF variable of interest. The variables can be integers, floats, or doubles.
datmat The shape of datmat must match the shape of the netCDF variable. Only 1D or 2D variables are currently supported.


model_time = get_model_time( )
integer :: get_model_time

Returns the valid time of the model state vector.

model_time The valid time of the model state vector.

[top]

FILES

filename purpose
input.nml to read the model_mod namelist
clm_restart.nc both read and modified by the CLM model_mod
clm_history.nc read by the CLM model_mod for metadata purposes.
*.h1.* history files may be read by the obs_def_tower_mod for observation operator purposes.
dart_log.out the run-time diagnostic output
dart_log.nml the record of all the namelists actually USED - contains the default values

[top]

REFERENCES

CLM User's Guide is an excellent reference for CLM.

[top]

ERROR CODES and CONDITIONS

Routine Message Comment
nc_write_model_atts
nc_write_model_vars
Various netCDF-f90 interface error messages From one of the netCDF calls in the named routine

KNOWN BUGS

none at this time

[top]

FUTURE PLANS

none at this time

[top]

PRIVATE COMPONENTS

N/A

[top]

Terms of Use

DART software - Copyright 2004 - 2013 UCAR.
This open source software is provided by UCAR, "as is",
without charge, subject to all terms of use at
http://www.image.ucar.edu/DAReS/DART/DART_download

Contact: DART core group
Revision: $Revision: 6420 $
Source: $URL: https://svn-dares-dart.cgd.ucar.edu/DART/releases/Lanai/models/clm/model_mod.html $
Change Date: $Date: 2013-08-22 17:44:03 -0600 (Thu, 22 Aug 2013) $
Change history:  try "svn log" or "svn diff"