source: CONFIG_DEVT/IPSLCM6.2.2_ENSEMBLES/config/IPSLCM6/CM622-ENSEMBLES.01/DRIVER/opa9.driver @ 6232

Last change on this file since 6232 was 6232, checked in by aclsce, 23 months ago

Fixed pb when starting from different initial restart files.
Added configuration files for non depeuplement launching.

File size: 15.7 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    if [ X$ResolOce != X ]; then 
10        #ResolOce is set in config.card
11        RESOL_OCE=${ResolOce}
12        IGCM_debug_Print 1 "RESOL_OCE      : ${RESOL_OCE}"
13
14    elif [ -f ${SUBMIT_DIR}/../.resol ] ; then
15        RESOL_OCE_ICE=$( echo ${RESOL} | awk "-Fx" '{print $1}' )
16        case ${RESOL_OCE_ICE} in
17            ( *LIM2* ) SEAICE_MODEL=LIM2 ;      LIM_VERSION=2 ;;
18            ( *LIM3* ) SEAICE_MODEL=LIM3 ;      LIM_VERSION=3 ;;
19            ( *CICE* ) SEAICE_MODEL=CICE                  ;;
20            ( *      ) SEAICE_MODEL=UNKNOWN               ;;
21        esac
22        RESOL_OCE=$( echo ${RESOL_OCE_ICE} | sed "s/${SEAICE_MODEL}//" )
23        IGCM_debug_Print 1 "RESOL_OCE_ICE  : ${RESOL_OCE_ICE}"
24        IGCM_debug_Print 1 "RESOL          : ${RESOL}"
25        IGCM_debug_Print 1 "SEAICE_MODEL   : ${SEAICE_MODEL}"
26        IGCM_debug_Print 1 "LIM_VERSION    : ${LIM_VERSION}"
27        IGCM_debug_Print 1 "RESOL_OCE      : ${RESOL_OCE}"
28    else
29        IGCM_debug_Exit "ResolAtm is not set in config.card and the .resol file does not exist."
30        IGCM_debug_Verif_Exit
31    fi
32
33    # Local function to find namelists parameters
34    #supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" ; }
35    supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" -e "s%^ *$1 *=%%" ; }
36    ##--Variables used by OPA --
37    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
38    IGCM_debug_Print 1 "namelist_cfg : ${NAMELIST_OPA_CFG}"
39    if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
40        IGCM_debug_Exit "${NAMELIST_OPA_CFG} not found"
41        IGCM_debug_Verif_Exit
42    fi
43    OPA_RDT=$(       supergrep rn_rdt        ${NAMELIST_OPA_CFG} )
44    OPA_NN_FSBC=$(   supergrep nn_fsbc       ${NAMELIST_OPA_CFG} )
45    #
46    # OPA_RDT=$(       supergrep rn_rdt        namelist_cfg )
47    # OPA_NN_FSBC=$(   supergrep nn_fsbc       namelist_cfg )
48    (( OPA_NPDT_DAY   =  86400 / OPA_RDT        ))
49    (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
50    (( OPA_RDT_SBC    =  OPA_RDT * OPA_NN_FSBC ))
51 
52    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
53    # /!\ Needed by OPA namelist to compute file names /!\
54    (( DaysSinceJC = $( IGCM_date_DaysSinceJC ${DateBegin} ) + 1 ))
55
56    IGCM_debug_Print 1 " "
57    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
58    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
59    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
60    IGCM_debug_Print 1 "OPA_NPDT_DAY   ${OPA_NPDT_DAY}"
61    IGCM_debug_Print 1 "OPA_NPDT_YEAR  ${OPA_NPDT_YEAR}"
62    IGCM_debug_Print 1 "DaysSinceJC    ${DaysSinceJC}"
63
64    ## Check that nn_fsbc is correct compare to coupling frequency
65    FreqCoupling=${oasis_UserChoices_FreqCoupling:-86400}
66   
67    ## This informations are used for diaptr, trends and diagap files
68    ## only the first frequency is used for this files
69   
70    IGCM_debug_Print 1 "FreqCoupling    ${FreqCoupling}"
71    IGCM_debug_Print 1 "OPA_NN_FSBC    ${OPA_NN_FSBC}"
72    IGCM_debug_Print 1 "OPA_RDT        ${OPA_RDT}"
73    IGCM_debug_Print 1 "OPA_RDT_SBC    ${OPA_RDT_SBC}"
74   
75    if [[ ${OPA_RDT_SBC} -gt ${FreqCoupling} ]] ; then
76        IGCM_debug_Exit "OPA_RDT_SBC=${OPA_RDT_SBC} is greater than FreqCoupling=${FreqCoupling}"
77        IGCM_debug_Verif_Exit
78    fi
79
80    IGCM_debug_PopStack "OCE_Initialize"
81   
82}
83
84#-----------------------------------------------------------------
85function OCE_Update
86{
87    IGCM_debug_PushStack "OCE_Update"
88 
89    ##--Write Frequency for iomput
90    ## Differents frequencies are allowed for OCE files
91
92    V1D_ENABLE=".FALSE."
93    V5D_ENABLE=".FALSE."
94    V1M_ENABLE=".FALSE."
95    V1Y_ENABLE=".FALSE."
96
97    for frequency in ${config_OCE_WriteFrequency} ; do
98        case ${frequency} in
99            ( 1D|1d ) V1D_ENABLE=".TRUE." ;;
100            ( 5D|5d ) V5D_ENABLE=".TRUE." ;;
101            ( 1M|1m ) V1M_ENABLE=".TRUE." ;;
102            ( *[yY] ) V1Y_ENABLE=".TRUE." ;;
103        esac
104    done
105
106    # Period Length In Days between DateBegin and first day of calendar 0001 01 01
107    # Needed by OPA namelist to compute correct file names
108    (( PeriodDaysSinceJC =  $( IGCM_date_DaysSinceJC ${PeriodDateBegin} ) + 1  ))
109
110    ##-- Number of time steps updated : the first, the last and the number of time steps
111    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NPDT_DAY + 1 ))
112    (( OPA_NPDT   = PeriodLengthInDays * OPA_NPDT_DAY ))
113    (( OPA_NITEND = OPA_NIT000 + OPA_NPDT - 1))
114
115    ##-- We force one restart file at the end of the trunk
116    OPA_NSTOCK="${OPA_NITEND}"
117
118
119    ##-- Additionnal Restart Option to force reproducibility ; force kt to kt red in restart file
120    ## ${opa9_UserChoices_Reproducibility_after_restart}
121
122    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices Reproducibility_after_restart
123
124   ##-- Restart configuration
125    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
126      OPA_LRSTAR=.TRUE.
127      OPA_NRSTDT=2
128      #echo "OPA RESTART"
129      IGCM_debug_Print 1 'WARNING : dangerous option for NEMO opa9 pisces lim3'
130      IGCM_debug_Print 1 'Reproducibility_after_Restart forced ie kt forced to kt red in restart file : ' ${opa9_UserChoices_Reproducibility_after_restart}
131
132    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
133      OPA_LRSTAR=.FALSE.
134      OPA_NRSTDT=0
135      #echo "NO OPA RESTART"
136    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
137      OPA_LRSTAR=.TRUE.
138      OPA_NRSTDT=0
139      #echo "OPA RESTART"
140    else
141      OPA_LRSTAR=.TRUE.
142      OPA_NRSTDT=2
143      #echo "OPA RESTART"
144    fi
145
146    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${opa9_UserChoices_Restart_TS_only}" = "y" ] ) ; then
147      OPA_LRSTAR_TS=.TRUE.
148    else
149      OPA_LRSTAR_TS=.FALSE.
150    fi
151
152    if ( [ "${opa9_UserChoices_Dynamics_on_ClosedSeas}" = "n" ] ) ; then
153      OPA_CLODYN=.TRUE.
154    else
155      OPA_CLODYN=.FALSE.
156    fi
157
158    ##-- Meshmask option. Forced only once.
159    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask
160
161    OPA_NMSH=0
162    if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then
163        OPA_NMSH=1
164        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n"
165    fi
166
167    # nleapy configuration
168    case ${config_UserChoices_CalendarType} in
169        ( leap|gregorian) OPA_NLEAPY=1  ;;
170        ( noleap        ) OPA_NLEAPY=0  ;;
171        ( 360d          ) OPA_NLEAPY=30 ;;
172        ( *             ) OPA_NLEAPY=30 ;;
173    esac
174    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
175        cd ..
176        if [ ${config_Ensemble_EnsembleXIOS} = TRUE ] ; then
177            for (( pool_member_rank=$(($pool_rank*$config_Ensemble_PoolSize)) ; pool_member_rank < $((($pool_rank+1)*$config_Ensemble_PoolSize)) ; pool_member_rank++ ))
178            do
179                if [ -d MEMBER_$pool_member_rank ] ; then
180                    cd MEMBER_$pool_member_rank
181                    NEMO_RESTART_FILE=restartopa.nc
182                    [ -f restartopa_0000.nc ] && NEMO_RESTART_FILE=restartopa_0000.nc
183
184                    ##-- Getting from restart file the last time step of the run at which we want to re-start
185                    NEMO_KT_FROM_RESTART=$(ncdump -v kt ${NEMO_RESTART_FILE}|grep 'kt ='|awk '{print $3}' )
186                   
187                    if ( [ "${CumulPeriod}" -eq 1 ] ) ; then
188                        ## Force the date in the restart file to be the last day before the begining of the new run
189                        dateendprevious=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} -1 )
190                        IGCM_debug_Print 1 "Previous Date  ${dateendprevious}"
191                        IGCM_debug_Print 1 "cmd done to modify NEMO restartfile:   ncap2 -s ndastp=${dateendprevious} ${NEMO_RESTART_FILE}  tmp.nc"
192                        if [ -f restartopa_0000.nc ] ; then
193                            typeset -Z4 ncpu=0
194                            while [ $ncpu -lt ${OCE_PROC_MPI} ] ; do
195                                ncap2 -s "ndastp=${dateendprevious}" restartopa_${ncpu}.nc  tmp.nc
196                                mv tmp.nc restartopa_${ncpu}.nc
197                                (( ncpu = ncpu + 1 ))
198                            done
199                        else
200                            ncap2 -s "ndastp=${dateendprevious}" ${NEMO_RESTART_FILE}  tmp.nc
201                            mv tmp.nc ${NEMO_RESTART_FILE}
202                        fi
203                        ##-- Getting from restart file the "new" restart date of run at which we want to re-start
204                        NEMO_NDASTP_FROM_RESTART=$(ncdump -v ndastp ${NEMO_RESTART_FILE}|grep 'ndastp ='|awk '{print $3}' )
205                        IGCM_debug_Print 1 "NEMO_NDASTP (from Restart) for 1st Period       : ${NEMO_NDASTP_FROM_RESTART}"
206                       
207                    fi
208                   
209                    (( NEMO_NIT000 = NEMO_KT_FROM_RESTART + 1 ))
210                    (( NEMO_NITEND = NEMO_KT_FROM_RESTART + OPA_NITEND - OPA_NIT000 + 1 ))
211                    IGCM_debug_Print 1 "NEMO_NIT000 (from Restart)        : ${NEMO_NIT000}"
212                    IGCM_debug_Print 1 "NEMO_NITEND (from Restart + ... ) : ${NEMO_NITEND}"
213                    ##-- We force one restart file at the end of the trunk
214                    OPA_NSTOCK="${NEMO_NITEND}"
215                    OPA_NIT000="${NEMO_NIT000}"
216                    OPA_NITEND="${NEMO_NITEND}"
217
218                    cp  --remove-destination ../ENSEMBLE_TEMPLATE/namelist_cfg namelist_cfg
219
220                    IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp       ${config_UserChoices_JobName}
221                    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000     ${OPA_NIT000}
222                    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend     ${OPA_NITEND}
223                    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart    ${OPA_LRSTAR}
224                    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart_ts ${OPA_LRSTAR_TS}
225                    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_clodyn    ${OPA_CLODYN}
226                    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock     ${OPA_NSTOCK}
227                    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl    ${OPA_NRSTDT}
228                    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0     ${PeriodDateBegin}
229                    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh       ${OPA_NMSH}
230                    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_rnf_depth_file  ${OPA_NMSH}
231                    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy     ${OPA_NLEAPY}
232
233                    # Domain decomposition : use of value in opa9.card or DEFAULT value.
234
235                    if [ ! X${opa9_UserChoices_Nproc_ni} = X ] ; then
236                        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpni ${opa9_UserChoices_Nproc_ni}
237                    else
238                        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpni DEFAULT
239                    fi
240                    if [ ! X${opa9_UserChoices_Nproc_nj} = X ] ; then
241                        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnj ${opa9_UserChoices_Nproc_nj}
242                    else
243                        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnj DEFAULT
244                    fi
245                    if [ ! X${opa9_UserChoices_Total_nproc} = X ] ; then
246                        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnij ${opa9_UserChoices_Total_nproc}
247                    else
248                        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnij DEFAULT
249                    fi
250                   
251                   
252                    cd ..
253                fi
254            done
255            cd ENSEMBLE_TEMPLATE
256        fi
257    fi
258    # typeset -r PRECIS=8
259    # NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) )
260
261    # IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp       ${config_UserChoices_JobName}
262    # IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000     ${OPA_NIT000}
263    # IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend     ${OPA_NITEND}
264    # IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart    ${OPA_LRSTAR}
265    # IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart_ts ${OPA_LRSTAR_TS}
266    # IGCM_comp_modifyNamelist blocker    namelist_cfg ln_clodyn    ${OPA_CLODYN}
267    # IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock     ${OPA_NSTOCK}
268    # IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl    ${OPA_NRSTDT}
269    # IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0     ${PeriodDateBegin}
270    # IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh       ${OPA_NMSH}
271    # IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_rnf_depth_file  ${OPA_NMSH}
272    # IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy     ${OPA_NLEAPY}
273
274    # # Domain decomposition : use of value in opa9.card or DEFAULT value.
275
276    # if [ ! X${opa9_UserChoices_Nproc_ni} = X ] ; then
277    #    IGCM_comp_modifyNamelist nonblocker namelist_cfg jpni ${opa9_UserChoices_Nproc_ni}
278    # else
279    #   IGCM_comp_modifyNamelist nonblocker namelist_cfg jpni DEFAULT
280    # fi
281    # if [ ! X${opa9_UserChoices_Nproc_nj} = X ] ; then
282    #    IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnj ${opa9_UserChoices_Nproc_nj}
283    # else
284    #     IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnj DEFAULT
285    # fi
286    # if [ ! X${opa9_UserChoices_Total_nproc} = X ] ; then
287    #    IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnij ${opa9_UserChoices_Total_nproc}
288    # else
289    #     IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnij DEFAULT
290    # fi
291
292    # Update iodef.xml
293
294    IGCM_debug_Print 1 'Informations into iodef.xml : V1D_ENABLE V5D_ENABLE V1M_ENABLE V1Y_ENABLE '
295    IGCM_debug_Print 1 ${V1D_ENABLE}  ${V5D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE}
296
297    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa enabled ${V1D_ENABLE}
298    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa enabled ${V5D_ENABLE}
299    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa enabled ${V1M_ENABLE}
300    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa enabled ${V1Y_ENABLE}
301
302    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa output_level ${opa9_UserChoices_OutputLevel}
303    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa output_level ${opa9_UserChoices_OutputLevel}
304    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa output_level ${opa9_UserChoices_OutputLevel}
305    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa output_level ${opa9_UserChoices_OutputLevel}
306
307
308    # Update reference year/month/day
309    IGCM_date_GetYearMonthDay ${DateBegin} iyear imonth iday
310    IGCM_comp_modifyXmlFile force context_nemo.xml ref_year  NONE ${iyear} 
311    IGCM_comp_modifyXmlFile force context_nemo.xml ref_month NONE ${imonth} 
312    IGCM_comp_modifyXmlFile force context_nemo.xml ref_day   NONE ${iday} 
313   
314   
315    # for MPP and switch to different number of procs for NEMO.  We need to suppres restartopa the second period, if restartopa_0000 exist
316    # same thing for restart_trc and restart_ice_in
317
318    for restartfilenemo in restartopa restart_trc restart_ice_in ; do
319      [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc
320    done
321
322    # Add include of nemo context in iodef.xml
323    # In iodef.xml add on next line after "COMPONENT CONTEXT"
324    #  <context id="nemo" src="./context_nemo.xml"/>
325    echo '<context id="nemo" src="./context_nemo.xml"/>' > add.tmp
326    if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
327      echo '<context id="nemo" src="./ping_nemo.xml"/>' >> add.tmp
328          echo '<context id="nemo" src="./dr2xml_opa9.xml"/>' >> add.tmp
329    fi
330    cp iodef.xml iodef.xml.tmp
331    sed -e "/COMPONENT CONTEXT/r add.tmp" \
332        iodef.xml.tmp > iodef.xml
333    rm iodef.xml.tmp add.tmp
334
335    #Long Name as global attribute (if LongName is not empty)
336    if [ ! "X${config_UserChoices_LongName}" = "X" ] ; then
337        listfile=$(ls file_def_nemo*.xml)
338        echo "<variable id=\"LongName\" type=\"string\">${config_UserChoices_LongName}</variable>" > add.tmp
339        for file in ${listfile}
340        do
341            cp ${file} ${file}.tmp
342            sed -e "/<file id/r add.tmp" \
343                ${file}.tmp > ${file}
344            rm ${file}.tmp
345        done
346        rm add.tmp
347    fi
348
349    #Compression level (if CompressionLevel is not empty)
350    if [ ! "X${config_UserChoices_CompressionLevel}" = "X" ] ; then
351        echo "NetCDF output files compression level is " ${config_UserChoices_CompressionLevel}
352        listfile=$(ls file_def_nemo*.xml)
353        for file in ${listfile}
354        do
355            sed -i -e "s/\(compression_level=\"\)[^\"]*\(\"\)/\1${config_UserChoices_CompressionLevel}\2/" ${file}
356        done
357    fi
358
359
360    IGCM_debug_PopStack "OCE_Update"
361}
362
363#-----------------------------------
364function OCE_Finalize
365{
366    IGCM_debug_PushStack "OCE_Finalize"
367
368    IGCM_debug_Print 1 FINALIZE OCE !!!
369
370    IGCM_debug_PopStack "OCE_Finalize"
371}
Note: See TracBrowser for help on using the repository browser.