pulo 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pulo.rb +28 -0
  3. data/lib/pulo/exceptions.rb +6 -0
  4. data/lib/pulo/figure/figure2d.rb +248 -0
  5. data/lib/pulo/figure/figure3d.rb +166 -0
  6. data/lib/pulo/formatting.rb +140 -0
  7. data/lib/pulo/frames/frame.rb +289 -0
  8. data/lib/pulo/frames/frame_cell.rb +83 -0
  9. data/lib/pulo/frames/frame_column.rb +149 -0
  10. data/lib/pulo/frames/frame_row.rb +87 -0
  11. data/lib/pulo/helpers.rb +1 -0
  12. data/lib/pulo/machine/hydraulics/pipe.rb +71 -0
  13. data/lib/pulo/machine/machines.rb +10 -0
  14. data/lib/pulo/machine/mechanics/moments_of_inertia.rb +64 -0
  15. data/lib/pulo/machine/steam/boiler.rb +61 -0
  16. data/lib/pulo/machine/steam/boiler_deaerator.rb +64 -0
  17. data/lib/pulo/machine/steam/deaerator.rb +37 -0
  18. data/lib/pulo/machine/steam/desuperheater.rb +29 -0
  19. data/lib/pulo/machine/steam/header.rb +20 -0
  20. data/lib/pulo/machine/steam/if97.rb +378 -0
  21. data/lib/pulo/machine/steam/steam_process.rb +27 -0
  22. data/lib/pulo/machine/steam/steam_turbine.rb +42 -0
  23. data/lib/pulo/machine/steam/water_steam.rb +229 -0
  24. data/lib/pulo/material/water.rb +34 -0
  25. data/lib/pulo/quantity/dimension.rb +63 -0
  26. data/lib/pulo/quantity/numeric_overloads.rb +217 -0
  27. data/lib/pulo/quantity/quantity.rb +285 -0
  28. data/lib/pulo/quantity/quantity_builder.rb +185 -0
  29. data/lib/pulo/quantity/quantity_definitions.rb +8 -0
  30. data/lib/pulo/quantity/quantity_definitions/area_volume.rb +73 -0
  31. data/lib/pulo/quantity/quantity_definitions/basic.rb +157 -0
  32. data/lib/pulo/quantity/quantity_definitions/electric.rb +22 -0
  33. data/lib/pulo/quantity/quantity_definitions/energy.rb +50 -0
  34. data/lib/pulo/quantity/quantity_definitions/fluids.rb +23 -0
  35. data/lib/pulo/quantity/quantity_definitions/force_power.rb +82 -0
  36. data/lib/pulo/quantity/quantity_definitions/rotation.rb +49 -0
  37. data/lib/pulo/quantity/quantity_definitions/value.rb +65 -0
  38. data/lib/pulo/quantity/quantity_definitions/velocity_acc_flow.rb +66 -0
  39. data/lib/pulo/quantity/quantity_groups/quantity_groups.rb +36 -0
  40. data/lib/pulo/quantity/unit.rb +45 -0
  41. data/lib/pulo/quantity_checker.rb +13 -0
  42. data/lib/pulo/tables/density.rb +10 -0
  43. data/lib/pulo/tables/melting_temperature.rb +9 -0
  44. data/lib/pulo/tables/specific_energy.rb +10 -0
  45. data/lib/pulo/tables/speed_of_sound.rb +9 -0
  46. data/lib/pulo/tables/tables.rb +104 -0
  47. data/lib/pulo/tables/tensile_strength.rb +10 -0
  48. data/lib/pulo/tables/yield_strength.rb +10 -0
  49. data/lib/pulo/version.rb +3 -0
  50. metadata +51 -3
