forked from avaudrey/PsychroPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsychropy.py
908 lines (901 loc) · 43 KB
/
psychropy.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# flake8: noqa
"""
Python package dedicated to calculations dealing with moist air and HVAC
application, mostly based on the CoolProp package (http://www.coolprop.org/).
Author: [email protected]
"""
# ---------------------------------------------------------------------------
# Copyright (C) 2018 <Alexandre Vaudrey> |
# |
# This program is free software: you can redistribute it and/or modify |
# it under the terms of the GNU General Public License as published by |
# the Free Software Foundation, either version 3 of the License, or |
# (at your option) any later version. |
# |
# This program is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# GNU General Public License for more details. |
# |
# You should have received a copy of the GNU General Public License |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
# --------------------------------------------------------------------------|
import numpy as np # Properties of humid air
from CoolProp.CoolProp import HAPropsSI
# Value of one atmosphere in [Pa]
ATM = 1.01325 * 1e5
# Specific heats at constant pressure of dry air and water vapor, in [J/(kg.K)]
DRY_AIR_CP, WATER_VAPOR_CP, LIQUID_WATER_CP = 1004., 1805., 4186.
# Specific gas constants of dry air and water vapor, in [J/(kg.K)]
DRY_AIR_R, WATER_VAPOR_R = 287.055, 462.52
# Ratio of the water molar mass on the dry air one
ALPHAW = DRY_AIR_R/WATER_VAPOR_R
# Water specific enthalpy of vaporization, in [J/(kg.K)]
WATER_LW = 2501e+3
single_parameter_set_message = "At least two complementary properties of moist air are required to unambiguously identify the latter, any sole parameter can then not be used for so."
class MoistAir(object):
"""
Object containing the state of a given moist air. Temperature is expressed
in [K], pressure is expressed in Pa and specific enthalpy in kJ/kg. Although
three parameters, as e.g. temperature (T), relative humidity (R) and
pressure (P) are theoretically required to identify the specific state of
any moist air, pressure will be implicitly considered as equal to its
default value, i.e. 1 atm, until a different value is specifically entered
as attribute. A couple of parameter as e.g. RT, RW, TW, must then be used to
enter the specific state of the air (as it is used for example in CANTERA)
with:
R = relative humidity
T = dry bulb temperature
W = specific humidity or humidity ratio
B = wet bulb temperature
D = dew point temperature
H = specific enthalpy
See the README file for further information.
"""
def __init__(self):
# Name of the state
self.name = 'State 1'
# When the class is involved in computations dealing with a large amount
# of data, the below attribute can be switched to True in order to
# accelerate the calculation is avoiding as far as possible the use of
# the CoolProp package. Obtained results are usually a little bit less
# accurate than the ones obtained by Coolprop
self.fast_computation = False
# Pressure, in Pa
self.pressure = 1*ATM
# Temperature, in [K]
self._temperature = 20. + 273.15
# Relative humidity, dimensionless
self._relative_humidity = 0.5
# Specific humidity, dimensionless
self._specific_humidity = HAPropsSI('W',
'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Wet bulb temperature, in [K]
self._wet_bulb_temperature = HAPropsSI('B',
'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Dew point temperature, in [K]
self._dew_point_temperature = HAPropsSI('D',
'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H',
'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)*1e-3
# Specific volume, in m3/kg
self._specific_volume = HAPropsSI('V',
'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Static functions ========================================================
@staticmethod
def __equilibrium_vapor_pressure(temperature):
"""
Saturation or equilibrium pressure of water, in Pa. Correlation
extracted from the ASHRAE Handbook.
"""
if (temperature <= 0):
Cneg = np.array([-5.6745359e+3, 6.3925247, -9.677843e-3,
6.2215701e-7, 2.0747825e-9, -9.484024e-13,
4.1635019])
# Equation which gives the equilibrium pressure of water over its
# solid phase on a temperature range such as -100°C < T < 0°C. This
# equation is used when fast computation are required.
lnpeq = Cneg[0]/(temperature)+\
Cneg[1]+\
Cneg[2]*(temperature)+\
Cneg[3]*pow(temperature,2)+\
Cneg[4]*pow(temperature,3)+\
Cneg[5]*pow(temperature,4)+\
Cneg[6]*np.log(temperature)
else:
Cpos = np.array([-5.8002206e+3, 1.3914993, -4.8640239e-2,
4.176476e-5, -1.4452093e-8, 6.5459673])
# Equation which gives the equilibrium pressure of water over its
# liquid phase on a temperature range such as 0°C < T < 200°C. This
# equation is used when fast computation are required.
lnpeq = Cpos[0]/(temperature)+\
Cpos[1]+\
Cpos[2]*(temperature)+\
Cpos[3]*pow(temperature,2)+\
Cpos[4]*pow(temperature,3)+\
Cpos[5]*np.log(temperature)
return np.exp(lnpeq)
@staticmethod
def __logmeantemperature(temp1, temp2):
"""
Log mean temperature of temperature temp1 and temp2, in K, with both
temperature entered in [K].
"""
# This function is used for example in the calculation of the specific
# thermal exergy of moist air.
if temp1 == temp2:
lmtemp = temp1
else:
lmtemp = (temp1-temp2)/np.log((temp1)/(temp2))
return lmtemp
# @classmethod
def _TBtoW(self, D, B):
"""
Fast calculation, using the ASHRAE method, of the specific humidity
using the dry and wet bulb temperature measurements.
"""
# Calculation of the equilibrium pressure of water at the dry bulb
# temperature.
psatw = self.__equilibrium_vapor_pressure(B)
# Maximum specific humidity at the wet bulb temperature
wsatw = ALPHAW*psatw/(self.pressure-psatw)
# Calculation of specific humidity using [1, page 6.9, relation (35)]
W = ((WATER_LW-(LIQUID_WATER_CP-WATER_VAPOR_CP)*B)*wsatw-\
DRY_AIR_CP*(D-B))/(WATER_LW+WATER_VAPOR_CP*D-LIQUID_WATER_CP*B)
return W
# ==== Single properties of moist air =====================================
# At least two values being required to identify unambiguously the state of
# a given moist air, any new moist air must be entered thanks to a couple of
# properties, as e.g. the dry and the wet bulb temperature or the dry
# temperature and the relative humidity. Both single property of moist air
# can then be get but not set directly.
# ---- Temperature --------------------------------------------------------
@property
def temperature(self):
"""
Usual (dry bulb) temperature, in [K].
"""
return self._temperature
@temperature.setter
def temperature(self, value):
print(single_parameter_set_message)
@temperature.deleter
def temperature(self):
raise AttributeError("Can't delete attribute")
# ---- Relative humidity --------------------------------------------------
@property
def relative_humidity(self):
"""
Relative humidity, dimensionless, defined as the ratio of the actual
water vapour partial pressure on the maximum one equal to the
equilibrium pressure.
"""
return self._relative_humidity
@relative_humidity.setter
def relative_humidity(self, value):
print(single_parameter_set_message)
@relative_humidity.deleter
def relative_humidity(self):
raise AttributeError("Can't delete attribute")
# ---- Specific humidity --------------------------------------------------
@property
def specific_humidity(self):
"""
Specific humidity, aka humidity ratio, defined as the ratio of the mass
of water vapour on the dry air one it is mixed with. Dimensionless.
"""
return self._specific_humidity
@specific_humidity.setter
def specific_humidity(self):
print(single_parameter_set_message)
@specific_humidity.deleter
def specific_humidity(self):
raise AttributeError("Can't delete attribute")
# ---- Wet bulb temperature -----------------------------------------------
@property
def wet_bulb_temperature(self):
"""
Wet bulb temperature in [K], se the one of moist air if cooled down to
saturation through an adiabatic process, i.e. with a constant specific
enthalpy.
"""
return self._wet_bulb_temperature
@wet_bulb_temperature.setter
def wet_bulb_temperature(self, value):
print(single_parameter_set_message)
@wet_bulb_temperature.deleter
def wet_bulb_temperature(self, value):
raise AttributeError("Can't delete attribute")
# ---- Dew point temperature ----------------------------------------------
@property
def dew_point_temperature(self):
"""
Dew point temperature in [K], so the one of moist air if cooled down to
saturation with a constant specific humidity.
"""
return self._dew_point_temperature
@dew_point_temperature.setter
def dew_point_temperature(self, value):
print(single_parameter_set_message)
@dew_point_temperature.deleter
def dew_point_temperature(self, value):
raise AttributeError("Can't delete attribute")
# ---- Specific enthalpy --------------------------------------------------
@property
def specific_enthalpy(self):
"""
Specific enthalpy of moist air, in kJ/kg.
"""
return self._specific_enthalpy
@specific_enthalpy.setter
def specific_enthalpy(self):
print(single_parameter_set_message)
@specific_enthalpy.deleter
def specific_enthalpy(self):
raise AttributeError("Can't delete attribute")
# ---- Specific volume ----------------------------------------------------
@property
def specific_volume(self):
"""
Specific volume of moist air, in m^3/kg.
"""
return self._specific_volume
@specific_volume.setter
def specific_volume(self):
print(single_parameter_set_message)
@specific_volume.deleter
def specific_volume(self):
raise AttributeError("Can't delete attribute")
# ==== Couples of parameters to set the moist air physical properties =====
# Dry temperature and relative humidity as entered parameters -------------
@property
def TR(self):
"""
Dry temperature and relative humidity as entered properties of the moist
air.
"""
return self.temperature, self.relative_humidity
@TR.setter
def TR(self, values):
# Set of the temperature value
self._temperature = values[0]
# Check if the entered value of relative humidity is between 0 and 1
if (values[1] < 0) or (values[1] > 1):
raise ValueError("Relative humidity must be between 0% and 100%!")
else:
self._relative_humidity = values[1]
# Calculation of the corresponding specific humidity value
self._specific_humidity = HAPropsSI('W', 'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Wet bulb temperature
self._wet_bulb_temperature = HAPropsSI('B', 'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Dew point temperature
self._dew_point_temperature = HAPropsSI('D', 'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'T', self.temperature,
'R', self.relative_humidity)
@property
def RT(self):
"""
Relative humidity and dry temperature as entered properties of the moist
air.
"""
return self.relative_humidity, self.temperature
@RT.setter
def RT(self, values):
self.TR = values[::-1]
# Dry and wet bulb temperature as entered parameters ----------------------
@property
def TB(self):
"""
Dry and wet bulb temperatures as entered properties of the moist air.
"""
return self.temperature, self.wet_bulb_temperature
@TB.setter
def TB(self, values):
# Set of the temperature value
self._temperature = values[0]
# Check if the entered wet bulb temperature value is lower than the dry
# one
if (values[1] > values[0]):
raise ValueError("Wet bulb temperature is lower than the dry one!")
else:
self._wet_bulb_temperature = values[1]
# The use of dry and wet bulb temperatures being usually quite slow with
# CoolProp, the option fast_computation can be used here when a large
# amount of temperature values is involved
if not self.fast_computation:
# Calculation of the corresponding relative humidity, using the
# CoolProp package
self._relative_humidity = HAPropsSI('R',
'P', self.pressure,
'T', self.temperature,
'B', self.wet_bulb_temperature\
)
# Calculation of the corresponding specific humidity value
self._specific_humidity = HAPropsSI('W', 'P', self.pressure,
'T', self.temperature,
'B', self.wet_bulb_temperature\
)
# Dew point temperature
self._dew_point_temperature = HAPropsSI('D', 'P', self.pressure,
'T',\
self.temperature,
'B',\
self.wet_bulb_temperature\
)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'T', self.temperature,
'B', self.wet_bulb_temperature\
)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'T', self.temperature,
'B', self.wet_bulb_temperature\
)
else:
# When fast computation is called, specific humidity is computed
# in a simplified way, according to the ASHRAE method .
self._specific_humidity = self._TBtoW(self.temperature,\
self.wet_bulb_temperature)
# Partial pressure of water vapour
pvap = self.pressure*self.specific_humidity/\
(self.specific_humidity+ALPHAW)
# Equilibrium pressure of water vapour at the dry temperature
psatd = self.__equilibrium_vapor_pressure(self.temperature)
# Relative humidity
self._relative_humidity = pvap/psatd
# Dew point temperature, see [1, page 6.10]
lnpvap = np.log(pvap*1e-3)
if self.temperature >= 0:
self._dew_point_temperature = 6.54+14.526*lnpvap\
+0.7389*pow(lnpvap,2)+0.09486*pow(lnpvap,3)\
+0.4569*pow(pvap*1e-3,0.1984)
else:
self._dew_point_temperature = 6.09+12.608*lnpvap\
+0.4959*pow(lnpvap,2)
# Specific enthalpy, in kJ/kg, see [1, page 6.9]
self._specific_enthalpy = (DRY_AIR_CP*self.temperature\
+self.specific_humidity*(WATER_VAPOR_CP*self.temperature\
+WATER_LW))*1e-3
# Specific volume, in m^3/kg, using the ideal gas law
self._specific_volume = WATER_VAPOR_R\
*(ALPHAW+self.specific_humidity)*(self.temperature)\
/((1+self.specific_humidity)*self.pressure)
@property
def BT(self):
"""
Wet and dry bulb temperatures as entered properties of the moist air.
"""
return self.wet_bulb_temperature, self.temperature
@BT.setter
def BT(self, values):
self.TB = values[::-1]
# Dry and dew point temperatures as entered properties --------------------
@property
def TD(self):
"""
Dry and dew point temperatures as entered properties of the moist air.
"""
return self.temperature, self.dew_point_temperature
@TD.setter
def TD(self, values):
# TODO : fast computation must be implemented here.
# Set of the temperature value
self._temperature = values[0]
# Check if the entered dew point temperature value is lower than the dry
# one
if (values[1] > values[0]):
raise ValueError("Dew point temperature is lower than the dry one!")
else:
self._dew_point_temperature = values[1]
# Calculation of the corresponding relative humidity
self._relative_humidity = HAPropsSI('R', 'P', self.pressure,
'T', self.temperature,
'D', self.dew_point_temperature\
)
# Calculation of the corresponding specific humidity value
self._specific_humidity = HAPropsSI('W', 'P', self.pressure,
'T', self.temperature,
'D', self.dew_point_temperature\
)
# Dew point temperature
self._wet_bulb_temperature = HAPropsSI('B', 'P', self.pressure,
'T', self.temperature,
'D', self.dew_point_temperature\
)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'T', self.temperature,
'D', self.dew_point_temperature\
)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'T', self.temperature,
'D', self.dew_point_temperature\
)
@property
def DT(self):
"""
Dew point and dry bulb temperatures as entered properties of the moist
air.
"""
return self.dew_point_temperature, self.temperature
@DT.setter
def DT(self, values):
self.TD = values[::-1]
# Relative humidity and wet bulb temperature as entered properties --------
@property
def RB(self):
"""
Relative humidity and wet bulb temperature as entered properties of the
moist air.
"""
return self.relative_humidity, self.wet_bulb_temperature
@RB.setter
def RB(self, values):
# TODO : fast computation must be implemented here.
# Set of the wet bulb temperature value
self._wet_bulb_temperature = values[1]
# Check if the entered value of relative humidity is between 0 and 1
if (values[0] < 0) or (values[0] > 1):
raise ValueError("Relative humidity must be between 0% and 100%!")
else:
self._relative_humidity = values[0]
# Calculation of the corresponding dry bulb temperature
self._temperature = HAPropsSI('T', 'P', self.pressure,
'R', self.relative_humidity,
'B', self.wet_bulb_temperature\
)
# Calculation of the corresponding specific humidity value
self._specific_humidity = HAPropsSI('W', 'P', self.pressure,
'R', self.relative_humidity,
'B', self.wet_bulb_temperature\
)
# Dew point temperature
self._dew_point_temperature = HAPropsSI('D', 'P', self.pressure,
'R', self.relative_humidity,
'B', self.wet_bulb_temperature\
)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'R', self.relative_humidity,
'B', self.wet_bulb_temperature\
)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'R', self.relative_humidity,
'B', self.wet_bulb_temperature\
)
@property
def BR(self):
"""
Wet bulb temperature and relative humidity as entered properties of the
moist air.
"""
return self.wet_bulb_temperature, self.relative_humidity
@BR.setter
def BR(self, values):
self.RB = values[::-1]
# Relative humidity and dew point temperature as entered properties --------
@property
def RD(self):
"""
Relative humidity and dew point temperature as entered properties of the
moist air.
"""
return self.relative_humidity, self.dew_point_temperature
@RD.setter
def RD(self, values):
# TODO : fast computation must be implemented here.
# Set of the dew point temperature value
self._dew_point_temperature = values[1]
# Check if the entered value of relative humidity is between 0 and 1
if (values[0] < 0) or (values[0] > 1):
raise ValueError("Relative humidity must be between 0% and 100%!")
else:
self._relative_humidity = values[0]
# Calculation of the corresponding dry bulb temperature
self._temperature = HAPropsSI('T', 'P', self.pressure,
'R', self.relative_humidity,
'D', self.dew_point_temperature\
)
# Calculation of the corresponding specific humidity value
self._specific_humidity = HAPropsSI('W', 'P', self.pressure,
'R', self.relative_humidity,
'D', self.dew_point_temperature\
)
# Wet bulb temperature
self._wet_bulb_temperature = HAPropsSI('B', 'P', self.pressure,
'R', self.relative_humidity,
'D', self.dew_point_temperature\
)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'R', self.relative_humidity,
'D', self.dew_point_temperature\
)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'R', self.relative_humidity,
'D', self.dew_point_temperature\
)
@property
def DR(self):
"""
Dew point temperature and relative humidity as entered properties of the
moist air.
"""
return self.dew_point_temperature, self.relative_humidity
@DR.setter
def DR(self, values):
self.RD = values[::-1]
# Wet bulb and dew point temperatures as entered properties ---------------
@property
def BD(self):
"""
Wet bulb and dew point temperatures as entered properties of the moist
air.
"""
return self.wet_bulb_temperature, self.dew_point_temperature
@BD.setter
def BD(self, values):
# TODO : fast computation must be implemented here.
# Set of the wet bulb temperature value
self._wet_bulb_temperature = values[0]
# Set of the dew point temperature value
self._dew_point_temperature = values[1]
# Calculation of the corresponding dry bulb temperature
self._temperature = HAPropsSI('T', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'D', self.dew_point_temperature)
# Relative humidity
self._relative_humidity = HAPropsSI('R', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'D', self.dew_point_temperature
)
# Calculation of the corresponding specific humidity value
self._specific_humidity = HAPropsSI('W', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'D', self.dew_point_temperature\
)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'D', self.dew_point_temperature
)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'D', self.dew_point_temperature\
)
@property
def DB(self):
"""
Dew point and wet bulb temperatures humidity as entered properties of
the moist air.
"""
return self.dew_point_temperature, self.wet_bulb_temperature
@DB.setter
def DB(self, values):
self.BD = values[::-1]
# Dry temperature and specific humidity as entered properties -------------
@property
def TW(self):
"""
Dry temperature and specific humidity as entered properties of the moist
air.
"""
return self.temperature, self.specific_humidity
@TW.setter
def TW(self, values):
# TODO : fast computation must be implemented here.
# Set of the dry temperature value
self._temperature = values[0]
# Check if the entered value of specific humidity makes sense, so if it
# is between 0 and its maximum value when saturation is reached at the
# same dry temperature
wmax = HAPropsSI('W', 'P', self.pressure, 'R', 1.0,\
'T', values[0])
if (values[1] < 0):
raise ValueError("Specific humidity is positive")
elif (values[1] > wmax):
raise ValueError("Specific humidity is higher than at saturation")
else:
# Set of the specific humidity value
self._specific_humidity = values[1]
# Relative humidity
self._relative_humidity = HAPropsSI('R', 'P', self.pressure,
'T', self.temperature,
'W', self.specific_humidity)
# Calculation of the corresponding wet bulb temperature
self._wet_bulb_temperature = HAPropsSI('B', 'P', self.pressure,
'T', self.temperature,
'W',
self.specific_humidity)
# Calculation of the corresponding dew point temperature
self._dew_point_temperature = HAPropsSI('D', 'P', self.pressure,
'T', self.temperature,
'W', self.specific_humidity)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'T', self.temperature,
'W', self.specific_humidity)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'T', self.temperature,
'W', self.specific_humidity)
@property
def WT(self):
"""
Specific humidity and dry temperature as entered properties of the moist
air.
"""
return self.specific_humidity, self.temperature
@WT.setter
def WT(self, values):
self.TW = values[::-1]
# Relative and specific humidities as entered parameters ------------------
@property
def RW(self):
"""
Relative and specific humidities as entered properties of the moist
air.
"""
return self.relative_humidity, self.specific_humidity
@RW.setter
def RW(self, values):
# TODO : fast computation must be implemented here.
# Check if the entered value of relative humidity is between 0 and 1
if (values[0] < 0) or (values[0] > 1):
raise ValueError("Relative humidity must be between 0% and 100%!")
else:
self._relative_humidity = values[0]
# Check if the entered value of specific humidity makes sense
if (values[1] < 0):
raise ValueError("Specific humidity is positive")
else:
# Set of the specific humidity value
self._specific_humidity = values[1]
# Dry temperature
self._temperature = HAPropsSI('T', 'P', self.pressure,
'R', self.relative_humidity,
'W', self.specific_humidity)
# Calculation of the corresponding wet bulb temperature
self._wet_bulb_temperature = HAPropsSI('B', 'P', self.pressure,
'R', self.relative_humidity,
'W', self.specific_humidity)
# Calculation of the corresponding dew point temperature
self._dew_point_temperature = HAPropsSI('D', 'P', self.pressure,
'R', self.relative_humidity,
'W', self.specific_humidity)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'R', self.relative_humidity,
'W', self.specific_humidity)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'R', self.relative_humidity,
'W', self.specific_humidity)
@property
def WR(self):
"""
Specific and relative humidities as entered properties of the moist
air.
"""
return self.specific_humidity, self.temperature
@WR.setter
def WR(self, values):
self.RW = values[::-1]
# Wet bulb temperature and specific humidity as entered properties -------------
@property
def BW(self):
"""
Wet bulb temperature and specific humidity as entered properties of the
moist air.
"""
return self.wet_bulb_temperature, self.specific_humidity
@BW.setter
def BW(self, values):
# TODO : fast computation must be implemented here.
# Set of the wet bulb temperature value
self._wet_bulb_temperature = values[0]
# Check if the entered value of specific humidity makes sense, so if it
# is between 0 and its maximum value when saturation is reached at the
# same dry temperature
wmax = HAPropsSI('W', 'P', self.pressure, 'R', 1.0,\
'B', values[0])
if (values[1] < 0):
raise ValueError("Specific humidity is positive")
elif (values[1] > wmax):
raise ValueError("Specific humidity is higher than at saturation")
else:
# Set of the specific humidity value
self._specific_humidity = values[1]
# Dry temperature
self._temperature = HAPropsSI('T', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'W', self.specific_humidity)
# Relative humidity
self._relative_humidity = HAPropsSI('R', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'W', self.specific_humidity)
# Calculation of the corresponding dew point temperature
self._dew_point_temperature = HAPropsSI('D', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'W', self.specific_humidity)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'W', self.specific_humidity)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'B', self.wet_bulb_temperature,
'W', self.specific_humidity)
@property
def WB(self):
"""
Specific humidity and wet bulb temperature as entered properties of the
moist air.
"""
return self.specific_humidity, self.wet_bulb_temperature
@WB.setter
def WB(self, values):
self.BW = values[::-1]
# Dew point temperature and specific humidity as entered properties -------
@property
def DW(self):
"""
Dew point temperature and specific humidity as entered properties(self.specific_humidity*WATER_VAPOR_R\
*np.log(self.specific_humidity/ref_state.specific_humidity)\
-(DRY_AIR_R+self.specific_humidity of the
moist air.
"""
return self.dew_point_temperature, self.specific_humidity
@DW.setter
def DW(self, values):
# TODO : fast computation must be implemented here.
# Set of the dew point temperature value
self._dew_point_temperature = values[0]
# Check if the entered value of specific humidity makes sense, so if it
# is between 0 and its maximum value when saturation is reached at the
# same dry temperature
wmax = HAPropsSI('W', 'P', self.pressure, 'R', 1.0,\
'D', values[0])
if (values[1] < 0):
raise ValueError("Specific humidity is positive")
elif (values[1] > wmax):
raise ValueError("Specific humidity is higher than at saturation")
else:
# Set of the specific humidity value
self._specific_humidity = values[1]
# Dry temperature
self._temperature = HAPropsSI('T', 'P', self.pressure,
'D', self.dew_point_temperature,
'W', self.specific_humidity)
# Relative humidity
self._relative_humidity = HAPropsSI('R', 'P', self.pressure,
'D', self.dew_point_temperature,
'W', self.specific_humidity)
# Calculation of the corresponding wet bulb temperature
self._wet_bulb_temperature = HAPropsSI('B', 'P', self.pressure,
'D', self.dew_point_temperature,
'W', self.specific_humidity)
# Specific enthalpy, in kJ/kg
self._specific_enthalpy = HAPropsSI('H', 'P', self.pressure,
'D', self.dew_point_temperature,
'W', self.specific_humidity)*1e-3
# Specific volume, in m^3/kg
self._specific_volume = HAPropsSI('V', 'P', self.pressure,
'D', self.dew_point_temperature,
'W', self.specific_humidity)
@property
def WD(self):
"""
Specific humidity and dew point temperature as entered properties of the
moist air.
"""
return self.specific_humidity, self.dew_point_temperature
@WD.setter
def WD(self, values):
self.DW = values[::-1]
# ==== Usual class methods ================================================
def absolute_humidity(self):
"""
Absolute humidity in kilogramme of water vapour per cubic meter of dry
air.
"""
return self.specific_humidity/self.specific_volume
def maximum_specific_humidity(self):
"""
Maximum value of the humidity content for a given air, corresponding to
a 100% relative humidity.
"""
w0sat = HAPropsSI('W', 'T', self.temperature, 'R', 1.0,\
'P', self.pressure)
return w0sat
def specific_thermal_exergy(self, ref_state):
"""
Specific thermal exergy of moist air, in J/kg, regarding to a reference
state represented by its corresponding MoistAir object.
"""
# Check if the entered reference state is a MoistAir object
if type(ref_state) != MoistAir:
raise TypeError("Reference state must be a MoisAir object!")
# Calculation of the Carnot factor
Tml0 = self.__logmeantemperature(self.temperature,\
ref_state.temperature)
CarnotFactor = 1-(ref_state.temperature)/Tml0
# And specific thermal exergy
return (DRY_AIR_CP+self.specific_humidity*WATER_VAPOR_CP)\
*(self.temperature-ref_state.temperature)*CarnotFactor
def specific_mechanical_exergy(self, ref_state):
"""
Specific mechanical exergy of moist air, in J/kg, regarding to a
reference state represented by its corresponding MoistAir object.
"""
# Check if the entered reference state is a MoistAir object
if type(ref_state) != MoistAir:
raise TypeError("Reference state must be a MoisAir object!")
return (DRY_AIR_R+self.specific_humidity*WATER_VAPOR_R)\
*(ref_state.temperature)\
*np.log(self.pressure/ref_state.pressure)
def specific_chemical_exergy(self, ref_state):
"""
Specific chemical exergy of moist air, in J/kg, regarding to a
reference state represented by its corresponding MoistAir object.
"""
# Check if the entered reference state is a MoistAir object
if type(ref_state) != MoistAir:
raise TypeError("Reference state must be a MoistAir object!")
# Specific humidities of the concerned moist air
w = self.specific_humidity
# And maximum specific humidity of the reference moist air
w0sat = ref_state.maximum_specific_humidity()
T0 = ref_state.temperature
return T0*(w*WATER_VAPOR_R*np.log(w/w0sat)-(DRY_AIR_R+w*WATER_VAPOR_R)\
*np.log((w+ALPHAW)/(w0sat+ALPHAW)))
def specific_exergy(self, ref_state):
"""
Specific exergy of moist air, in J/kg, regarding to a reference state
represented by its corresponding MoistAir object.
"""
# Check if the entered reference state is a MoistAir object
if type(ref_state) != MoistAir:
raise TypeError("Reference state must be a MoisAir object!")
return self.specific_thermal_exergy(ref_state)\
+self.specific_mechanical_exergy(ref_state)\
+self.specific_chemical_exergy(ref_state)
if __name__ == '__main__':
inside = MoistAir()
inside.TW = 20.0, 7e-3
outside = MoistAir()
outside.TW = 0.0, 3e-3
# ==== References =============================================================
#
# [1] “ASHRAE Handbook : Fundamentals” (2001). In : American Society of Heating,
# Refrigerating and Air-Conditioning Engineers. Chap. 6 : Psychrometrics.