Ejemplo n.º 1
0
 def _flash_sequential_substitution_TP(self,
                                       T,
                                       P,
                                       zs,
                                       Psats=None,
                                       restart=None):
     Psats = self._Psats(Psats=Psats, T=T)
     if self.retention and restart:
         V_over_F, xs, ys = restart
     else:
         Ks = self.Ks(T, P, zs, zs, Psats)
         V_over_F, xs, ys = flash_inner_loop(zs, Ks)
     for i in range(100):
         if any(i < 0 for i in xs):
             xs = zs
         if any(i < 0 for i in ys):
             ys = zs
         Ks = self.Ks(T, P, xs, ys, Psats)
         V_over_F, xs_new, ys_new = flash_inner_loop(zs, Ks)
         err = (
             sum([abs(x_new - x_old) for x_new, x_old in zip(xs_new, xs)]) +
             sum([abs(y_new - y_old) for y_new, y_old in zip(ys_new, ys)]))
         xs, ys = xs_new, ys_new
         if err < 1E-7:
             break
     return V_over_F, xs, ys
Ejemplo n.º 2
0
 def flash_UNIFAC_sequential_substitution(T, P, zs, Psats, chemgroups):
     gammas = UNIFAC(chemgroups=chemgroups, T=T, xs=zs)
     Ks = [K_value(P=P, Psat=Psat, gamma=gamma) for Psat, gamma in zip(Psats, gammas)]
     V_over_F, xs, ys = flash_inner_loop(zs, Ks)
     for i in range(100):
         gammas = UNIFAC(chemgroups=chemgroups, T=T, xs=xs)
         Ks = [K_value(P=P, Psat=Psat, gamma=gamma) for Psat, gamma in zip(Psats, gammas)]
         V_over_F, xs_new, ys_new = flash_inner_loop(zs, Ks)
         err = (sum([abs(x_new - x_old) for x_new, x_old in zip(xs_new, xs)]) +
               sum([abs(y_new - y_old) for y_new, y_old in zip(ys_new, ys)]))
         xs, ys = xs_new, ys_new
         if err < 1E-11:
             break
     return V_over_F, xs, ys
Ejemplo n.º 3
0
 def flash_PVF_zs(self, P, VF, zs):
     assert 0 <= VF <= 1
     Tsats = self._Tsats(P)
     T = brenth(self._P_VF_err,
                min(Tsats) * (1 + 1E-7),
                max(Tsats) * (1 - 1E-7),
                args=(P, VF, zs))
     Psats = self._Psats(T)
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     V_over_F, xs, ys = flash_inner_loop(zs=zs, Ks=Ks)
     return 'l/g', xs, ys, V_over_F, T
Ejemplo n.º 4
0
 def _flash_sequential_substitution_TP(self, T, P, zs, Psats=None, restart=None):
     Psats = self._Psats(Psats=Psats, T=T)
     if self.retention and restart:
         V_over_F, xs, ys = restart
     else:
         Ks = self.Ks(T, P, zs, zs, Psats)
         V_over_F, xs, ys = flash_inner_loop(zs, Ks)
     for i in range(100):
         if any(i < 0 for i in xs):
             xs = zs
         if any(i < 0 for i in ys):
             ys = zs
         Ks = self.Ks(T, P, xs, ys, Psats)
         V_over_F, xs_new, ys_new = flash_inner_loop(zs, Ks)
         err = (sum([abs(x_new - x_old) for x_new, x_old in zip(xs_new, xs)]) +
               sum([abs(y_new - y_old) for y_new, y_old in zip(ys_new, ys)]))
         xs, ys = xs_new, ys_new
         if err < 1E-7:
             break
     return V_over_F, xs, ys
Ejemplo n.º 5
0
 def flash_UNIFAC_sequential_substitution(T, P, zs, Psats, chemgroups):
     gammas = UNIFAC(chemgroups=chemgroups, T=T, xs=zs)
     Ks = [
         K_value(P=P, Psat=Psat, gamma=gamma)
         for Psat, gamma in zip(Psats, gammas)
     ]
     V_over_F, xs, ys = flash_inner_loop(zs, Ks)
     for i in range(100):
         gammas = UNIFAC(chemgroups=chemgroups, T=T, xs=xs)
         Ks = [
             K_value(P=P, Psat=Psat, gamma=gamma)
             for Psat, gamma in zip(Psats, gammas)
         ]
         V_over_F, xs_new, ys_new = flash_inner_loop(zs, Ks)
         err = (
             sum([abs(x_new - x_old) for x_new, x_old in zip(xs_new, xs)]) +
             sum([abs(y_new - y_old) for y_new, y_old in zip(ys_new, ys)]))
         xs, ys = xs_new, ys_new
         if err < 1E-11:
             break
     return V_over_F, xs, ys
