Exemplo n.º 1
0
 def _run(self):
     wet_solids, air, natural_gas = self.ins
     dry_solids, hot_air, emissions = self.outs
     wet_solids.split_to(hot_air, dry_solids, self.split)
     sep.adjust_moisture_content(dry_solids, hot_air, self.moisture_content)
     emissions.phase = air.phase = natural_gas.phase = hot_air.phase = 'g'
     design_results = self.design_results
     design_results['Evaporation'] = evaporation = hot_air.F_mass
     air.imass['N2', 'O2'] = np.array([0.78, 0.32]) * self.R * evaporation
     hot_air.mol += air.mol
     dry_solids.T = hot_air.T = self.T
     emissions.T = self.T + 30.
     natural_gas.empty()
     emissions.empty()
     if self.utility_agent == 'Natural gas':
         LHV = self.chemicals.CH4.LHV
         def f(CH4):
             CO2 = CH4    
             H2O = 2. * CH4
             natural_gas.imol['CH4'] = CH4
             emissions.imol['CO2', 'H2O'] = [CO2, H2O]    
             duty = (dry_solids.H + hot_air.H + emissions.H) - (wet_solids.H + air.H + natural_gas.H)
             CH4 = duty / LHV
             return CH4
         flx.wegstein(f, 0., 1e-3)
 def simulate_multi_stage_lle_without_side_draws(self):
     f = self.multi_stage_lle_without_side_draws_iter
     extract_flow_rates = self.initialize_multi_stage_lle_without_side_draws(
     )
     self.extract_flow_rates = extract_flow_rates = flx.wegstein(
         f, extract_flow_rates, xtol=0.1, maxiter=10, checkiter=False)
     self.update_multi_stage_lle_without_side_draws(extract_flow_rates)
     for i in self.stages:
         i.balance_raffinate_flows()
Exemplo n.º 3
0
def solve_y(y_phi, phi, T, P, y_guess):
    if isinstance(phi, IdealFugacityCoefficients): return y_phi
    return flx.wegstein(y_iter,
                        y_phi,
                        1e-9,
                        args=(y_phi, phi, T, P),
                        checkiter=False,
                        checkconvergence=False,
                        convergenceiter=3)
Exemplo n.º 4
0
 def _solve_x(self, T):
     solute_chemical = self.chemicals.tuple[self._solute_index]
     Tm = solute_chemical.Tm
     if Tm is None: raise RuntimeError(f"solute {solute_chemical} does not have a melting temperature, Tm")
     Cpl = solute_chemical.Cn.l(T)
     Cps = solute_chemical.Cn.s(T)
     Hm = solute_chemical.Hfus
     if Tm is None: raise RuntimeError(f"solute {solute_chemical} does not have a heat of fusion, Hfus")
     gamma = 1.
     x = solubility_eutectic(T, Tm, Hm, Cpl, Cps, gamma) # Initial guess
     args = (T, Tm, Cpl, Cps, Hm)
     return flx.wegstein(self._x_iter, x, xtol=1e-6, args=args)
Exemplo n.º 5
0
def test_fixedpoint_array_solvers2():
    original_feed = feed.copy()
    p = flx.Profiler(f2)
    solution = flx.wegstein(p, feed, xtol=1e-8, maxiter=200)
    assert_allclose(solution, real_solution2)
    p.archive('Wegstein')
    
    with pytest.raises(RuntimeError):
        solution = flx.wegstein(f2, feed, convergenceiter=4, xtol=1e-8, maxiter=200)
    with pytest.raises(RuntimeError):
        solution = flx.wegstein(f2, feed, xtol=1e-8, maxiter=20)
    with pytest.raises(RuntimeError):
        solution = flx.aitken(f2, feed, convergenceiter=4, xtol=1e-8, maxiter=200)
        
    solution = flx.wegstein(p, feed, checkconvergence=False, convergenceiter=4, xtol=1e-8)
    p.archive('Wegstein early termination')
    assert_allclose(solution, real_solution2, rtol=1e-3)
    
    solution = flx.aitken(p, feed, xtol=1e-8, maxiter=10000)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution2)
    p.archive('Aitken')
    
    solution = flx.aitken(p, feed, checkconvergence=False, convergenceiter=4, xtol=1e-8)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution2, rtol=1e-3)
    p.archive('Aitken early termination')
    
    solution = flx.fixed_point(p, feed, xtol=5e-8, maxiter=200)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution2)
    p.archive('Fixed point')
    
    solution = flx.fixed_point(p, feed, maxiter=500, checkconvergence=False, convergenceiter=4, xtol=5e-8)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution2, rtol=1e-3)
    p.archive('Fixed point early termination')
    assert p.sizes() == {'Wegstein': 61, 'Wegstein early termination': 18, 
                         'Aitken': 392, 'Aitken early termination': 91,
                         'Fixed point': 191, 'Fixed point early termination': 191}
