Class: Pulo::Steam::WaterSteam

Inherits:
Object
  • Object
show all
Defined in:
lib/pulo/machine/steam/water_steam.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pressure: nil, temperature: nil, specific_entropy: nil, specific_enthalpy: nil, quality: nil) ⇒ WaterSteam

Returns a new instance of WaterSteam.



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
# File 'lib/pulo/machine/steam/water_steam.rb', line 56

def initialize(pressure: nil,temperature: nil,specific_entropy: nil, specific_enthalpy: nil, quality: nil)

  return if !pressure && !temperature && !specific_entropy && !specific_enthalpy && !quality

  @temperature=temperature.kelvin if temperature
  @pressure=pressure.megapascals if pressure
  @specific_entropy=specific_entropy.kilojoules_per_kilogram_kelvin if specific_entropy
  @specific_enthalpy=specific_enthalpy.kilojoules_per_kilogram if specific_enthalpy
  @quality=quality.n if quality
  @mass_flow=MassFlow.new(0)
  @energy_flow=Power.new(0)

  if @temperature && (@temperature>Temperature.kelvin(1073.15) || @temperature<Temperature.kelvin(273.15))
    raise "Temperature outside valid range 273.15K to 1073.15K"
    #TODO: Implement R5
  end
  if @pressure && (@pressure<Pressure.megapascals(0) || @pressure>Pressure.megapascals(100))
    raise "Pressure outside valid range 0MPa to 100MPa"
  end

  if (quality && (pressure || temperature))
    @if97_region="4"
    if temperature
      @pressure=IF97.pressure_from_temperature_r4 @temperature
    else
      @temperature=IF97.temperature_from_pressure_r4 @pressure
    end
    fluid=WaterSteam.new
    IF97.other_props_r1(@temperature,@pressure,fluid)

    gas=WaterSteam.new
    IF97.other_props_r2(@temperature,@pressure,gas)

    @specific_enthalpy=fluid.specific_enthalpy+(gas.specific_enthalpy-fluid.specific_enthalpy)*@quality
    @specific_entropy=fluid.specific_entropy+(gas.specific_entropy-fluid.specific_entropy)*@quality
    @specific_volume=fluid.specific_volume+(gas.specific_volume-fluid.specific_volume)*@quality
    @specific_internal_energy=fluid.specific_internal_energy+(gas.specific_internal_energy-fluid.specific_internal_energy)*@quality
    return
  end

  if (temperature && !pressure && !specific_entropy  && !specific_enthalpy) || (!temperature && pressure && !specific_entropy && !specific_enthalpy)
    #if97 region 4 saturated steam
    @if97_region="4"
    if temperature
      @pressure=IF97.pressure_from_temperature_r4 @temperature
    else
      @temperature=IF97.temperature_from_pressure_r4 @pressure
    end
    @saturation_temperature=@temperature
    @saturation_pressure=@pressure
    return
  end

  if @temperature && @pressure
    #determine region
    if @temperature<Temperature.kelvin(623.15)
      @saturation_pressure=IF97.pressure_from_temperature_r4 @temperature
      @saturation_temperature=IF97.temperature_from_pressure_r4 @pressure
      if @pressure<@saturation_pressure
        @if97_region="2"
        IF97.other_props_r2(@temperature,@pressure,self)
      else
        @if97_region="1"
        IF97.other_props_r1(@temperature,@pressure,self)
      end
    else
      p_b23=IF97.pressure_from_b23(@temperature)
      if @pressure>p_b23
        @if97_region="3"
        #TODO: Implement R3 forward
      else
        @if97_region="2"
        IF97.other_props_r2(temperature,@pressure,self)
      end
    end
    return
  end

  if @pressure && @specific_enthalpy
    region=IF97.get_region_ph(@pressure,@specific_enthalpy)
    case region
      when 1
        #raise "Reverse for region 1 not implemented"
        IF97.temperature_from_pressure_enthalpy_r1(@pressure,@specific_enthalpy,self)
        IF97.other_props_r1(@temperature,@pressure,self)
        @if97_region="1"
      when 2
        IF97.temperature_from_pressure_enthalpy_r2(@pressure,@specific_enthalpy,self)
        IF97.other_props_r2(@temperature,@pressure,self)
        @if97_region="2"
      when 3
        raise "Reverse for region 3 not implemented"
        @if97_region="3"
      when 4
        @temperature=IF97.temperature_from_pressure_r4 @pressure
        @if97_region="4"

        fluid=WaterSteam.new
        IF97.other_props_r1(@temperature,@pressure,fluid)

        gas=WaterSteam.new
        IF97.other_props_r2(@temperature,@pressure,gas)

        @quality=(self.specific_enthalpy-fluid.specific_enthalpy)/(gas.specific_enthalpy-fluid.specific_enthalpy)
        @specific_entropy=fluid.specific_entropy+(gas.specific_entropy-fluid.specific_entropy)*@quality
        @specific_volume=fluid.specific_volume+(gas.specific_volume-fluid.specific_volume)*@quality
        @specific_internal_energy=fluid.specific_internal_energy+(gas.specific_internal_energy-fluid.specific_internal_energy)*@quality
    end
    return
  end

  if @pressure && @specific_entropy
    #get the r1,r2 boundary saturation entropy
    region=IF97.get_region_ps(@pressure,@specific_entropy)

    case region
      when 1
        IF97.temperature_from_pressure_entropy_r1(@pressure,@specific_entropy,self)
        IF97.other_props_r1(@temperature,@pressure,self)
        @if97_region="1"
      when 2
        IF97.temperature_from_pressure_entropy_r2(@pressure,@specific_entropy,self)
        IF97.other_props_r2(@temperature,@pressure,self)
        @if97_region="2"
      when 3
        raise "Reverse for region 3 not implemented"
        @if97_region="3"
      when 4
        @temperature=IF97.temperature_from_pressure_r4 @pressure
        @if97_region="4"

        fluid=WaterSteam.new
        IF97.other_props_r1(@temperature,@pressure,fluid)

        gas=WaterSteam.new
        IF97.other_props_r2(@temperature,@pressure,gas)

        @quality=(self.specific_entropy-fluid.specific_entropy)/(gas.specific_entropy-fluid.specific_entropy)
        @specific_enthalpy=fluid.specific_enthalpy+(gas.specific_enthalpy-fluid.specific_enthalpy)*@quality
        @specific_volume=fluid.specific_volume+(gas.specific_volume-fluid.specific_volume)*@quality
        @specific_internal_energy=fluid.specific_internal_energy+(gas.specific_internal_energy-fluid.specific_internal_energy)*@quality
    end

    case region
      when 1
        IF97.temperature_from_pressure_entropy_r1(@pressure,@specific_entropy,self)
        @if97_region="1"
      when 2
        IF97.temperature_from_pressure_entropy_r2(@pressure,@specific_entropy,self)
        @if97_region="2"
      when 3
        raise "Reverse for region 3 not implemented"
        @if97_region="3"
      when 4
        @temperature=IF97.temperature_from_pressure_r4 @pressure
        @if97_region="4"

        fluid=WaterSteam.new
        IF97.other_props_r1(@temperature,@pressure,fluid)

        gas=WaterSteam.new
        IF97.other_props_r2(@temperature,@pressure,gas)

        @quality=(self.specific_entropy-fluid.specific_entropy)/(gas.specific_entropy-fluid.specific_entropy)
        @specific_enthalpy=fluid.specific_enthalpy+(gas.specific_enthalpy-fluid.specific_enthalpy)*@quality
        @specific_volume=fluid.specific_volume+(gas.specific_volume-fluid.specific_volume)*@quality
        @specific_internal_energy=fluid.specific_internal_energy+(gas.specific_internal_energy-fluid.specific_internal_energy)*@quality
      return
    end
  end
