def test_reaction():
    # Test corners in code
    tmo.settings.set_thermo(['H2O', 'H2', 'O2'], cache=True)
    reaction = tmo.Reaction('', reactant='H2O', X=1.,
                            correct_atomic_balance=True)
    assert not reaction.stoichiometry.any()
    
    # Test math cycles, making sure they balance out
    reaction = tmo.Reaction('2H2O -> 2H2 + O2', reactant='H2O',
                            correct_atomic_balance=True, X=0.5)
    same_reaction = reaction.copy()
    reaction += same_reaction
    reaction -= same_reaction
    assert_allclose(reaction.X, same_reaction.X)
    reaction *= 2.
    reaction /= 2.
    assert_allclose(reaction.X, same_reaction.X)
    
    # Test negative math
    negative_reaction = 2 * -reaction
    assert_allclose(negative_reaction.X, -1.)
    
    # Test errors with incompatible phases
    reaction = tmo.Reaction('H2O,l -> H2,g + O2,g', reactant='H2O',
                            correct_atomic_balance=True, X=0.7)
    stream = tmo.MultiStream(None, l=[('H2O', 10)], phases='lL')
    with pytest.raises(ValueError): reaction(stream)
    
    # Test errors with incompatible chemicals
    stream = tmo.MultiStream(None, l=[('Water', 10)], 
                             thermo=tmo.Thermo(['Water', 'Ethanol']),
                             phases='gl')
    with pytest.raises(tmo.exceptions.UndefinedChemical): reaction(stream)
Example #2
0
def test_multistream():
    import thermosteam as tmo
    tmo.settings.set_thermo(['Water'], cache=True)
    stream = tmo.MultiStream(None, l=[('Water', 1)], T=300)
    assert [stream.chemicals.Water] == stream.available_chemicals
    assert_allclose(stream.epsilon, 77.72395675564552)
    assert_allclose(stream.alpha * 1e6, 0.1462889847474686)
    assert_allclose(stream.nu, 8.596760626756933e-07)
    assert_allclose(stream.Pr, 5.876560454361681)
    assert_allclose(stream.Cn, 75.29555729396768)
    assert_allclose(stream.C, 75.29555729396768)
    assert_allclose(stream.Cp, 4.179538552493643)
    assert_allclose(stream.P_vapor, 3533.918074415897)
    assert_allclose(stream.mu, 0.0008564676992124578)
    assert_allclose(stream.kappa, 0.609138593165859)
    assert_allclose(stream.rho, 996.2679390499142)
    assert_allclose(stream.V, 1.808276598480142e-05)
    assert_allclose(stream.H, 139.3139852692184)
    assert_allclose(stream.S, 0.4658177637668395)
    assert_allclose(stream.sigma, 0.07168596252716256)
    assert_allclose(stream.z_mol, [1.0])
    assert_allclose(stream.z_mass, [1.0])
    assert_allclose(stream.z_vol, [1.0])
    assert not stream.source
    assert not stream.sink
    assert stream.main_chemical == 'Water'
    assert not stream.isfeed()
    assert not stream.isproduct()
    assert stream.vapor_fraction == 0.
    with pytest.raises(ValueError):
        stream.get_property('isfeed', 'kg/hr')
    with pytest.raises(ValueError):
        stream.set_property('invalid property', 10, 'kg/hr')
    with pytest.raises(ValueError):
        tmo.MultiStream(None, l=[('Water', 1)], units='kg')
    
    stream.empty()
    
    with pytest.raises(AttributeError):
        stream.mol = 1.
    with pytest.raises(AttributeError):
        stream.mass = 1.
    with pytest.raises(AttributeError):
        stream.vol = 1.
    with pytest.raises(AttributeError):
        stream.F_mol = 1.
    with pytest.raises(AttributeError):
        stream.F_mass = 1.
    with pytest.raises(AttributeError):
        stream.F_vol = 1.
Example #3
0
 def __init__(self,
              ID='',
              ins=None,
              outs=(),
              thermo=None,
              top_chemical=None):
     super().__init__(ID, ins, outs, thermo)
     self._multistream = tmo.MultiStream(None,
                                         phases=('L', 'l'),
                                         thermo=thermo)
     self.top_chemical = top_chemical
Example #4
0
 def __init__(self,
              ID='',
              ins=None,
              outs=(),
              *,
              reactions,
              sludge_split,
              T):
     Unit.__init__(self, ID, ins, outs)
     self.reactions = reactions
     self.sludge_split = sludge_split
     self.multi_stream = tmo.MultiStream()
     self.T = T
