def draw_ts():
    '''
    simplified isolines for mixtures in which the calc_isolines() function does not work

    Returns
    -------
    None.

    '''
    states_sat = StateContainer()
    N = 100
    sat_l = CP.AbstractState(library, fluid)
    sat_v = CP.AbstractState(library, fluid)
    Tsat = np.linspace(limits[2],T_crit-0.00001,N)
    s_l = np.zeros(N)
    s_v = np.zeros(N)
    
    if '&' in fluid:
        sat_l.set_mole_fractions([x_molar, 1 - x_molar])
        sat_v.set_mole_fractions([x_molar, 1 - x_molar])
    for i,T in enumerate(Tsat):
        sat_l.update(CP.QT_INPUTS,0,T)
        s_l[i] = sat_l.keyed_output(CP.iSmass)
        sat_v.update(CP.QT_INPUTS,1,T)
        s_v[i] = sat_v.keyed_output(CP.iSmass)
    for i in range(N):
        states_sat.append({'T':Tsat[i],'S':s_l[i]})
    for i in range(N):
        states_sat.append({'T':Tsat[N-1-i],'S':s_v[N-1-i]})
    
    with NoStdStreams():
        pp.draw_process(states_sat,line_opts={'color':'black','linewidth':0.3})
    
    for x in range(1,10):
        states_x = StateContainer()
        for i in range(3,N):
             s = x/10 * s_l[i] + (1-x/10) * s_v[i]
             states_x.append({'T':Tsat[i],'S':s})
        with NoStdStreams():
            pp.draw_process(states_x,line_opts={'color':'black','linewidth':0.1})
Esempio n. 2
0
def create_ts_plot(states: list, fluid: str):
    cycle_states = StateContainer()

    # plot only displays a dot for the state if it occurs twice
    merged_states = []
    for state in states:
        merged_states.append(state['data'])
        if state['marker']:
            merged_states.append(state['data'])

    states = merged_states

    i = 0
    for state in states:
        cycle_states[i, 'P'] = state['P']
        cycle_states[i]['T'] = state['T']
        cycle_states[i]['S'] = state['S']
        cycle_states[i]['H'] = state['H']
        i += 1

    plot = PropertyPlot(fluid, 'TS', tp_limits='ORC')
    plot.calc_isolines(CP.iQ, num=2)
    plot.calc_isolines(CP.iP)

    style = {}
    '''
    style = {
        'marker': 'o',
        'markerfacecolor': 'blue',
        'markeredgecolor': 'blue',
        'color': matplotlib.colors.to_rgba('#ff0000'),
    }
    '''

    plot.draw_process(cycle_states, line_opts=style)

    return plot