end

Instance Attribute Details

#energy_flowObject

Returns the value of attribute energy_flow.



14
15
16
# File 'lib/pulo/machine/steam/water_steam.rb', line 14

def energy_flow
  @energy_flow
end

#if97_regionObject

Returns the value of attribute if97_region.



12
13
14
# File 'lib/pulo/machine/steam/water_steam.rb', line 12

def if97_region
  @if97_region
end

#mass_flowObject

Returns the value of attribute mass_flow.



14
15
16
# File 'lib/pulo/machine/steam/water_steam.rb', line 14

def mass_flow
  @mass_flow
end

#pressureObject

Returns the value of attribute pressure.



8
9
10
# File 'lib/pulo/machine/steam/water_steam.rb', line 8

def pressure
  @pressure
end

#qualityObject

Returns the value of attribute quality.



13
14
15
# File 'lib/pulo/machine/steam/water_steam.rb', line 13

def quality
  @quality
end

#saturation_pressureObject

Returns the value of attribute saturation_pressure.



11
12
13
# File 'lib/pulo/machine/steam/water_steam.rb', line 11

def saturation_pressure
  @saturation_pressure
end

#saturation_temperatureObject

Returns the value of attribute saturation_temperature.



11
12
13
# File 'lib/pulo/machine/steam/water_steam.rb', line 11

