Beispiel #1
0
    def extrapolate_error(self):
        """Estimate the numerical error to be expected when applying all
        methods available based on the results of the current and the
        last method.

        Note that this expolation strategy cannot be applied on the first
        method.  If the current method is the first one, `-999.9` is returned.

        >>> from hydpy.models.test_v1 import *
        >>> parameterstep()
        >>> model.numvars.error = 1e-2
        >>> model.numvars.last_error = 1e-1
        >>> model.numvars.idx_method = 10
        >>> model.extrapolate_error()
        >>> from hydpy import round_
        >>> round_(model.numvars.extrapolated_error)
        0.01
        >>> model.numvars.idx_method = 9
        >>> model.extrapolate_error()
        >>> round_(model.numvars.extrapolated_error)
        0.001
        """
        if self.numvars.idx_method > 2:
            self.numvars.extrapolated_error = modelutils.exp(
                modelutils.log(self.numvars.error) +
                (modelutils.log(self.numvars.error) -
                 modelutils.log(self.numvars.last_error)) *
                (self.numconsts.nmb_methods - self.numvars.idx_method))
        else:
            self.numvars.extrapolated_error = -999.9
Beispiel #2
0
 def __call__(model: modeltools.Model) -> None:
     flu = model.sequences.fluxes.fastaccess
     old = model.sequences.states.fastaccess_old
     new = model.sequences.states.fastaccess_new
     if flu.rk <= 0.:
         new.qa = new.qz
     elif flu.rk > 1e200:
         new.qa = old.qa+new.qz-old.qz
     else:
         d_temp = (1.-modelutils.exp(-1./flu.rk))
         new.qa = (old.qa +
                   (old.qz-old.qa)*d_temp +
                   (new.qz-old.qz)*(1.-flu.rk*d_temp))
Beispiel #3
0
 def __call__(model: modeltools.Model) -> None:
     inp = model.sequences.inputs.fastaccess
     flu = model.sequences.fluxes.fastaccess
     flu.saturationvapourpressure = 0.6108 * modelutils.exp(
         17.27 * inp.airtemperature / (inp.airtemperature + 237.3))
Beispiel #4
0
def calc_qa_v1(self):
    """Calculate outflow.

    The working equation is the analytical solution of the linear storage
    equation under the assumption of constant change in inflow during
    the simulation time step.

    Required flux sequence:
      |RK|

    Required state sequence:
      |QZ|

    Updated state sequence:
      |QA|

    Basic equation:
       :math:`QA_{neu} = QA_{alt} +
       (QZ_{alt}-QA_{alt}) \\cdot (1-exp(-RK^{-1})) +
       (QZ_{neu}-QZ_{alt}) \\cdot (1-RK\\cdot(1-exp(-RK^{-1})))`

    Examples:

        A normal test case:

        >>> from hydpy.models.lstream import *
        >>> parameterstep()
        >>> fluxes.rk(0.1)
        >>> states.qz.old = 2.0
        >>> states.qz.new = 4.0
        >>> states.qa.old = 3.0
        >>> model.calc_qa_v1()
        >>> states.qa
        qa(3.800054)

        First extreme test case (zero division is circumvented):

        >>> fluxes.rk(0.0)
        >>> model.calc_qa_v1()
        >>> states.qa
        qa(4.0)

        Second extreme test case (numerical overflow is circumvented):

        >>> fluxes.rk(1e201)
        >>> model.calc_qa_v1()
        >>> states.qa
        qa(5.0)
    """
    flu = self.sequences.fluxes.fastaccess
    old = self.sequences.states.fastaccess_old
    new = self.sequences.states.fastaccess_new
    aid = self.sequences.aides.fastaccess
    if flu.rk <= 0.:
        new.qa = new.qz
    elif flu.rk > 1e200:
        new.qa = old.qa + new.qz - old.qz
    else:
        aid.temp = (1. - modelutils.exp(-1. / flu.rk))
        new.qa = (old.qa + (old.qz - old.qa) * aid.temp + (new.qz - old.qz) *
                  (1. - flu.rk * aid.temp))