Changes between Initial Version and Version 1 of ImplementAnalysis_3DVar_classical


Ignore:
Timestamp:
Dec 9, 2021, 12:01:16 PM (3 years ago)
Author:
lnerger
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ImplementAnalysis_3DVar_classical

    v1 v1  
     1= Implementation of the Analysis Step for 3D-Var without using OMI =
     2
     3
     4{{{
     5#!html
     6<div class="wiki-toc">
     7<h4>Implementation Guide</h4>
     8<ol><li><a href="ImplementationGuide">Main page</a></li>
     9<li><a href="AdaptParallelization">Adaptation of the parallelization</a></li>
     10<li><a href="InitPdaf">Initialization of PDAF</a></li>
     11<li><a href="ModifyModelforEnsembleIntegration">Modifications for ensemble integration</a></li>
     12<li><a href="ImplementationofAnalysisStep">Implementation of the analysis step</a></li>
     13<ol>
     14<li><a href="ImplementAnalysisestkf">Implementation for ESTKF</a></li>
     15<li><a href="ImplementAnalysislestkf">Implementation for LESTKF</a></li>
     16<li><a href="ImplementAnalysisetkf">Implementation for ETKF</a></li>
     17<li>Implementation for LETKF</li>
     18<li><a href="ImplementAnalysisseik">Implementation for SEIK</a></li>
     19<li><a href="ImplementAnalysislseik">Implementation for LSEIK</a></li>
     20<li><a href="ImplementAnalysisseek">Implementation for SEEK</a></li>
     21<li><a href="ImplementAnalysisenkf">Implementation for EnKF</a></li>
     22<li><a href="ImplementAnalysislenkf">Implementation for LEnKF</a></li>
     23<li><a href="ImplementAnalysisnetf">Implementation for NETF</a></li>
     24<li><a href="ImplementAnalysislnetf">Implementation for LNETF</a></li>
     25<li><a href="ImplementAnalysispf">Implementation for PF</a></li>
     26<li>Implementation for 3D-Var</li>
     27<li><a href="ImplementAnalysis_3dEnVar_classical">Implementation for 3D Ensemble Var</a></li>
     28<li><a href="ImplementAnalysis_Hyb3DVar_classical">Implementation for Hybrid 3D-Var</a></li>
     29</ol>
     30<li><a href="AddingMemoryandTimingInformation">Memory and timing information</a></li>
     31<li><a href="EnsembleGeneration">Ensemble Generation</a></li>
     32<li><a href="DataAssimilationDiagnostics">Diagnostics</a></li>
     33</ol>
     34</div>
     35}}}
     36
     37[[PageOutline(2-3,Contents of this page)]]
     38
     39== Overview ==
     40
     41With Version 2.0 with introduced 3D variational assimilation methods to PDAF. There are genenerally three different variants: parameterized 3D-Var, 3D Ensemble Var, and hybrid (parameterized + ensemble) 3D-Var.
     42
     43This page describes the implementation of the analysis step for the parameterized 3D-Var in the classical way without using PDAF-OMI.
     44
     45For the analysis step of 3D-Var we need different operations related to the observations. These operations are requested by PDAF by calling user-supplied routines. Intentionally, the operations are split into separate routines in order to keep the operations rather elementary as this procedure should simplify the implementation. The names of the required routines are specified in the call to the routine `PDAF_assimilate_3dvar` in the fully-parallel implementation (or `PDAF_put_state_3dvar` for the 'flexible' implementation) described below. With regard to the parallelization, all these routines (except `U_collect_state`) are executed by the filter processes (`filterpe=.true.`) only.
     46
     47For completeness we discuss here all user-supplied routines that are specified in the interface to `PDAF_assimilate_3dvar`. Thus, some of the user-supplied routines that are explained on the page describing the modification of the model code for the ensemble integration are repeated here.
     48
     49
     50== `PDAF_assimilate_3dvar` ==
     51
     52The general aspects of the filter (or solver) specific routines `PDAF_assimilate_*` have been described on the page [ModifyModelforEnsembleIntegration Modification of the model code for the ensemble integration] and its sub-page on [InsertAnalysisStep inserting the analysis step]. The routine is used in the fully-parallel implementation variant of the data assimilation system. When the 'flexible' implementation variant is used, the routines `PDAF_put_state_*` is used as described further below. Here, we list the full interface of the routine. Subsequently, the user-supplied routines specified in the call is explained.
     53
     54The interface for using the parameterized 3D-Var is:
     55{{{
     56  SUBROUTINE PDAF_assimilate_3dvar(U_collect_state, U_distribute_state, &
     57                                 U_init_dim_obs, U_obs_op, U_init_obs, U_prodRinvA, &
     58                                 U_cvt, U_cvt_adj, U_obs_op_lin, U_obs_op_adj, &
     59                                 U_prepoststep, U_next_observation, outflag)
     60}}}
     61with the following arguments:
     62 * [#U_collect_statecollect_state_pdaf.F90 U_collect_state]: The name of the user-supplied routine that initializes a state vector from the array holding the ensemble of model states from the model fields. This is basically the inverse operation to `U_distribute_state` used in `PDAF_get_state` as well as here.
     63 * [#U_distribute_statedistribute_state_pdaf.F90 U_distribute_state]:  The name of a user supplied routine that initializes the model fields from the array holding the ensemble of model state vectors.
     64 * [#U_init_dim_obsinit_dim_obs_pdaf.F90 U_init_dim_obs]: The name of the user-supplied routine that provides the size of observation vector
     65 * [#U_obs_opobs_op_pdaf.F90 U_obs_op]: The name of the user-supplied routine that acts as the observation operator on some state vector
     66 * [#U_init_obsinit_obs_pdaf.F90 U_init_obs]: The name of the user-supplied routine that initializes the vector of observations
     67 * [#U_prodRinvAprodrinva_pdaf.F90 U_prodRinvA]: The name of the user-supplied routine that computes the product of the inverse of the observation error covariance matrix with some matrix provided to the routine by PDAF. This operation occurs during the analysis step of the ETKF.
     68 * [#U_cvtcvt_pdaf.F90 U_cvt]: The name of the user-supplied routine that applies the control-vector transformation (square-root of the B-matrix) on some control vector to obtain a state vector.
     69 * [#U_cvt_adjcvt_adj_pdaf.F90 U_cvt_adj]: The name of the user-supplied routine that applies the adjoint control-vector transformation (with square-root of the B-matrix) on some state vector to obtain the control vector.
     70 * [#U_obs_op_linobs_op_lin_pdaf.F90 U_obs_op_lin]: The name of the user-supplied routine that acts as the linearized observation operator on some state vector
     71 * [#U_obs_op_adjobs_op_adj_pdaf.F90 U_obs_op_adj]: The name of the user-supplied routine that acts as the adjoint observation operator on some state vector
     72 * [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep]: The name of the pre/poststep routine as in `PDAF_get_state`
     73 * [#U_next_observationnext_observation.F90 U_next_observation]: The name of a user supplied routine that initializes the variables `nsteps`, `timenow`, and `doexit`. The same routine is also used in `PDAF_get_state`.
     74 * `status`: The integer status flag. It is zero, if the routine is exited without errors.
     75
     76
     77== `PDAFomi_put_state_global` ==
     78
     79When the 'flexible' implementation variant is chosen for the assimilation system, the routine `PDAFomi_put_state_global` has to be used instead of `PDAFomi_assimilate_global`. The general aspects of the filter specific routines `PDAF_put_state_*` have been described on the page [ModifyModelforEnsembleIntegration Modification of the model code for the ensemble integration]. The interface of the routine is identical with that of `PDAF_assimilate_global` with the exception the specification of the user-supplied routines `U_distribute_state` and `U_next_observation` are missing.
     80
     81The interface when using one of the global filters is the following:
     82{{{
     83  SUBROUTINE PDAFomi_assimilate_3dvar(collect_state_pdaf, &
     84                                 U_init_dim_obs, U_obs_op, U_init_obs, U_prodRinvA, &
     85                                 U_cvt, U_cvt_adj, U_obs_op_lin, U_obs_op_adj, &
     86                                 prepoststep_pdaf, outflag)
     87}}}
     88
     89== User-supplied routines ==
     90
     91Here all user-supplied routines are described that are required in the call to `PDAFomi_assimilate_3dvar`. For some of the generic routines, we link to the page on [ModifyModelforEnsembleIntegration modifying the model code for the ensemble integration].
     92
     93To indicate user-supplied routines we use the prefix `U_`. In the template directory `templates/` as well as in the tutorial implementations in `tutorial/` these routines exist without the prefix, but with the extension `_pdaf.F90`. The user-routines relating to OMI are collected in the file `callback_obs_pdafomi.F90`. In the section titles below we provide the name of the template file in parentheses.
     94
     95In the subroutine interfaces some variables appear with the suffix `_p`. This suffix indicates that the variable is particular to a model sub-domain, if a domain decomposed model is used. Thus, the value(s) in the variable will be different for different model sub-domains.
     96
     97
     98=== `U_collect_state` (collect_state_pdaf.F90) ===
     99
     100This routine is independent of the filter algorithm used.
     101
     102See the page on [InsertAnalysisStep#U_collect_statecollect_state_pdaf.F90 inserting the analysis step] for the description of this routine.
     103
     104
     105=== `U_distribute_state` (distribute_state_pdaf.F90) ===
     106
     107This routine is independent of the filter algorithm used.
     108
     109See the page on [InsertAnalysisStep#U_distribute_statedistribute_state_pdaf.F90 inserting the analysis step] for the description of this routine.
     110
     111
     112=== `U_init_dim_obs` (init_dim_obs_pdaf.F90) ===
     113
     114This routine is used by all global filter algorithms (SEEK, SEIK, EnKF, ETKF) and the 3D-Var methods.
     115
     116The interface for this routine is:
     117{{{
     118SUBROUTINE init_dim_obs(step, dim_obs_p)
     119
     120  INTEGER, INTENT(in)  :: step       ! Current time step
     121  INTEGER, INTENT(out) :: dim_obs_p  ! Dimension of observation vector
     122}}}
     123
     124The routine is called at the beginning of each analysis step.  It has to initialize the size `dim_obs_p` of the observation vector according to the current time step. Without parallelization `dim_obs_p` will be the size for the full model domain. When a domain-decomposed model is used, `dim_obs_p` will be the size of the observation vector for the sub-domain of the calling process.
     125
     126Some hints:
     127 * It can be useful to not only determine the size of the observation vector at this point. One can also already gather information about the locations of the observations, which will be used later, e.g. to implement the observation operator. An array for the locations can be defined in a module like `mod_assimilation` of the example implementation.
     128
     129
     130=== `U_obs_op` (obs_op_pdaf.F90) ===
     131
     132This routine is used by all global filter algorithms (SEEK, SEIK, EnKF, ETKF) and the 3D-Var methods.
     133
     134The interface for this routine is:
     135{{{
     136SUBROUTINE obs_op(step, dim_p, dim_obs_p, state_p, m_state_p)
     137
     138  INTEGER, INTENT(in) :: step               ! Current time step
     139  INTEGER, INTENT(in) :: dim_p              ! PE-local dimension of state
     140  INTEGER, INTENT(in) :: dim_obs_p          ! Dimension of observed state
     141  REAL, INTENT(in)    :: state_p(dim_p)     ! PE-local model state
     142  REAL, INTENT(out) :: m_state_p(dim_obs_p) ! PE-local observed state
     143}}}
     144
     145The routine is called during the analysis step. It has to perform the operation of the observation operator acting on a state vector that is provided as `state_p`. The observed state has to be returned in `m_state_p`.
     146
     147For a model using domain decomposition, the operation is on the PE-local sub-domain of the model and has to provide the observed sub-state for the PE-local domain.
     148
     149Hint:
     150 * If the observation operator involves a global operation, e.g. some global integration, while using domain-decomposition one has to gather the information from the other model domains using MPI communication.
     151
     152
     153=== `U_init_obs` (init_obs_pdaf.F90) ===
     154
     155This routine is used by all global filter algorithms (SEEK, SEIK, EnKF, ETKF) and the 3D-Var methods.
     156
     157The interface for this routine is:
     158{{{
     159SUBROUTINE init_obs(step, dim_obs_p, observation_p)
     160
     161  INTEGER, INTENT(in) :: step             ! Current time step
     162  INTEGER, INTENT(in) :: dim_obs_p        ! PE-local dimension of obs. vector
     163  REAL, INTENT(out)   :: observation_p(dim_obs_p) ! PE-local observation vector
     164}}}
     165
     166The routine is called during the analysis step.
     167It has to provide the vector of observations in `observation_p` for the current time step.
     168
     169For a model using domain decomposition, the vector of observations that exist on the model sub-domain for the calling process has to be initialized.
     170
     171
     172
     173
     174=== `U_prodRinvA` (prodrinva_pdaf.F90) ===
     175
     176This routine is used by all filter algorithms that use the inverse of the observation error covariance matrix (SEEK, SEIK, and ETKF) and the 3D-Var methods.
     177
     178The interface for this routine is:
     179{{{
     180SUBROUTINE prodRinvA(step, dim_obs_p, dim_ens, obs_p, A_p, C_p)
     181
     182  INTEGER, INTENT(in) :: step                ! Current time step
     183  INTEGER, INTENT(in) :: dim_obs_p           ! PE-local dimension of obs. vector
     184  INTEGER, INTENT(in) :: dim_ens             ! Ensemble size
     185  REAL, INTENT(in)    :: obs_p(dim_obs_p)    ! PE-local vector of observations
     186  REAL, INTENT(in)    :: A_p(dim_obs_p, dim_ens) ! Input matrix from analysis routine
     187  REAL, INTENT(out)   :: C_p(dim_obs_p, dim_ens) ! Output matrix
     188}}}
     189
     190The routine is called during the analysis step. In the algorithms the product of the inverse of the observation error covariance matrix with some matrix has to be computed. For the ETKF, this matrix holds the observed part of the ensemble perturbations. The matrix is provided as `A_p`. The product has to be given as `C_p`.
     191
     192For a model with domain decomposition, `A_p` contains the part of the matrix that resides on the model sub-domain of the calling process. The product has to be computed for this sub-domain, too.
     193
     194Hints:
     195 * The routine does not require that the product is implemented as a real matrix-matrix product. Rather, the product can be implemented in its most efficient form. For example, if the observation error covariance matrix is diagonal, only the multiplication of the diagonal with matrix `A_p` has to be implemented.
     196 * The observation vector `obs_p` is provided through the interface for cases where the observation error variance is relative to the actual value of the observations.
     197 * The interface has a difference for SEIK and ETKF: For ETKF the third argument is the ensemble size (`dim_ens`), while for SEIK it is the rank of the covariance matrix (usually ensemble size minus one). In addition, the second dimension of `A_p` and `C_p` has size `dim_ens` for ETKF, while it is `rank` for the SEIK filter.  (Practically, one can usually ignore this difference as the fourth argument of the interface can be named arbitrarily in the routine.)
     198
     199
     200
     201
     202=== `U_cvt` (cvt_pdaf.F90) ===
     203
     204The interface for this routine is:
     205{{{
     206SUBROUTINE cvt_pdaf(iter, dim_p, dim_cvec, cv_p, Vv_p)
     207
     208  INTEGER, INTENT(in) :: iter           ! Iteration of optimization
     209  INTEGER, INTENT(in) :: dim_p          ! PE-local observation dimension
     210  INTEGER, INTENT(in) :: dim_cvec       ! Dimension of control vector
     211  REAL, INTENT(in)    :: cv_p(dim_cvec) ! PE-local control vector
     212  REAL, INTENT(inout) :: Vv_p(dim_p)    ! PE-local result vector (state vector increment)
     213}}}
     214
     215The routine is called during the analysis step during the iterative minimization of the cost function.
     216It has to apply the control vector transformation to the control vector and return the transformed result vector. Usually this transformation is the multiplication with the square-root of the background error covariance matrix '''B'''.
     217
     218If the control vector is decomposed in case of parallelization it first needs to the gathered on each processor and afterwards the transformation is computed on the potentially domain-decomposed state vector.
     219
     220
     221=== `U_cvt_adj` (cvt_adj_pdaf.F90) ===
     222
     223The interface for this routine is:
     224{{{
     225SUBROUTINE cvt_adj_pdaf(iter, dim_p, dim_cvec, Vv_p, cv_p)
     226
     227  INTEGER, INTENT(in) :: iter           ! Iteration of optimization
     228  INTEGER, INTENT(in) :: dim_p          ! PE-local observation dimension
     229  INTEGER, INTENT(in) :: dim_cvec       ! Dimension of control vector
     230  REAL, INTENT(in)    :: Vv_p(dim_p)    ! PE-local result vector (state vector increment)
     231  REAL, INTENT(inout) :: cv_p(dim_cvec) ! PE-local control vector
     232}}}
     233
     234The routine is called during the analysis step during the iterative minimization of the cost function.
     235It has to apply the adjoint control vector transformation to a state vector and return the control vector. Usually this transformation is the multiplication with transposed of the square-root of the background error covariance matrix '''B'''.
     236
     237If the state vector is decomposed in case of parallelization one needs to take care that the application of the trasformation is complete. This usually requries a comminucation with MPI_Allreduce to obtain a global sun.
     238
     239
     240
     241=== `U_obs_op_lin` (obs_op_pdaf_lin.F90) ===
     242
     243This routine is used by all 3D-Var methods.
     244
     245The interface for this routine is:
     246{{{
     247SUBROUTINE obs_op_lin(step, dim_p, dim_obs_p, state_p, m_state_p)
     248
     249  INTEGER, INTENT(in) :: step               ! Current time step
     250  INTEGER, INTENT(in) :: dim_p              ! PE-local dimension of state
     251  INTEGER, INTENT(in) :: dim_obs_p          ! Dimension of observed state
     252  REAL, INTENT(in)    :: state_p(dim_p)     ! PE-local model state
     253  REAL, INTENT(out) :: m_state_p(dim_obs_p) ! PE-local observed state
     254}}}
     255
     256The routine is called during the analysis step. It has to perform the operation of the linearized observation operator acting on a state vector increment that is provided as `state_p`. The observed state has to be returned in `m_state_p`.
     257
     258For a model using domain decomposition, the operation is on the PE-local sub-domain of the model and has to provide the observed sub-state for the PE-local domain.
     259
     260Hint:
     261 * If the observation operator involves a global operation, e.g. some global integration, while using domain-decomposition one has to gather the information from the other model domains using MPI communication.
     262
     263
     264=== `U_obs_op_adj` (obs_op_pdaf_adj.F90) ===
     265
     266This routine is used by all 3D-Var methods.
     267
     268The interface for this routine is:
     269{{{
     270SUBROUTINE obs_op_adj(step, dim_p, dim_obs_p, state_p, m_state_p)
     271
     272  INTEGER, INTENT(in) :: step                 ! Current time step
     273  INTEGER, INTENT(in) :: dim_p                ! PE-local dimension of state
     274  INTEGER, INTENT(in) :: dim_obs_p            ! Dimension of observed state
     275  REAL, INTENT(in)    :: m_state_p(dim_obs_p) ! PE-local observed state
     276  REAL, INTENT(out)   :: state_p(dim_p)       ! PE-local model state
     277}}}
     278
     279The routine is called during the analysis step. It has to perform the operation of the adjoint observation operator acting on a vector in observation space that is provided as m_state_p. The resulting state vector has to be returned in `m_state_p`.
     280
     281For a model using domain decomposition, the operation is on the PE-local sub-domain of the model and has to provide the observed sub-state for the PE-local domain.
     282
     283Hint:
     284 * If the observation operator involves a global operation, e.g. some global integration, while using domain-decomposition one has to gather the information from the other model domains using MPI communication.
     285
     286
     287
     288=== `U_prepoststep` (prepoststep_ens_pdaf.F90) ===
     289
     290The routine has already been described for modifying the model for the ensemble integration and for inserting the analysis step.
     291
     292See the page on [InsertAnalysisStep#U_prepoststepprepoststep_ens_pdaf.F90 inserting the analysis step] for the description of this routine.
     293
     294
     295=== `U_next_observation` (next_observation_pdaf.F90) ===
     296
     297This routine is independent of the filter algorithm used.
     298
     299See the page on [InsertAnalysisStep#U_next_observationnext_observation_pdaf.F90 inserting the analysis step] for the description of this routine.
     300
     301
     302== Execution order of user-supplied routines ==
     303
     304The user-supplied routines are essentially executed in the order they are listed in the interface to `PDAFomi_assimilate_3dvar`. The order can be important as some routines can perform preparatory work for later routines. For example, `U_init_dim_obs_pdafomi` prepares an index array that provides the information for executing the observation operator in `U_obs_op_pdafomi`. How this information is initialized is described in the documentation of OMI.
     305
     306Before the analysis step is called the following routine is executed:
     307 1. [#U_collect_statecollect_state_pdaf.F90 U_collect_state]
     308
     309The analysis step is executed when the ensemble integration of the forecast is completed. During the analysis step the following routines are executed in the given order:
     310 1. [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep] (Call to act on the forecast ensemble, called with negative value of the time step)
     311 1. [#U_init_dim_obs_pdafomicallback_obs_pdafomi.F90 U_init_dim_obs_pdafomi]
     312 1. [#U_obs_op_pdafomicallback_obs_pdafomi.F90 U_obs_op_pdafomi] (multiple calls, one for each ensemble member)
     313
     314Inside the analysis step the interative optimization is computed. This involves the repeated call of the routines:
     315 1. [#U_cvtcvt_pdaf.F90 U_cvt]
     316 1. [#U_obs_op_linpdafomicallback_obs_pdafomi.F90 U_obs_op_lin_pdafomi]
     317 1. [#U_obs_op_adjpdafomicallback_obs_pdafomi.F90 U_obs_op_adj_pdafomi]
     318 1. [#U_cvt_adjcvt_adj_pdaf.F90 U_cvt_adj]
     319
     320After the iterative optimization the following routines are executes to complte the analysis step:
     321 1. [#U_cvtcvt_pdaf.F90 U_cvt] (Call to the control vector transform to compute the final state vector increment
     322 1. [#U_prepoststepprepoststep_ens_pdaf.F90 U_prepoststep] (Call to act on the analysis ensemble, called with (positive) value of the time step)
     323
     324In case of the routine `PDAFomi_assimilate_3dvar`, the following routines are executed after the analysis step:
     325 1. [#U_distribute_statedistribute_state_pdaf.F90 U_distribute_state]
     326 1. [#U_next_observationnext_observation_pdaf.F90 U_next_observation]