In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
In [2]:
import libr3
In [3]:
# Pressure in [Pa]
bar = 1e5
P = 0.1*bar
gen = libr3.GeneratorLiBr(P,1,60,0.5,0.75)
In [4]:
gen
Out[4]:
-----------  ----------------  -----
P             10000            Pa
x_in              0.5          kg/kg
x_out             0.75         kg/kg
T_in             60            C
m_in              1            kg/s
T_sat            71.5728       C
T_out           129.644        C
m_out             0.666667     kg/s
m_vapor_out       0.333333     kg/s
h_in         127480            J/kg
h_sat        152894            J/kg
h_out        378382            J/kg
h_vapor_out       2.54927e+06  J/kg
Q_preheat     25413.7          W
Q_desorb     949118            W
Q_total      974532            W
-----------  ----------------  -----
In [5]:
gen.q(91.9642)
Out[5]:
array(472624.30215689156)
In [6]:
T = np.linspace(gen.T_in,gen.T_out)
plt.plot(gen.q(T),T,'-o')
plt.xlabel('q (W)')
plt.ylabel('T ($^\circ$C)')
Out[6]:
<matplotlib.text.Text at 0x7c20050>
In [7]:
from HRHX_integral_model import *
useHotT = True

cold = streamExample1(0)
hot = streamExample1(1,-1)
ci = counterflow_integrator(cold, hot, useHotT)
Qmax = ci.Qmax
print "Qmax=",Qmax
UA=ci.calcUA(Qmax/2)
print "UA=",UA

plotFlow(ci)
plotNN(ci)

c2 = streamExample2(-5.,100.,1.,1.,10.)
h2 = streamExample1(120.,-1.5)
ci2 = counterflow_integrator(c2,h2, useHotT)
print ci2.Qmax

plotFlow(ci2)
plotNN(ci2)
plt.show()

c3 = streamExample2(-5.,100.,1.,1.,10.)
h3 = streamExample2(15.,100.,-1.,1.,10.)
ci3 = counterflow_integrator(c3,h3, useHotT)
print ci3.Qmax

plotFlow(ci3)
plotNN(ci3)
plt.show()

QQ=np.arange(0,35)
Tc=c3.T(QQ)
Th=h3.T(QQ)
TT=np.arange(95,110)
Qc=c3.q(TT)
Qh=h3.q(TT)
plt.figure();plt.plot(QQ,Tc,QQ,Th);plt.plot(Qc,TT,'.',Qh,TT,'.')
qc =  1.0
    nfev: 32
 success: True
     fun: 1.0
       x: array([ 0.32564491])
 message: 'Optimization terminated successfully.'
     nit: 1
Qmax= 1.0
UA= 1.0
qc =  35.0
    nfev: 203
 success: True
     fun: array([ 35.0009628])
       x: array([ 30.0028884])
 message: 'Optimization terminated successfully.'
     jac: array([ 0.33333407])
     nit: 8
35.0009628011
qc =  20.0
    nfev: 169
 success: True
     fun: array([ 10.00083088])
       x: array([ 5.00083088])
 message: 'Optimization terminated successfully.'
     jac: array([ 0.99999991])
     nit: 6
10.0008308816
C:\Python27\lib\site-packages\scipy\integrate\quadpack.py:352: IntegrationWarning: The maximum number of subdivisions (50) has been achieved.
  If increasing the limit yields no improvement it is advised to analyze 
  the integrand in order to determine the difficulties.  If the position of a 
  local difficulty can be determined (singularity, discontinuity) one will 
  probably gain from splitting up the interval and calling the integrator 
  on the subranges.  Perhaps a special-purpose integrator should be used.
  warnings.warn(msg, IntegrationWarning)
Out[7]:
[<matplotlib.lines.Line2D at 0xe037db0>,
 <matplotlib.lines.Line2D at 0xe0455b0>]