Exemplo n.º 6
0
def solve_x(x_guess, x_gamma_poyinting, T, f_gamma, gamma_args, f_pcf,
            pcf_args):
    args = (x_gamma_poyinting, T, f_gamma, gamma_args, f_pcf, pcf_args)
    try:
        x = flx.wegstein(x_iter,
                         x_guess,
                         1e-10,
                         args=args,
                         checkiter=False,
                         checkconvergence=False,
                         convergenceiter=3)
    except:
        return x_gamma_poyinting
    return x
Exemplo n.º 7
0
 def simulate_multi_stage_lle_without_side_draws(self):
     f = self.multi_stage_lle_without_side_draws_iter
     if hasattr(self, 'extract_flow_rates'):
         extract_flow_rates = self.extract_flow_rates
     else:
         extract_flow_rates = self.initialize_multi_stage_lle_without_side_draws(
         )
     extract_flow_rates = flx.wegstein(f,
                                       extract_flow_rates,
                                       xtol=0.1,
                                       maxiter=10,
                                       checkiter=False)
     self.extract_flow_rates = extract_flow_rates
     self.update_multi_stage_lle_without_side_draws(extract_flow_rates)
Exemplo n.º 8
0
 def _y_iter(self, y, Psats_over_P, T, P):
     phi = self._phi(y, T, P)
     Psat_over_P_phi = Psats_over_P / phi
     try:
         x = flx.wegstein(self._x_iter,
                          self._x,
                          1e-12,
                          args=(Psat_over_P_phi, ))
     except flx.SolverError as solver_error:
         x = flx.aitken(self._x_iter,
                        solver_error.x,
                        1e-6,
                        args=(Psat_over_P_phi, ))
     self._x = x
     v = self._F_mol_vle * self._V * x * self._Ks
     return fn.normalize(v)
Exemplo n.º 9
0
 def _solve_v(self, T, P):
     """Solve for vapor mol"""
     Psats_over_P = np.array([i(T) for i in self._bubble_point.Psats]) / P
     self._T = T
     v = self._v
     y = fn.normalize(v)
     l = self._mol - v
     self._x = fn.normalize(l)
     if isinstance(self._phi, IdealFugacityCoefficients):
         self._y = self._y_iter(y, Psats_over_P, T, P)
     else:
         self._y = flx.wegstein(self._y_iter,
                                v / v.sum(),
                                1e-6,
                                args=(Psats_over_P, T, P))
     self._v = self._F_mol_vle * self._V * self._y
     return self._v
Exemplo n.º 10
0
def test_fixedpoint_array_solvers():
    original_feed = feed.copy()
    p = flx.Profiler(f)
    
    solution = flx.wegstein(p, feed, convergenceiter=4, xtol=1e-8, maxiter=200)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution)
    p.archive('Wegstein')
    
    solution = flx.aitken(p, feed, convergenceiter=4, xtol=1e-8, maxiter=200)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution)
    p.archive('Aitken')
    
    solution = flx.fixed_point(p, feed, convergenceiter=4, xtol=5e-8, maxiter=200)
    assert_allclose(feed, original_feed)
    assert_allclose(solution, real_solution)
    p.archive('Fixed point')
    
    assert p.sizes() == {'Wegstein': 5, 'Aitken': 5, 'Fixed point': 194}
Exemplo n.º 11
0
    p.archive('[Scipy] Brent-Q') # Save/archive results with given name
    x_brenth = opt.brenth(p, x0, x1)
    p.archive('[Scipy] Brent-H')
    x_IQ = flx.IQ_interpolation(p, x0, x1)
    p.archive('IQ-interpolation')
    x_false_position = flx.false_position(p, x0, x1)
    p.archive('False position')
    p.plot(r'$f(x) = 0 = x^3 + 2 \cdot x - 40$ where $-5 < x < 5$')
    
    p = flx.Profiler(f)
    x_guess = -5
    x_aitken_secant = flx.aitken_secant(p, x_guess)
    p.archive('Aitken')
    x_secant = flx.secant(p, x_guess)
    p.archive('Secant')
    x_newton = opt.newton(p, x_guess)
    p.archive('[Scipy] Newton')
    p.plot(r'$f(x) = 0 = x^3 + 2 \cdot x - 40$')
    
    # Note that x = 40/x^2 - 2/x is the same
    # objective function as x**3 - 40 + 2*x = 0
    f = lambda x: 40/x**2 - 2/x
    p = flx.Profiler(f)
    x_guess = 5.
    x_wegstein = flx.wegstein(p, x_guess)
    p.archive('Wegstein')
    x_aitken = flx.aitken(p, x_guess)
    p.archive('Aitken')
    p.plot(r'$f(x) = x = \frac{40}{x^2} - \frac{2}{x}$', markbounds=False)
    # ^ Fixed-point iteration is non-convergent for this equation; so we don't include it here