Esempio n. 3
0
    def draw_process(self, statecontainer, points=None, line_opts={'color' : 'r', 'lw' : 1.5}):
        """ Draw process or cycle from x and y values in axis units

        Parameters
        ----------
        statecontainer : CoolProp.Plots.SimpleCycles.StateContainer()
            A state container object that contains all the information required to draw the process.
            Note that points that appear several times get added to a special of highlighted points.
        line_opts : dict
            Line options (please see :func:`matplotlib.pyplot.plot`), optional
            Use this parameter to pass a label for the legend.
            
        Examples
        --------
        >>> import CoolProp
        >>> from CoolProp.Plots import PropertyPlot
        >>> pp = PropertyPlot('HEOS::Water', 'TS', unit_system='EUR')
        >>> pp.calc_isolines(CoolProp.iP        )
        >>> pp.calc_isolines(CoolProp.iHmass    )
        >>> pp.calc_isolines(CoolProp.iQ, num=11)
        >>> cycle = SimpleRankineCycle('HEOS::Water', 'TS', unit_system='EUR')
        >>> T0 = 300
        >>> pp.state.update(CoolProp.QT_INPUTS,0.0,T0+15)
        >>> p0 = pp.state.keyed_output(CoolProp.iP)
        >>> T2 = 700
        >>> pp.state.update(CoolProp.QT_INPUTS,1.0,T2-150)
        >>> p2 = pp.state.keyed_output(CoolProp.iP)
        >>> cycle.simple_solve(T0, p0, T2, p2, 0.7, 0.8, SI=True)
        >>> cycle.steps = 50
        >>> sc = cycle.get_state_changes()
        >>> pp.draw_process(sc)
        >>> # The same calculation can be carried out in another unit system:
        >>> cycle.simple_solve(T0-273.15-10, p0/1e5, T2-273.15+50, p2/1e5-5, 0.7, 0.8, SI=False)
        >>> sc2 = cycle.get_state_changes()
        >>> pp.draw_process(sc2, line_opts={'color':'blue', 'lw':1.5})
        >>> pp.show()
        
        """
        warnings.warn("You called the function \"draw_process\", which is not tested.",UserWarning)
        
        
        dimx = self.system[self.x_index]
        dimy = self.system[self.y_index]
        
        marker = line_opts.pop('marker','o')
        style  = line_opts.pop('linestyle','solid')
        style  = line_opts.pop('ls',style)
        
        if points is None: points = StateContainer()
        
        xdata = []
        ydata = []        
        old = statecontainer[len(statecontainer)-1]
        for i in statecontainer:
            point = statecontainer[i]
            if point == old: 
                points.append(point)
                old = point
                continue
            xdata.append(point[self.x_index])
            ydata.append(point[self.y_index])
            old = point
        xdata = dimx.from_SI(numpy.asarray(xdata))
        ydata = dimy.from_SI(numpy.asarray(ydata))
        self.axis.plot(xdata,ydata,marker='None',linestyle=style,**line_opts)
        
        xdata = numpy.empty(len(points))
        ydata = numpy.empty(len(points))
        for i in points:
            point = points[i]
            xdata[i] = point[self.x_index]
            ydata[i] = point[self.y_index]
        xdata = dimx.from_SI(numpy.asarray(xdata))
        ydata = dimy.from_SI(numpy.asarray(ydata))
        line_opts['label'] = ''
        self.axis.plot(xdata,ydata,marker=marker,linestyle='None',**line_opts)
