source: CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/DRIVER/opa9.driver @ 4873

Last change on this file since 4873 was 4873, checked in by acosce, 4 years ago

Add flag Reproducibility_after_restart in OPA to allow simulation to be identical even if we make a restart during the simulation

File size: 11.0 KB
Line 
1#!/bin/ksh
2#-----------------------------------------------------------------
3function OCE_Initialize
4{
5    IGCM_debug_PushStack "OCE_Initialize"
6
7    JOB_NAME=${config_UserChoices_JobName}
8
9    RESOL_OCE_ICE=$( echo ${RESOL} | awk "-Fx" '{print $1}' )
10    case ${RESOL_OCE_ICE} in
11        ( *LIM2* ) SEAICE_MODEL=LIM2 ;  LIM_VERSION=2 ;;
12        ( *LIM3* ) SEAICE_MODEL=LIM3 ;  LIM_VERSION=3 ;;
13        ( *CICE* ) SEAICE_MODEL=CICE                  ;;
14        ( *      ) SEAICE_MODEL=UNKNOWN               ;;
15    esac
16    RESOL_OCE=$( echo ${RESOL_OCE_ICE} | sed "s/${SEAICE_MODEL}//" )
17
18    IGCM_debug_Print 1 "RESOL          : ${RESOL}"
19    IGCM_debug_Print 1 "RESOL_OCE_ICE  : ${RESOL_OCE_ICE}"
20    IGCM_debug_Print 1 "SEAICE_MODEL   : ${SEAICE_MODEL}"
21    IGCM_debug_Print 1 "LIM_VERSION    : ${LIM_VERSION}"
22    IGCM_debug_Print 1 "RESOL_OCE      : ${RESOL_OCE}"
23
24    # Local function to find namelists parameters
25    #supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" ; }
26    supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" -e "s%^ *$1 *=%%" ; }
27    ##--Variables used by OPA --
28    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
29    IGCM_debug_Print 1 "namelist_cfg : ${NAMELIST_OPA_CFG}"
30    if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
31        IGCM_debug_Exit "${NAMELIST_OPA_CFG} not found"
32        IGCM_debug_Verif_Exit
33    fi
34    OPA_RDT=$(       supergrep rn_rdt        ${NAMELIST_OPA_CFG} )
35    OPA_NN_FSBC=$(   supergrep nn_fsbc       ${NAMELIST_OPA_CFG} )
36    #
37    # OPA_RDT=$(       supergrep rn_rdt        namelist_cfg )
38    # OPA_NN_FSBC=$(   supergrep nn_fsbc       namelist_cfg )
39    (( OPA_NPDT_DAY   =  86400 / OPA_RDT        ))
40    (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
41    (( OPA_RDT_SBC    =  OPA_RDT * OPA_NN_FSBC ))
42 
43    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
44    # /!\ Needed by OPA namelist to compute file names /!\
45    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
46
47    IGCM_debug_Print 1 " "
48    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
49    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
50    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
51    IGCM_debug_Print 1 "OPA_NPDT_DAY   ${OPA_NPDT_DAY}"
52    IGCM_debug_Print 1 "OPA_NPDT_YEAR  ${OPA_NPDT_YEAR}"
53    IGCM_debug_Print 1 "DaysSinceJC    ${DaysSinceJC}"
54
55    ## Check that nn_fsbc is correct compare to coupling frequency
56    FreqCoupling=${oasis_UserChoices_FreqCoupling:-86400}
57   
58    ## This informations are used for diaptr, trends and diagap files
59    ## only the first frequency is used for this files
60   
61    IGCM_debug_Print 1 "FreqCoupling    ${FreqCoupling}"
62    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
63    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
64    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
65   
66    if [[ ${OPA_RDT_SBC} -gt ${FreqCoupling} ]] ; then
67        IGCM_debug_Exit "OPA_RDT_SBC=${OPA_RDT_SBC} is greater than FreqCoupling=${FreqCoupling}"
68        IGCM_debug_Verif_Exit
69    fi
70   
71    IGCM_debug_PopStack "OCE_Initialize"
72   
73}
74
75#-----------------------------------------------------------------
76function OCE_Update
77{
78    IGCM_debug_PushStack "OCE_Update"
79 
80    ##--Write Frequency for iomput
81    ## Differents frequencies are allowed for grid_[TUVW] and icemod files
82
83    V1D_ENABLE=".FALSE."
84    V1M_ENABLE=".FALSE."
85    V1Y_ENABLE=".FALSE."
86
87    for frequency in ${config_OCE_WriteFrequency} ; do
88        case ${frequency} in
89            ( 1D|1d ) V1D_ENABLE=".TRUE." ;;
90            ( 1M|1m ) V1M_ENABLE=".TRUE." ;;
91            ( *[yY] ) V1Y_ENABLE=".TRUE." ;;
92        esac
93    done
94
95    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
96    # Needed by OPA namelist to compute correct file names
97    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
98
99    ##-- Number of time steps updated : the first, the last and the number of time steps
100    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NPDT_DAY + 1 ))
101    (( OPA_NPDT   = PeriodLengthInDays * OPA_NPDT_DAY ))
102    (( OPA_NITEND = OPA_NIT000 + OPA_NPDT - 1))
103
104    ##-- We force one restart file at the end of the trunk
105    OPA_NSTOCK="${OPA_NITEND}"
106
107    ##-- Additionnal Restart Option to force reproducibility ; force kt to kt red in restart file
108    ## ${opa9_UserChoices_Reproducibility_after_restart}
109   
110    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices Reproducibility_after_restart
111
112    ##-- Restart configuration
113    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
114        OPA_LRSTAR=.TRUE.
115        OPA_NRSTDT=2
116        #echo "OPA RESTART"
117        IGCM_debug_Print 1 'WARNING : dangerous option for NEMO opa9 pisces lim3'
118        IGCM_debug_Print 1 'Reproducibility_after_Restart forced ie kt forced to kt red in restart file : ' ${opa9_UserChoices_Reproducibility_after_restart}
119        OPA_NMSH=0
120    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
121        OPA_LRSTAR=.FALSE.
122        OPA_NRSTDT=0
123        # Put OPA_NMSH=0 when OPA running in parallel mode
124        OPA_NMSH=1
125        #echo "NO OPA RESTART"
126    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
127        OPA_LRSTAR=.TRUE.
128        OPA_NRSTDT=0
129        OPA_NMSH=1
130        #echo "OPA RESTART"
131    else
132        OPA_LRSTAR=.TRUE.
133        OPA_NRSTDT=2
134        OPA_NMSH=0
135        #echo "OPA RESTART"
136    fi
137
138    ##-- Meshmask option
139    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask
140
141    if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then
142        OPA_NMSH=1
143        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n"
144    fi
145
146    # nleapy configuration
147    case ${config_UserChoices_CalendarType} in
148        ( leap|gregorian) OPA_NLEAPY=1  ;;
149        ( noleap        ) OPA_NLEAPY=0  ;;
150        ( 360d          ) OPA_NLEAPY=30 ;;
151        ( *             ) OPA_NLEAPY=30 ;;
152    esac
153
154    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
155        ##-- choose the right restart file
156        NEMO_RESTART_FILE=restartopa.nc
157        [ -f restartopa_0000.nc ] && NEMO_RESTART_FILE=restartopa_0000.nc
158        ##-- Getting from restart file the last time step of the run at which we want to re-start
159        NEMO_KT_FROM_RESTART=$(ncdump -v kt ${NEMO_RESTART_FILE}|grep 'kt ='|awk '{print $3}' )
160
161        if ( [ "${CumulPeriod}" -eq 1 ] ) ; then
162            ## Force the date in the restart file to be the last day before the begining of the new run
163            dateendprevious=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} -1 )
164            IGCM_debug_Print 1 "Previous Date  ${dateendprevious}"
165            IGCM_debug_Print 1 "cmd done to modify NEMO restartfile:   ncap2 -s ndastp=${dateendprevious} ${NEMO_RESTART_FILE}  tmp.nc"
166            if [ -f restartopa_0000.nc ] ; then
167                typeset -Z4 ncpu=0
168                while [ $ncpu -lt ${OCE_PROC_MPI} ] ; do
169                    ncap2 -s "ndastp=${dateendprevious}" restartopa_${ncpu}.nc  tmp.nc
170                    mv tmp.nc restartopa_${ncpu}.nc
171                    (( ncpu = ncpu + 1 ))
172                done
173            else
174                ncap2 -s "ndastp=${dateendprevious}" ${NEMO_RESTART_FILE}  tmp.nc
175                mv tmp.nc ${NEMO_RESTART_FILE}
176            fi
177            ##-- Getting from restart file the "new" restart date of run at which we want to re-start
178            NEMO_NDASTP_FROM_RESTART=$(ncdump -v ndastp ${NEMO_RESTART_FILE}|grep 'ndastp ='|awk '{print $3}' )
179            IGCM_debug_Print 1 "NEMO_NDASTP (from Restart) for 1st Period       : ${NEMO_NDASTP_FROM_RESTART}"
180
181        fi
182
183        (( NEMO_NIT000 = NEMO_KT_FROM_RESTART + 1 ))
184        (( NEMO_NITEND = NEMO_KT_FROM_RESTART + OPA_NITEND - OPA_NIT000 + 1 ))
185        IGCM_debug_Print 1 "NEMO_NIT000 (from Restart)        : ${NEMO_NIT000}"
186        IGCM_debug_Print 1 "NEMO_NITEND (from Restart + ... ) : ${NEMO_NITEND}"
187        ##-- We force one restart file at the end of the trunk
188        OPA_NSTOCK="${NEMO_NITEND}"
189        OPA_NIT000="${NEMO_NIT000}"
190        OPA_NITEND="${NEMO_NITEND}"
191    fi
192
193    typeset -r PRECIS=8
194    NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
195
196    IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp    ${config_UserChoices_JobName}
197    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000  ${OPA_NIT000}
198    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend  ${OPA_NITEND}
199    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart ${OPA_LRSTAR}
200    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock  ${OPA_NSTOCK}
201    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl ${OPA_NRSTDT}
202    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0  ${PeriodDateBegin}
203    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh    ${OPA_NMSH}
204    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_rnf_depth_file  ${OPA_NMSH}
205    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy  ${OPA_NLEAPY}
206   
207    # Update iodef.xml
208
209    IGCM_debug_Print 1 'Informations into iodef.xml : V1D_ENABLE V1M_ENABLE V1Y_ENABLE '
210    IGCM_debug_Print 1 ${V1D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE}
211
212    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d enabled ${V1D_ENABLE}
213    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m enabled ${V1M_ENABLE}
214    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y enabled ${V1Y_ENABLE}
215       
216    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-lim.xml 1d enabled ${V1D_ENABLE}
217    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-lim.xml 1m enabled ${V1M_ENABLE}
218    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-lim.xml 1y enabled ${V1Y_ENABLE}
219
220    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-pisces.xml 1d enabled ${V1D_ENABLE}
221    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-pisces.xml 1m enabled ${V1M_ENABLE}
222    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-pisces.xml 1y enabled ${V1Y_ENABLE}
223
224    # vargas/titane/MPP and switch from 1 proc to 5 procs. We need to suppres restartopa the second month, if restartopa_0000 exist
225    # same thing for restart_trc and restart_ice_in
226
227    for restartfilenemo in restartopa restart_trc restart_ice_in ; do
228      [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc
229    done
230
231    # Add include of nemo context in iodef.xml
232    # In iodef.xml add on next line after "COMPONENT CONTEXT"
233    #  <context id="nemo" src="./context_nemo.xml"/>
234    echo '<context id="nemo" src="./context_nemo.xml"/>' > add.tmp
235    cp iodef.xml iodef.xml.tmp
236    sed -e "/COMPONENT CONTEXT/r add.tmp" \
237        iodef.xml.tmp > iodef.xml
238    rm iodef.xml.tmp add.tmp
239
240    #Long Name as global attribute (if LongName is not empty)
241    if [ ! "X${config_UserChoices_LongName}" = "X" ] ; then
242        listfile=$(ls file_def_nemo*.xml)
243        echo "<variable id=\"LongName\" type=\"string\">${config_UserChoices_LongName}</variable>" > add.tmp
244        for file in ${listfile}
245        do
246            cp ${file} ${file}.tmp
247            sed -e "/<file id/r add.tmp" \
248                ${file}.tmp > ${file}
249            rm ${file}.tmp
250        done
251        rm add.tmp
252    fi
253
254    IGCM_debug_PopStack "OCE_Update"
255}
256
257#-----------------------------------
258function OCE_Finalize
259{
260    IGCM_debug_PushStack "OCE_Finalize"
261
262    IGCM_debug_Print 1 FINALIZE OCE !!!
263
264    IGCM_debug_PopStack "OCE_Finalize"
265}
Note: See TracBrowser for help on using the repository browser.