@@ -0,0 +1,64 @@
1
+
2
+ module Pulo
3
+ module Steam
4
+ class BoilerDeaerator
5
+
6
+ attr_reader :boiler,:deaerator
7
+
8
+ def initialize (
9
+ header_pressure: nil,header_temperature: nil,outlet_massflow: nil,deaerator_pressure: nil,deaerator_vent_rate: nil, condensate_massflow: nil,
10
+ boiler_efficiency: nil,boiler_blowdown_rate: nil,condensate_temperature: nil,condensate_pressure: nil,
11
+ makeup_temperature: nil,fuel_power: nil,additional_makeup: nil)
12
+
13
+ raise "Need all params" unless header_pressure && outlet_massflow && deaerator_pressure && condensate_pressure && condensate_massflow
14
+ deaerator_vent_rate && boiler_efficiency && boiler_blowdown_rate && condensate_temperature && makeup_temperature && additional_makeup &&
15
+ (header_temperature || fuel_power)
16
+
17
+ condensate=WaterSteam.new(pressure: condensate_pressure, temperature: condensate_temperature)
18
+ makeup=WaterSteam.new(temperature: makeup_temperature, pressure: Pressure.psig(0.0))
19
+
20
+ boiler_feed_massflow=outlet_massflow+outlet_massflow*(deaerator_vent_rate+boiler_blowdown_rate) #Starting assumption
21
+
22
+ begin
23
+ boiler_feed_massflow+=MassFlow.pounds_per_hour(50)
24
+ if fuel_power
25
+ b=Boiler.new(
26
+ feedwater_pressure: deaerator_pressure,
27
+ blowdown_rate: boiler_blowdown_rate,
28
+ combustion_efficiency: boiler_efficiency,
29
+ steam_pressure: header_pressure,
30
+ fuel_power: fuel_power,
31
+ feedwater_massflow: boiler_feed_massflow)
32
+ header_temperature=b.steam.temperature
33
+ else
34
+ b=Boiler.new(
35
+ feedwater_pressure: deaerator_pressure,
36
+ blowdown_rate: boiler_blowdown_rate,
37
+ combustion_efficiency: boiler_efficiency,
38
+ steam_pressure: header_pressure,
39
+ steam_temperature: header_temperature,
40
+ feedwater_massflow: boiler_feed_massflow)
41
+ end
42
+
43
+ makeup_massflow=boiler_feed_massflow*(deaerator_vent_rate+boiler_blowdown_rate)+additional_makeup
44
+ #condensate_massflow=outlet_massflow*condensate_return_rate
45
+ deaerator_feed_enthalpy=(
46
+ condensate.specific_enthalpy*condensate_massflow+
47
+ makeup.specific_enthalpy*makeup_massflow)/(makeup_massflow+condensate_massflow)
48
+
49
+ deaerator_feed=WaterSteam.new(pressure: deaerator_pressure, specific_enthalpy: deaerator_feed_enthalpy)
50
+ d=Deaerator.new(
51
+ deaerator_pressure: deaerator_pressure,vent_rate: deaerator_vent_rate,
52
+ feedwater_massflow: boiler_feed_massflow,inlet_pressure: deaerator_feed.pressure,
53
+ inlet_temperature: deaerator_feed.temperature,steam_pressure:header_pressure,
54
+ steam_temperature: header_temperature)
55
+
56
+ test_outlet_massflow=b.steam.mass_flow-d.steam.mass_flow
57
+ end while (outlet_massflow-test_outlet_massflow)/outlet_massflow>Dimensionless.percent(0.1)
58
+ @boiler=b
59
+ @deaerator=d
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,37 @@
1
+
2
+ module Pulo
3
+ module Steam
4
+ class Deaerator
5
+ attr_reader :steam, :feedwater,:vent,:inlet
6
+ attr_reader :dearator_pressure,:vent_rate
7
+ attr_reader :dearator_mass_flow
8
+
9
+ def initialize(deaerator_pressure: nil,vent_rate: nil,feedwater_massflow: nil,inlet_pressure: nil,
10
+ inlet_temperature: nil,steam_pressure:nil, steam_temperature:nil)
11
+
12
+ raise "Need all parameters" unless deaerator_pressure && vent_rate && feedwater_massflow && inlet_pressure && inlet_temperature && steam_pressure && steam_temperature
13
+
14
+ @deaerator_pressure=deaerator_pressure
15
+ @vent_rate=vent_rate
16
+
17
+ @inlet=WaterSteam.new(pressure: inlet_pressure, temperature: inlet_temperature)
18
+
19
+ @steam=WaterSteam.new(pressure: steam_pressure, temperature: steam_temperature)
20
+
21
+ @vent=WaterSteam.new(pressure: deaerator_pressure, quality: Dimensionless.n(1))
22
+
23
+ @feedwater=WaterSteam.new(pressure: deaerator_pressure, quality: Dimensionless.n(0))
24
+ @feedwater.mass_flow=feedwater_massflow
25
+
26
+ @vent.mass_flow=@feedwater.mass_flow*@vent_rate
27
+ @deaereator_mass_flow=@vent.mass_flow+@feedwater.mass_flow
28
+ @deaereator_power=@vent.energy_flow+@feedwater.energy_flow
29
+
30
+ min_in_power=@inlet.specific_enthalpy*@deaereator_mass_flow
31
+ add_pow=@deaereator_power-min_in_power
32
+ @steam.mass_flow=add_pow/(@steam.specific_enthalpy-@inlet.specific_enthalpy)
33
+ @inlet.mass_flow=@deaereator_mass_flow-@steam.mass_flow
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+
2
+ module Pulo
3
+ module Steam
4
+ class Desuperheater
5
+
6
+ attr_reader :inlet_steam,:outlet_steam,:water
7
+
8
+ def initialize(inlet_pressure: nil, inlet_temperature: nil,
9
+ inlet_massflow: nil, outlet_massflow:nil)
10
+
11
+ raise "Need all parameters" unless inlet_pressure && inlet_temperature && (inlet_massflow || outlet_massflow)
12
+
13
+ @inlet_steam=WaterSteam.new(pressure: inlet_pressure, temperature: inlet_temperature)
14
+ @outlet_steam=WaterSteam.new(pressure: inlet_pressure, quality: Dimensionless.n(1))
15
+ @water=WaterSteam.new(pressure: Pressure.psig(0),temperature: Temperature.celsius(25))
16
+
17
+ if inlet_massflow
18
+ @inlet_steam.mass_flow=inlet_massflow
19
+ @water.mass_flow=inlet_massflow*(@inlet_steam.specific_enthalpy-@outlet_steam.specific_enthalpy)/(@outlet_steam.specific_enthalpy-@water.specific_enthalpy)
20
+ @outlet_steam.mass_flow=inlet_massflow+@water.mass_flow
21
+ else
22
+ @outlet_steam.mass_flow=outlet_massflow
23
+ @water.mass_flow=outlet_massflow*(@inlet_steam.specific_enthalpy-@outlet_steam.specific_enthalpy)/(@inlet_steam.specific_enthalpy-@water.specific_enthalpy)
24
+ @inlet_steam.mass_flow=outlet_massflow-@water.mass_flow
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module Pulo
3
+ module Steam
4
+ class Header
5
+ attr_reader :inlet,:outlet
6
+ attr_reader :pressure,:inlet_temperature,:mass_flow,:energy_loss_pct
7
+
8
+ def initialize(pressure: nil,inlet_temperature: nil,energy_loss_pct: nil)
9
+
10
+ raise "Need all parameters" unless pressure && inlet_temperature && energy_loss_pct
11
+ @pressure=pressure
12
+ @inlet_temperature=inlet_temperature
13
+ @energy_loss_pct=energy_loss_pct
14
+
15
+ @inlet=WaterSteam.new(temperature: inlet_temperature,pressure: pressure)
16
+ @outlet=WaterSteam.new(pressure: pressure, specific_enthalpy: @inlet.specific_enthalpy*(1-energy_loss_pct))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,378 @@
1
+ # encoding: utf-8
2
+
3
+ module Pulo
4
+ module Steam
5
+ class IF97
6
+ class << self
7
+ def specific_gas_constant
8
+ SpecificHeat.kilojoules_per_kilogram_kelvin(0.461526)
9
+ end
10
+ def critical_temperature
11
+ Temperature.kelvin(647.096)
12
+ end
13
+ def critical_pressure
14
+ Pressure.megapascals(22.064)
15
+ end
16
+ def critical_density
17
+ Density.kilograms_per_cubic_meter(322)
18
+ end
19
+
20
+ def pressure_from_b23 temperature
21
+ cf=[0.34805185628969*10**3,-0.11671859879975*10**1,0.10192970039326*10**-2,0.57254459862746*10**3,0.13918839778870*10**2]
22
+ theta=temperature.value
23
+ pi=cf[0]+cf[1]*theta+cf[2]*theta**2
24
+ Pressure.new(pi,:megapascal)
25
+ end
26
+ def temperature_from_b23 pressure
27
+ cf=[0.34805185628969*10**3,-0.11671859879975*10**1,0.10192970039326*10**-2,0.57254459862746*10**3,0.13918839778870*10**2]
28
+ pi=pressure.value
29
+ theta=cf[3]+((pi-cf[4])/cf[2])**0.5
30
+ Temperature.new(theta,:kelvin)
31
+ end
32
+
33
+ def pressure_from_temperature_r4 temperature
34
+ n1= 0.11670521452767*10**4;n6= 0.14915108613530*10**2;n2=-0.72421316703206*10**6;n7=-0.48232657361591*10**4;n3=-0.17073846940092*10**2
35
+ n8= 0.40511340542057*10**6;n4= 0.12020824702470*10**5;n9=-0.23855557567849;n5=-0.32325550322333*10**7;n10=0.65017534844798*10**3
36
+ t=temperature.value
37
+ l=t+n9/(t-n10)
38
+ a=l**2+n1*l+n2
39
+ b=n3*l**2+n4*l+n5
40
+ c=n6*l**2+n7*l+n8
41
+ p=(2*c/(-b+(b**2-4*a*c)**0.5))**4
42
+ Pressure.megapascals(p)
43
+ end
44
+ def temperature_from_pressure_r4 pressure
45
+ n1= 0.11670521452767*10**4;n6= 0.14915108613530*10**2;n2=-0.72421316703206*10**6;n7=-0.48232657361591*10**4;n3=-0.17073846940092*10**2
46
+ n8= 0.40511340542057*10**6;n4= 0.12020824702470*10**5;n9=-0.23855557567849;n5=-0.32325550322333*10**7;n10=0.65017534844798*10**3
47
+ b=pressure.value**0.25
48
+ e=b**2+n3*b+n6
49
+ f=n1*b**2+n4*b+n7
50
+ g=n2*b**2+n5*b+n8
51
+ d=2*g/(-f-(f**2-4*e*g)**0.5)
52
+ t=(n10+d-((n10+d)**2-4*(n9+n10*d))**0.5)/2
53
+ Temperature.kelvin(t)
54
+ end
55
+ def other_props_r4 temperature,water
56
+ cb=[1.99274064,1.09965342,-0.510839303,-1.75493479,-45.5170352,-6.74694450*10**5]
57
+ theta=(temperature/critical_temperature).value
58
+ tau=1-theta
59
+ rho=(1+cb[0]*tau**(1/3)+cb[1]*tau**(2/3)+cb[2]*tau**(5/3)+cb[3]*tau**(16/3)+cb[4]*tau**(43/3)+cb[5]*tau**(110/3))
60
+ water.specific_volume_liquid=1/(rho*critical_density)
61
+ cc=[-2.03150240,-2.68302940,-5.38626492,-17.2991605,-44.7586581,-63.9201063]
62
+ rho2=(cc[0]*tau**(2/6)+cc[1]*tau**(4/6)+cc[2]*tau**(8/6)+cc[3]*tau**(18/6)+cc[4]*tau**(37/6)+cc[5]*tau**(71/6))
63
+ water.specific_volume=1/(Math.exp(rho2)*critical_density)
64
+ end
65
+
66
+ def other_props_r1 temperature,pressure,water
67
+
68
+ cf=[
69
+ [0 ,-2 , 0.14632971213167],[0 ,-1 ,-0.84548187169114],[0 , 0 ,-0.37563603672040*10**1],[0 , 1 , 0.33855169168385*10**1],[0 , 2 ,-0.95791963387872],[0 , 3 , 0.15772038513228],[0 , 4 ,-0.16616417199501*10**-1 ],[0 , 5 , 0.81214629983568*10**-3 ],[1 ,-9 , 0.28319080123804*10**-3 ],[1 ,-7 ,-0.60706301565874*10**-3 ],[1 ,-1 ,-0.18990068218419*10**-1 ],[1 , 0 ,-0.32529748770505*10**-1 ],[1 , 1 ,-0.21841717175414*10**-1 ],[1 , 3 ,-0.52838357969930*10**-4 ],[2 ,-3 ,-0.47184321073267*10**-3 ],[2 , 0 ,-0.30001780793026*10**-3 ],
70
+ [2 , 1 , 0.47661393906987*10**-4 ],[2 , 3 ,-0.44141845330846*10**-5 ],[2 , 17,-0.72694996297594*10**-15],[3 ,-4 ,-0.31679644845054*10**-4 ],[3 , 0 ,-0.28270797985312*10**-5 ],[3 , 6 ,-0.85205128120103*10**-9 ],[4 ,-5 ,-0.22425281908000*10**-5 ],[4 ,-2 ,-0.65171222895601*10**-6 ],[4 , 10,-0.14341729937924*10**-12],[5 ,-8 ,-0.40516996860117*10**-6 ],
71
+ [8 ,-11,-0.12734301741641*10**-8 ],[8 , -6,-0.17424871230634*10**-9 ],[21,-29,-0.68762131295531*10**-18],[23,-31, 0.14478307828521*10**-19],[29,-38, 0.26335781662795*10**-22],[30,-39,-0.11947622640071*10**-22],[31,-40, 0.18228094581404*10**-23],[32,-41,-0.93537087292458*10**-25]]
72
+ p_star=16.53
73
+ t_star=1386.0
74
+ tau=t_star/temperature.kelvin.value
75
+ pi=pressure.megapascals.value/p_star
76
+ dpi=cf.inject(0) do |sum,cfi|
77
+ sum+(-cfi[2]*cfi[0]*(7.1-pi)**(cfi[0]-1)*(tau-1.222)**cfi[1])
78
+ end
79
+ dtau=cf.inject(0) do |sum,cfi|
80
+ sum+(cfi[2]*(7.1-pi)**cfi[0]*cfi[1]*(tau-1.222)**(cfi[1]-1))
81
+ end
82
+ gam=cf.inject(0) do |sum,cfi|
83
+ sum+(cfi[2]*(7.1-pi)**cfi[0]*(tau-1.222)**cfi[1])
84
+ end
85
+
86
+ water.temperature||=temperature
87
+ water.pressure||=pressure
88
+ water.specific_volume=pi*dpi*specific_gas_constant*temperature/pressure
89
+
90
+ water.specific_internal_energy=(tau*dtau-pi*dpi)*specific_gas_constant*temperature
91
+ water.specific_entropy=(tau*dtau-gam)*specific_gas_constant
92
+ water.specific_enthalpy=(tau*dtau)*specific_gas_constant*temperature
93
+ end
94
+ def temperature_from_pressure_enthalpy_r1 pressure, specific_enthalpy,water
95
+ cf=[
96
+ [0,0,-0.23872489924521*10**3],[0,1,0.40421188637945*10**3],[0,2,0.11349746881718*10**3],[0,6,-0.58457616048039*10**1],[0,22,-0.15285482413140*10**-3],[0,32,-0.10866707695377*10**-5],[1,0,-0.13391744872602*10**2],[1,1,0.43211039183559*10**2],[1,2,-0.54010067170506*10**2],[1,3,0.30535892203916*10**2],
97
+ [1,4,-0.65964749423638*10**1],[1,10,0.93965400878363*10**-2],[1,32,0.11573647505340*10**-6],[2,10,-0.25858641282073*10**-4],[2,32,-0.40644363084799*10**-8],[3,10,0.66456186191635*10**-7],[3,32,0.80670734103027*10**-10],[4,32,-0.93477771213947*10**-12],[5,32,0.58265442020601*10**-14],[6,32,-0.15020185953503*10**-16]]
98
+ pi=pressure.value
99
+ eta=(specific_enthalpy.kilojoules_per_kilogram.value/SpecificEnthalpy.kilojoules_per_kilogram(2500.0).value)
100
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
101
+ sum+(cfi[2]*pi**cfi[0]*(eta+1.0)**cfi[1])
102
+ end)
103
+ water.specific_enthalpy||=specific_enthalpy
104
+ water.pressure||=pressure
105
+ end
106
+ def temperature_from_pressure_entropy_r1 pressure,specific_entropy,water
107
+ cf=[
108
+ [0,0,0.17478268058307*10**3],[0,1,0.34806930892873*10**2],[0,2,0.65292584978455*10**1],[0,3,0.33039981775489],[0,11,-0.19281382923196*10**-6],[0,31,-0.24909197244573*10**-22],[1,0,-0.26107636489332],
109
+ [1,1,0.22592965981586],[1,2,-0.64256463395226*10**-1],[1,3,0.78876289270526*10**-2],[1,12,0.35672110607366*10**-9],[1,31,0.17332496994895*10**-23],[2,0,0.56608900654837*10**-3],[2,1,-0.32635483139717*10**-3],[2,2,0.44778286690632*10**-4],
110
+ [2,9,-0.51322156908507*10**-9],[2,31,-0.42522657042207*10**-25],[3,10,0.26400441360689*10**-12],[3,32,0.78124600459723*10**-28],[4,32,-0.30732199903668*10**-30]]
111
+ pi=pressure.value
112
+ delta=specific_entropy.kilojoules_per_kilogram_kelvin.value
113
+
114
+ water.pressure||=pressure
115
+ water.specific_entropy||=specific_entropy
116
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
117
+ sum+(cfi[2]*pi**cfi[0]*(delta+2)**cfi[1])
118
+ end)
119
+
120
+ end
121
+
122
+ def other_props_r2 temperature,pressure,water
123
+ cfo=[
124
+ [0,-0.96927686500217*10**1],[1,0.10086655968018*10**2],[-5,-0.56087911283020*10**-2],
125
+ [-4,0.71452738081455*10**-1],[-3,-0.40710498223928],[-2,0.14240819171444*10**1],[-1,-0.43839511319450*10**1],[2,-0.28408632460772],[3,0.21268463753307*10**-1]]
126
+ cfr=[
127
+ [1,0,-0.17731742473213*10**-2],[1,1,-0.17834862292358*10**-1],[1,2,-0.45996013696365*10**-1],[1,3,-0.57581259083432*10**-1],[1,6,-0.50325278727930*10**-1],[2,1,-0.33032641670203*10**-4],[2,2,-0.18948987516315*10**-3],[2,4,-0.39392777243355*10**-2],[2,7,-0.43797295650573*10**-1],[2,36,-0.26674547914087*10**-4],
128
+ [3,0,0.20481737692309*10**-7],[3,1,0.43870667284435*10**-6],[3,3,-0.32277677238570*10**-4],[3,6,-0.15033924542148*10**-2],[3,35,-0.40668253562649*10**-1],[4,1,-0.78847309559367*10**-9],[4,2,0.12790717852285*10**-7],[4,3,0.48225372718507*10**-6],[5,7,0.22922076337661*10**-5],
129
+ [6,3,-0.16714766451061*10**-10],[6,16,-0.21171472321355*10**-2],[6,35,-0.23895741934104*10**2],[7,0,-0.59059564324270*10**-17],[7,11,-0.12621808899101*10**-5],[7,25,-0.38946842435739*10**-1],[8,8,0.11256211360459*10**-10],[8,36,-0.82311340897998*10**1],
130
+ [9,13,0.19809712802088*10**-7],[10,4,0.10406965210174*10**-18],[10,10,-0.10234747095929*10**-12],[10,14,-0.10018179379511*10**-8],[16,29,-0.80882908646985*10**-10],[16,50,0.10693031879409],[18,57,-0.33662250574171],[20,20,0.89185845355421*10**-24],
131
+ [20,35,0.30629316876232*10**-12],[20,48,-0.42002467698208*10**-5],[21,21,-0.59056029685639*10**-25],[22,53,0.37826947613457*10**-5],[23,39,-0.12768608934681*10**-14],[24,26,0.73087610595061*10**-28],[24,40,0.55414715350778*10**-16],[24,58,-0.94369707241210*10**-6]]
132
+ pi=pressure.value
133
+ tau=(Temperature.kelvin(540)/temperature.kelvin).value
134
+ gamma_r_pi=cfr.inject(0) do |sum,cfr|
135
+ sum+(cfr[2]*cfr[0]*pi**(cfr[0]-1)*(tau-0.5)**cfr[1])
136
+ end
137
+ gamma_o_pi=1.0/pi
138
+ gamma_r_tau=cfr.inject(0) do |sum,cfr|
139
+ sum+(cfr[2]*pi**cfr[0]*cfr[1]*(tau-0.5)**(cfr[1]-1))
140
+ end
141
+ gamma_o_tau=cfo.inject(0) do |sum,cfo|
142
+ sum+(cfo[1]*cfo[0]*tau**(cfo[0]-1))
143
+ end
144
+ gamma_r=cfr.inject(0) do |sum,cfr|
145
+ sum+(cfr[2]*pi**cfr[0]*(tau-0.5)**cfr[1])
146
+ end
147
+ gamma_o=Math.log(pi) + cfo.inject(0) do |sum,cfo|
148
+ sum+(cfo[1]*tau**cfo[0])
149
+ end
150
+
151
+ water.temperature||=temperature
152
+ water.pressure||=pressure
153
+ water.specific_volume=(pi*(gamma_o_pi+gamma_r_pi))*specific_gas_constant*temperature/pressure
154
+
155
+ water.specific_internal_energy=(tau*(gamma_o_tau+gamma_r_tau)-pi*(gamma_o_pi+gamma_r_pi))*specific_gas_constant*temperature
156
+ water.specific_entropy=(tau*(gamma_o_tau+gamma_r_tau)-(gamma_o+gamma_r))*specific_gas_constant
157
+ water.specific_enthalpy=(tau*(gamma_o_tau+gamma_r_tau))*specific_gas_constant*temperature
158
+ end
159
+ def b2bc pressure
160
+ cf=[0.90584278514723*10**3,
161
+ -0.67955786399241,
162
+ 0.12809002730136*10**-3,
163
+ 0.26526571908428*10**4,
164
+ 0.45257578905948*10**1]
165
+ pi=pressure.megapascals.value
166
+ n=cf[3]+((pi-cf[4])/cf[2])**0.5
167
+ SpecificEnthalpy.new(n,:kilojoule_per_kilogram)
168
+ end
169
+ def temperature_from_pressure_enthalpy_r2 pressure,specific_enthalpy,water
170
+ raise "Specific enthalpy too high for region 2" if specific_enthalpy>SpecificEnergy.kilojoules_per_kilogram(4142.5)
171
+ if pressure>=Pressure.megapascals(4)
172
+ if pressure<Pressure.megapascals(6.54670) || specific_enthalpy>=b2bc(pressure)
173
+ #2b
174
+ cf=[[0,0,0.14895041079516*10**4],[0,1,0.74307798314034*10**3],[0,2,-0.97708318797837*10**2],[0,12,0.24742464705674*10**1],[0,18,-0.63281320016026],[0,24,0.11385952129658*10**1],[0,28,-0.47811863648625],[0,40,0.85208123431544*10**-2],[1,0,0.93747147377932],[1,2,0.33593118604916*10**1],[1,6,0.33809355601454*10**1],[1,12,0.16844539671904],[1,18,0.73875745236695],[1,24,-0.47128737436186],[1,28,0.15020273139707],[1,40,-0.21764114219750*10**-2],
175
+ [2,2,-0.21810755324761*10**-1],[2,8,-0.10829784403677],[2,18,-0.46333324635812*10**-1],[2,40,0.71280351959551*10**-4],[3,1,0.11032831789999*10**-3],[3,2,0.18955248387902*10**-3],[3,12,0.30891541160537*10**-2],[3,24,0.13555504554949*10**-2],[4,2,0.28640237477456*10**-6],[4,12,0.10779857357512*10**-4],[4,18,0.76462712454814*10**-4],
176
+ [4,24,0.14052392818316*10**-4],[4,28,0.31083814331434*10**-4],[4,40,0.10302738212103*10**-5],[5,18,0.28217281635040*10**-6],[5,24,0.12704902271945*10**-5],[5,40,0.73803353468292*10**-7],[6,28,0.11030139238909*10**-7],[7,2,0.81456365207833*10**-13],[7,28,0.25180545682962*10**-10],[9,1,0.17565233969407*10**-17],[9,40,0.86934156344163*10**-14]]
177
+ pi=pressure.value
178
+ n=(specific_enthalpy/SpecificEnthalpy.kilojoules_per_kilogram(2000)).value
179
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
180
+ sum+(cfi[2]*(pi-2)**cfi[0]*(n-2.6)**cfi[1])
181
+ end)
182
+ else
183
+ #2c
184
+ cf=[
185
+ [-7,0,-0.32368398555242*10**13],[-7,4,0.73263350902181*10**13],[-6,0,0.35825089945447*10**12],[-7,2,-0.58340131851590*10**12],[-5,0,-0.10783068217470*10**11],[-5,2,0.20825544563171*10**11],[-2,0,0.61074783564516*10**6],[-2,1,0.85977722535580*10**6],[-1,0,-0.25745723604170*10**5],[-1,2,0.31081088422714*10**5],[0,0,0.12082315865936*10**4],[0,1,0.48219755109255*10**3],
186
+ [1,4,0.37966001272486*10**1],[1,8,-0.10842984880077*10**2],[2,4,-0.45364172676660*10**-1],[6,0,0.14559115658698*10**-12],[6,1,0.11261597407230*10**-11],[6,4,-0.17804982240686*10**-10],[6,10,0.12324579690832*10**-6],[6,12,-0.11606921130984*10**-5],[6,16,0.27846367088554*10**-4],[6,20,-0.59270038474176*10**-3],[6,22,0.12918582991878*10**-2]]
187
+ pi=pressure.value
188
+ n=(specific_enthalpy/SpecificEnthalpy.kilojoules_per_kilogram(2000)).value
189
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
190
+ sum+(cfi[2]*(pi+25)**cfi[0]*(n-1.8)**cfi[1])
191
+ end)
192
+ end
193
+ else
194
+ #2a
195
+ cf=[
196
+ [0,0,0.10898952318288*10**4],[0,1,0.84951654495535*10**3],[0,2,-0.10781748091826*10**3],[0,3,0.33153654801263*10**2],[0,7,-0.74232016790248*10**1],[0,20,0.11765048724356*10**2],[1,0,0.18445749355790*10**1],[1,1,-0.41792700549624*10**1],[1,2,0.62478196935812*10**1],[1,3,-0.17344563108114*10**2],[1,7,-0.20058176862096*10**3],[1,9,0.27196065473796*10**3],[1,11,-0.45511318285818*10**3],
197
+ [1,18,0.30919688604755*10**4],[1,44,0.25226640357872*10**6],[2,0,-0.61707422868339*10**-2],[2,2,-0.31078046629583],[2,7,0.11670873077107*10**2],[2,36,0.12812798404046*10**9],[2,38,-0.98554909623276*10**9],[2,40,0.28224546973002*10**10],[2,42,-0.35948971410703*10**10],[2,44,0.17227349913197*10**10],[3,24,-0.13551334240775*10**5],
198
+ [3,44,0.12848734664650*10**8],[4,12,0.13865724283226*10**1],[4,32,0.23598832556514*10**6],[4,44,-0.13105236545054*10**8],[5,32,0.73999835474766*10**4],[5,36,-0.55196697030060*10**6],[5,42,0.37154085996233*10**7],[6,34,0.19127729239660*10**5],[6,44,-0.41535164835634*10**6],[7,28,-0.62459855192507*10**2]]
199
+
200
+ pi=pressure.value
201
+ n=(specific_enthalpy.kilojoules_per_kilogram.value/2000.0)
202
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
203
+ sum+(cfi[2]*pi**cfi[0]*(n-2.1)**cfi[1])
204
+ end)
205
+ end
206
+ water.pressure||=pressure
207
+ water.specific_enthalpy||=specific_enthalpy
208
+ end
209
+ def temperature_from_pressure_entropy_r2 pressure,specific_entropy,water
210
+ if pressure>=Pressure.megapascals(4)
211
+ if specific_entropy>=SpecificEntropy.joules_per_kilogram_kelvin(5.85)
212
+ #2b
213
+ cf=[[-6,0,0.31687665083497*10**6],[-6,11,0.20864175881858*10**2],[-5,0,-0.39859399803599*10**6],[-5,11,-0.21816058518877*10**2],[-4,0,0.22369785194242*10**6],[-4,1,-0.27841703445817*10**4],[-4,11,0.99207436071480*10**1],[-3,0,-0.75197512299157*10**5],
214
+ [-3,1,0.29708605951158*10**4],[-3,11,-0.34406878548526*10**1],[-3,12,0.38815564249115],[-2,0,0.17511295085750*10**5],[-2,1,-0.14237112854449*10**4],[-2,6,0.10943803364167*10**1],[-2,10,0.89971619308495],[-1,0,-0.33759740098958*10**4],[-1,1,0.47162885818355*10**3],
215
+ [-1,5,-0.19188241993679*10**1],[-1,8,0.41078580492196],[-1,9,-0.33465378172097],[0,0,0.13870034777505*10**4],[0,1,-0.40663326195838*10**3],[0,2,0.41727347159610*10**2],[0,4,0.21932549434532*10**1],[0,5,-0.10320050009077*10**1],[0,6,0.35882943516703],
216
+ [0,9,0.52511453726066*10**-2],[1,0,0.12838916450705*10**2],[1,1,-0.28642437219381*10**1],[1,2,0.56912683664855],[1,3,-0.99962954584931*10**-1],[1,7,-0.32632037778459*10**-2],[1,8,0.23320922576723*10**-3],[2,0,-0.15334809857450],[2,1,0.29072288239902*10**-1],
217
+ [2,5,0.37534702741167*10**-3],[3,0,0.17296691702411*10**-2],[3,1,-0.38556050844504*10**-3],[3,3,-0.35017712292608*10**-4],[4,0,-0.14566393631492*10**-4],[4,1,0.56420857267269*10**-5],[5,0,0.41286150074605*10**-7],[5,1,-0.20684671118824*10**-7],[5,2,0.16409393674725*10**-8]]
218
+ pi=pressure.megapascals.value
219
+ delta=(specific_entropy/SpecificEntropy.kilojoules_per_kilogram_kelvin(0.7853)).value
220
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
221
+ sum+(cfi[2]*pi**cfi[0]*(10-delta)**cfi[1])
222
+ end)
223
+ else
224
+ #2c
225
+ cf=[[-2,0,0.90968501005365*10**3],[-2,1,0.24045667088420*10**4],[-1,0,-0.59162326387130*10**3],[0,0,0.54145404128074*10**3],[0,1,-0.27098308411192*10**3],
226
+ [0,2,0.97976525097926*10**3],[0,3,-0.46966772959435*10**3],[1,0,0.14399274604723*10**2],[1,1,-0.19104204230429*10**2],[1,3,0.53299167111971*10**1],[1,4,-0.21252975375934*10**2],[2,0,-0.31147334413760],[2,1,0.60334840894623],[2,2,-0.42764839702509*10**-1],
227
+ [3,0,0.58185597255259*10**-2],[3,1,-0.14597008284753*10**-1],[3,5,0.56631175631027*10**-2],[4,0,-0.76155864584577*10**-4],[4,1,0.22440342919332*10**-3],[4,4,-0.12561095013413*10**-4],[5,0,0.63323132660934*10**-6],[5,1,-0.20541989675375*10**-5],[5,2,0.36405370390082*10**-7],
228
+ [6,0,-0.29759897789215*10**-8],[6,1,0.10136618529763*10**-7],[7,0,0.59925719692351*10**-11],[7,1,-0.20677870105164*10**-10],[7,3,-0.20874278181886*10**-10],[7,4,0.10162166825089*10**-9],[7,5,-0.16429828281347*10**-9]]
229
+ pi=pressure.value
230
+ delta=(specific_entropy/SpecificEntropy.kilojoules_per_kilogram_kelvin(2.9251)).value
231
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
232
+ sum+(cfi[2]*pi**cfi[0]*(2-delta)**cfi[1])
233
+ end)
234
+ end
235
+ else
236
+ #2a
237
+ cf=[[-1.5,-24,-0.39235983861984*10**6],[-1.5,-23,0.51526573827270*10**6],[-1.5,-19,0.40482443161048*10**5],[-1.5,-13,-0.32193790923902*10**3],
238
+ [-1.5,-11,0.96961424218694*10**2],[-1.5,-10,-0.22867846371773*10**2],[-1.25,-19,-0.44942914124357*10**6],[-1.25,-15,-0.50118336020166*10**4],[-1.25,-6,0.35684463560015],[-1.0,-26,0.44235335848190*10**5],[-1.0,-21,-0.13673388811708*10**5],[-1.0,-17,0.42163260207864*10**6],[-1.0,-16,0.22516925837475*10**5],[-1.0,-9,0.47442144865646*10**3],[-1.0,-8,-0.14931130797647*10**3],[-0.75,-15,-0.19781126320452*10**6],[-0.75,-14,-0.23554399470760*10**5],[-0.5,-26,-0.19070616302076*10**5],
239
+ [-0.5,-13,0.55375669883164*10**5],[-0.5,-9,0.38293691437363*10**4],[-0.5,-7,-0.60391860580567*10**3],[-0.25,-27,0.19363102620331*10**4],[-0.25,-25,0.42660643698610*10**4],[-0.25,-11,-0.59780638872718*10**4],[-0.25,-6,-0.70401463926862*10**3],[0.25,1,0.33836784107553*10**3],[0.25,4,0.20862786635187*10**2],[0.25,8,0.33834172656196*10**-1],[0.25,11,-0.43124428414893*10**-4],[0.5,0,0.16653791356412*10**3],[0.5,1,-0.13986292055898*10**3],[0.5,5,-0.78849547999872],
240
+ [0.5,6,0.72132411753872*10**-1],[0.5,10,-0.59754839398283*10**-2],[0.5,14,-0.12141358953904*10**-4],[0.5,16,0.23227096733871*10**-6],[0.75,0,-0.10538463566194*10**2],[0.75,4,0.20718925496502*10**1],[0.75,9,-0.72193155260427*10**-1],[0.75,17,0.20749887081120*10**-6],[1.0,7,-0.18340657911379*10**-1],[1.0,18,0.29036272348696*10**-6],[1.25,3,0.21037527893619],[1.25,15,0.25681239729999*10**-3],[1.5,5,-0.12799002933781*10**-1],[1.5,18,-0.82198102652018*10**-5]]
241
+ pi=pressure.value
242
+ delta=(specific_entropy/SpecificEntropy.kilojoules_per_kilogram_kelvin(2)).value
243
+ water.temperature=Temperature.kelvin(cf.inject(0) do |sum,cfi|
244
+ sum+(cfi[2]*pi**cfi[0]*(delta-2)**cfi[1])
245
+ end)
246
+ end
247
+ water.pressure||=pressure
248
+ water.specific_entropy||=specific_entropy
249
+ end
250
+
251
+ def other_props_r3
252
+ # cf=[['_','_',-0.10658070028513*10**1],[0,0,-0.15732845290239*10**2],[0,1,0.20944396974307*10**2],[0,2,-0.76867707878716*10**1],[0,7,0.26185947787954*10**1],[0,10,-0.28080781148620*10**1],[0,12,0.12053369696517*10**1],[0,23,-0.84566812812502*10**-2],[1,2,-0.12654315477714*10**1],[1,6,-0.11524407806681*10**1],[1,15,0.88521043984318],[1,17,-0.64207765181607],
253
+ # [2,0,0.38493460186671],[2,2,-0.85214708824206],[2,6,0.48972281541877*10**1],[2,7,-0.30502617256965*10**1],[2,22,0.39420536879154*10**-1],[2,26,0.12558408424308],[3,0,-0.27999329698710],[3,2,0.13899799569460*10**1],[3,4,-0.20189915023570*10**1],[3,16,-0.82147637173963*10**-2],
254
+ # [3,26,-0.47596035734923],[4,0,0.43984074473500*10**-1],[4,2,-0.44476435428739],[4,4,0.90572070719733],[4,26,0.70522450087967],[5,1,0.10770512626332],[5,3,-0.32913623258954],[5,26,-0.50871062041158],[6,0,-0.22175400873096*10**-1],
255
+ # [6,2,0.94260751665092*10**-1],[6,26,0.16436278447961],[7,2,-0.13503372241348*10**-1],[8,26,-0.14834345352472*10**-1],[9,2,0.57922953628084*10**-3],[9,26,0.32308904703711*10**-2],[10,0,0.80964802996215*10**-4],[10,1,-0.16557679795037*10**-3],[11,26,-0.44923899061815*10**-4]]
256
+ end
257
+
258
+ def get_region_ph pressure,specific_enthalpy
259
+ p132=Pressure.megapascals(16.529164252604478)
260
+ h13=SpecificEnthalpy.kilojoules_per_kilogram(1670.8582182745835)
261
+ h32=SpecificEnthalpy.kilojoules_per_kilogram(2563.592004)
262
+
263
+ if specific_enthalpy<h13 && pressure<p132
264
+ return chkh_r1_r4 pressure,specific_enthalpy
265
+ end
266
+ if specific_enthalpy<h13 && pressure>p132
267
+ return chkh_r1_r3 pressure,specific_enthalpy
268
+ end
269
+ if pressure<p132 && specific_enthalpy>h13 && specific_enthalpy<h32
270
+ return 4
271
+ end
272
+ if specific_enthalpy>h32 and pressure<p132
273
+ return chkh_r2_r4 pressure,specific_enthalpy
274
+ end
275
+ if specific_enthalpy>h13 && specific_enthalpy<h32 && pressure<critical_pressure
276
+ return chkh_r3_r4 pressure,specific_enthalpy
277
+ end
278
+ if pressure>p132 && specific_enthalpy>h13
279
+ return chkh_r2_r3 pressure,specific_enthalpy
280
+ end
281
+ raise "Region not identified for h: #{specific_enthalpy.to_s} and p: #{pressure.to_s}"
282
+ end
283
+ def chkh_r1_r4 pressure,specific_enthalpy
284
+ ts=temperature_from_pressure_r4 pressure
285
+ w=WaterSteam.new
286
+ other_props_r1(ts,pressure,w)
287
+ if w.specific_enthalpy>specific_enthalpy then 1 else 4 end
288
+ end
289
+ def chkh_r3_r4 pressure,specific_enthalpy
290
+ #cf=[[0,0,0.639767553612785],[1,1,-0.129727445393014*10**2],[1,32,-0.224595125848403*10**16],[4,7,0.177466741801846*10**7],[12,4,0.717079349571538*10**10],[12,14,-0.378829107169011*10**18],[16,36,-0.955586736431328*10**35],[24,10,0.187269814676188*10**24],[28,0,0.119254746466473*10**12],[32,18,0.110649277244882*10**37]]
291
+ #delta=(specific_entropy/SpecificEntropy.kilojoules_per_kilogram_kelvin(5.2)).value
292
+ #p3s=Pressure.megapascals(cf.inject(0) do |sum,cfi|
293
+ # sum+(cfi[2]*(delta-1.03)**cfi[0]*(delta-0.699)**cfi[1])
294
+ #end*22)
295
+ #p p3s.to_s
296
+ #if p3s>pressure then 4 else 3 end
297
+ raise "not implemented 4 3"
298
+ end
299
+ def chkh_r2_r4 pressure,specific_enthalpy
300
+ ts=temperature_from_pressure_r4 pressure
301
+ w=WaterSteam.new
302
+ other_props_r2(ts,pressure,w)
303
+ if w.specific_enthalpy>specific_enthalpy then 4 else 2 end
304
+ end
305
+ def chkh_r1_r3 pressure,specific_enthalpy
306
+ w=WaterSteam.new
307
+ other_props_r1(Temperature.kelvin(623.15),pressure,w)
308
+ if specific_enthalpy>w.specific_enthalpy then 3 else 1 end
309
+ end
310
+ def chkh_r2_r3 pressure,specific_enthalpy
311
+ raise "not implemented 2 3"
312
+ t=temperature_from_b23 pressure
313
+ w=WaterSteam.new
314
+ other_props_r2(t,pressure,w)
315
+ if w.specific_enthalpy>specific_enthalpy then 3 else 2 end
316
+ end
317
+
318
+ def get_region_ps pressure,specific_entropy
319
+ p132=Pressure.megapascals(16.529164252604478)
320
+ s13=SpecificEntropy.kilojoules_per_kilogram_kelvin(3.77828133954424)
321
+ s32=SpecificEntropy.kilojoules_per_kilogram_kelvin(5.210887824930662)
322
+ if specific_entropy<s13 && pressure<p132
323
+ return chk_r1_r4 pressure,specific_entropy
324
+ end
325
+ if specific_entropy<s13 && pressure>p132
326
+ return chk_r1_r3 pressure,specific_entropy
327
+ end
328
+ if pressure<p132 && specific_entropy>s13 && specific_entropy<s32
329
+ return 4
330
+ end
331
+ if specific_entropy>s32 and pressure<p132
332
+ return chk_r2_r4 pressure,specific_entropy
333
+ end
334
+ if specific_entropy>s13 && specific_entropy<s32 && pressure<critical_pressure
335
+ return chk_r3_r4 pressure,specific_entropy
336
+ end
337
+ if pressure>p132 && specific_entropy>s13
338
+ return chk_r2_r3 pressure,specific_entropy
339
+ end
340
+
341
+ raise "Region not identified for s: #{specific_entropy.to_s} and p: #{pressure.to_s}"
342
+ end
343
+ def chk_r1_r4 pressure,specific_entropy
344
+ ts=temperature_from_pressure_r4 pressure
345
+ w=WaterSteam.new
346
+ other_props_r1(ts,pressure,w)
347
+ if w.specific_entropy>specific_entropy then 1 else 4 end
348
+ end
349
+ def chk_r3_r4 pressure,specific_entropy
350
+ cf=[[0,0,0.639767553612785],[1,1,-0.129727445393014*10**2],[1,32,-0.224595125848403*10**16],[4,7,0.177466741801846*10**7],[12,4,0.717079349571538*10**10],[12,14,-0.378829107169011*10**18],[16,36,-0.955586736431328*10**35],[24,10,0.187269814676188*10**24],[28,0,0.119254746466473*10**12],[32,18,0.110649277244882*10**37]]
351
+ delta=(specific_entropy/SpecificEntropy.kilojoules_per_kilogram_kelvin(5.2)).value
352
+ p3s=Pressure.megapascals(cf.inject(0) do |sum,cfi|
353
+ sum+(cfi[2]*(delta-1.03)**cfi[0]*(delta-0.699)**cfi[1])
354
+ end*22)
355
+ p p3s.to_s
356
+ if p3s>pressure then 4 else 3 end
357
+ end
358
+ def chk_r2_r4 pressure,specific_entropy
359
+ ts=temperature_from_pressure_r4 pressure
360
+ w=WaterSteam.new
361
+ other_props_r2(ts,pressure,w)
362
+ if w.specific_entropy>specific_entropy then 4 else 2 end
363
+ end
364
+ def chk_r1_r3 pressure,specific_entropy
365
+ w=WaterSteam.new
366
+ other_props_r1(Temperature.kelvin(623.15),pressure,w)
367
+ if specific_entropy>w.specific_entropy then 3 else 1 end
368
+ end
369
+ def chk_r2_r3 pressure,specific_entropy
370
+ t=temperature_from_b23 pressure
371
+ w=WaterSteam.new
372
+ other_props_r2(t,pressure,w)
373
+ if w.specific_entropy>specific_entropy then 3 else 2 end
374
+ end
375
+ end
376
+ end
377
+ end
378
+ end