In [8]:
# Pressure in [Pa]
bar = 1e5
P = 0.1*bar
m_in = 0.2 #kg/s
T_in = 60 # deg C
x_in,x_out = 0.5,0.69
gen2 = libr3.GeneratorLiBr(P,m_in,T_in,x_in,x_out)
print gen2
print gen2.Tmax
-----------  ----------------  -----
P             10000            Pa
x_in              0.5          kg/kg
x_out             0.69         kg/kg
T_in             60            C
m_in              0.2          kg/s
T_sat            71.5728       C
T_out           112.987        C
m_out             0.144928     kg/s
m_vapor_out       0.0550725    kg/s
h_in         127480            J/kg
h_sat        152894            J/kg
h_out        307808            J/kg
h_vapor_out       2.54927e+06  J/kg
Q_preheat      5082.74         W
Q_desorb     154426            W
Q_total      159509            W
-----------  ----------------  -----
115.476821248
In [9]:
#%%prun
T = np.linspace(gen2.T_in,gen2.T_out)
Qc = gen2.q(T)
QQ = np.linspace(0,2e5)
Tc = gen2.T(QQ)

plt.figure()
plt.plot(QQ,Tc)
plt.plot(Qc,T,'.')
plt.xlabel('q (W)')
plt.ylabel('T ($^\circ$C)')
Out[9]:
<matplotlib.text.Text at 0x7dec670>
In [10]:
#%%prun
genhot = streamExample1(130,-10000,1)
#cigen = counterflow_integrator(gen2,genhot, False)
"""      1446681 function calls (1445561 primitive calls) in 25.872 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    46222    9.878    0.000   10.462    0.000 libr_props.py:53(thetaFun)
    27880    9.728    0.000    9.930    0.000 {CoolProp.CoolProp.PropsSI}
     5576    2.255    0.000    9.536    0.002 libr_props.py:187(massSpecificEnthalp"""
cigen = counterflow_integrator(gen2,genhot, True)
qc =  196814.493348
    nfev: 132
 success: True
     fun: array([ 196814.49334797])
       x: array([ 0.])
 message: 'Optimization terminated successfully.'
     jac: array([ 0.82654878])
     nit: 7
        93629 function calls (93497 primitive calls) in 1.483 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     2982    0.576    0.000    0.616    0.000 libr_props.py:53(thetaFun)
     1720    0.569    0.000    0.569    0.000 {CoolProp.CoolProp.PropsSI}
      344    0.074    0.000    0.493    0.001 libr_props.py:187(massSpecificEnthalpy)
In [14]:
# Warning: this calls inverse function, T(q), and is very slow.
plotFlow(cigen)
plt.legend(loc='best')
Out[14]:
<matplotlib.legend.Legend at 0xdcc31b0>
In [16]:
# Pressure in [Pa]
bar = 1e5
P = 0.1*bar
m_in = 0.2 #kg/s
T_in = 60 # deg C
x_in,x_out = 0.5,0.69
gen3 = libr3.GeneratorLiBrInterpolated(P,m_in,T_in,x_in,x_out)
print gen3
print gen3.q
print gen3.q(115), gen3.q(116)
I am still alive!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[  60.           61.13218003   62.26436005   63.39654008   64.5287201
   65.66090013   66.79308015   67.92526018   69.0574402    70.18962023
   71.32180025   72.45398028   73.58616031   74.71834033   75.85052036
   76.98270038   78.11488041   79.24706043   80.37924046   81.51142048
   82.64360051   83.77578053   84.90796056   86.04014059   87.17232061
   88.30450064   89.43668066   90.56886069   91.70104071   92.83322074
   93.96540076   95.09758079   96.22976082   97.36194084   98.49412087
   99.62630089  100.75848092  101.89066094  103.02284097  104.15502099
  105.28720102  106.41938104  107.55156107  108.6837411   109.81592112
  110.94810115  112.08028117  113.2124612   114.34464122  115.47682125
  215.47682125]
