Esempio n. 1
0
def solve_point(point, molecules, pressure, temperature):
    i, j, k = point
    zcomp = normalize_list([j + 0.01, i + 0.01, k + 0.01])
    #print ('Solving zcomp:', zcomp)
    mix = Mixture(molecules, zcomp)
    Flash.flash_mixture(mix, pressure, temperature)
    return mix
Esempio n. 2
0
def create_composition_data(points):
    ternary_cols = ['M', 'z', 'x', 'y']
    rows = len(points)
    comp_dfs = []
    for comp in range(len(molecules)):
        comp_df = pd.DataFrame([[0 for _ in range(rows)]
                                for _ in range(len(ternary_cols))],
                               ternary_cols)
        comp_dfs.append(comp_df)
    count = 0
    for i, j, k in points:
        zFracs = [i + 0.1, j + 0.1, k + 0.1]
        normalize_list(zFracs)
        mix = Mixture(molecules, zFracs)
        Flash.flash_mixture(mix, psi, rankine)
        for m in range(len(molecules)):
            comp_dfs[m][count] = mix.fluids[['molecule', 'z', 'x', 'y']].ix[m]
        count += 1
    return comp_dfs
import Flash
from Mixture import Mixture

psi = 3000
rankine = 160 + 460
molecules = ['C1', 'C4', 'C10']
zFracs = [0.6301, 0.1055, 0.2644]

mix = Mixture()
mix.initialize_fluids(molecules, zFracs)

Flash.flash_mixture(mix, psi, rankine)

print
print '-----Results-----'
print mix.zFactors
print mix.xFracs
print mix.yFracs
Esempio n. 4
0
def create_ternary(molecules,
                   pressure,
                   temperature,
                   amt=30,
                   heatmap=False,
                   tie_lines=False,
                   specific_zFracs=[],
                   finish_curve=False):
    scale = 2
    points = len(list(ternary.helpers.simplex_iterator(scale)))
    while points <= amt:
        scale += 1
        points = len(list(ternary.helpers.simplex_iterator(scale)))
    scale -= 1
    points = list(ternary.helpers.simplex_iterator(scale))
    rows = len(points)
    print('using number of points:', rows)
    print('scale set to:', scale)
    cmap = plt.cm.get_cmap('summer')
    f, ax = plt.subplots(1, 1, figsize=(10, 8))
    figure, tax = ternary.figure(ax=ax, scale=scale)
    style = 'h'
    # can be changed for colorized axes on composition (b: bottom, l: left, r: right)
    axes_colors = {'b': 'black', 'l': 'black', 'r': 'black'}
    mixed_data = []
    if heatmap:
        mixed_data = create_composition_data(molecules, pressure, temperature,
                                             points, scale)
        values = mixed_data[0]
        tax.heatmap(dict(zip(points, values)),
                    scale=scale,
                    cmap=cmap,
                    vmax=1,
                    style=style,
                    colorbar=True)

    tax.boundary(linewidth=2.0, axes_colors=axes_colors)

    tax.left_axis_label("C3", offset=0.16, color=axes_colors['l'])
    tax.right_axis_label("C1", offset=0.16, color=axes_colors['r'])
    tax.bottom_axis_label("C2", offset=-0.06, color=axes_colors['b'])

    tax.gridlines(multiple=1,
                  linewidth=1,
                  horizontal_kwargs={'color': axes_colors['b']},
                  left_kwargs={'color': axes_colors['l']},
                  right_kwargs={'color': axes_colors['r']},
                  alpha=0.6)

    ticks = [round(i / float(scale), 1) for i in reversed(range(scale + 1))]
    tax.ticks(ticks=ticks,
              axis='lbr',
              linewidth=1,
              clockwise=True,
              axes_colors=axes_colors,
              offset=0.03)
    tax.clear_matplotlib_ticks()
    tax._redraw_labels()
    #tie-lines
    prev_xs = []
    prev_ys = []
    max_phases = [0.64, 0.21, 0.15]
    print('max phases:', max_phases)
    cnt = 0
    while max_phases[1] > 0 and cnt < 10 and tie_lines:
        pnt = (max_phases[0], max_phases[1], max_phases[2])
        tie_mix = Mixture(molecules, max_phases)
        Flash.flash_mixture(tie_mix, pressure, temperature)
        diff = 0.05
        max_phases[1] -= diff
        max_phases[2] += diff
        if tie_mix.vapor == 0 or tie_mix.vapor == 1:
            print('not in two-phase', pnt)
            continue
        cnt += 1
        fluids = tie_mix.fluids
        xs = [
            fluids['x'][1] * scale, fluids['x'][0] * scale,
            fluids['x'][2] * scale
        ]
        ys = [
            fluids['y'][1] * scale, fluids['y'][0] * scale,
            fluids['y'][2] * scale
        ]
        if len(prev_xs) > 0 and len(prev_ys) > 0:
            tax.plot([xs, prev_xs],
                     linewidth=1.0,
                     label="Two-Phase Curve",
                     color='b')
            tax.plot([ys, prev_ys],
                     linewidth=1.0,
                     label="Two-Phase Curve",
                     color='b')
        prev_xs = xs
        prev_ys = ys
        tax.plot([xs, ys], linewidth=1, label="Tie-Line", color='b')
    if len(specific_zFracs) > 0:
        z1 = specific_zFracs[1]
        z2 = specific_zFracs[0]
        z3 = specific_zFracs[2]
        specific_mix = Mixture(molecules, [z1, z2, z3])
        Flash.flash_mixture(specific_mix, pressure, temperature)
        fluids = specific_mix.fluids
        zss = [
            fluids['z'][1] * scale, fluids['z'][0] * scale,
            fluids['z'][2] * scale
        ]
        xss = [
            fluids['x'][1] * scale, fluids['x'][0] * scale,
            fluids['x'][2] * scale
        ]
        yss = [
            fluids['y'][1] * scale, fluids['y'][0] * scale,
            fluids['y'][2] * scale
        ]
        tax.plot([xss, zss], linewidth=2.5, label="Specific-Line", color='r')
        tax.plot([zss, yss],
                 linewidth=2.5,
                 label="Specific-Line",
                 color='pink')
    if tie_lines and heatmap and finish_curve:
        prev_xs = []
        prev_ys = []
        final_mixes = mixed_data[2]
        for f_mix in final_mixes:
            print f_mix
            fluids = f_mix.fluids
            xs = [
                fluids['x'][1] * scale, fluids['x'][0] * scale,
                fluids['x'][2] * scale
            ]
            ys = [
                fluids['y'][1] * scale, fluids['y'][0] * scale,
                fluids['y'][2] * scale
            ]
            if len(prev_xs) > 0 and len(prev_ys) > 0:
                tax.plot([xs, prev_xs],
                         linewidth=1.0,
                         label="Two-Phase Curve",
                         color='b')
                tax.plot([ys, prev_ys],
                         linewidth=1.0,
                         label="Two-Phase Curve",
                         color='b')
            prev_xs = xs
            prev_ys = ys
            tax.plot([xs, ys], linewidth=1, label="Tie-Line", color='b')
    tax.show()
    return tax