def add_distillation_cut_boiling_point(imported_rec, oil): ''' if cuts exist: copy them over else: get a single cut from the API ''' for c in imported_rec.cuts: # Most of our oils seem to be fractional amounts regardless of # the stated cut units. There are only a small number of outliers # - 2 cuts are negative, which is impossible # - 55 are between 1.0 and 10.0 which could possibly be percent # values, but since they are so low, it is unlikely. if c.fraction >= 0.0 and c.fraction <= 1.0: oil.cuts.append(c) else: print('{0}: {1}: bad distillation cut!'.format(imported_rec, c)) if not oil.cuts: mass_left = 1.0 mass_left -= sum([ f.fraction for f in oil.sara_fractions if f.sara_type in ('Resins', 'Asphaltenes') ]) # if imported_rec.resins: # mass_left -= imported_rec.resins # # if imported_rec.asphaltene_content: # mass_left -= imported_rec.asphaltene_content summed_boiling_points = [] for t, f in get_boiling_points_from_api(5, mass_left, oil.api): added_to_sums = False for idx, [ut, summed_value] in enumerate(summed_boiling_points): if np.isclose(t, ut): summed_boiling_points[idx][1] += f added_to_sums = True break if added_to_sums is False: summed_boiling_points.append([t, f]) accumulated_frac = 0.0 for t_i, fraction in summed_boiling_points: accumulated_frac += fraction oil.cuts.append(Cut(fraction=accumulated_frac, vapor_temp_k=t_i)) oil.estimated.cuts = True
def add_distillation_cut_boiling_point(imported_rec, oil): ''' if cuts exist: copy them over else: get a single cut from the API ''' for c in imported_rec.cuts: # Most of our oils seem to be fractional amounts regardless of # the stated cut units. There are only a small number of outliers # - 2 cuts are negative, which is impossible # - 55 are between 1.0 and 10.0 which could possibly be percent # values, but since they are so low, it is unlikely. if c.fraction >= 0.0 and c.fraction <= 1.0: oil.cuts.append(c) else: print ('{0}: {1}: bad distillation cut!'.format(imported_rec, c)) if not oil.cuts: mass_left = 1.0 mass_left -= sum([f.fraction for f in oil.sara_fractions if f.sara_type in ('Resins', 'Asphaltenes')]) # if imported_rec.resins: # mass_left -= imported_rec.resins # # if imported_rec.asphaltene_content: # mass_left -= imported_rec.asphaltene_content summed_boiling_points = [] for t, f in get_boiling_points_from_api(5, mass_left, oil.api): added_to_sums = False for idx, [ut, summed_value] in enumerate(summed_boiling_points): if np.isclose(t, ut): summed_boiling_points[idx][1] += f added_to_sums = True break if added_to_sums is False: summed_boiling_points.append([t, f]) accumulated_frac = 0.0 for t_i, fraction in summed_boiling_points: accumulated_frac += fraction oil.cuts.append(Cut(fraction=accumulated_frac, vapor_temp_k=t_i)) oil.estimated.cuts = True
def test_boiling_point(max_cuts): ''' some basic testing of boiling_point function - checks the expected BP for 0th component for api=1 - checks len(bp) == max_cuts * 2 - also checks the BP for saturates == BP for aromatics ''' api = 1 slope = 1356.7 intercept = 457.16 - 3.3447 exp_bp_0 = 1. / (max_cuts * 2) * slope + intercept bp = get_boiling_points_from_api(max_cuts, 1.0, api) print '\nBoiling Points: ' print bp assert len(bp) == max_cuts * 2 assert ([bp[ix][0] - bp[ix + 1][0] for ix in range(0, max_cuts * 2, 2)] == [0.0] * max_cuts) assert [n[0] for n in bp[:2]] == [exp_bp_0] * 2
def test_boiling_point(max_cuts): ''' some basic testing of boiling_point function - checks the expected BP for 0th component for api=1 - checks len(bp) == max_cuts * 2 - also checks the BP for saturates == BP for aromatics ''' api = 1 slope = 1356.7 intercept = 457.16 - 3.3447 exp_bp_0 = 1./(max_cuts * 2) * slope + intercept bp = get_boiling_points_from_api(max_cuts, 1.0, api) print '\nBoiling Points: ' print bp assert len(bp) == max_cuts * 2 assert ([bp[ix][0] - bp[ix + 1][0] for ix in range(0, max_cuts * 2, 2)] == [0.0] * max_cuts) assert [n[0] for n in bp[:2]] == [exp_bp_0] * 2