[      0.             497.25107409     994.50214819    1491.75322228
    1989.00429638    2486.25537047    2983.50644457    3480.75751866
    3978.00859275    4475.25966685    4972.51074094   10186.10953806
   16479.51677793   22507.71242783   28299.56778798   33879.87988638
   39270.06377871   44488.70239458   49551.98644479   54474.06961306
   59267.35607741   63942.73569648   68509.77703129   72976.88646954
   77351.44087776   81639.89840446   85847.89235847   89980.31153635
   94041.37027086   98034.67069742  101963.25949798  105829.68096205
  109636.02784097  113383.99107503  117074.90903392  120709.81642504
  124289.49249965  127814.5076909   131285.26692764  134702.04869832
  138065.03602077  141374.33860479  144630.00266058  147832.00709895
  150980.24430549  154074.48546978  157114.33163364  160099.15382032
  163028.02832313  165899.67655228  165899.67655228]
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------  ----------------  -----
P             10000            Pa
x_in              0.5          kg/kg
x_out             0.69         kg/kg
T_in             60            C
m_in              0.2          kg/s
T_sat            71.5728       C
T_out           112.987        C
m_out             0.144928     kg/s
m_vapor_out       0.0550725    kg/s
h_in         127480            J/kg
h_sat        152894            J/kg
h_out        307808            J/kg
h_vapor_out       2.54927e+06  J/kg
Q_preheat      5082.74         W
Q_desorb     154426            W
Q_total      159509            W
-----------  ----------------  -----
<scipy.interpolate._monotone.PchipInterpolator object at 0x0E56D670>
165098.408646 nan
In [15]:
#%%prun
T = np.linspace(gen3.T_in,gen3.Tmax+10)
Qc = gen3.q(T)
QQ = np.linspace(0,gen3._q(gen3.Tmax)*1.2)
Tc = gen3.T(QQ)

plt.figure()
plt.plot(QQ,Tc)
plt.plot(Qc,T,'.')
plt.xlabel('q (W)')
plt.ylabel('T ($^\circ$C)')
print gen2.Tmax
115.476821248
In [13]:
import tabulate
print gen3.Tmax, gen3._q(gen3.Tmax), gen3.q(gen3.Tmax)
print tabulate.tabulate(zip(T,Qc,Tc,QQ))
115.476821248 165899.676552 nan
--------  -----------  --------  ---------
 55        30014.6      60            0
 56.4383   11879.4      67.7088    3385.71
 57.8766    2922.95     71.8027    6771.42
 59.3149      86.7132   72.4483   10157.1
 60.7532     312.276    73.0666   13542.8
 62.1915     962.508    73.6688   16928.5
 63.6298    1594.21     74.301    20314.2
 65.0681    2225.91     74.9477   23700
 66.5064    2857.61     75.6097   27085.7
 67.9447    3489.31     76.2863   30471.4
 69.383     4121        76.978    33857.1
 70.8213    4696.19     77.6847   37242.8
 72.2596    9128.42     78.4061   40628.5
 73.6979   17086.1      79.1427   44014.2
 75.1362   24671.8      79.894    47399.9
 76.5745   31891        80.66     50785.6
 78.0128   38791.5      81.4409   54171.3
 79.4511   45412.6      82.2363   57557
 80.8894   51786.8      83.0461   60942.7
 82.3277   57942.4      83.8704   64328.4
 83.766    63903        84.7089   67714.2
 85.2044   69688.6      85.5615   71099.9
 86.6427   75316        86.428    74485.6
 88.081    80799.7      87.3084   77871.3
 89.5193   86151.8      88.2025   81257
 90.9576   91382.4      89.1103   84642.7
 92.3959   96499.9      90.0316   88028.4
 93.8342  101511        90.9664   91414.1
 95.2725  106422        91.9146   94799.8
 96.7108  111235        92.8764   98185.5
 98.1491  115956        93.8516  101571
 99.5874  120586        94.8405  104957
