Changes between Version 9 and Version 10 of ExternalModelLoop


Ignore:
Timestamp:
May 24, 2025, 1:48:51 PM (8 weeks ago)
Author:
lnerger
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ExternalModelLoop

    v9 v10  
    5353  END DO pdaf_modelloop
    5454}}}
    55 This example is taken from the example implementation in `templates/online_flexible/`. The unconditional DO loop (while loop) allows for an arbirary number of repetitions. The exit of the loop is controlled by the exit flag `doexit`, which is obtained from `PDAF_get_fcst_info`. The variable `nsteps`, also obtained from PDAF_get_fcst_info, defines the number of time steps to be computed during the current forecast phase. This value has to be used in the model time stepping loop.
    56 
    57 The code changes for the ''flexible'' parallelization variant can usually be obtained by adapting the code for the ''fully parallel'' implementation variant.
    58 
    59 Apart from the changes described above we need to initialize the ensemble forecasting as in the ''fully parallel'' variant. In particular , we need to write the ensemble state vector values into the model fields. We need to set for PDAF how many time steps need to be done until the first observations are assimilated.  For these operations, we call the routine `PDAF_init_forecast` in the routine `init_pdaf`. This call is identical to that used in the ''fully parallel' variant.
     55This example is taken from the template implementation in `templates/online_flexible/`. The unconditional DO loop (while loop) allows for an arbirary number of repetitions. The exit of the loop is controlled by the exit flag `doexit`, which is obtained from `PDAF_get_fcst_info`. The variable `nsteps`, also obtained from PDAF_get_fcst_info, defines the number of time steps to be computed during the current forecast phase. This value has to be used in the model time stepping loop.
     56
     57To complete the forecasting there are four further steps required:
     581. We need to initialize the ensemble forecasting. Thus, we need to set how many time steps need to be done until the first observations are assimilated. In addition, we need to write the ensemble state vector values into the model fields. For these operations, we call the routine `PDAF_init_forecast` in the routine `init_pdaf`.
     591. We need to adapt for model code for the additional ensemble loop and related control structure with calling `PDAF_get_fcst_info` as described above.
     601. To enable that the analysis can be performed, we then have to insert the routine `assimilate_pdaf` into the model code.
     611. To be able to test whether the forecasting works correctly we also recommend to implement the routine `collect_state_pdaf` at this point. The routine is used in `assimilate_pdaf` to write the forecasted model fields into a state vector.
     62
     63These steps are described below. The code changes for the ''flexible'' parallelization variant can usually be obtained by adapting the code for the ''fully parallel'' implementation variant.
    6064
    6165
     
    8084
    8185
    82 == `PDAF_get_fcst_info` ==
     86== Adding `PDAF_get_fcst_info` ==
    8387
    8488The interface is the following:
     
    9195}}}
    9296
    93 These variables are intialized by `next_observation_pdaf` that was called by `PDAF_init_forecast`. At later forecast phases in the assimilation processing, the analysis routine `PDAF3_assimilation` (or more specifalize routines) will case `next_observation_pdaf`.
     97These variables are intialized by `next_observation_pdaf` that was called by `PDAF_init_forecast` and returned here to the user code. At later forecast phases in the assimilation processing, the analysis routine `PDAF3_assimilation` (or more specifalize routines) will case `next_observation_pdaf`.
    9498
    9599== Inserting `assimilate_pdaf` into the model code ==
     
    105109Details on the implementations of the user-routines for the analysis step ar provided in the [wiki:ImplementationofAnalysisStep Page on implementating the analysis step].
    106110
     111Relevant for the forecasting is that `PDAF3_assimilate` calls the user-supplied routine `collect_state_pdaf` which writes forecasted model fields into a state vector from PDAF's ensemble array. We recommend to implement the functionality in `collect_state_pdaf` at this point, even though we explain `PDAF3_assimilation` only later.
     112
     113== Completing `collect_state_pdaf`  ==
     114
     115The routine `collect_state_pdaf` (In file collect_state_pdaf.F90 in the tutorials and template), is called during the forecast phase for each state vector of the ensemble to write the forecasted model fields back into a state vector. This is the reserve operation to what is done in `distribute_state_pdaf`. The routine is executed by all processes that belong to model tasks.
     116
     117The full interface of this call-back routine is explained further below with the other user-supplied routines. When the functionality is implemented, one can test the forecasting. In particular one can already test funtionality in `prepoststep_pdaf` because PDAF will provide this routine with the ensemble array that was filled with the information from model fields by calls to `collect_state_pdaf`.
    107118
    108119== User-supplied routines ==
     
    188199
    189200
    190 == Compiling and testing ==
    191 
    192 To be able to test the ensemble forecasting, we need also need the user-supplied routine `collect_state_pdaf`. This routine writes the model fields after a forecast into the state vectors. This will be done in the call to `PDAF3_assimilate` in `assimilate_pdaf`. While we explain `assimilate_pdaf` on the following page, we include `collect_state_pdaf` here.
    193 
    194 Having implemented also `collect_state_pdaf`, one can test the program without having implemented the actual assimilation step. In the template code `template/online` all required user-supplied routines are included, but they don't contain functionality. However, one can use them to be able to compile and run the assimilation program for testing. In particular one can check if the ensemble forecasting works correctly.
    195 
    196 == `collect_state_pdaf` (collect_state_pdaf.F90) ==
     201
     202=== `collect_state_pdaf` (collect_state_pdaf.F90) ===
    197203
    198204The interface for this routine is
     
    204210}}}
    205211
    206 This routine is called during the forecast phase as many times as there are states to be integrated by a model task. It is called at the end of the integration of a state from the ensemble. The routine is executed by all processes that belong to model tasks.
    207 
    208 When the routine is called, a state vector `state_p` and its size `dim_p` are provided. The operation to be performed in this routine is inverse to that of the routine `distribute_state_pdaf`. That is, the state vector `state_p` has to be filled from the model fields.
     212The routine is called by `PDAF3_assimilate`, or similar assimilate routine, for each ensemble state for which a forecast was computed . It is executed by all processes that participate in the model integrations.
     213
     214PDAF calls this routine providing the state vector `state_p` and its size `dim_p`. The routine has to write the information from the model fields into this state vector. This is the reverse operation to that of the routine `distribute_state_pdaf`.
    209215
    210216Hint:
    211217* If the model is not parallelized, `state_p` will contain a full state vector. If the model is parallelized using domain decomposition, `state_p` will contain the part of the state vector that corresponds to the model sub-domain for the calling process.
    212218
     219== Compiling and testing ==
     220
     221One can test the program without having implemented the actual assimilation step. In the template code `template/online_flexible` all required user-supplied routines are included, but they do not contain functionality. However, one can use them to be able to compile and run the assimilation program for testing. In particular one can check if the ensemble forecasting works correctly.
     222
     223The flow of the modified model is now the following: `distribute_state_pdaf` provides each model task with a model state that is to be integrated. Having computed the forecast, `collect_state_pdaf` writes the propagated model fields back into a state vector from the ensemble array of PDAF. This array is then provided to `prepoststep_pdaf`. Thus, one can check if the forecasting works correctly. In `prepoststep_pdaf` one can access the ensemble. Here one can, e.g. compute the ensemble mean - thus the state estimate of the ensemble assimilation - and write this into a file.
     224