-
Notifications
You must be signed in to change notification settings - Fork 114
/
mixture.py
2716 lines (2319 loc) · 93.9 KB
/
mixture.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
'''Chemical Engineering Design Library (ChEDL). Utilities for process modeling.
Copyright (C) 2017, Caleb Bell <Caleb.Andrew.Bell@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.'''
from __future__ import division
__all__ = ['Mixture']
import numpy as np
from scipy.optimize import newton
from collections import Counter, OrderedDict
from pprint import pprint
from fluids.core import *
from fluids.core import Reynolds, Capillary, Weber, Bond, Grashof, Peclet_heat
from thermo.chemical import Chemical
from thermo.identifiers import *
from thermo.identifiers import _MixtureDict
from thermo.phase_change import Tliquidus
from thermo.activity import identify_phase_mixture, Pbubble_mixture, Pdew_mixture
from thermo.critical import Tc_mixture, Pc_mixture, Vc_mixture
from thermo.acentric import omega_mixture
from thermo.thermal_conductivity import ThermalConductivityLiquidMixture, ThermalConductivityGasMixture
from thermo.volume import VolumeLiquidMixture, VolumeGasMixture, VolumeSolidMixture
from thermo.permittivity import *
from thermo.heat_capacity import HeatCapacitySolidMixture, HeatCapacityGasMixture, HeatCapacityLiquidMixture
from thermo.interface import SurfaceTensionMixture
from thermo.viscosity import ViscosityLiquidMixture, ViscosityGasMixture
from thermo.safety import LFL_mixture, UFL_mixture
from thermo.utils import *
from thermo.elements import atom_fractions, mass_fractions, simple_formula_parser, molecular_weight
from thermo.eos import *
from thermo.eos_mix import *
# RDKIT
try:
from rdkit import Chem
from rdkit.Chem import Descriptors
from rdkit.Chem import AllChem
except: # pragma: no cover
pass
class Mixture(object):
'''Creates a Mixture object which contains basic information such as
molecular weight and the structure of the species, as well as thermodynamic
and transport properties as a function of temperature and pressure.
The components of the mixture must be specified by specifying the names of
the chemicals; the composition can be specified by providing any one of the
following parameters:
* Mass fractions `ws`
* Mole fractions `zs`
* Liquid volume fractions (based on pure component densities) `Vfls`
* Gas volume fractions (based on pure component densities) `Vfgs`
If volume fractions are provided, by default the pure component volumes
are calculated at the specified `T` and `P`. To use another reference
temperature and pressure specify it as a tuple for the argument `Vf_TP`.
Parameters
----------
IDs : list, optional
List of chemical identifiers - names, CAS numbers, SMILES or InChi
strings can all be recognized and may be mixed [-]
zs : list or dict, optional
Mole fractions of all components in the mixture [-]
ws : list or dict, optional
Mass fractions of all components in the mixture [-]
Vfls : list or dict, optional
Volume fractions of all components as a hypothetical liquid phase based
on pure component densities [-]
Vfgs : list, or dict optional
Volume fractions of all components as a hypothetical gas phase based
on pure component densities [-]
T : float, optional
Temperature of the chemical (default 298.15 K), [K]
P : float, optional
Pressure of the chemical (default 101325 Pa) [Pa]
Vf_TP : tuple(2, float), optional
The (T, P) at which the volume fractions are specified to be at, [K]
and [Pa]
Attributes
----------
MW : float
Mole-weighted average molecular weight all chemicals in the mixture,
[g/mol]
names : list of str
Names of all the species in the mixture, [-]
CASs : list of str
CAS numbers of all species in the mixture, [-]
MWs : list of float
Molecular weights of all chemicals in the mixture, [g/mol]
Tms : list of float
Melting temperatures of all chemicals in the mixture, [K]
Tbs : list of float
Boiling temperatures of all chemicals in the mixture, [K]
Tcs : list of float
Critical temperatures of all chemicals in the mixture, [K]
Pcs : list of float
Critical pressures of all chemicals in the mixture, [Pa]
Vcs : list of float
Critical volumes of all chemicals in the mixture, [m^3/mol]
Zcs : list of float
Critical compressibilities of all chemicals in the mixture, [-]
rhocs : list of float
Critical densities of all chemicals in the mixture, [kg/m^3]
rhocms : list of float
Critical molar densities of all chemicals in the mixture, [mol/m^3]
omegas : list of float
Acentric factors of all chemicals in the mixture, [-]
StielPolars : list of float
Stiel Polar factors of all chemicals in the mixture,
see :obj:`thermo.acentric.StielPolar` for the definition, [-]
Tts : list of float
Triple temperatures of all chemicals in the mixture, [K]
Pts : list of float
Triple pressures of all chemicals in the mixture, [Pa]
Hfuss : list of float
Enthalpy of fusions of all chemicals in the mixture, [J/kg]
Hfusms : list of float
Molar enthalpy of fusions of all chemicals in the mixture, [J/mol]
Hsubs : list of float
Enthalpy of sublimations of all chemicals in the mixture, [J/kg]
Hsubms : list of float
Molar enthalpy of sublimations of all chemicals in the mixture, [J/mol]
Hfs : list of float
Enthalpy of formations of all chemicals in the mixture, [J/mol]
Hcs : list of float
Molar enthalpy of combustions of all chemicals in the mixture, [J/mol]
Tflashs : list of float
Flash points of all chemicals in the mixture, [K]
Tautoignitions : list of float
Autoignition points of all chemicals in the mixture, [K]
LFLs : list of float
Lower flammability limits of the gases in an atmosphere at STP, mole
fractions, [-]
UFLs : list of float
Upper flammability limit of the gases in an atmosphere at STP, mole
fractions, [-]
TWAs : list of list of tuple(quantity, unit)
Time-Weighted Average limits on worker exposure to dangerous chemicals.
STELs : list of tuple(quantity, unit)
Short-term Exposure limits on worker exposure to dangerous chemicals.
Ceilings : list of tuple(quantity, unit)
Ceiling limits on worker exposure to dangerous chemicals.
Skins : list of bool
Whether or not each of the chemicals can be absorbed through the skin.
Carcinogens : list of str or dict
Carcinogen status information for each chemical in the mixture.
Chemicals : list of Chemical instances
Chemical instances used in calculating mixture properties, [-]
dipoles : list of float
Dipole moments of all chemicals in the mixture in debye,
[3.33564095198e-30 ampere*second^2]
Stockmayers : list of float
Lennard-Jones depth of potential-energy minimum over k for all
chemicals in the mixture, [K]
molecular_diameters : list of float
Lennard-Jones molecular diameters of all chemicals in the mixture,
[angstrom]
GWPs : list of float
Global warming potentials (default 100-year outlook) (impact/mass
chemical)/(impact/mass CO2) of all chemicals in the mixture, [-]
ODPs : list of float
Ozone Depletion potentials (impact/mass chemical)/(impact/mass CFC-11),
of all chemicals in the mixture, [-]
logPs : list of float
Octanol-water partition coefficients of all chemicals in the mixture,
[-]
Psat_298s : list of float
Vapor pressure of the chemicals in the mixture at 298.15 K, [Pa]
phase_STPs : list of str
Phase of the chemicals in the mixture at 298.15 K and 101325 Pa; one of
's', 'l', 'g', or 'l/g'.
Vml_Tbs : list of float
Molar volumes of the chemicals in the mixture as liquids at their
normal boiling points, [m^3/mol]
Vml_Tms : list of float
Molar volumes of the chemicals in the mixture as liquids at their
melting points, [m^3/mol]
Vml_STPs : list of float
Molar volume of the chemicals in the mixture as liquids at 298.15 K and
101325 Pa, [m^3/mol]
Vmg_STPs : list of float
Molar volume of the chemicals in the mixture as gases at 298.15 K and
101325 Pa, [m^3/mol]
Hvap_Tbms : list of float
Molar enthalpies of vaporization of the chemicals in the mixture at
their normal boiling points, [J/mol]
Hvap_Tbs : list of float
Mass enthalpies of vaporization of the chemicals in the mixture at
their normal boiling points, [J/kg]
alpha
alphag
alphags
alphal
alphals
atom_fractions
atom_fractionss
atomss
Bvirial
charges
Cp
Cpg
Cpgm
Cpgms
Cpgs
Cpl
Cplm
Cplms
Cpls
Cpm
Cps
Cpsm
Cpsms
Cpss
Cvg
Cvgm
Cvgms
Cvgs
economic_statuses
eos
formulas
Hvapms
Hvaps
InChI_Keys
InChIs
isentropic_exponent
isentropic_exponents
isobaric_expansion
isobaric_expansion_g
isobaric_expansion_gs
isobaric_expansion_l
isobaric_expansion_ls
IUPAC_names
JT
JTg
JTgs
JTl
JTls
k
kg
kgs
kl
kls
legal_statuses
mass_fractions
mass_fractionss
mu
mug
mugs
mul
muls
nu
nug
nugs
nul
nuls
permittivites
Pr
Prg
Prgs
Prl
Prls
Psats
PSRK_groups
PubChems
rho
rhog
rhogm
rhogms
rhogm_STP
rhogs
rhog_STP
rhol
rholm
rholms
rholm_STP
rhols
rhol_STP
rhom
rhosms
rhoss
ringss
sigma
sigmas
smiless
solubility_parameters
synonymss
UNIFAC_Dortmund_groups
UNIFAC_groups
Vm
Vmg
Vmgs
Vmg_STP
Vml
Vmls
Vml_STP
Vmss
Z
Zg
Zgs
Zg_STP
Zl
Zls
Zl_STP
Zss
Examples
--------
Creating Mixture objects:
>>> Mixture(['water', 'ethanol'], Vfls=[.6, .4], T=300, P=1E5)
<Mixture, components=['water', 'ethanol'], mole fractions=[0.8299, 0.1701], T=300.00 K, P=100000 Pa>
For mixtures with large numbers of components, it may be confusing to enter
the composition separate from the names of the chemicals. For that case,
the syntax using dictionaries as follows is supported with any composition
specification:
>>> comp = OrderedDict([('methane', 0.96522),
... ('nitrogen', 0.00259),
... ('carbon dioxide', 0.00596),
... ('ethane', 0.01819),
... ('propane', 0.0046),
... ('isobutane', 0.00098),
... ('butane', 0.00101),
... ('2-methylbutane', 0.00047),
... ('pentane', 0.00032),
... ('hexane', 0.00066)])
>>> m = Mixture(zs=comp)
'''
eos_in_a_box = []
ks = None
Vms = None
rhos = None
xs = None
ys = None
phase = None
V_over_F = None
conductivity = None
Hm = None
H = None
def __repr__(self):
return '<Mixture, components=%s, mole fractions=%s, T=%.2f K, P=%.0f \
Pa>' % (self.names, [round(i,4) for i in self.zs], self.T, self.P)
def __init__(self, IDs=None, zs=None, ws=None, Vfls=None, Vfgs=None,
T=298.15, P=101325, Vf_TP=(None, None)):
self.P = P
self.T = T
if hasattr(IDs, 'strip') or (isinstance(IDs, list) and len(IDs) == 1):
try:
mixname = mixture_from_any(IDs)
_d = _MixtureDict[mixname]
IDs = _d["CASs"]
ws = _d["ws"]
self.mixname = mixname
self.mixsource = _d["Source"]
except:
if hasattr(IDs, 'strip'):
IDs = [IDs]
zs = [1]
elif isinstance(IDs, list) and len(IDs) == 1:
pass
else:
raise Exception('Could not recognize the mixture IDs')
# Handle numpy array inputs; also turn mutable inputs into copies
if zs is not None:
t = type(zs)
if t == list:
zs = list(zs)
elif t == np.ndarray:
zs = zs.tolist()
elif isinstance(zs, (OrderedDict, dict)):
IDs = list(zs.keys())
zs = list(zs.values())
length_matching = len(zs) == len(IDs)
elif ws is not None:
t = type(ws)
if t == list:
ws = list(ws)
elif t == np.ndarray:
ws = ws.tolist()
elif isinstance(ws, (OrderedDict, dict)):
IDs = list(ws.keys())
ws = list(ws.values())
length_matching = len(ws) == len(IDs)
elif Vfls is not None:
t = type(Vfls)
if t == list:
Vfls = list(Vfls)
elif t == np.ndarray:
Vfls = Vfls.tolist()
elif isinstance(Vfls, (OrderedDict, dict)):
IDs = list(Vfls.keys())
Vfls = list(Vfls.values())
length_matching = len(Vfls) == len(IDs)
elif Vfgs is not None:
t = type(Vfgs)
if t == list:
Vfgs = list(Vfgs)
elif t == np.ndarray:
Vfgs = Vfgs.tolist()
elif isinstance(Vfgs, (OrderedDict, dict)):
IDs = list(Vfgs.keys())
Vfgs = list(Vfgs.values())
length_matching = len(Vfgs) == len(IDs)
else:
raise Exception("One of 'zs', 'ws', 'Vfls', or 'Vfgs' is required to define the mixture")
# Do not to a test on multiple composition inputs in case the user specified
# a composition, plus one was set (it will be zero anyway)
if len(IDs) > 1 and ((zs is not None) + (ws is not None) + (Vfgs is not None) + (Vfls is not None)) > 1:
raise Exception('Multiple different composition arguments were '
"specified; specify only one of the arguments "
"'zs', 'ws', 'Vfls', or 'Vfgs'.")
if not length_matching:
raise Exception('Composition is not the same length as the component identifiers')
self.components = tuple(IDs)
self.Chemicals = [Chemical(component, P=P, T=T) for component in self.components]
self.names = [i.name for i in self.Chemicals]
self.MWs = [i.MW for i in self.Chemicals]
self.CASs = [i.CAS for i in self.Chemicals]
# Required for densities for volume fractions before setting fractions
self.set_chemical_constants()
self.set_chemical_TP()
self.set_Chemical_property_objects()
if zs:
self.zs = zs if sum(zs) == 1 else [zi/sum(zs) for zi in zs]
self.ws = zs_to_ws(zs, self.MWs)
elif ws:
self.ws = ws if sum(ws) == 1 else [wi/sum(ws) for wi in ws]
self.zs = ws_to_zs(ws, self.MWs)
elif Vfls or Vfgs:
T_vf, P_vf = Vf_TP
if T_vf is None:
T_vf = T
if P_vf is None:
P_vf = P
if Vfls:
Vfs = Vfls if sum(Vfls) == 1 else [Vfli/sum(Vfls) for Vfli in Vfls]
VolumeObjects = self.VolumeLiquids
Vms_TP = self.Vmls
else:
Vfs = Vfgs if sum(Vfgs) == 1 else [Vfgi/sum(Vfgs) for Vfgi in Vfgs]
VolumeObjects = self.VolumeGases
Vms_TP = self.Vmgs
if T_vf != T or P_vf != P:
Vms_TP = [i(T_vf, P_vf) for i in VolumeObjects]
self.zs = Vfs_to_zs(Vfs, Vms_TP)
self.ws = zs_to_ws(self.zs, self.MWs)
else:
raise Exception('One of mole fractions `zs`, weight fractions `ws`,'
' pure component liquid volume fractions `Vfls`, or'
' pure component gas volume fractions `Vfgs` must '
'be provided.')
self.MW = mixing_simple(self.zs, self.MWs)
self.set_constant_sources()
self.set_constants()
self.set_TP_sources()
self.set_TP()
self.set_phase()
def set_chemical_constants(self):
# Set lists of everything set by Chemical.set_constants
self.Tms = [i.Tm for i in self.Chemicals]
self.Tbs = [i.Tb for i in self.Chemicals]
# Critical Point
self.Tcs = [i.Tc for i in self.Chemicals]
self.Pcs = [i.Pc for i in self.Chemicals]
self.Vcs = [i.Vc for i in self.Chemicals]
self.omegas = [i.omega for i in self.Chemicals]
self.StielPolars = [i.StielPolar for i in self.Chemicals]
self.Zcs = [i.Zc for i in self.Chemicals]
self.rhocs = [i.rhoc for i in self.Chemicals]
self.rhocms = [i.rhocm for i in self.Chemicals]
# Triple point
self.Pts = [i.Pt for i in self.Chemicals]
self.Tts = [i.Tt for i in self.Chemicals]
# Enthalpy
self.Hfuss = [i.Hfus for i in self.Chemicals]
self.Hsubs = [i.Hsub for i in self.Chemicals]
self.Hfusms = [i.Hfusm for i in self.Chemicals]
self.Hsubms = [i.Hsubm for i in self.Chemicals]
# Chemistry
self.Hfs = [i.Hf for i in self.Chemicals]
self.Hcs = [i.Hc for i in self.Chemicals]
# Fire Safety Limits
self.Tflashs = [i.Tflash for i in self.Chemicals]
self.Tautoignitions = [i.Tautoignition for i in self.Chemicals]
self.LFLs = [i.LFL for i in self.Chemicals]
self.UFLs = [i.UFL for i in self.Chemicals]
# Chemical Exposure Limits
self.TWAs = [i.TWA for i in self.Chemicals]
self.STELs = [i.STEL for i in self.Chemicals]
self.Ceilings = [i.Ceiling for i in self.Chemicals]
self.Skins = [i.Skin for i in self.Chemicals]
self.Carcinogens = [i.Carcinogen for i in self.Chemicals]
# Misc
self.dipoles = [i.dipole for i in self.Chemicals]
self.molecular_diameters = [i.molecular_diameter for i in self.Chemicals]
self.Stockmayers = [i.Stockmayer for i in self.Chemicals]
# Environmental
self.GWPs = [i.GWP for i in self.Chemicals]
self.ODPs = [i.ODP for i in self.Chemicals]
self.logPs = [i.logP for i in self.Chemicals]
# Analytical
self.RIs = [i.RI for i in self.Chemicals]
self.conductivities = [i.conductivity for i in self.Chemicals]
# Constant properties obtained from TP
self.Vml_STPs = [i.Vml_STP for i in self.Chemicals]
self.Vmg_STPs = [i.Vmg_STP for i in self.Chemicals]
self.Psat_298s = [i.Psat_298 for i in self.Chemicals]
self.phase_STPs = [i.phase_STP for i in self.Chemicals]
self.Vml_Tbs = [i.Vml_Tb for i in self.Chemicals]
self.Vml_Tms = [i.Vml_Tm for i in self.Chemicals]
self.Hvap_Tbms = [i.Hvap_Tbm for i in self.Chemicals]
self.Hvap_Tbs = [i.Hvap_Tb for i in self.Chemicals]
### More stuff here
def set_chemical_TP(self):
# Tempearture and Pressure Denepdence
# Get and choose initial methods
[i.calculate(self.T, self.P) for i in self.Chemicals]
try:
self.Hs = [i.H for i in self.Chemicals]
self.Hms = [i.Hm for i in self.Chemicals]
self.Ss = [i.S for i in self.Chemicals]
self.Sms = [i.Sm for i in self.Chemicals]
# Ignore G, A, U - which depend on molar volume
except:
self.Hs = None
self.Hsm = None
self.Ss = None
self.Sms = None
def set_constant_sources(self):
# None of this takes much time or is important
# Tliquidus assumes worst-case for now
self.Tm_methods = Tliquidus(Tms=self.Tms, ws=self.ws, xs=self.zs, CASRNs=self.CASs, AvailableMethods=True)
self.Tm_method = self.Tm_methods[0]
# Critical Point, Methods only for Tc, Pc, Vc
self.Tc_methods = Tc_mixture(Tcs=self.Tcs, zs=self.zs, CASRNs=self.CASs, AvailableMethods=True)
self.Tc_method = self.Tc_methods[0]
self.Pc_methods = Pc_mixture(Pcs=self.Pcs, zs=self.zs, CASRNs=self.CASs, AvailableMethods=True)
self.Pc_method = self.Pc_methods[0]
self.Vc_methods = Vc_mixture(Vcs=self.Vcs, zs=self.zs, CASRNs=self.CASs, AvailableMethods=True)
self.Vc_method = self.Vc_methods[0]
self.omega_methods = omega_mixture(omegas=self.omegas, zs=self.zs, CASRNs=self.CASs, AvailableMethods=True)
self.omega_method = self.omega_methods[0]
# No Flammability limits
self.LFL_methods = LFL_mixture(ys=self.zs, LFLs=self.LFLs, AvailableMethods=True)
self.LFL_method = self.LFL_methods[0]
self.UFL_methods = UFL_mixture(ys=self.zs, UFLs=self.UFLs, AvailableMethods=True)
self.UFL_method = self.UFL_methods[0]
# No triple point
# Mixed Hf linear
# Exposure limits are minimum of any of them or lower
def set_constants(self):
# None of this takes much time or is important
# Melting point
self.Tm = Tliquidus(Tms=self.Tms, ws=self.ws, xs=self.zs, CASRNs=self.CASs, Method=self.Tm_method)
# Critical Point
self.Tc = Tc_mixture(Tcs=self.Tcs, zs=self.zs, CASRNs=self.CASs, Method=self.Tc_method)
self.Pc = Pc_mixture(Pcs=self.Pcs, zs=self.zs, CASRNs=self.CASs, Method=self.Pc_method)
self.Vc = Vc_mixture(Vcs=self.Vcs, zs=self.zs, CASRNs=self.CASs, Method=self.Vc_method)
self.omega = omega_mixture(omegas=self.omegas, zs=self.zs, CASRNs=self.CASs, Method=self.omega_method)
self.Zc = Z(self.Tc, self.Pc, self.Vc) if all((self.Tc, self.Pc, self.Vc)) else None
self.rhoc = Vm_to_rho(self.Vc, self.MW) if self.Vc else None
self.rhocm = 1./self.Vc if self.Vc else None
self.LFL = LFL_mixture(ys=self.zs, LFLs=self.LFLs, Method=self.LFL_method)
self.UFL = UFL_mixture(ys=self.zs, UFLs=self.UFLs, Method=self.UFL_method)
def set_eos(self, T, P, eos=PRMIX):
try:
self.eos = eos(T=T, P=P, Tcs=self.Tcs, Pcs=self.Pcs, omegas=self.omegas, zs=self.zs)
except:
# Handle overflow errors and so on
self.eos = GCEOS_DUMMY(T=T, P=P)
@property
def eos(self):
r'''Equation of state object held by the mixture. See :
obj:`thermo.eos_mix` for a full listing.
Examples
--------
'''
return self.eos_in_a_box[0]
@eos.setter
def eos(self, eos):
if self.eos_in_a_box:
self.eos_in_a_box.pop()
self.eos_in_a_box.append(eos)
def set_Chemical_property_objects(self):
self.VolumeSolids = [i.VolumeSolid for i in self.Chemicals]
self.VolumeLiquids = [i.VolumeLiquid for i in self.Chemicals]
self.VolumeGases = [i.VolumeGas for i in self.Chemicals]
self.HeatCapacitySolids = [i.HeatCapacitySolid for i in self.Chemicals]
self.HeatCapacityLiquids = [i.HeatCapacityLiquid for i in self.Chemicals]
self.HeatCapacityGases = [i.HeatCapacityGas for i in self.Chemicals]
self.ViscosityLiquids = [i.ViscosityLiquid for i in self.Chemicals]
self.ViscosityGases = [i.ViscosityGas for i in self.Chemicals]
self.ThermalConductivityLiquids = [i.ThermalConductivityLiquid for i in self.Chemicals]
self.ThermalConductivityGases = [i.ThermalConductivityGas for i in self.Chemicals]
self.SurfaceTensions = [i.SurfaceTension for i in self.Chemicals]
self.Permittivities = [i.Permittivity for i in self.Chemicals]
self.VaporPressures = [i.VaporPressure for i in self.Chemicals]
self.EnthalpyVaporizations = [i.EnthalpyVaporization for i in self.Chemicals]
def set_TP_sources(self):
self.VolumeSolidMixture = VolumeSolidMixture(CASs=self.CASs, VolumeSolids=self.VolumeSolids)
self.VolumeLiquidMixture = VolumeLiquidMixture(MWs=self.MWs, Tcs=self.Tcs, Pcs=self.Pcs, Vcs=self.Vcs, Zcs=self.Zcs, omegas=self.omegas, CASs=self.CASs, VolumeLiquids=self.VolumeLiquids)
self.VolumeGasMixture = VolumeGasMixture(eos=self.eos_in_a_box, CASs=self.CASs, VolumeGases=self.VolumeGases)
self.HeatCapacityLiquidMixture = HeatCapacityLiquidMixture(MWs=self.MWs, CASs=self.CASs, HeatCapacityLiquids=self.HeatCapacityLiquids)
self.HeatCapacityGasMixture = HeatCapacityGasMixture(CASs=self.CASs, HeatCapacityGases=self.HeatCapacityGases)
self.HeatCapacitySolidMixture = HeatCapacitySolidMixture(CASs=self.CASs, HeatCapacitySolids=self.HeatCapacitySolids)
self.ViscosityLiquidMixture = ViscosityLiquidMixture(CASs=self.CASs, ViscosityLiquids=self.ViscosityLiquids)
self.ViscosityGasMixture = ViscosityGasMixture(MWs=self.MWs, molecular_diameters=self.molecular_diameters, Stockmayers=self.Stockmayers, CASs=self.CASs, ViscosityGases=self.ViscosityGases)
self.ThermalConductivityLiquidMixture = ThermalConductivityLiquidMixture(CASs=self.CASs, ThermalConductivityLiquids=self.ThermalConductivityLiquids)
self.ThermalConductivityGasMixture = ThermalConductivityGasMixture(MWs=self.MWs, Tbs=self.Tbs, CASs=self.CASs, ThermalConductivityGases=self.ThermalConductivityGases, ViscosityGases=self.ViscosityGases)
self.SurfaceTensionMixture = SurfaceTensionMixture(MWs=self.MWs, Tbs=self.Tbs, Tcs=self.Tcs, CASs=self.CASs, SurfaceTensions=self.SurfaceTensions, VolumeLiquids=self.VolumeLiquids)
def set_TP(self, T=None, P=None):
if T:
self.T = T
if P:
self.P = P
self.set_chemical_TP()
self.set_eos(T=self.T, P=self.P)
def set_phase(self):
try:
self.phase_methods = identify_phase_mixture(T=self.T, P=self.P, zs=self.zs, Tcs=self.Tcs, Pcs=self.Pcs, Psats=self.Psats, CASRNs=self.CASs, AvailableMethods=True)
self.phase_method = self.phase_methods[0]
self.phase, self.xs, self.ys, self.V_over_F = identify_phase_mixture(T=self.T, P=self.P, zs=self.zs, Tcs=self.Tcs, Pcs=self.Pcs, Psats=self.Psats, CASRNs=self.CASs, Method=self.phase_method)
if self.phase == 'two-phase':
self.wsl = zs_to_ws(self.xs, self.MWs)
self.wsg = zs_to_ws(self.ys, self.MWs)
ng = self.V_over_F
nl = (1. - self.V_over_F)
self.MWl = mixing_simple(self.xs, self.MWs)
self.MWg = mixing_simple(self.ys, self.MWs)
self.x = self.quality = ng*self.MWg/(nl*self.MWl + ng*self.MWg)
self.Pbubble_methods = Pbubble_mixture(T=self.T, zs=self.zs, Psats=self.Psats, CASRNs=self.CASs, AvailableMethods=True)
self.Pbubble_method = self.Pbubble_methods[0]
self.Pbubble = Pbubble_mixture(T=self.T, zs=self.zs, Psats=self.Psats, CASRNs=self.CASs, Method=self.Pbubble_method)
self.Pdew_methods = Pdew_mixture(T=self.T, zs=self.zs, Psats=self.Psats, CASRNs=self.CASs, AvailableMethods=True)
self.Pdew_method = self.Pdew_methods[0]
self.Pdew = Pdew_mixture(T=self.T, zs=self.zs, Psats=self.Psats, CASRNs=self.CASs, Method=self.Pdew_method)
if not None in self.Hs:
self.H = mixing_simple(self.Hs, self.ws)
self.Hm = property_mass_to_molar(self.H, self.MW)
if not None in self.Ss:
# Ideal gas contribution
self.Sm = mixing_simple(self.Sms, self.zs) - R*sum([zi*log(zi) for zi in self.zs if zi > 0])
self.S = property_molar_to_mass(self.Sm, self.MW)
except:
pass
def calculate(self, T=None, P=None):
if T:
if T < 0:
raise Exception('Negative value specified for Mixture temperature - aborting!')
self.T = T
else:
T = self.T
if P:
if P < 0:
raise Exception('Negative value specified for Mixture pressure - aborting!')
else:
P = self.P
self.set_TP(T=T, P=P)
self.set_phase()
def calculate_TH(self, T, H):
def to_solve(P):
self.calculate(T, P)
return self.H - H
return newton(to_solve, self.P)
def calculate_PH(self, P, H):
def to_solve(T):
self.calculate(T, P)
return self.H - H
return newton(to_solve, self.T)
def calculate_TS(self, T, S):
def to_solve(P):
self.calculate(T, P)
return self.S - S
return newton(to_solve, self.P)
def calculate_PS(self, P, S):
def to_solve(T):
self.calculate(T, P)
return self.S - S
return newton(to_solve, self.T)
def Vfls(self, T=None, P=None):
r'''Volume fractions of all species in a hypothetical pure-liquid phase
at the current or specified temperature and pressure. If temperature
or pressure are specified, the non-specified property is assumed to be
that of the mixture. Note this is a method, not a property. Volume
fractions are calculated based on **pure species volumes only**.
Examples
--------
>>> Mixture(['hexane', 'pentane'], zs=[.5, .5], T=315).Vfls()
[0.5299671144566751, 0.47003288554332484]
>>> S = Mixture(['hexane', 'decane'], zs=[0.25, 0.75])
>>> S.Vfls(298.16, 101326)
[0.18301434895886864, 0.8169856510411313]
'''
if (T is None or T == self.T) and (P is None or P == self.P):
Vmls = self.Vmls
else:
if T is None: T = self.T
if P is None: P = self.P
Vmls = [i(T, P) for i in self.VolumeLiquids]
if none_and_length_check([Vmls]):
return zs_to_Vfs(self.zs, Vmls)
return None
def Vfgs(self, T=None, P=None):
r'''Volume fractions of all species in a hypothetical pure-gas phase
at the current or specified temperature and pressure. If temperature
or pressure are specified, the non-specified property is assumed to be
that of the mixture. Note this is a method, not a property. Volume
fractions are calculated based on **pure species volumes only**.
Examples
--------
>>> Mixture(['sulfur hexafluoride', 'methane'], zs=[.2, .9], T=315).Vfgs()
[0.18062059238682632, 0.8193794076131737]
>>> S = Mixture(['sulfur hexafluoride', 'methane'], zs=[.1, .9])
>>> S.Vfgs(P=1E2)
[0.0999987466608421, 0.9000012533391578]
'''
if (T is None or T == self.T) and (P is None or P == self.P):
Vmgs = self.Vmgs
else:
if T is None: T = self.T
if P is None: P = self.P
Vmgs = [i(T, P) for i in self.VolumeGases]
if none_and_length_check([Vmgs]):
return zs_to_Vfs(self.zs, Vmgs)
return None
# Unimportant constants
@property
def PubChems(self):
r'''PubChem Component ID numbers for all chemicals in the mixture.
Examples
--------
>>> Mixture(['benzene', 'toluene'], ws=[0.5, 0.5]).PubChems
[241, 1140]
'''
return [i.PubChem for i in self.Chemicals]
@property
def formulas(self):
r'''Chemical formulas for all chemicals in the mixture.
Examples
--------
>>> Mixture(['ethanol', 'trichloroethylene', 'furfuryl alcohol'],
... ws=[0.5, 0.2, 0.3]).formulas
['C2H6O', 'C2HCl3', 'C5H6O2']
'''
return [i.formula for i in self.Chemicals]
@property
def smiless(self):
r'''SMILES strings for all chemicals in the mixture.
Examples
--------
>>> Mixture(['methane', 'ethane', 'propane', 'butane'],
... zs=[0.25, 0.25, 0.25, 0.25]).smiless
['C', 'CC', 'CCC', 'CCCC']
'''
return [i.smiles for i in self.Chemicals]
@property
def InChIs(self):
r'''InChI strings for all chemicals in the mixture.
Examples
--------
>>> Mixture(['methane', 'ethane', 'propane', 'butane'],
... zs=[0.25, 0.25, 0.25, 0.25]).InChIs
['CH4/h1H4', 'C2H6/c1-2/h1-2H3', 'C3H8/c1-3-2/h3H2,1-2H3', 'C4H10/c1-3-4-2/h3-4H2,1-2H3']
'''
return [i.InChI for i in self.Chemicals]
@property
def InChI_Keys(self):
r'''InChI keys for all chemicals in the mixture.
Examples
--------
>>> Mixture(['1-nonene'], zs=[1]).InChI_Keys
['JRZJOMJEPLMPRA-UHFFFAOYSA-N']
'''
return [i.InChI_Key for i in self.Chemicals]
@property
def IUPAC_names(self):
r'''IUPAC names for all chemicals in the mixture.
Examples
--------
>>> Mixture(['1-hexene', '1-nonene'], zs=[.7, .3]).IUPAC_names
['hex-1-ene', 'non-1-ene']
'''
return [i.IUPAC_name for i in self.Chemicals]
@property
def synonymss(self):
r'''Lists of synonyms for all chemicals in the mixture.
Examples
--------
>>> Mixture(['Tetradecene', 'Pentadecene'], zs=[.1, .9]).synonymss
[['tetradec-2-ene', 'tetradecene', '2-tetradecene', 'tetradec-2-ene', '26952-13-6', '35953-53-8', '1652-97-7'], ['pentadec-1-ene', '1-pentadecene', 'pentadecene,1-', 'pentadec-1-ene', '13360-61-7', 'pentadecene']]
'''
return [i.synonyms for i in self.Chemicals]
@property
def charges(self):
r'''Charges for all chemicals in the mixture, [faraday].
Examples
--------
>>> Mixture(['water', 'sodium ion', 'chloride ion'], zs=[.9, .05, .05]).charges
[0, 1, -1]
'''
return [i.charge for i in self.Chemicals]
@property
def similarity_variables(self):
r'''Similarity variables for all chemicals in the mixture, see
:obj:`thermo.elements.similarity_variable` for the definition, [mol/g]
Examples
--------
>>> Mixture(['benzene', 'toluene'], ws=[0.5, 0.5]).similarity_variables
[0.15362587797189262, 0.16279853724428964]
'''
return [i.similarity_variable for i in self.Chemicals]
@property
def atomss(self):
r'''List of dictionaries of atom counts for all chemicals in the mixture.
Examples
--------
>>> Mixture(['nitrogen', 'oxygen'], zs=[.01, .99]).atomss
[{'N': 2}, {'O': 2}]
'''
return [i.atoms for i in self.Chemicals]
@property
def ringss(self):
r'''List of ring counts for all chemicals in the mixture.
Examples
--------
>>> Mixture(['Docetaxel', 'Paclitaxel'], zs=[.5, .5]).ringss
[6, 7]
'''
return [i.rings for i in self.Chemicals]
@property
def atom_fractionss(self):
r'''List of dictionaries of atomic fractions for all chemicals in the
mixture.
Examples
--------
>>> Mixture(['oxygen', 'nitrogen'], zs=[.5, .5]).atom_fractionss
[{'O': 1.0}, {'N': 1.0}]
'''
return [i.atom_fractions for i in self.Chemicals]
@property
def atom_fractions(self):
r'''Dictionary of atomic fractions for each atom in the mixture.
Examples
--------
>>> Mixture(['CO2', 'O2'], zs=[0.5, 0.5]).atom_fractions
{'C': 0.2, 'O': 0.8}
'''
things = dict()
for zi, atoms in zip(self.zs, self.atomss):
for atom, count in atoms.iteritems():
if atom in things:
things[atom] += zi*count
else:
things[atom] = zi*count
tot = sum(things.values())
return {atom : value/tot for atom, value in things.iteritems()}
@property
def mass_fractionss(self):
r'''List of dictionaries of mass fractions for all chemicals in the mixture.
Examples
--------
>>> Mixture(['oxygen', 'nitrogen'], zs=[.5, .5]).mass_fractionss
[{'O': 1.0}, {'N': 1.0}]
'''
return [i.mass_fractions for i in self.Chemicals]
@property
def mass_fractions(self):
r'''Dictionary of mass fractions for each atom in the mixture.
Examples