Ejemplo n.º 6
0
 def flash_PVF_zs(self, P, VF, zs):
     assert 0 <= VF <= 1
     Tsats = self._Tsats(P)
     # handle one component
     if self.N == 1:
         return 'l/g', [1.0], [1.0], VF, Tsats[0]
     
     T = brenth(self._P_VF_err, min(Tsats)*(1+1E-7), max(Tsats)*(1-1E-7), args=(P, VF, zs))
     Psats = self._Psats(T)
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     V_over_F, xs, ys = flash_inner_loop(zs=zs, Ks=Ks)
     return 'l/g', xs, ys, V_over_F, T
Ejemplo n.º 7
0
 def flash_TP_zs(self, T, P, zs):
     Psats = self._Psats(T)
     Pdew = dew_at_T(zs, Psats)
     Pbubble = bubble_at_T(zs, Psats)
     if P <= Pdew:
         # phase, ys, xs, quality
         return 'g', None, zs, 1
     elif P >= Pbubble:
         return 'l', zs, None, 0
     else:
         Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
         V_over_F, xs, ys = flash_inner_loop(zs=zs, Ks=Ks)
         return 'l/g', xs, ys, V_over_F
Ejemplo n.º 8
0
 def flash_TVF_zs(self, T, VF, zs):
     assert 0 <= VF <= 1
     Psats = self._Psats(T)
     if VF == 0:
         P = bubble_at_T(zs, Psats)
     elif VF == 1:
         P = dew_at_T(zs, Psats)
     else:
         P = brenth(self._T_VF_err,
                    min(Psats) * (1 + 1E-7),
                    max(Psats) * (1 - 1E-7),
                    args=(VF, zs, Psats))
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     V_over_F, xs, ys = flash_inner_loop(zs=zs, Ks=Ks)
     return 'l/g', xs, ys, V_over_F, P
Ejemplo n.º 9
0
 def flash_TVF_zs(self, T, VF, zs):
     assert 0 <= VF <= 1
     Psats = self._Psats(T)
     # handle one component
     if self.N == 1:
         return 'l/g', [1.0], [1.0], VF, Psats[0]
     
     if VF == 0:
         P = bubble_at_T(zs, Psats)
     elif VF == 1:
         P = dew_at_T(zs, Psats)
     else:
         P = brenth(self._T_VF_err, min(Psats)*(1+1E-7), max(Psats)*(1-1E-7), args=(VF, zs, Psats))
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     V_over_F, xs, ys = flash_inner_loop(zs=zs, Ks=Ks)
     return 'l/g', xs, ys, V_over_F, P
Ejemplo n.º 10
0
 def flash_TP_zs(self, T, P, zs):
     Psats = self._Psats(T)
     if self.N == 1:
         Pdew = Pbubble = Psats[0]
     else:
         Pdew = dew_at_T(zs, Psats)
         Pbubble = bubble_at_T(zs, Psats)
     if P <= Pdew:
         # phase, ys, xs, quality - works for 1 comps too
         return 'g', None, zs, 1
     elif P >= Pbubble:
         return 'l', zs, None, 0
     else:
         Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
         V_over_F, xs, ys = flash_inner_loop(zs=zs, Ks=Ks)
         return 'l/g', xs, ys, V_over_F
Ejemplo n.º 11
0
 def _P_VF_err(self, T, P, VF, zs):
     Psats = self._Psats(T)
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     return flash_inner_loop(zs=zs, Ks=Ks)[0] - VF
Ejemplo n.º 12
0
 def _T_VF_err(self, P, VF, zs, Psats):
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     return flash_inner_loop(zs=zs, Ks=Ks)[0] - VF
Ejemplo n.º 13
0
 def _P_VF_err(self, T, P, VF, zs):
     Psats = self._Psats(T)
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     return flash_inner_loop(zs=zs, Ks=Ks)[0] - VF
Ejemplo n.º 14
0
 def _T_VF_err(self, P, VF, zs, Psats):
     Ks = [K_value(P=P, Psat=Psat) for Psat in Psats]
     return flash_inner_loop(zs=zs, Ks=Ks)[0] - VF