Example #5
0
 def __init__(self,
              T=298.15,
              P=101325,
              feed=None,
              solvent=None,
              thermo=None,
              carrier_chemical=None):
     self.feed = feed
     self.solvent = solvent
     thermo = self._load_thermo(thermo)
     self.multi_stream = multi_stream = tmo.MultiStream(None,
                                                        T=T,
                                                        P=P,
                                                        phases=('l', 'L'),
                                                        thermo=thermo)
     self.raffinate = multi_stream['l']
     self.extract = multi_stream['L']
     self.carrier_chemical = carrier_chemical
 def __init__(self,
              N_stages,
              feed,
              solvent,
              carrier_chemical=None,
              thermo=None,
              partition_data=None):
     thermo = self._load_thermo(thermo)
     self.multi_stream = tmo.MultiStream(None,
                                         phases=('l', 'L'),
                                         thermo=thermo)
     self.stages = stages = [
         StageLLE(thermo=thermo) for i in range(N_stages)
     ]
     self.carrier_chemical = carrier_chemical
     self.partition_data = partition_data
     for i in range(N_stages - 1):
         stage = stages[i]
         next_stage = stages[i + 1]
         next_stage.feed = stage.raffinate
         stage.solvent = next_stage.extract
     stages[0].feed = feed
     stages[-1].solvent = solvent
 def _load_components(self):
     self.multi_stream = tmo.MultiStream(thermo=self.thermo)
Example #8
0
 def __init__(self,
              ID='',
              ins=None,
              outs=(),
              thermo=None,
              *,
              reactions=None,
              sludge_split=None):
     Unit.__init__(self, ID, ins, outs, thermo)
     chemicals = self.chemicals
     if not reactions:
         digestables = get_digestable_organic_chemicals(chemicals)
         reactions = anaerobic_digestion_reactions(digestables,
                                                   chemicals.WWTsludge.MW,
                                                   thermo=self.thermo)
     self.reactions = reactions
     if sludge_split is None:
         sludge_split = dict(Water=0.07087,
                             Ethanol=0.0625,
                             Furfural=0.06667,
                             Glycerol=0.07377,
                             LacticAcid=0.07084,
                             SuccinicAcid=0.07377,
                             HNO3=0.0678,
                             Denaturant=0.07377,
                             DAP=0.0678,
                             AmmoniumAcetate=0.07084,
                             AmmoniumSulfate=0.0678,
                             NaNO3=0.0678,
                             Oil=0.07377,
                             HMF=0.06667,
                             NH3=0.07048,
                             Glucose=0.06667,
                             Xylose=0.07609,
                             Sucrose=0.06915,
                             Mannose=0.06915,
                             Galactose=0.06915,
                             Arabinose=0.06915,
                             Extract=0.07084,
                             Tar=0.7473,
                             CaO=0.7473,
                             Ash=0.7473,
                             NaOH=0.0678,
                             Lignin=0.744,
                             SolubleLignin=0.07084,
                             GlucoseOligomer=0.07143,
                             GalactoseOligomer=0.07143,
                             MannoseOligomer=0.07143,
                             XyloseOligomer=0.07143,
                             ArabinoseOligomer=0.07143,
                             Z_mobilis=0.7438,
                             T_reesei=0.7438,
                             Cellulose=0.76,
                             Protein=0.7391,
                             Enzyme=0.7391,
                             Xylan=0.75,
                             Xylitol=0.07377,
                             Cellobiose=0.06915,
                             DenaturedEnzyme=0.7391,
                             Arabinan=1,
                             Mannan=1,
                             Galactan=1,
                             WWTsludge=0.7438,
                             Cellulase=0.07084)
         remove_undefined_chemicals(sludge_split, chemicals)
     self.sludge_split = chemicals.isplit(sludge_split)
     self.multi_stream = tmo.MultiStream(thermo=self.thermo)
    def __init__(self,
                 ID='',
                 ins=None,
                 outs=(),
                 thermo=None,
                 P=101325,
                 *,
                 LHK,
                 k,
                 Rmin=0.3,
                 Lr=None,
                 Hr=None,
                 y_top=None,
                 x_bot=None,
                 product_specification_format=None,
                 vessel_material='Carbon steel',
                 tray_material='Carbon steel',
                 tray_type='Sieve',
                 tray_spacing=450,
                 stage_efficiency=None,
                 velocity_fraction=0.8,
                 foaming_factor=1.0,
                 open_tray_area_fraction=0.1,
                 downcomer_area_fraction=None,
                 is_divided=False):
        Unit.__init__(self, ID, ins, outs, thermo)

        # Operation specifications
        self.k = k
        self.P = P
        self.Rmin = Rmin
        self.LHK = LHK
        self._set_distillation_product_specifications(
            product_specification_format, x_bot, y_top, Lr, Hr)

        # Construction specifications
        self.vessel_material = vessel_material
        self.tray_type = tray_type
        self.tray_material = tray_material
        self.tray_spacing = tray_spacing
        self.stage_efficiency = stage_efficiency
        self.velocity_fraction = velocity_fraction
        self.foaming_factor = foaming_factor
        self.open_tray_area_fraction = open_tray_area_fraction
        self.downcomer_area_fraction = downcomer_area_fraction
        self.is_divided = is_divided

        # Setup components
        thermo = self.thermo

        #: [MultiStream] Overall feed to the distillation column
        self.feed = tmo.MultiStream(None, thermo=thermo)

        #: [HXutility] Condenser.
        self.condenser = HXutility(None,
                                   ins=tmo.Stream(None,
                                                  phase='g',
                                                  thermo=thermo),
                                   outs=tmo.MultiStream(None, thermo=thermo),
                                   thermo=thermo)
        #: [HXutility] Boiler.
        self.boiler = HXutility(None,
                                ins=tmo.Stream(None, thermo=thermo),
                                outs=tmo.MultiStream(None, thermo=thermo),
                                thermo=thermo)
        self.heat_utilities = self.condenser.heat_utilities + self.boiler.heat_utilities
        self.reset_cache()
