-
Notifications
You must be signed in to change notification settings - Fork 62
/
psychrolib.cs
1226 lines (1035 loc) · 58.2 KB
/
psychrolib.cs
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
/*
* PsychroLib (version 2.5.0) (https://github.com/psychrometrics/psychrolib).
* Copyright (c) 2018-2020 The PsychroLib Contributors for the current library implementation.
* Copyright (c) 2017 ASHRAE Handbook — Fundamentals for ASHRAE equations and coefficients.
* Licensed under the MIT License.
*/
using System;
namespace PsychroLib
{
/// <summary>
/// Class of functions to enable the calculation of psychrometric properties of moist and dry air.
/// </summary>
public class Psychrometrics
{
/******************************************************************************************************
* Global constants
*****************************************************************************************************/
/// <summary>
/// Zero degree Fahrenheit (°F) expressed as degree Rankine (°R).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 39.
/// </summary>
private const double ZERO_FAHRENHEIT_AS_RANKINE = 459.67;
/// <summary>
/// Zero degree Celsius (°C) expressed as Kelvin (K).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 39.
/// </summary>
private const double ZERO_CELSIUS_AS_KELVIN = 273.15;
/// <summary>
/// Universal gas constant for dry air (IP version) in ft lb_Force lb_DryAir⁻¹ R⁻¹.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.
/// </summary>
private const double R_DA_IP = 53.350;
/// <summary>
/// Universal gas constant for dry air (SI version) in J kg_DryAir⁻¹ K⁻¹.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.
/// </summary>
private const double R_DA_SI = 287.042;
/// <summary>
/// Invalid value (dimensionless).
/// </summary>
private const double INVALID = -99999;
/// <summary>
/// Maximum number of iterations before exiting while loops.
/// </summary>
private const double MAX_ITER_COUNT = 100;
/// <summary>
/// Minimum acceptable humidity ratio used/returned by any functions.
/// Any value above 0 or below the MIN_HUM_RATIO will be reset to this value.
/// </summary>
private const double MIN_HUM_RATIO = 1e-7;
/// <summary>
/// Freezing point of water in Fahrenheit.
/// </summary>
private const double FREEZING_POINT_WATER_IP = 32.0;
/// <summary>
/// Freezing point of water in Celsius.
/// </summary>
private const double FREEZING_POINT_WATER_SI = 0.0;
/// <summary>
/// Triple point of water in Fahrenheit.
/// </summary>
private const double TRIPLE_POINT_WATER_IP = 32.018;
/// <summary>
/// Triple point of water in Celsius.
/// </summary>
private const double TRIPLE_POINT_WATER_SI = 0.01;
/// <summary>
/// Gets or Sets the current system of units for the calculations.
/// </summary>
public UnitSystem UnitSystem
{
get => _unitSystem;
set
{
_unitSystem = value;
if (value == UnitSystem.IP)
PSYCHROLIB_TOLERANCE = 0.001 * 9.0 / 5.0;
else
PSYCHROLIB_TOLERANCE = 0.001;
}
}
private double PSYCHROLIB_TOLERANCE;
private UnitSystem _unitSystem;
/// <summary>
/// Constructor to create instance with the specified unit system.
/// </summary>
/// <param name="unitSystem">System of units to utilize for calculations.</param>
public Psychrometrics(UnitSystem unitSystem)
{
UnitSystem = unitSystem;
}
/******************************************************************************************************
* Conversion between temperature units
*****************************************************************************************************/
/// <summary>
/// Utility function to convert temperature to degree Rankine (°R)
/// given temperature in degree Fahrenheit (°F).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tF">Temperature in Fahrenheit (°F)</param>
/// <returns>Rankine (°R)</returns>
public double GetTRankineFromTFahrenheit(double tF)
{
return tF + ZERO_FAHRENHEIT_AS_RANKINE; /* exact */
}
/// <summary>
/// Utility function to convert temperature to degree Fahrenheit (°F)
/// given temperature in degree Rankine (°R).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tR">Temperature in Rankine (°R)</param>
/// <returns>Fahrenheit (°F)</returns>
public double GetTFahrenheitFromTRankine(double tR)
{
return tR - ZERO_FAHRENHEIT_AS_RANKINE; /* exact */
}
/// <summary>
/// Utility function to convert temperature to Kelvin (K)
/// given temperature in degree Celsius (°C).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tC">Temperature in Celsius (°C)</param>
/// <returns>Rankine (°R)</returns>
public double GetTKelvinFromTCelsius(double tC)
{
return tC + ZERO_CELSIUS_AS_KELVIN; /* exact */
}
/// <summary>
/// Utility function to convert temperature to degree Celsius (°C)
/// given temperature in Kelvin (K).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tK">Temperature in Rankine (°R)</param>
/// <returns>Celsius (°C)</returns>
public double GetTCelsiusFromTKelvin(double tK)
{
return tK - ZERO_CELSIUS_AS_KELVIN; /* exact */
}
/******************************************************************************************************
* Conversions between dew point, wet bulb, and relative humidity
*****************************************************************************************************/
/// <summary>
/// Return wet-bulb temperature given dry-bulb temperature, dew-point temperature, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="tDewPoint">Dew point temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Wet bulb temperature in °F [IP] or °C [SI]</returns>
public double GetTWetBulbFromTDewPoint(double tDryBulb, double tDewPoint, double pressure)
{
if (!(tDewPoint <= tDryBulb))
throw new InvalidOperationException("Dew point temperature is above dry bulb temperature");
var humRatio = GetHumRatioFromTDewPoint(tDewPoint, pressure);
return GetTWetBulbFromHumRatio(tDryBulb, humRatio, pressure);
}
/// <summary>
/// Return wet-bulb temperature given dry-bulb temperature, relative humidity, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="relHum">Relative humidity [0-1]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Wet bulb temperature in °F [IP] or °C [SI]</returns>
public double GetTWetBulbFromRelHum(double tDryBulb, double relHum, double pressure)
{
if (!(relHum >= 0.0 && relHum <= 1.0))
throw new InvalidOperationException("Relative humidity is outside range [0,1]");
var humRatio = GetHumRatioFromRelHum(tDryBulb, relHum, pressure);
return GetTWetBulbFromHumRatio(tDryBulb, humRatio, pressure);
}
/// <summary>
/// Return relative humidity given dry-bulb temperature and dew-point temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 22
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="tDewPoint">Dew point temperature in °F [IP] or °C [SI]</param>
/// <returns>Relative humidity [0-1]</returns>
public double GetRelHumFromTDewPoint(double tDryBulb, double tDewPoint)
{
if (!(tDewPoint <= tDryBulb))
throw new InvalidOperationException("Dew point temperature is above dry bulb temperature");
var vapPres = GetSatVapPres(tDewPoint);
var satVapPres = GetSatVapPres(tDryBulb);
return vapPres / satVapPres;
}
/// <summary>
/// Return relative humidity given dry-bulb temperature, wet bulb temperature and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="tWetBulb">Wet bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Relative humidity [0-1]</returns>
public double GetRelHumFromTWetBulb(double tDryBulb, double tWetBulb, double pressure)
{
if (!(tWetBulb <= tDryBulb))
throw new InvalidOperationException("Wet bulb temperature is above dry bulb temperature");
var humRatio = GetHumRatioFromTWetBulb(tDryBulb, tWetBulb, pressure);
return GetRelHumFromHumRatio(tDryBulb, humRatio, pressure);
}
/// <summary>
/// Return dew-point temperature given dry-bulb temperature and relative humidity.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="relHum">Relative humidity [0-1]</param>
/// <returns>Dew Point temperature in °F [IP] or °C [SI]</returns>
public double GetTDewPointFromRelHum(double tDryBulb, double relHum)
{
if (!(relHum >= 0.0 && relHum <= 1.0))
throw new InvalidOperationException("Relative humidity is outside range [0,1]");
var vapPres = GetVapPresFromRelHum(tDryBulb, relHum);
return GetTDewPointFromVapPres(tDryBulb, vapPres);
}
/// <summary>
/// Return dew-point temperature given dry-bulb temperature, wet-bulb temperature, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="tWetBulb">Wet bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Dew Point temperature in °F [IP] or °C [SI]</returns>
public double GetTDewPointFromTWetBulb(double tDryBulb, double tWetBulb, double pressure)
{
if (!(tWetBulb <= tDryBulb))
throw new InvalidOperationException("Wet bulb temperature is above dry bulb temperature");
var humRatio = GetHumRatioFromTWetBulb(tDryBulb, tWetBulb, pressure);
return GetTDewPointFromHumRatio(tDryBulb, humRatio, pressure);
}
/******************************************************************************************************
* Conversions between dew point, or relative humidity and vapor pressure
*****************************************************************************************************/
/// <summary>
/// Return partial pressure of water vapor as a function of relative humidity and temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 12, 22
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="relHum">Relative humidity [0-1]</param>
/// <returns>Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]</returns>
public double GetVapPresFromRelHum(double tDryBulb, double relHum)
{
if (!(relHum >= 0.0 && relHum <= 1.0))
throw new InvalidOperationException("Relative humidity is outside range [0,1]");
return relHum * GetSatVapPres(tDryBulb);
}
/// <summary>
/// Return relative humidity given dry-bulb temperature and vapor pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 12, 22
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="vapPres">Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]</param>
/// <returns>Relative humidity [0-1]</returns>
public double GetRelHumFromVapPres(double tDryBulb, double vapPres)
{
if (!(vapPres >= 0.0))
throw new InvalidOperationException("Partial pressure of water vapor in moist air is negative");
return vapPres / GetSatVapPres(tDryBulb);
}
/// <summary>
/// Helper function returning the derivative of the natural log of the saturation vapor pressure
/// as a function of dry-bulb temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 5 & 6
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <returns>Derivative of natural log of vapor pressure of saturated air in Psi [IP] or Pa [SI]</returns>
private double dLnPws_(double tDryBulb)
{
double dLnPws, T;
if (UnitSystem == UnitSystem.IP)
{
T = GetTRankineFromTFahrenheit(tDryBulb);
if (tDryBulb <= TRIPLE_POINT_WATER_IP)
dLnPws = 1.0214165E+04 / Math.Pow(T, 2) - 5.3765794E-03 + 2 * 1.9202377E-07 * T
+ 3 * 3.5575832E-10 * Math.Pow(T, 2) - 4 * 9.0344688E-14 * Math.Pow(T, 3)
+ 4.1635019 / T;
else
dLnPws = 1.0440397E+04 / Math.Pow(T, 2) - 2.7022355E-02 + 2 * 1.2890360E-05 * T
- 3 * 2.4780681E-09 * Math.Pow(T, 2) + 6.5459673 / T;
}
else
{
T = GetTKelvinFromTCelsius(tDryBulb);
if (tDryBulb <= TRIPLE_POINT_WATER_SI)
dLnPws = 5.6745359E+03 / Math.Pow(T, 2) - 9.677843E-03 + 2 * 6.2215701E-07 * T
+ 3 * 2.0747825E-09 * Math.Pow(T, 2) - 4 * 9.484024E-13 * Math.Pow(T, 3)
+ 4.1635019 / T;
else
dLnPws = 5.8002206E+03 / Math.Pow(T, 2) - 4.8640239E-02 + 2 * 4.1764768E-05 * T
- 3 * 1.4452093E-08 * Math.Pow(T, 2) + 6.5459673 / T;
}
return dLnPws;
}
/// <summary>
/// Return dew-point temperature given dry-bulb temperature and vapor pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 5 and 6
/// Notes: the dew point temperature is solved by inverting the equation giving water vapor pressure
/// at saturation from temperature rather than using the regressions provided
/// by ASHRAE (eqn. 37 and 38) which are much less accurate and have a
/// narrower range of validity.
/// The Newton-Raphson (NR) method is used on the logarithm of water vapour
/// pressure as a function of temperature, which is a very smooth function
/// Convergence is usually achieved in 3 to 5 iterations.
/// tDryBulb is not really needed here, just used for convenience.
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="vapPres">Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]</param>
/// <returns>(o) Dew Point temperature in °F [IP] or °C [SI]</returns>
public double GetTDewPointFromVapPres(double tDryBulb, double vapPres)
{
// Bounds function of the system of units
var bounds = UnitSystem == UnitSystem.IP
? new[] {-148.0, 392.0}
: new[] {-100.0, 200.0};
// Bounds outside which a solution cannot be found
if (vapPres < GetSatVapPres(bounds[0]) || vapPres > GetSatVapPres(bounds[1]))
throw new InvalidOperationException(
"Partial pressure of water vapor is outside range of validity of equations");
// We use NR to approximate the solution.
// First guess
var tDewPoint =
tDryBulb; // Calculated value of dew point temperatures, solved for iteratively in °F [IP] or °C [SI]
var lnVP = Math.Log(vapPres); // Natural logarithm of partial pressure of water vapor pressure in moist air
double tDewPoint_iter; // Value of tDewPoint used in NR calculation
double lnVP_iter; // Value of log of vapor water pressure used in NR calculation
var index = 1;
do
{
// Current point
tDewPoint_iter = tDewPoint;
lnVP_iter = Math.Log(GetSatVapPres(tDewPoint_iter));
// Derivative of function, calculated analytically
var d_lnVP = dLnPws_(tDewPoint_iter);
// New estimate, bounded by domain of validity of eqn. 5 and 6
tDewPoint = tDewPoint_iter - (lnVP_iter - lnVP) / d_lnVP;
tDewPoint = Math.Max(tDewPoint, bounds[0]);
tDewPoint = Math.Min(tDewPoint, bounds[1]);
if (index > MAX_ITER_COUNT)
throw new InvalidOperationException(
"Convergence not reached in GetTDewPointFromVapPres. Stopping.");
index++;
} while (Math.Abs(tDewPoint - tDewPoint_iter) > PSYCHROLIB_TOLERANCE);
return Math.Min(tDewPoint, tDryBulb);
}
/// <summary>
/// Return vapor pressure given dew point temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 36
/// </summary>
/// <param name="tDewPoint">Dew point temperature in °F [IP] or °C [SI]</param>
/// <returns>Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]</returns>
public double GetVapPresFromTDewPoint(double tDewPoint)
{
return GetSatVapPres(tDewPoint);
}
/******************************************************************************************************
* Conversions from wet-bulb temperature, dew-point temperature, or relative humidity to humidity ratio
*****************************************************************************************************/
/// <summary>
/// Return wet-bulb temperature given dry-bulb temperature, humidity ratio, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 33 and 35 solved for Tstar
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Wet bulb temperature in °F [IP] or °C [SI]</returns>
public double GetTWetBulbFromHumRatio(double tDryBulb, double humRatio, double pressure)
{
// Declarations
double Wstar;
double tDewPoint, tWetBulb, tWetBulbSup, tWetBulbInf, boundedHumRatio;
var index = 1;
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
tDewPoint = GetTDewPointFromHumRatio(tDryBulb, boundedHumRatio, pressure);
// Initial guesses
tWetBulbSup = tDryBulb;
tWetBulbInf = tDewPoint;
tWetBulb = (tWetBulbInf + tWetBulbSup) / 2.0;
// Bisection loop
while ((tWetBulbSup - tWetBulbInf) > PSYCHROLIB_TOLERANCE)
{
// Compute humidity ratio at temperature Tstar
Wstar = GetHumRatioFromTWetBulb(tDryBulb, tWetBulb, pressure);
// Get new bounds
if (Wstar > boundedHumRatio)
tWetBulbSup = tWetBulb;
else
tWetBulbInf = tWetBulb;
// New guess of wet bulb temperature
tWetBulb = (tWetBulbSup + tWetBulbInf) / 2.0;
if (index > MAX_ITER_COUNT)
throw new InvalidOperationException(
"Convergence not reached in GetTWetBulbFromHumRatio. Stopping.");
index++;
}
return tWetBulb;
}
/// <summary>
/// Return humidity ratio given dry-bulb temperature, wet-bulb temperature, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 33 and 35
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="tWetBulb">Wet bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Humidity Ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</returns>
public double GetHumRatioFromTWetBulb(double tDryBulb, double tWetBulb, double pressure)
{
double wsstar;
double humRatio = INVALID;
if (!(tWetBulb <= tDryBulb))
throw new InvalidOperationException("Wet bulb temperature is above dry bulb temperature");
wsstar = GetSatHumRatio(tWetBulb, pressure);
if (UnitSystem == UnitSystem.IP)
{
if (tWetBulb >= FREEZING_POINT_WATER_IP)
humRatio = ((1093.0 - 0.556 * tWetBulb) * wsstar - 0.240 * (tDryBulb - tWetBulb))
/ (1093.0 + 0.444 * tDryBulb - tWetBulb);
else
humRatio = ((1220.0 - 0.04 * tWetBulb) * wsstar - 0.240 * (tDryBulb - tWetBulb))
/ (1220.0 + 0.444 * tDryBulb - 0.48 * tWetBulb);
}
else
{
if (tWetBulb >= FREEZING_POINT_WATER_SI)
humRatio = ((2501.0 - 2.326 * tWetBulb) * wsstar - 1.006 * (tDryBulb - tWetBulb))
/ (2501.0 + 1.86 * tDryBulb - 4.186 * tWetBulb);
else
humRatio = ((2830.0 - 0.24 * tWetBulb) * wsstar - 1.006 * (tDryBulb - tWetBulb))
/ (2830.0 + 1.86 * tDryBulb - 2.1 * tWetBulb);
}
// Validity check.
return Math.Max(humRatio, MIN_HUM_RATIO);
}
/// <summary>
/// Return humidity ratio given dry-bulb temperature, relative humidity, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="relHum">Relative humidity [0-1]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Humidity Ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</returns>
public double GetHumRatioFromRelHum(double tDryBulb, double relHum, double pressure)
{
if (!(relHum >= 0.0 && relHum <= 1.0))
throw new InvalidOperationException("Relative humidity is outside range [0,1]");
var vapPres = GetVapPresFromRelHum(tDryBulb, relHum);
return GetHumRatioFromVapPres(vapPres, pressure);
}
/// <summary>
/// Return relative humidity given dry-bulb temperature, humidity ratio, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Relative humidity [0-1]</returns>
public double GetRelHumFromHumRatio(double tDryBulb, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var vapPres = GetVapPresFromHumRatio(humRatio, pressure);
return GetRelHumFromVapPres(tDryBulb, vapPres);
}
/// <summary>
/// Return humidity ratio given dew-point temperature and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDewPoint">Dew point temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Humidity Ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</returns>
public double GetHumRatioFromTDewPoint(double tDewPoint, double pressure)
{
var vapPres = GetSatVapPres(tDewPoint);
return GetHumRatioFromVapPres(vapPres, pressure);
}
/// <summary>
/// Return dew-point temperature given dry-bulb temperature, humidity ratio, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Dew Point temperature in °F [IP] or °C [SI]</returns>
public double GetTDewPointFromHumRatio(double tDryBulb, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var vapPres = GetVapPresFromHumRatio(humRatio, pressure);
return GetTDewPointFromVapPres(tDryBulb, vapPres);
}
/******************************************************************************************************
* Conversions between humidity ratio and vapor pressure
*****************************************************************************************************/
/// <summary>
/// Return humidity ratio given water vapor pressure and atmospheric pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 20
/// </summary>
/// <param name="vapPres">Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Humidity Ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</returns>
public double GetHumRatioFromVapPres(double vapPres, double pressure)
{
if (!(vapPres >= 0.0))
throw new InvalidOperationException("Partial pressure of water vapor in moist air is negative");
var humRatio = 0.621945 * vapPres / (pressure - vapPres);
// Validity check.
return Math.Max(humRatio, MIN_HUM_RATIO);
}
/// <summary>
/// Return vapor pressure given humidity ratio and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 20 solved for pw
/// </summary>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Partial pressure of water vapor in moist air in Psi [IP] or Pa [SI]</returns>
public double GetVapPresFromHumRatio(double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
var vapPres = pressure * boundedHumRatio / (0.621945 + boundedHumRatio);
return vapPres;
}
/******************************************************************************************************
* Conversions between humidity ratio and specific humidity
*****************************************************************************************************/
/// <summary>
/// Return the specific humidity from humidity ratio (aka mixing ratio)
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 9b
/// </summary>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <returns>Specific humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</returns>
public double GetSpecificHumFromHumRatio(double humRatio)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
return boundedHumRatio / (1.0 + boundedHumRatio);
}
/// <summary>
/// Return the humidity ratio (aka mixing ratio) from specific humidity
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 9b (solved for humidity ratio)
/// </summary>
/// <param name="specificHum"></param>
/// <returns>Humidity ratio in lb_H₂O lb_Dry_Air⁻¹ [IP] or kg_H₂O kg_Dry_Air⁻¹ [SI]</returns>
public double GetHumRatioFromSpecificHum(double specificHum)
{
if (!(specificHum >= 0.0 && specificHum < 1.0))
throw new InvalidOperationException("Specific humidity is outside range [0, 1)");
var humRatio = specificHum / (1.0 - specificHum);
// Validity check
return Math.Max(humRatio, MIN_HUM_RATIO);
}
/******************************************************************************************************
* Dry Air Calculations
*****************************************************************************************************/
/// <summary>
/// Return dry-air enthalpy given dry-bulb temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 28
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <returns>Dry air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹ [SI]</returns>
public double GetDryAirEnthalpy(double tDryBulb)
{
if (UnitSystem == UnitSystem.IP)
return 0.240 * tDryBulb;
return 1006.0 * tDryBulb;
}
/// <summary>
/// Return dry-air density given dry-bulb temperature and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// Notes: eqn 14 for the perfect gas relationship for dry air.
/// Eqn 1 for the universal gas constant.
/// The factor 144 in IP is for the conversion of Psi = lb in⁻² to lb ft⁻².
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Dry air density in lb ft⁻³ [IP] or kg m⁻³ [SI]</returns>
public double GetDryAirDensity(double tDryBulb, double pressure)
{
if (UnitSystem == UnitSystem.IP)
return (144.0 * pressure) / R_DA_IP / GetTRankineFromTFahrenheit(tDryBulb);
return pressure / R_DA_SI / GetTKelvinFromTCelsius(tDryBulb);
}
/// <summary>
/// Return dry-air volume given dry-bulb temperature and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.
/// Notes: eqn 14 for the perfect gas relationship for dry air.
/// Eqn 1 for the universal gas constant.
/// The factor 144 in IP is for the conversion of Psi = lb in⁻² to lb ft⁻².
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Dry air volume ft³ lb⁻¹ [IP] or in m³ kg⁻¹ [SI]</returns>
public double GetDryAirVolume(double tDryBulb, double pressure)
{
if (UnitSystem == UnitSystem.IP)
return R_DA_IP * GetTRankineFromTFahrenheit(tDryBulb) / (144.0 * pressure);
return R_DA_SI * GetTKelvinFromTCelsius(tDryBulb) / pressure;
}
/// <summary>
/// Return dry bulb temperature from enthalpy and humidity ratio.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.
/// Notes: based on the `GetMoistAirEnthalpy` function, rearranged for temperature.
/// </summary>
/// <param name="moistAirEnthalpy">Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <returns>Dry-bulb temperature in °F [IP] or °C [SI]</returns>
public double GetTDryBulbFromEnthalpyAndHumRatio(double moistAirEnthalpy, double humRatio)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
if (UnitSystem == UnitSystem.IP)
return (moistAirEnthalpy - 1061.0 * boundedHumRatio) / (0.240 + 0.444 * boundedHumRatio);
return (moistAirEnthalpy / 1000.0 - 2501.0 * boundedHumRatio) / (1.006 + 1.86 * boundedHumRatio);
}
/// <summary>
/// Return humidity ratio from enthalpy and dry-bulb temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.
/// Notes: based on the `GetMoistAirEnthalpy` function, rearranged for humidity ratio.
/// </summary>
/// <param name="moistAirEnthalpy">Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹</param>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <returns>Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻</returns>
public double GetHumRatioFromEnthalpyAndTDryBulb(double moistAirEnthalpy, double tDryBulb)
{
{
double humRatio;
if (UnitSystem == UnitSystem.IP)
humRatio = (moistAirEnthalpy - 0.240 * tDryBulb) / (1061.0 + 0.444 * tDryBulb);
else
humRatio = (moistAirEnthalpy / 1000.0 - 1.006 * tDryBulb) / (2501.0 + 1.86 * tDryBulb);
// Validity check.
return Math.Max(humRatio, MIN_HUM_RATIO);
}
}
/******************************************************************************************************
* Saturated Air Calculations
*****************************************************************************************************/
/// <summary>
/// Return saturation vapor pressure given dry-bulb temperature.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 5 & 6
/// Important note: the ASHRAE formulae are defined above and below the freezing point but have
/// a discontinuity at the freezing point. This is a small inaccuracy on ASHRAE's part: the formulae
/// should be defined above and below the triple point of water (not the feezing point) in which case
/// the discontinuity vanishes. It is essential to use the triple point of water otherwise function
/// GetTDewPointFromVapPres, which inverts the present function, does not converge properly around
/// the freezing point.
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <returns>Vapor pressure of saturated air in Psi [IP] or Pa [SI]</returns>
public double GetSatVapPres(double tDryBulb)
{
double lnPws;
if (UnitSystem == UnitSystem.IP)
{
if (!(tDryBulb >= -148.0 && tDryBulb <= 392.0))
throw new InvalidOperationException("Dry bulb temperature is outside range [-148, 392]");
var T = GetTRankineFromTFahrenheit(tDryBulb);
if (tDryBulb <= TRIPLE_POINT_WATER_IP)
lnPws = (-1.0214165E+04 / T - 4.8932428 - 5.3765794E-03 * T + 1.9202377E-07 * T * T
+ 3.5575832E-10 * Math.Pow(T, 3) -
9.0344688E-14 * Math.Pow(T, 4) + 4.1635019 * Math.Log(T));
else
lnPws = -1.0440397E+04 / T - 1.1294650E+01 - 2.7022355E-02 * T + 1.2890360E-05 * T * T
- 2.4780681E-09 * Math.Pow(T, 3) + 6.5459673 * Math.Log(T);
}
else
{
if (!(tDryBulb >= -100.0 && tDryBulb <= 200.0))
throw new InvalidOperationException("Dry bulb temperature is outside range [-100, 200]");
var T = GetTKelvinFromTCelsius(tDryBulb);
if (tDryBulb <= TRIPLE_POINT_WATER_SI)
lnPws = -5.6745359E+03 / T + 6.3925247 - 9.677843E-03 * T + 6.2215701E-07 * T * T
+ 2.0747825E-09 * Math.Pow(T, 3) -
9.484024E-13 * Math.Pow(T, 4) + 4.1635019 * Math.Log(T);
else
lnPws = -5.8002206E+03 / T + 1.3914993 - 4.8640239E-02 * T + 4.1764768E-05 * T * T
- 1.4452093E-08 * Math.Pow(T, 3) + 6.5459673 * Math.Log(T);
}
return Math.Exp(lnPws);
}
/// <summary>
/// Return humidity ratio of saturated air given dry-bulb temperature and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 36, solved for W
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Humidity ratio of saturated air in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</returns>
public double GetSatHumRatio(double tDryBulb, double pressure)
{
var satVaporPres = GetSatVapPres(tDryBulb);
var satHumRatio = 0.621945 * satVaporPres / (pressure - satVaporPres);
// Validity check.
return Math.Max(satHumRatio, MIN_HUM_RATIO);
}
/// <summary>
/// Return saturated air enthalpy given dry-bulb temperature and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Saturated air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹ [SI]</returns>
public double GetSatAirEnthalpy(double tDryBulb, double pressure)
{
return GetMoistAirEnthalpy(tDryBulb, GetSatHumRatio(tDryBulb, pressure));
}
/******************************************************************************************************
* Moist Air Calculations
*****************************************************************************************************/
/// <summary>
/// Return Vapor pressure deficit given dry-bulb temperature, humidity ratio, and pressure.
/// Reference: see Oke (1987) eqn. 2.13a
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Vapor pressure deficit in Psi [IP] or Pa [SI]</returns>
public double GetVaporPressureDeficit(double tDryBulb, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var relHum = GetRelHumFromHumRatio(tDryBulb, humRatio, pressure);
return GetSatVapPres(tDryBulb) * (1.0 - relHum);
}
/// <summary>
/// Return the degree of saturation (i.e humidity ratio of the air / humidity ratio of the air at saturation
/// at the same temperature and pressure) given dry-bulb temperature, humidity ratio, and atmospheric pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2009) ch. 1 eqn. 12
/// Notes: the definition is absent from the 2017 Handbook
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Degree of saturation (unitless)</returns>
public double GetDegreeOfSaturation(double tDryBulb, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
return boundedHumRatio / GetSatHumRatio(tDryBulb, pressure);
}
/// <summary>
/// Return moist air enthalpy given dry-bulb temperature and humidity ratio.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 30
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <returns>Moist Air Enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹ [SI]</returns>
public double GetMoistAirEnthalpy(double tDryBulb, double humRatio)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
if (UnitSystem == UnitSystem.IP)
return 0.240 * tDryBulb + boundedHumRatio * (1061.0 + 0.444 * tDryBulb);
return (1.006 * tDryBulb + boundedHumRatio * (2501.0 + 1.86 * tDryBulb)) * 1000.0;
}
/// <summary>
/// Return moist air specific volume given dry-bulb temperature, humidity ratio, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 26
/// Notes: in IP units, R_DA_IP / 144 equals 0.370486 which is the coefficient appearing in eqn 26.
/// The factor 144 is for the conversion of Psi = lb in⁻² to lb ft⁻².
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Specific Volume ft³ lb⁻¹ [IP] or in m³ kg⁻¹ [SI]</returns>
public double GetMoistAirVolume(double tDryBulb, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
if (UnitSystem == UnitSystem.IP)
return R_DA_IP * GetTRankineFromTFahrenheit(tDryBulb) * (1.0 + 1.607858 * boundedHumRatio) /
(144.0 * pressure);
return R_DA_SI * GetTKelvinFromTCelsius(tDryBulb) * (1.0 + 1.607858 * boundedHumRatio) / pressure;
}
/// <summary>
/// Return dry-bulb temperature given moist air specific volume, humidity ratio, and pressure.
/// Reference:
/// ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 26
/// Notes:
/// In IP units, R_DA_IP / 144 equals 0.370486 which is the coefficient appearing in eqn 26
/// The factor 144 is for the conversion of Psi = lb in⁻² to lb ft⁻².
/// Based on the `GetMoistAirVolume` function, rearranged for dry-bulb temperature.
/// </summary>
/// <param name="MoistAirVolume">Specific volume of moist air in ft³ lb⁻¹ of dry air [IP] or in m³ kg⁻¹ of dry air [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Dry-bulb temperature in °F [IP] or °C [SI]</returns>
public double GetTDryBulbFromMoistAirVolumeAndHumRatio(double MoistAirVolume, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
if (UnitSystem == UnitSystem.IP)
return GetTFahrenheitFromTRankine(MoistAirVolume * (144 * pressure) / (R_DA_IP * (1 + 1.607858 * boundedHumRatio)));
return GetTCelsiusFromTKelvin(MoistAirVolume * pressure / (R_DA_SI * (1 + 1.607858 * boundedHumRatio)));
}
/// <summary>
/// Return moist air density given humidity ratio, dry bulb temperature, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 11
/// </summary>
/// <param name="tDryBulb">Dry bulb temperature in °F [IP] or °C [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Moist air density in lb ft⁻³ [IP] or kg m⁻³ [SI]</returns>
public double GetMoistAirDensity(double tDryBulb, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);
return (1.0 + boundedHumRatio) / GetMoistAirVolume(tDryBulb, boundedHumRatio, pressure);
}
/******************************************************************************************************
* Standard atmosphere
*****************************************************************************************************/
/// <summary>
/// Return standard atmosphere barometric pressure, given the elevation (altitude).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 3
/// </summary>
/// <param name="altitude">altitude in ft [IP] or m [SI]</param>
/// <returns>Standard atmosphere barometric pressure in Psi [IP] or Pa [SI]</returns>
public double GetStandardAtmPressure(double altitude)
{
if (UnitSystem == UnitSystem.IP)
return 14.696 * Math.Pow(1.0 - 6.8754e-06 * altitude, 5.2559);
return 101325.0 * Math.Pow(1.0 - 2.25577e-05 * altitude, 5.2559);
}
/// <summary>
/// Return standard atmosphere temperature, given the elevation (altitude).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 4
/// </summary>
/// <param name="altitude">altitude in ft [IP] or m [SI]</param>
/// <returns> Standard atmosphere dry bulb temperature in °F [IP] or °C [SI]</returns>
public double GetStandardAtmTemperature(double altitude)
{
if (UnitSystem == UnitSystem.IP)