def _run(self):
     steam = self.ins[1]
     steam_mol = steam.F_mol or 1.
     f = self.pressure_objective_function
     steam_mol = flx.IQ_interpolation(f,
                                      *flx.find_bracket(
                                          f, 0., steam_mol, None, None),
                                      xtol=1e-2,
                                      ytol=1e-4,
                                      maxiter=500,
                                      checkroot=False)
Beispiel #2
0
def test_bounded_solvers():
    x0, x1 = [-10, 20]
    f = lambda x: x**3 - 40 + 2 * x
    assert_allclose(flx.IQ_interpolation(f, x0, x1),
                    3.225240462791775,
                    rtol=1e-5)
    assert_allclose(flx.bisection(f, x0, x1), 3.225240461761132, rtol=1e-5)
    assert_allclose(flx.false_position(f, x0, x1),
                    3.2252404627266342,
                    rtol=1e-5)
    assert_allclose(flx.find_bracket(f, -5, 5), (-5, 5, -175, 95), rtol=1e-5)
    assert_allclose(flx.find_bracket(f, -5, 0), (-5, 10.0, -175, 980.0),
                    rtol=1e-5)
    assert_allclose(flx.find_bracket(f, -10, -5), (-10, 5.0, -1060, 95.0),
                    rtol=1e-5)
    assert_allclose(flx.find_bracket(f, 5, 10),
                    (-6.073446327683616, 10, -276.1765907762578, 980),
                    rtol=1e-5)
    assert_allclose(flx.find_bracket(f, 10, 5),
                    (-6.073446327683616, 10, -276.1765907762578, 980),
                    rtol=1e-5)
 def _solve_Underwood_constant(self, alpha_mean, alpha_LK):
     q = self._get_feed_quality()
     z_f = self.ins[0].get_normalized_mol(self._IDs_vle)
     args = (q, z_f, alpha_mean)
     ub = np.inf
     lb = -np.inf
     bracket = flx.find_bracket(objective_function_Underwood_constant, 1.0,
                                alpha_LK, lb, ub, args)
     theta = flx.IQ_interpolation(objective_function_Underwood_constant,
                                  *bracket,
                                  args=args,
                                  checkiter=False,
                                  checkbounds=False)
     return theta
def solve_phase_fraction_Rashford_Rice(zs, Ks, guess, za, zb):
    """
    Return phase fraction for N-component binary equilibrium by
    numerically solving the Rashford Rice equation.
    
    """
    if Ks.max() < 1.0 and not za: return 0.
    if Ks.min() > 1.0 and not zb: return 1.
    K_minus_1 = Ks - 1.
    args = (- zs * K_minus_1, K_minus_1, za, zb)
    f = phase_fraction_objective_function
    x0 = 0.
    x1 = 1.
    y0 = -np.inf if za else f(x0, *args) 
    y1 = np.inf if zb else f(x1, *args)
    if y0 > y1 > 0.: return 1
    if y1 > y0 > 0.: return 0.
    if y0 < y1 < 0.: return 1.
    if y1 < y0 < 0.: return 0.
    x0, x1, y0, y1 = flx.find_bracket(f, x0, x1, y0, y1, args, tol=5e-8)
    if abs(x1 - x0) < 1e-6: return (x0 + x1) / 2.
    return flx.IQ_interpolation(f, x0, x1, y0, y1,
                                guess, 1e-16, 1e-16,
                                args, checkiter=False)