def saturation_temperature
  @saturation_temperature
end

#specific_enthalpyObject

Returns the value of attribute specific_enthalpy.



10
11
12
# File 'lib/pulo/machine/steam/water_steam.rb', line 10

def specific_enthalpy
  @specific_enthalpy
end

#specific_entropyObject

Returns the value of attribute specific_entropy.



10
11
12
# File 'lib/pulo/machine/steam/water_steam.rb', line 10

def specific_entropy
  @specific_entropy
end

#specific_internal_energyObject

Returns the value of attribute specific_internal_energy.



10
11
12
# File 'lib/pulo/machine/steam/water_steam.rb', line 10

def specific_internal_energy
  @specific_internal_energy
end

#specific_volumeObject

Returns the value of attribute specific_volume.



9
10
11
# File 'lib/pulo/machine/steam/water_steam.rb', line 9

def specific_volume
  @specific_volume
end

#specific_volume_liquidObject

Returns the value of attribute specific_volume_liquid.



9
10
11
# File 'lib/pulo/machine/steam/water_steam.rb', line 9

def specific_volume_liquid
  @specific_volume_liquid
end

#stateObject

Returns the value of attribute state.



12
13
14
# File 'lib/pulo/machine/steam/water_steam.rb', line 12

def state
  @state
end

#temperatureObject

Returns the value of attribute temperature.



8
9
10
# File 'lib/pulo/machine/steam/water_steam.rb', line 8

def temperature
  @temperature
end

Instance Method Details

#to_s(us: false) ⇒ Object



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
# File 'lib/pulo/machine/steam/water_steam.rb', line 16

def to_s(us: false)
  r=case if97_region
       when "1"
         "Water "
       when "2" || "3"
         "Superheated "
      when "4"
        case quality
          when Dimensionless.n(1)
            "Dry steam "
          when Dimensionless.n(0)
            "Water "
          else
            "Quality:#{quality} "
        end

       else
         if97_region.to_s
     end.ljust(12)
  if us
    r+="mf:#{mass_flow.pounds_per_hour.to_s(0).rjust(15)} ef:#{energy_flow.millions_btu_per_hour.to_s.rjust(17)} p:#{pressure.psig.to_s.rjust(9)}  t:#{temperature.fahrenheit.to_s(0).rjust(8)}  h:#{specific_enthalpy.btu_per_pound.to_s(0).rjust(15)} s:#{specific_entropy.btu_per_pound_rankine}"
  else
    r+="mf:#{mass_flow.kilograms_per_second.to_s(0).rjust(15)} ef:#{energy_flow.megawatts.to_s.rjust(17)} p:#{pressure.megapascals} t:#{temperature.kelvin} #{temperature.celsius} h:#{specific_enthalpy.kilojoules_per_kilogram} s:#{specific_entropy.kilojoules_per_kilogram_kelvin}"
  end

end