def test_multistream():
    import thermosteam as tmo
    tmo.settings.set_thermo(['Water', 'Ethanol'], cache=True)
    stream = tmo.MultiStream(None, l=[('Water', 1)], T=300)
    assert [stream.chemicals.Water] == stream.available_chemicals
    assert_allclose(stream.epsilon, 77.70030000000003)
    assert_allclose(stream.alpha * 1e6, 1.4330776454124502e-01)
    assert_allclose(stream.nu, 8.799123532986536e-07)
    assert_allclose(stream.Pr, 6.14001869413997)
    assert_allclose(stream.Cn, 75.29555729396768)
    assert_allclose(stream.C, 75.29555729396768)
    assert_allclose(stream.Cp, 4.179538552493643)
    assert_allclose(stream.P_vapor, 3533.918074415897)
    assert_allclose(stream.mu, 0.0008766363688287887)
    assert_allclose(stream.kappa, 0.5967303492959747)
    assert_allclose(stream.rho, 996.2769195618362)
    assert_allclose(stream.V, 1.80826029854462e-05)
    assert_allclose(stream.H, 139.31398526921475)
    assert_allclose(stream.S, 70.465818)
    assert_allclose(stream.sigma, 0.07176932405246211)
    assert_allclose(stream.z_mol, [1.0, 0.])
    assert_allclose(stream.z_mass, [1.0, 0.])
    assert_allclose(stream.z_vol, [1.0, 0.])
    assert not stream.source
    assert not stream.sink
    assert stream.main_chemical == 'Water'
    assert not stream.isfeed()
    assert not stream.isproduct()
    assert stream.vapor_fraction == 0.
    assert stream.liquid_fraction == 1.
    assert stream.solid_fraction == 0.
    with pytest.raises(ValueError):
        stream.get_property('isfeed', 'kg/hr')
    with pytest.raises(ValueError):
        stream.set_property('invalid property', 10, 'kg/hr')
    with pytest.raises(ValueError):
        tmo.MultiStream(None, l=[('Water', 1)], units='kg')
    stream.empty()
    with pytest.raises(AttributeError):
        stream.mol = 1.
    with pytest.raises(AttributeError):
        stream.mass = 1.
    with pytest.raises(AttributeError):
        stream.vol = 1.
    with pytest.raises(AttributeError):
        stream.F_mol = 1.
    with pytest.raises(AttributeError):
        stream.F_mass = 1.
    with pytest.raises(AttributeError):
        stream.F_vol = 1.

    # Casting
    stream.as_stream()
    assert stream.phase == 'g'  # Phase of an empty multi-stream defaults to stream.phases[0]
    assert type(stream) is tmo.Stream
    stream.phases = 'gl'
    assert stream.phases == ('g', 'l')
    stream.phases = 'gls'
    stream.phases == ('g', 'l', 's')
    stream.phases = 's'
    assert type(stream) is tmo.Stream
    assert stream.phase == 's'

    # Linking
    stream.phase = 'l'
    stream.phases = 'lg'
    other = stream.copy()
    stream.link_with(other)
    other.imol['l', 'Water'] = 10
    other.vle(V=0.5, P=2 * 101325)
    assert_allclose(other.mol, stream.mol)
    assert_allclose(other.T, stream.T)
    assert_allclose(other.P, stream.P)

    # Indexing
    assert_allclose(stream.imol['Water'], 10.)
    assert_allclose(stream.imol['Water', 'Ethanol'], [10., 0.])
    UndefinedChemical = tmo.exceptions.UndefinedChemical
    UndefinedPhase = tmo.exceptions.UndefinedPhase
    with pytest.raises(UndefinedChemical):
        stream.imol['Octanol']
    with pytest.raises(UndefinedChemical):
        stream.imol['l', 'Octanol']
    with pytest.raises(TypeError):
        stream.imol['l', ['Octanol', 'Water']]
    with pytest.raises(IndexError):
        stream.imol[None, 'Octanol']
    with pytest.raises(UndefinedPhase):
        stream.imol['s', 'Octanol']

    # Other
    stream = tmo.MultiStream(None, l=[('Water', 1)], T=300, units='g/s')
    assert stream.get_flow('g/s', 'Water') == stream.F_mass / 3.6 == 1.
    stream.empty()