Exemplo n.º 1
0
    def courant(self, rainfall, delta_t, ratio):

        # ratio se muze zmensit  a max_delta_t_mult zvetsit
        # pokud je courant v ryhach <= 0.2
        #
        # pokud je courant > 0.5 deje se opak
        # to je ale reseno lokalne
        # v  ./src/processes/rill.py
        #
        # if (self.cour_most_rill < 0.1) :
        # ratio = max(1,ratio-1) # ratio nemuze byt mensi nez 1
        # if ratio == 1 :
        # self.max_delta_t_mult = 1.0
        # else :
        # self.max_delta_t_mult = min(1.0, self.max_delta_t_mult*1/(0.9)) #
        # max_delta_t_mult nemuze byt vetsi nez 1.0

        # ratio se drzi na 10
        # vyse nelze jit
        # proto se zmensuje max_delta_t_mult
        # ktery nasobi vysledne delta
        #
        # if ((ratio > self.maxratio) or (self.cour_most_rill > 1.0)) :
        # ratio = self.maxratio
        # ratio = 1
        # self.max_delta_t_mult *= 0.9

        # pokud je maximalni courant mimo dovolena kryteria
        # mensi nez cour_least a vetsi nez cour_crit
        # explicitne se dopocita dt na nejvetsi mozne
        #                                      xor
        if ((self.cour_most < self.cour_least) !=
            (self.cour_crit <= self.cour_most)):

            # pokud se na povrchu nic nedeje
            # nema se zmena dt cim ridit
            # a zmeni se podle maxima nasobeneho max_delta_t_mult
            # max_delta_t_mult se meni podle ryh, vyse v teto funkci
            #
            if (self.cour_speed == 0.0):
                return self.max_delta_t * self.max_delta_t_mult, ratio

            dt = round((Gl.mat_efect_cont[self.i, self.j] * self.cour_crit *
                        self.cour_coef) / self.cour_speed, 4)

            # nove dt nesmi byt vetsi nez je maxdt * max_delta_t_mult
            # max_delta_t_mult se meni podle ryh, vyse v teto funkci

            # return dt*self.max_delta_t_mult, ratio
            # return min(dt,self.max_delta_t*self.max_delta_t_mult), ratio
            # print 'asdf', self.cour_speed, dt, self.max_delta_t_mult
            return min(dt * self.max_delta_t_mult,
                       self.max_delta_t * self.max_delta_t_mult), ratio

        # pokud je courant v povolenem rozmezi
        # skontrolje se pouze pokud neni vetsi nez maxdt * max_delta_t_mult
        # max_delta_t_mult se meni podle ryh, vyse v teto funkci
        else:
            # print 'fdafdsfasdfadsfadsfadsfaf'
            # return delta_t, ratio
            # print 'asdf', dt, dt*self.max_delta_t_mult, ratio
            if ((ratio <= self.maxratio) and (self.cour_most_rill < 0.5)):
                return delta_t, ratio
            else:
                return delta_t * self.max_delta_t_mult, ratio

        Logger.critical(
            'courant.cour() missed all its time step conditions\n no rule to preserve or change the time step!'
        )
Exemplo n.º 2
0
def load_precipitation(fh):
    y2 = 0
    try:
        fh = open(fh, "r")
        x = []
        for line in fh.readlines():
            z = line.split()
            if len(z) == 0:
                continue
            elif z[0].find('#') >= 0:
                continue
            else:
                if (len(z) == 0):  # if raw in text file is empty
                    continue
                elif (
                    (float(z[0]) == 0) & (float(z[1]) > 0)
                ):  # if the record start with zero minutes the line has to be corrected
                    raise ErrorInRainfallRecord()
                elif (
                    (float(z[0]) == 0) & (float(z[1]) == 0)
                ):  # if the record start with zero minutes and rainfall the line is ignored
                    continue
                else:
                    y0 = float(z[0]) * 60.0  # prevod na vteriny
                    y1 = float(z[1]) / 1000.0  # prevod na metry
                    if y1 < y2:
                        raise NonCumulativeRainData()
                    y2 = y1
                    mv = y0, y1
                    x.append(mv)
        fh.close

        # Values ordered by time ascending
        dtype = [('cas', float), ('value', float)]
        val = np.array(x, dtype=dtype)
        x = np.sort(val, order='cas')
        # Test if time time is more than once the same
        state = 0
        k = 1
        itera = len(x)  # iter is needed in main loop
        for k in range(itera):
            if x[k][0] == x[k - 1][0] and itera != 1:
                state = 1
                y = np.delete(x, k, 0)

        if state == 0:
            x = x
        else:
            x = y
        # Amount of rainfall in individual intervals
        if len(x) == 0:
            sr = 0
        else:
            sr = np.zeros([itera, 2], float)
            for i in range(itera):
                if i == 0:
                    sr_int = x[i][1] / x[i][0]
                    sr[i][0] = x[i][0]
                    sr[i][1] = sr_int

                else:
                    sr_int = (x[i][1] - x[i - 1][1]) / (x[i][0] - x[i - 1][0])
                    sr[i][0] = x[i][0]
                    sr[i][1] = sr_int

        #for  i, item in enumerate(sr):
        #print item[0], '\t', item[1]
        return sr, itera

    except IOError:
        Logger.critical("The rainfall file does not exist!")
    except:
        Logger.critical("Unexpected error:", sys.exc_info()[0])
        raise