101.026   125126        95.8431  108343
102.464   129579        96.8597  111728
103.902   133944        97.8905  115114
105.341   138222        98.9359  118500
106.779   142414        99.9962  121885
108.217   146519       101.072   125271
109.655   150537       102.164   128657
111.094   154469       103.272   132043
112.532   158312       104.398   135428
113.97    162066       105.542   138814
115.409   165880       106.705   142200
116.847      nan       107.887   145585
118.285      nan       109.091   148971
119.724      nan       110.317   152357
121.162      nan       111.567   155743
122.6        nan       112.842   159128
124.039      nan       114.144   162514
125.477      nan       115.477   165900
--------  -----------  --------  ---------
In [14]:
%%prun
#cigen = counterflow_integrator(gen2,genhot, False)
cigen = counterflow_integrator(gen3,genhot, True)
qc =  nan
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-0371f834cf64> in <module>()
----> 1 get_ipython().run_cell_magic(u'prun', u'', u'#cigen = counterflow_integrator(gen2,genhot, False)\ncigen = counterflow_integrator(gen3,genhot, True)')

C:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)
   2160             magic_arg_s = self.var_expand(line, stack_depth)
   2161             with self.builtin_trap:
-> 2162                 result = fn(magic_arg_s, cell)
   2163             return result
   2164 

C:\Python27\lib\site-packages\IPython\core\magics\execution.pyc in prun(self, parameter_s, cell)

C:\Python27\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194 
    195         if callable(arg):

C:\Python27\lib\site-packages\IPython\core\magics\execution.pyc in prun(self, parameter_s, cell)
    251             arg_str += '\n' + cell
    252         arg_str = self.shell.input_splitter.transform_cell(arg_str)
--> 253         return self._run_with_profiler(arg_str, opts, self.shell.user_ns)
    254 
    255     def _run_with_profiler(self, code, opts, namespace):

C:\Python27\lib\site-packages\IPython\core\magics\execution.pyc in _run_with_profiler(self, code, opts, namespace)
    273         prof = profile.Profile()
    274         try:
--> 275             prof = prof.runctx(code, namespace, namespace)
    276             sys_exit = ''
    277         except SystemExit:

C:\Python27\lib\cProfile.pyc in runctx(self, cmd, globals, locals)
    138         self.enable()
    139         try:
--> 140             exec cmd in globals, locals
    141         finally:
    142             self.disable()

<string> in <module>()

C:\Users\nfette\Documents\GitHub\openACHP\src\HRHX_integral_model.pyc in __init__(self, cold, hot, useHotT)
     63         self.hot = hot
     64         self.useHotT = useHotT
---> 65         self.calcQmax()
     66     def calcUA(self,Q):
     67         func = lambda(q):1./(self.hot.T(Q-q)-self.cold.T(q))

C:\Users\nfette\Documents\GitHub\openACHP\src\HRHX_integral_model.pyc in calcQmax(self, extra, brute)
     89                         "jac":lambda(Q):-1}]
     90         if brute:
---> 91             opt = scipy.optimize.differential_evolution(func,[(0,qc)])
     92             print opt
     93         else:

C:\Python27\lib\site-packages\scipy\optimize\_differentialevolution.pyc in differential_evolution(func, bounds, args, strategy, maxiter, popsize, tol, mutation, recombination, seed, callback, disp, polish, init)
    199                                          callback=callback,
    200                                          disp=disp,
--> 201                                          init=init)
    202     return solver.solve()
    203 

C:\Python27\lib\site-packages\scipy\optimize\_differentialevolution.pyc in __init__(self, func, bounds, args, strategy, maxiter, popsize, tol, mutation, recombination, seed, maxfun, callback, disp, polish, init)
    350         if (np.size(self.limits, 0) != 2
    351                 or not np.all(np.isfinite(self.limits))):
--> 352             raise ValueError('bounds should be a sequence containing '
    353                              'real valued (min, max) pairs for each value'
    354                              ' in x')

ValueError: bounds should be a sequence containing real valued (min, max) pairs for each value in x
In [20]:
%
ERROR: Cell magic `%%version` not found.
In [ ]: