Comments (5)
As suggested by the error, Na2HPO4 is missing Psat, Tb, and Hvap (so does KH2PO4), those properties won't be added by the default function, so you need to define these values before compiling.
The following should work:
import thermosteam as tmo
chemical_list = ('Na2HPO4', 'KH2PO4')
chemical_objects = tmo.Chemicals([])
for chemical in chemical_list:
try:
chemical_objects.append(tmo.Chemical(chemical))
except LookupError:
chemical_objects.append(create_fake_chemical(chemical))
chemical_objects.Na2HPO4.Psat.add_model(0) # set Psat to a constant
chemical_objects.Na2HPO4.Hvap.add_model(0) # set Hvap to a constant
chemical_objects.Na2HPO4.Tb = 1000
chemical_objects.KH2PO4.Psat.add_model(0) # set Psat to a constant
chemical_objects.KH2PO4.Hvap.add_model(0) # set Hvap to a constant
chemical_objects.KH2PO4.Tb = 1000
chemical_objects.compile()
chemical_objects.Na2HPO4.show()
chemical_objects.KH2PO4.show()
Note that I was using filler values for those properties, Psat and Hvap, you can copy Psat and Hvap models from other chemicals, e.g.:
Water = tmo.Chemical('Water')
chemical_objects.Na2HPO4.copy_models_from(Water, ['Hvap', 'Psat'])
hemical_objects.Na2HPO4.Psat # you can check the models
Water.Psat(373)
chemical_objects.Na2HPO4.Psat(373) # the same as water
from biosteam.
Hi Dmitry, great to hear from you. For solids or dissolved solids (or any substance that should exist in only one phase in the process), we can give them a phase and BioSTEAM won't ask you for Psat, Hvap and Tb.
Na2HPO4 = tmo.Chemical('Na2HPO4', phase='s', default=True)
KH2PO4 = tmo.Chemical('KH2PO4', phase='s', default=True)
chemicals = tmo.Chemicals([Na2HPO4, KH2PO4])
chemicals.compile()
Yalin's example works, but if a chemical only exists in one phase in the process, best to specify it.
If you really need to, it's also possible to specify ionic chemicals if you need to model dissociation reactions, but this is not something we commonly do even if the chemicals do dissociate in water.
Here we set the phase when we created the Chemical objects, but its also possible to use the "set_state" method to specify the phase after its created; this is how its done in the examples:
https://thermosteam.readthedocs.io/en/latest/tutorial/Thermo_property_packages.html
Let me know if you have anymore questions!
from biosteam.
Thank you very much.
Under the mentioned code both solutions worked just fine.
Then I have added the stream with the salts as a part of an in-stream to the Fermentation object.
Then @yalinli2 's solution worked just fine.
The @yoelcortes ' solution caused this error:
Traceback (most recent call last):
File "/Users/dim/.local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-0368ba7aaa53>", line 1, in <module>
runfile('/Users/dim/PycharmProjects/bioprocess_modelling/Bellossom/cut_out_fermentation.py', wdir='/Users/dim/PycharmProjects/bioprocess_modelling/Bellossom')
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/dim/PycharmProjects/bioprocess_modelling/Bellossom/cut_out_fermentation.py", line 20, in <module>
sys.simulate()
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/biosteam/_system.py", line 653, in simulate
self._converge()
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/biosteam/_system.py", line 586, in _converge
return self._converge_method() if self._recycle else self._run()
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/biosteam/_system.py", line 561, in _run
run_unit_in_path(i)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/biosteam/_system.py", line 57, in run_unit_in_path
try_method_with_object_stamp(unit, method)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/exceptions.py", line 71, in try_method_with_object_stamp
raise_error_with_object_stamp(object, error)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/exceptions.py", line 63, in raise_error_with_object_stamp
raise error
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/exceptions.py", line 67, in try_method_with_object_stamp
return method(*args)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/biosteam/units/_fermentation.py", line 237, in _run
effluent.mix_from(self.ins)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/_stream.py", line 757, in mix_from
H = sum([i.H for i in others])
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/_stream.py", line 757, in <listcomp>
H = sum([i.H for i in others])
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/_stream.py", line 590, in H
return self.mixture.H(self.phase, self.mol, *self._thermal_condition)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/mixture/mixture.py", line 122, in H
H = self._H(phase, mol, T)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/base/phase_handle.py", line 114, in __call__
return getattr(self, phase)(z, T, P)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/mixture/ideal_mixture_model.py", line 56, in __call__
return sum([j * i(T, P) for i, j in zip(self.models, mol) if j])
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/mixture/ideal_mixture_model.py", line 56, in <listcomp>
return sum([j * i(T, P) for i, j in zip(self.models, mol) if j])
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/base/functor.py", line 195, in __call__
return self.function(T, **self.__dict__)
File "/Users/dim/opt/anaconda3/lib/python3.7/site-packages/thermosteam/properties/free_energy.py", line 35, in Solid_Enthalpy_Ref_Liquid
return H_ref - H_int_Tm_to_T_ref_l - Hfus + Cn_s.integrate_by_T(Tm, T)
TypeError: <Fermentation: R301> unsupported operand type(s) for -: 'float' and 'NoneType'
from biosteam.
You were probably missing the heat of fusion (Hfus) and melting temperature (Tm) since we assumed its a solid. Since the chemical will always be in the given state, these values wouldn't actually make a difference in the energy balance (enthalpy is a state function). I just updated thermosteam so that this would work without having to pass Hfus and Tm:
import thermosteam as tmo
Na2HPO4 = tmo.Chemical('Na2HPO4', phase='s', default=True)
KH2PO4 = tmo.Chemical('KH2PO4', phase='s', default=True)
chemicals = tmo.Chemicals([Na2HPO4, KH2PO4])
# Test
tmo.settings.set_thermo(chemicals)
stream = tmo.Stream(None, Na2HPO4=1, KH2PO4=1, T=310)
stream.H # -> 2348.7323046048014
from biosteam.
I'd still suggest to pass the phase to chemical. It will prevent bugs in separations later
from biosteam.
Related Issues (20)
- High CAPEX cost at low pumping rates HOT 4
- Small error in `BoilerTurbogenerator` design cause negative work/cost HOT 2
- Negative water flows in permeate of AnMBR in high-rate WWT system HOT 4
- Notice: Moving to Python 3.11 in October
- AttributeError: 'Stream' object has no attribute 'indices' HOT 1
- Kinetic model does not take 't' into account HOT 1
- Unable to get graphic data like Diagrams and graphs HOT 1
- numba inlines biosteam.CE value into compiled code HOT 4
- Better batch design HOT 3
- Power consumption default in AeratedBioReactor needs more detail HOT 2
- Biogas upgrading HOT 1
- Depreciable capital in NPV calculation HOT 24
- Valve node has no label
- Unit z_mol_in and z_mol_out properties don't work
- Compressor type and adding Cooling Agent HOT 15
- Implement Blower as a Compressor type
- Include special-case utilities in utility worksheet.
- Sub class modelling of CSTR HOT 1
- Reactor duty for sub class modelling of CSTR
- Minor issues with high-rate WWT HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from biosteam.