def f_x(x, threshold, reld) :
    """ Function in range 0 to 1, to set soil water and groundwater
        flow to 0 below a user-specified threshold
        x: float
        threshold: f(x) is 0 below this threshold
        reld: relative "activation distance", the distance from the
              threshold (as a proportion of the threshold), at which
              f(x) is 1
        returns float f(x) evaluated at x
    """
    def f_x0(x): return -2*x**3 + 3*x**2
    d = threshold*reld
    if x < threshold       : return 0
    if x > threshold + d : return 1
    else: return f_x0( (x-threshold) / d )