Beispiel #1
0
    def _setup_atm_driver_rundir(self):
        """Set up the directory from which we will actually do the run"""
        lndroot = self._case.get_value('COMP_ROOT_DIR_LND')
        rundir = self._atm_driver_rundir()

        if not os.path.exists(rundir):
            os.makedirs(rundir)
            shutil.copyfile(src=os.path.join(lndroot, 'lilac', 'atm_driver', 'atm_driver_in'),
                            dst=os.path.join(rundir, 'atm_driver_in'))

        # As elsewhere: assume the land variables also apply to the atmosphere
        lnd_mesh = self._case.get_value('LND_DOMAIN_MESH')
        lnd_nx = self._case.get_value('LND_NX')
        lnd_ny = self._case.get_value('LND_NY')
        expect(self._case.get_value('STOP_OPTION') == 'ndays',
               'LILAC testing currently assumes STOP_OPTION of ndays, not {}'.format(
                   self._case.get_value('STOP_OPTION')))
        stop_n = self._case.get_value('STOP_N')
        casename = self._case.get_value('CASE')
        self._fill_in_variables_in_file(filepath=os.path.join(rundir, 'atm_driver_in'),
                                        replacements={'caseid':casename,
                                                      'atm_mesh_file':lnd_mesh,
                                                      'atm_global_nx':str(lnd_nx),
                                                      'atm_global_ny':str(lnd_ny),
                                                      'atm_stop_day':str(stop_n+1),
                                                      'atm_ndays_all_segs':str(stop_n)})

        for file_to_link in _LILAC_RUNTIME_FILES:
            symlink_force(os.path.join(self._runtime_inputs_dir(), file_to_link),
                          os.path.join(rundir, file_to_link))
Beispiel #2
0
 def set_ref_case(self, case):
     rundir = case.get_value("RUNDIR")
     case_root = case.get_value("CASEROOT")
     if case_root.endswith(".postad"):
         ref_case_root = case_root.replace(".postad", ".ad")
         root = ".ad"
     else:
         ref_case_root = case_root.replace(".transient", ".postad")
         root = ".postad"
     expect(
         os.path.isdir(ref_case_root),
         "ERROR: spinup must be completed first, could not find directory {}"
         .format(ref_case_root))
     with Case(ref_case_root) as refcase:
         refrundir = refcase.get_value("RUNDIR")
     case.set_value("RUN_REFDIR", refrundir)
     case.set_value("RUN_REFCASE", os.path.basename(ref_case_root))
     for reffile in glob.iglob(refrundir +
                               "/{}{}.*.nc".format(self.name, root)):
         m = re.search("(\d\d\d\d-\d\d-\d\d)-\d\d\d\d\d.nc", reffile)
         if m:
             refdate = m.group(1)
         symlink_force(reffile,
                       os.path.join(rundir, os.path.basename(reffile)))
     for rpfile in glob.iglob(refrundir + "/rpointer*"):
         safe_copy(rpfile, rundir)
     if not os.path.isdir(os.path.join(
             rundir, "inputdata")) and os.path.isdir(
                 os.path.join(refrundir, "inputdata")):
         symlink_force(os.path.join(refrundir, "inputdata"),
                       os.path.join(rundir, "inputdata"))
     case.set_value("RUN_REFDATE", refdate)
     if case_root.endswith(".postad"):
         case.set_value("RUN_STARTDATE", refdate)
Beispiel #3
0
    def _create_link_to_atm_driver(self):
        caseroot = self._case.get_value('CASEROOT')
        run_exe = (self._case.get_value('run_exe')).strip()

        # Make a symlink to the atm_driver executable so that the case's run command finds
        # it in the expected location
        symlink_force(os.path.join(caseroot, 'lilac_atm_driver', 'bld', 'atm_driver.exe'),
                      run_exe)
Beispiel #4
0
    def _build_atm_driver(self):
        caseroot = self._case.get_value('CASEROOT')
        lndroot = self._case.get_value('COMP_ROOT_DIR_LND')
        blddir = os.path.join(caseroot, 'lilac_atm_driver', 'bld')

        if not os.path.exists(blddir):
            os.makedirs(blddir)
        symlink_force(os.path.join(lndroot, 'lilac', 'atm_driver', 'Makefile'),
                      os.path.join(blddir, 'Makefile'))
        symlink_force(os.path.join(lndroot, 'lilac', 'atm_driver', 'atm_driver.F90'),
                      os.path.join(blddir, 'atm_driver.F90'))
        symlink_force(os.path.join(self._lilac_build_dir(), 'case', 'Macros.make'),
                      os.path.join(blddir, 'Macros.make'))

        makevars = 'COMPILER={compiler} DEBUG={debug} CTSM_MKFILE={ctsm_mkfile}'.format(
            compiler=self._case.get_value('COMPILER'),
            debug=str(self._case.get_value('DEBUG')).upper(),
            ctsm_mkfile=os.path.join(self._lilac_build_dir(), 'ctsm.mk'))
        makecmd = 'make {makevars} atm_driver'.format(makevars=makevars)

        # Normally the user will source either ctsm_build_environment.sh or
        # ctsm_build_environment.csh before building the atmosphere model. In the context
        # of this test case, case.load_env does the equivalent.
        self._case.load_env()

        self._run_build_cmd(makecmd, blddir, 'atm_driver.bldlog')
Beispiel #5
0
    def _link_to_output_files(self):
        """Make links to the output files so that they appear in the directory expected by the test case

        Note: We do the run from a different directory in order to ensure that the run
        isn't using any of the files that are staged by the test case in the standard run
        directory. But then we need to create these links afterwards for the sake of
        baseline generation / comparison.
        """
        casename = self._case.get_value('CASE')
        rundir = self._case.get_value('RUNDIR')
        pattern = '{}*.nc'.format(casename)

        # First remove any old files from the run directory
        old_files = glob.glob(os.path.join(rundir, pattern))
        for one_file in old_files:
            os.remove(one_file)

        # Now link to new files
        output_files = glob.glob(os.path.join(self._atm_driver_rundir(), pattern))
        for one_file in output_files:
            file_basename = os.path.basename(one_file)
            symlink_force(one_file, os.path.join(rundir, file_basename))
Beispiel #6
0
    def _build_atm_driver(self):
        caseroot = self._case.get_value('CASEROOT')
        lndroot = self._case.get_value('COMP_ROOT_DIR_LND')
        blddir = os.path.join(caseroot, 'lilac_atm_driver', 'bld')

        if not os.path.exists(blddir):
            os.makedirs(blddir)
        symlink_force(os.path.join(lndroot, 'lilac', 'atm_driver', 'Makefile'),
                      os.path.join(blddir, 'Makefile'))
        symlink_force(os.path.join(lndroot, 'lilac', 'atm_driver', 'atm_driver.F90'),
                      os.path.join(blddir, 'atm_driver.F90'))
        symlink_force(os.path.join(caseroot, 'Macros.make'),
                      os.path.join(blddir, 'Macros.make'))

        makevars = 'COMPILER={compiler} DEBUG={debug} CTSM_MKFILE={ctsm_mkfile}'.format(
            compiler=self._case.get_value('COMPILER'),
            debug=str(self._case.get_value('DEBUG')).upper(),
            ctsm_mkfile=os.path.join(caseroot, 'lilac_build', 'ctsm.mk'))
        makecmd = 'make {makevars} atm_driver'.format(makevars=makevars)
        self._run_build_cmd(makecmd, blddir, 'atm_driver.bldlog')