Esempio n. 4
0
    def draw_process(self, statecontainer, points=None, line_opts=None):
        """ Draw process or cycle from x and y values in axis units

        Parameters
        ----------
        statecontainer : CoolProp.Plots.SimpleCycles.StateContainer()
            A state container object that contains all the information required to draw the process.
            Note that points that appear several times get added to a special of highlighted points.
        line_opts : dict
            Line options (please see :func:`matplotlib.pyplot.plot`), optional
            Use this parameter to pass a label for the legend.
            
        Examples
        --------
        >>> import CoolProp
        >>> from CoolProp.Plots import PropertyPlot
        >>> pp = PropertyPlot('HEOS::Water', 'TS', unit_system='EUR')
        >>> pp.calc_isolines(CoolProp.iP        )
        >>> pp.calc_isolines(CoolProp.iHmass    )
        >>> pp.calc_isolines(CoolProp.iQ, num=11)
        >>> cycle = SimpleRankineCycle('HEOS::Water', 'TS', unit_system='EUR')
        >>> T0 = 300
        >>> pp.state.update(CoolProp.QT_INPUTS,0.0,T0+15)
        >>> p0 = pp.state.keyed_output(CoolProp.iP)
        >>> T2 = 700
        >>> pp.state.update(CoolProp.QT_INPUTS,1.0,T2-150)
        >>> p2 = pp.state.keyed_output(CoolProp.iP)
        >>> cycle.simple_solve(T0, p0, T2, p2, 0.7, 0.8, SI=True)
        >>> cycle.steps = 50
        >>> sc = cycle.get_state_changes()
        >>> pp.draw_process(sc)
        >>> # The same calculation can be carried out in another unit system:
        >>> cycle.simple_solve(T0-273.15-10, p0/1e5, T2-273.15+50, p2/1e5-5, 0.7, 0.8, SI=False)
        >>> sc2 = cycle.get_state_changes()
        >>> pp.draw_process(sc2, line_opts={'color':'blue', 'lw':1.5})
        >>> pp.show()
        
        """
        warnings.warn(
            "You called the function \"draw_process\", which is not tested.",
            UserWarning)

        # Default values
        line_opts = line_opts or {'color': 'r', 'lw': 1.5}

        dimx = self.system[self.x_index]
        dimy = self.system[self.y_index]

        marker = line_opts.pop('marker', 'o')
        style = line_opts.pop('linestyle', 'solid')
        style = line_opts.pop('ls', style)

        if points is None: points = StateContainer()

        xdata = []
        ydata = []
        old = statecontainer[len(statecontainer) - 1]
        for i in statecontainer:
            point = statecontainer[i]
            if point == old:
                points.append(point)
                old = point
                continue
            xdata.append(point[self.x_index])
            ydata.append(point[self.y_index])
            old = point
        xdata = dimx.from_SI(np.asarray(xdata))
        ydata = dimy.from_SI(np.asarray(ydata))
        self.axis.plot(xdata,
                       ydata,
                       marker='None',
                       linestyle=style,
                       **line_opts)

        xdata = np.empty(len(points))
        ydata = np.empty(len(points))
        for i in points:
            point = points[i]
            xdata[i] = point[self.x_index]
            ydata[i] = point[self.y_index]
        xdata = dimx.from_SI(np.asarray(xdata))
        ydata = dimy.from_SI(np.asarray(ydata))
        line_opts['label'] = ''
        self.axis.plot(xdata,
                       ydata,
                       marker=marker,
                       linestyle='None',
                       **line_opts)
s_ev,T_ev,T_cf,pinch_ev = hx(fluid,10,M_dot,h[6],h[1],p_low,p_low,T_w_su_ev,M_dot_cw*cp_w)

#%%

from CoolProp.Plots import PropertyPlot
from CoolProp.Plots.SimpleCycles import StateContainer
import pickle
import os

cache_plot = False
if cache_plot:
    filename = fluid + '.p'
    if os.path.isfile(filename):   # Load previously saved plot
        pp = pickle.load(open( filename, "rb" ) )
    else:
        states = StateContainer()
        states_hf = StateContainer()
        states_cf = StateContainer()
        pp = PropertyPlot('HEOS::'+fluid, 'TS')
        with NoStdStreams():
            pp.calc_isolines()
        with open(filename, 'wb') as f: 
            pickle.dump(pp, f) 
else:
    states = StateContainer()
    states_hf = StateContainer()
    states_cf = StateContainer()
    pp = PropertyPlot('HEOS::'+fluid, 'TS')
    with NoStdStreams():
        pp.calc_isolines()
        
Esempio n. 6
0
#fluid = 'Pentane[0.697615]&Hexane[0.302385]'
#fluid = 'Butane[0.5]&Hexane[0.5]'
fluid = 'Butane'

library = 'HEOS'
library = 'REFPROP'

limits = [0, 1.75, 250, 550]  # limits for plotting

cache_plot = False
if cache_plot:
    filename = fluid + '.p'
    if os.path.isfile(filename):  # Load previously saved plot
        pp = pickle.load(open(filename, "rb"))
    else:
        states = StateContainer()
        states_hf = StateContainer()
        states_cf = StateContainer()
        pp = PropertyPlot(library + '::' + fluid, 'TS')
        with NoStdStreams():
            pp.calc_isolines()
        with open(filename, 'wb') as f:
            pickle.dump(pp, f)
else:
    states = StateContainer()
    states_hf = StateContainer()
    states_cf = StateContainer()
    pp = PropertyPlot(library + '::' + fluid, 'TS')
    #    pp.set_axis_limits(limits)
    with NoStdStreams():
        pp.calc_isolines()