source: CONFIG/UNIFORM/v6/IPSLCM6.2/GENERAL/DRIVER/opa9.driver

Last change on this file was 6013, checked in by aclsce, 3 years ago
  • Reset ByPass_hgardfou_teta, ByPass_hgardfou_mats and mesh_mask in following period within the same Job.
File size: 13.6 KB
RevLine 
[583]1#!/bin/ksh
2#-----------------------------------------------------------------
3function OCE_Initialize
4{
5    IGCM_debug_PushStack "OCE_Initialize"
6
7    JOB_NAME=${config_UserChoices_JobName}
[2117]8
[4616]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}"
[583]13
[4616]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
[2109]32
[653]33    # Local function to find namelists parameters
[2540]34    #supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" ; }
35    supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" -e "s%^ *$1 *=%%" ; }
[583]36    ##--Variables used by OPA --
[2198]37    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
[2379]38    IGCM_debug_Print 1 "namelist_cfg : ${NAMELIST_OPA_CFG}"
[2198]39    if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
[2540]40        IGCM_debug_Exit "${NAMELIST_OPA_CFG} not found"
41        IGCM_debug_Verif_Exit
[2198]42    fi
[2540]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 )
[2861]48    (( OPA_NPDT_DAY   =  86400 / OPA_RDT        ))
49    (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
[2540]50    (( OPA_RDT_SBC    =  OPA_RDT * OPA_NN_FSBC ))
[2267]51 
[583]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
[2379]56    IGCM_debug_Print 1 " "
[2540]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}"
[2861]60    IGCM_debug_Print 1 "OPA_NPDT_DAY   ${OPA_NPDT_DAY}"
61    IGCM_debug_Print 1 "OPA_NPDT_YEAR  ${OPA_NPDT_YEAR}"
[2540]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}
[2267]66   
[2540]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
[3735]79
[583]80    IGCM_debug_PopStack "OCE_Initialize"
[2379]81   
[583]82}
83
84#-----------------------------------------------------------------
85function OCE_Update
86{
87    IGCM_debug_PushStack "OCE_Update"
[2540]88 
[777]89    ##--Write Frequency for iomput
[3434]90    ## Differents frequencies are allowed for OCE files
[777]91
92    V1D_ENABLE=".FALSE."
[2999]93    V5D_ENABLE=".FALSE."
[777]94    V1M_ENABLE=".FALSE."
95    V1Y_ENABLE=".FALSE."
96
97    for frequency in ${config_OCE_WriteFrequency} ; do
98        case ${frequency} in
[2540]99            ( 1D|1d ) V1D_ENABLE=".TRUE." ;;
[2999]100            ( 5D|5d ) V5D_ENABLE=".TRUE." ;;
[2540]101            ( 1M|1m ) V1M_ENABLE=".TRUE." ;;
102            ( *[yY] ) V1Y_ENABLE=".TRUE." ;;
[777]103        esac
104    done
105
[583]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
[2861]111    (( OPA_NIT000 = ( PeriodDaysSinceJC - DaysSinceJC ) * OPA_NPDT_DAY + 1 ))
112    (( OPA_NPDT   = PeriodLengthInDays * OPA_NPDT_DAY ))
[2540]113    (( OPA_NITEND = OPA_NIT000 + OPA_NPDT - 1))
[583]114
115    ##-- We force one restart file at the end of the trunk
[2540]116    OPA_NSTOCK="${OPA_NITEND}"
[583]117
[3193]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
[4480]125    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
[3193]126      OPA_LRSTAR=.TRUE.
127      OPA_NRSTDT=2
128      #echo "OPA RESTART"
[3786]129      IGCM_debug_Print 1 'WARNING : dangerous option for NEMO opa9 pisces lim3'
[3193]130      IGCM_debug_Print 1 'Reproducibility_after_Restart forced ie kt forced to kt red in restart file : ' ${opa9_UserChoices_Reproducibility_after_restart}
[3786]131
[3193]132    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "n" ] ) ; then
133      OPA_LRSTAR=.FALSE.
134      OPA_NRSTDT=0
135      #echo "NO OPA RESTART"
[583]136    elif ( [ "${CumulPeriod}" -eq 1 ] && [ "${config_OCE_Restart}" = "y" ] ) ; then
[3193]137      OPA_LRSTAR=.TRUE.
138      OPA_NRSTDT=0
139      #echo "OPA RESTART"
[583]140    else
[3193]141      OPA_LRSTAR=.TRUE.
142      OPA_NRSTDT=2
143      #echo "OPA RESTART"
[583]144    fi
145
[3523]146    if ( [ "${CumulPeriod}" -eq 1 ] && [ "${opa9_UserChoices_Restart_TS_only}" = "y" ] ) ; then
[3518]147      OPA_LRSTAR_TS=.TRUE.
148    else
149      OPA_LRSTAR_TS=.FALSE.
150    fi
[3193]151
[4795]152    if ( [ "${opa9_UserChoices_Dynamics_on_ClosedSeas}" = "n" ] ) ; then
[4721]153      OPA_CLODYN=.TRUE.
154    else
[4446]155      OPA_CLODYN=.FALSE.
156    fi
157
[3121]158    ##-- Meshmask option. Forced only once.
[902]159    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask
[819]160
[3121]161    OPA_NMSH=0
[819]162    if [ "${opa9_UserChoices_mesh_mask}" = "y" ]; then
[2540]163        OPA_NMSH=1
[6013]164        export opa9_UserChoices_mesh_mask=n
[902]165        IGCM_card_WriteOption ${SUBMIT_DIR}/COMP/opa9.card UserChoices mesh_mask "n"
[819]166    fi
167
[583]168    # nleapy configuration
169    case ${config_UserChoices_CalendarType} in
[2540]170        ( leap|gregorian) OPA_NLEAPY=1  ;;
171        ( noleap        ) OPA_NLEAPY=0  ;;
172        ( 360d          ) OPA_NLEAPY=30 ;;
173        ( *             ) OPA_NLEAPY=30 ;;
[583]174    esac
175
[3786]176    if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
[3785]177      ##-- choose the right restart file
178      NEMO_RESTART_FILE=restartopa.nc
179      [ -f restartopa_0000.nc ] && NEMO_RESTART_FILE=restartopa_0000.nc
[3775]180      ##-- Getting from restart file the last time step of the run at which we want to re-start
[3785]181      NEMO_KT_FROM_RESTART=$(ncdump -v kt ${NEMO_RESTART_FILE}|grep 'kt ='|awk '{print $3}' )
[3798]182
183      if ( [ "${CumulPeriod}" -eq 1 ] ) ; then
184        ## Force the date in the restart file to be the last day before the begining of the new run
[3908]185        dateendprevious=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} -1 )
186        IGCM_debug_Print 1 "Previous Date  ${dateendprevious}"
187        IGCM_debug_Print 1 "cmd done to modify NEMO restartfile:   ncap2 -s ndastp=${dateendprevious} ${NEMO_RESTART_FILE}  tmp.nc"
[3835]188        if [ -f restartopa_0000.nc ] ; then
189           typeset -Z4 ncpu=0
190           while [ $ncpu -lt ${OCE_PROC_MPI} ] ; do
[3908]191              ncap2 -s "ndastp=${dateendprevious}" restartopa_${ncpu}.nc  tmp.nc
[3835]192              mv tmp.nc restartopa_${ncpu}.nc
193              (( ncpu = ncpu + 1 ))
194           done
195        else
[3908]196           ncap2 -s "ndastp=${dateendprevious}" ${NEMO_RESTART_FILE}  tmp.nc
[3835]197           mv tmp.nc ${NEMO_RESTART_FILE}
198        fi
[3798]199        ##-- Getting from restart file the "new" restart date of run at which we want to re-start
200        NEMO_NDASTP_FROM_RESTART=$(ncdump -v ndastp ${NEMO_RESTART_FILE}|grep 'ndastp ='|awk '{print $3}' )
201        IGCM_debug_Print 1 "NEMO_NDASTP (from Restart) for 1st Period       : ${NEMO_NDASTP_FROM_RESTART}"
202
203      fi
204
[3193]205      (( NEMO_NIT000 = NEMO_KT_FROM_RESTART + 1 ))
206      (( NEMO_NITEND = NEMO_KT_FROM_RESTART + OPA_NITEND - OPA_NIT000 + 1 ))
207      IGCM_debug_Print 1 "NEMO_NIT000 (from Restart)        : ${NEMO_NIT000}"
208      IGCM_debug_Print 1 "NEMO_NITEND (from Restart + ... ) : ${NEMO_NITEND}"
209      ##-- We force one restart file at the end of the trunk
210      OPA_NSTOCK="${NEMO_NITEND}"
211      OPA_NIT000="${NEMO_NIT000}"
212      OPA_NITEND="${NEMO_NITEND}"
213    fi
214
[583]215    typeset -r PRECIS=8
[2540]216    NEMO_END=$( echo $( awk "BEGIN { printf \"%0${PRECIS}d\",${OPA_NITEND} }" ) ) 
[583]217
[3518]218    IGCM_comp_modifyNamelist blocker    namelist_cfg cn_exp       ${config_UserChoices_JobName}
219    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_it000     ${OPA_NIT000}
220    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_itend     ${OPA_NITEND}
221    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart    ${OPA_LRSTAR}
222    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_rstart_ts ${OPA_LRSTAR_TS}
[4446]223    IGCM_comp_modifyNamelist blocker    namelist_cfg ln_clodyn    ${OPA_CLODYN}
[3518]224    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_stock     ${OPA_NSTOCK}
225    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_rstctl    ${OPA_NRSTDT}
226    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_date0     ${PeriodDateBegin}
227    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_msh       ${OPA_NMSH}
[2625]228    IGCM_comp_modifyNamelist nonblocker namelist_cfg nn_rnf_depth_file  ${OPA_NMSH}
[3518]229    IGCM_comp_modifyNamelist blocker    namelist_cfg nn_leapy     ${OPA_NLEAPY}
[5512]230
231    # Domain decomposition : use of value in opa9.card or DEFAULT value.
232
233    if [ ! X${opa9_UserChoices_Nproc_ni} = X ] ; then
[5514]234       IGCM_comp_modifyNamelist nonblocker namelist_cfg jpni ${opa9_UserChoices_Nproc_ni}
[5512]235    else
[5514]236        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpni DEFAULT
[5512]237    fi
238    if [ ! X${opa9_UserChoices_Nproc_nj} = X ] ; then
[5514]239       IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnj ${opa9_UserChoices_Nproc_nj}
[5512]240    else
[5514]241        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnj DEFAULT
[5512]242    fi
243    if [ ! X${opa9_UserChoices_Total_nproc} = X ] ; then
[5514]244       IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnij ${opa9_UserChoices_Total_nproc}
[5512]245    else
[5514]246        IGCM_comp_modifyNamelist nonblocker namelist_cfg jpnij DEFAULT
[5512]247    fi
248
[2540]249    # Update iodef.xml
[583]250
[2999]251    IGCM_debug_Print 1 'Informations into iodef.xml : V1D_ENABLE V5D_ENABLE V1M_ENABLE V1Y_ENABLE '
252    IGCM_debug_Print 1 ${V1D_ENABLE}  ${V5D_ENABLE} ${V1M_ENABLE} ${V1Y_ENABLE}
[1021]253
[3491]254    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa enabled ${V1D_ENABLE}
255    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa enabled ${V5D_ENABLE}
256    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa enabled ${V1M_ENABLE}
257    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa enabled ${V1Y_ENABLE}
[3490]258
[3634]259    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1d_opa output_level ${opa9_UserChoices_OutputLevel}
260    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 5d_opa output_level ${opa9_UserChoices_OutputLevel}
261    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1m_opa output_level ${opa9_UserChoices_OutputLevel}
262    IGCM_comp_modifyXmlFile nonblocker file_def_nemo-opa.xml 1y_opa output_level ${opa9_UserChoices_OutputLevel}
263
264
[4295]265    # Update reference year/month/day
266    IGCM_date_GetYearMonthDay ${DateBegin} iyear imonth iday
267    IGCM_comp_modifyXmlFile force context_nemo.xml ref_year  NONE ${iyear} 
268    IGCM_comp_modifyXmlFile force context_nemo.xml ref_month NONE ${imonth} 
269    IGCM_comp_modifyXmlFile force context_nemo.xml ref_day   NONE ${iday} 
270   
271   
[3785]272    # for MPP and switch to different number of procs for NEMO.  We need to suppres restartopa the second period, if restartopa_0000 exist
[1436]273    # same thing for restart_trc and restart_ice_in
274
275    for restartfilenemo in restartopa restart_trc restart_ice_in ; do
276      [ -f ${restartfilenemo}.nc ] && [ -f ${restartfilenemo}_0000.nc ] && IGCM_sys_Rm -f ${restartfilenemo}.nc
277    done
278
[2270]279    # Add include of nemo context in iodef.xml
280    # In iodef.xml add on next line after "COMPONENT CONTEXT"
281    #  <context id="nemo" src="./context_nemo.xml"/>
282    echo '<context id="nemo" src="./context_nemo.xml"/>' > add.tmp
[5117]283    if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then
284      echo '<context id="nemo" src="./ping_nemo.xml"/>' >> add.tmp
285          echo '<context id="nemo" src="./dr2xml_opa9.xml"/>' >> add.tmp
[3476]286    fi
[2270]287    cp iodef.xml iodef.xml.tmp
288    sed -e "/COMPONENT CONTEXT/r add.tmp" \
289        iodef.xml.tmp > iodef.xml
290    rm iodef.xml.tmp add.tmp
291
[2833]292    #Long Name as global attribute (if LongName is not empty)
293    if [ ! "X${config_UserChoices_LongName}" = "X" ] ; then
[2876]294        listfile=$(ls file_def_nemo*.xml)
[2833]295        echo "<variable id=\"LongName\" type=\"string\">${config_UserChoices_LongName}</variable>" > add.tmp
296        for file in ${listfile}
297        do
298            cp ${file} ${file}.tmp
299            sed -e "/<file id/r add.tmp" \
300                ${file}.tmp > ${file}
301            rm ${file}.tmp
302        done
303        rm add.tmp
304    fi
305
[4296]306    #Compression level (if CompressionLevel is not empty)
307    if [ ! "X${config_UserChoices_CompressionLevel}" = "X" ] ; then
[4297]308        echo "NetCDF output files compression level is " ${config_UserChoices_CompressionLevel}
309        listfile=$(ls file_def_nemo*.xml)
310        for file in ${listfile}
311        do
312            sed -i -e "s/\(compression_level=\"\)[^\"]*\(\"\)/\1${config_UserChoices_CompressionLevel}\2/" ${file}
313        done
[4296]314    fi
315
316
[583]317    IGCM_debug_PopStack "OCE_Update"
318}
319
320#-----------------------------------
321function OCE_Finalize
322{
323    IGCM_debug_PushStack "OCE_Finalize"
324
[2379]325    IGCM_debug_Print 1 FINALIZE OCE !!!
[583]326
327    IGCM_debug_PopStack "OCE_Finalize"
328}
Note: See TracBrowser for help on using the repository browser.