def RunHY(inputdir, control_file):
    """Run hydraulics only"""
    try:
        HSP = ModelControl(inputdir, control_file, 2)
        HSP.Run()
    except Exception, stderr:
        f = open("HS_Error.txt", "w")
        print_exc(file=f)
        f.close()
        msgbox("".join(format_tb(exc_info()[2]))+"\nSynopsis: %s"%stderr, "HeatSource Error", err=True)
Exemplo n.º 2
0
def RunSH(sheet):
    """Run solar routines only"""
    try:
        HSP = ModelControl(sheet, 1)
        HSP.Run()
    except Exception, stderr:
        f = open("c:\\HSError.txt", "w")
        print_exc(file=f)
        f.close()
        msgbox("".join(format_tb(exc_info()[2]))+"\nSynopsis: %s"%stderr, "HeatSource Error", err=True)
def RunSetup(inputdir,control_file):
    """Run setup"""
    try:
        ErrLog = Logger
        CSVInterface(inputdir, control_file, ErrLog, 3)
    except Exception, stderr:
        f = open("HS_Error.txt", "w")
        print_exc(file=f)
        f.close()
        msgbox("".join(format_tb(exc_info()[2]))+"\nSynopsis: %s"%stderr, "HeatSource Error", err=True)        
        
def RunHS(inputdir, control_file):
    """Run full temperature model"""
    try:
        HSP = ModelControl(inputdir, control_file)
        HSP.Run()
        del HSP
    except Exception, stderr:
        f = open("HS_Error.txt", "w")
        print_exc(file=f)
        f.close()
        msgbox("".join(format_tb(exc_info()[2]))+"\nSynopsis: %s"%stderr, "HeatSource Error", err=True)
    def Run(self):
        """Run the model one time

        Use the Chronos instance and list of StreamNodes to cycle
        through each timestep and spacestep, calling the appropriate
        StreamNode functions to calculate heat and hydraulics."""
        time = Chronos.TheTime # Current time of the Chronos clock (i.e. this timestep)
        stop = Chronos.stop # Stop time for Chronos
        start = Chronos.start # Start time for Chronos, model start, not flush/spin start.
        flush = start-(IniParams["flushdays"]*86400) # in seconds
        # Number of timesteps is based on the division of the timesteps into the hour. In other words
        # 1 day with a 1 minute dt is 1440 timesteps, while a 3 minute dt is only 480 timesteps. Thus,
        # We define the timesteps by dividing dt (now in seconds) by 3600
        timesteps = (stop-flush)/IniParams["dt"]
        cnt = count() # Counter iterator for counting current timesteps passed
        out = 0 # Volume of water flowing out of mouth (for simple mass balance)
        time1 = Time() # Current computer time- for estimating total model runtime
        # Localize run_type for a bit more speed
        ################################################################
        # So, it's simple and stupid. We basically just cycle through the time
        # until we get to the model stop time, and each cycle, we call a method
        # that cycles through the StreamNodes, and calculates them in order.
        # A smarter way would be to thread this so we can start calculating
        # the second timestep (using another CPU or core) while the first one
        # is still unfinished.
        while time <= stop:
            year, month, day, hour, minute, second, JD, offset, JDC = Chronos.TimeTuple()
            # zero hour+minute+second means first timestep of new day
            # We want to zero out the daily flux sum at this point.
            if not (hour + minute + second):
                for nd in self.reachlist:
                    nd.F_DailySum = [0]*5
                    nd.Solar_Blocked = {}
                    for i in range(IniParams["radialsample_count"]):  # Radial Sample directions
                        nd.Solar_Blocked[i]=[0]*IniParams["transsample_count"] #A spot for each zone
                    nd.Solar_Blocked['diffuse']=0

            # Back to every timestep level of the loop. Here we wrap the call to
            # run_all() in a try block to catch the exceptions thrown.
            try:
                # Note that all of the run methods have to have the same signature
                self.run_all(time, hour, minute, second, JD, JDC)
            # Shit, there's a problem, throw an exception up using a graphical window.
            except HeatSourceError, (stderr):
                msg = "At %s and time %s\n"%(self, Chronos.PrettyTime())
                try:
                    msg += stderr+"\nThe model run has been halted. You may ignore any further error messages."
                except TypeError:
                    msg += `stderr`+"\nThe model run has been halted. You may ignore any further error messages."
                msgbox(msg)
                # Then just die
                raise SystemExit
                        # If minute and second are both zero, we are at the top of the hour. Performing

            # The following house keeping tasks each hours saves us enormous amounts of
            # runtime overhead over doing it every timestep.
            if not (minute + second):
                ts = cnt.next() # Number of actual timesteps per tick
                hr = 60/(IniParams["dt"]/60) # Number of timesteps in one hour
                # This writes a line to the status bar of Excel.
                print("%i of %i timesteps"% (ts*hr, timesteps))
                
                # Call the Output class to update the textfiles. We call this every
                # hour and store the data, then we write to file every day. Limiting
                # disk access saves us considerable time.
                self.Output(time, hour)
                
                # Check to see if the user pressed the stop button.
                # TODO


            # We've made it through the entire stream without an error, so we update our mass balance
            # by adding the discharge of the mouth...
            out += self.reachlist[-1].Q
            # and tell Chronos that we're moving time forward.
            time = Chronos(True)