Skip to content

Commit

Permalink
remove intermediate Fluid class by creating a factory that constructs…
Browse files Browse the repository at this point in the history
… and returns the scp classes directly, then operate directly on those scp class instances
  • Loading branch information
mitchute committed Apr 17, 2024
1 parent 26f6e08 commit b64b69d
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 165 deletions.
2 changes: 1 addition & 1 deletion glhe/profiles/constant_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
if flow_rate == 0:
return inputs

specific_heat = self.ip.props_mgr.fluid.get_cp(self.inlet_temp)
specific_heat = self.ip.props_mgr.fluid.cp(self.inlet_temp)
self.outlet_temp = self.load / (flow_rate * specific_heat) + self.inlet_temp
return SimulationResponse(inputs.time, inputs.time_step, inputs.flow_rate, self.outlet_temp)

Expand Down
2 changes: 1 addition & 1 deletion glhe/profiles/external_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
inlet_temp = inputs.temperature

self.load = self.get_value(t + dt)
specific_heat = self.ip.props_mgr.fluid.get_cp(inlet_temp)
specific_heat = self.ip.props_mgr.fluid.cp(inlet_temp)
self.outlet_temp = self.load / (flow_rate * specific_heat) + inlet_temp
return SimulationResponse(inputs.time, inputs.time_step, inputs.flow_rate, self.outlet_temp)

Expand Down
2 changes: 1 addition & 1 deletion glhe/profiles/pulse_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:

inlet_temp = inputs.temperature

specific_heat = self.ip.props_mgr.fluid.get_cp(inlet_temp)
specific_heat = self.ip.props_mgr.fluid.cp(inlet_temp)
self.outlet_temp = self.load / (flow_rate * specific_heat) + inlet_temp
return SimulationResponse(inputs.time, inputs.time_step, inputs.flow_rate, self.outlet_temp)
else:
Expand Down
2 changes: 1 addition & 1 deletion glhe/profiles/sinusoid_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
inlet_temp = inputs.temperature

self.load = self.amplitude * sin(2 * pi * (t + dt) / self.period) + self.offset
specific_heat = self.ip.props_mgr.fluid.get_cp(inlet_temp)
specific_heat = self.ip.props_mgr.fluid.cp(inlet_temp)
self.outlet_temp = self.load / (flow_rate * specific_heat) + inlet_temp
return SimulationResponse(inputs.time, inputs.time_step, inputs.flow_rate, self.outlet_temp)

Expand Down
2 changes: 1 addition & 1 deletion glhe/profiles/synthetic_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
inlet_temp = inputs.temperature

self.load = self.get_value(t + dt)
specific_heat = self.ip.props_mgr.fluid.get_cp(inlet_temp)
specific_heat = self.ip.props_mgr.fluid.cp(inlet_temp)
self.outlet_temp = self.load / (flow_rate * specific_heat) + inlet_temp
return SimulationResponse(inputs.time, inputs.time_step, inputs.flow_rate, self.outlet_temp)

Expand Down
28 changes: 28 additions & 0 deletions glhe/properties/fluid_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import annotations

from scp.ethyl_alcohol import EthylAlcohol
from scp.ethylene_glycol import EthyleneGlycol
from scp.methyl_alcohol import MethylAlcohol
from scp.propylene_glycol import PropyleneGlycol
from scp.water import Water


def get_fluid(inputs: dict) -> EthylAlcohol | EthyleneGlycol | MethylAlcohol | PropyleneGlycol | Water:
fluid_type_str = inputs['fluid-type'].upper()
if fluid_type_str == "WATER":
concentration = 0
return Water()
elif fluid_type_str == "EA":
concentration = inputs['concentration'] / 100.0
return EthylAlcohol(concentration)
elif fluid_type_str == "EG":
concentration = inputs['concentration'] / 100.0
return EthyleneGlycol(concentration)
elif fluid_type_str == "MA":
concentration = inputs['concentration'] / 100.0
return MethylAlcohol(concentration)
elif fluid_type_str == "PG":
concentration = inputs['concentration'] / 100.0
return PropyleneGlycol(concentration)
else:
raise ValueError(f"Fluid '{fluid_type_str}' fluid is not valid.")
92 changes: 0 additions & 92 deletions glhe/properties/fluid_properties.py

This file was deleted.

9 changes: 0 additions & 9 deletions glhe/properties/fluid_property_types.py

This file was deleted.

4 changes: 2 additions & 2 deletions glhe/properties/props_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from glhe.ground_temps.ground_temp_factory import make_ground_temp_model
from glhe.properties.base_properties import PropertiesBase
from glhe.properties.fluid_properties import Fluid
from glhe.properties.fluid_factory import get_fluid


class PropsMGR:
Expand Down Expand Up @@ -36,7 +36,7 @@ def _add_fluid_props_inst(self, inputs: dict) -> None:
:param inputs: fluid input dict
"""
self.fluid = Fluid(inputs)
self.fluid = get_fluid(inputs)

def _add_soil_props_inst(self, inputs: dict) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion glhe/topology/ground_heat_exchanger_long_time_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:

c_2 = (self.c_0 * g + resist_b * g_b)

cp = self.fluid.get_cp(inlet_temp)
cp = self.fluid.cp(inlet_temp)
c_3 = (flow_rate_path * cp) / self.h

q_prev = self.load_agg.get_q_prev()
Expand Down
12 changes: 6 additions & 6 deletions glhe/topology/ground_heat_exchanger_short_time_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def generate_g(self) -> None:
'diameter': d_ave_bh['diameter'],
'borehole-resistance': d_ave_bh['borehole-resistance'],
'convection-resistance': d_ave_bh['pipe-conv-resistance'],
'fluid-specific-heat': self.fluid.get_cp(20),
'fluid-density': self.fluid.get_rho(20),
'fluid-specific-heat': self.fluid.cp(20),
'fluid-density': self.fluid.rho(20),
'pipe-conductivity': d_ave_bh['pipe-conductivity'],
'pipe-specific-heat': d_ave_bh['pipe-specific-heat'],
'pipe-density': d_ave_bh['pipe-density'],
Expand Down Expand Up @@ -219,7 +219,7 @@ def generate_g_b(self, flow_rate=0.5):
g_b = []

for t in times:
cp = self.fluid.get_cp(temperature)
cp = self.fluid.cp(temperature)
temperature = temperature + q_tot / (flow_rate * cp)
response = SimulationResponse(t, dt, flow_rate, temperature)
temperature = self.simulate_time_step(response).temperature
Expand All @@ -235,7 +235,7 @@ def generate_g_b(self, flow_rate=0.5):
end_time = self.ip.input_dict['simulation']['runtime']
while err > 0.02:
t += dt
cp = self.fluid.get_cp(temperature)
cp = self.fluid.cp(temperature)
temperature = temperature + q_tot / (flow_rate * cp)
response = SimulationResponse(t, dt, flow_rate, temperature)
temperature = self.simulate_time_step(response).temperature
Expand Down Expand Up @@ -306,7 +306,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:

# update report variables
# TODO: generalize first-law computations everywhere
cp = self.fluid.get_cp(inlet_temp)
cp = self.fluid.cp(inlet_temp)
self.heat_rate = flow * cp * (inlet_temp - outlet_temp)
self.heat_rate_bh = self.get_heat_rate_bh()
self.inlet_temperature = inputs.temperature
Expand All @@ -333,7 +333,7 @@ def mix_paths(self, responses: list) -> float:
for r in responses:
temp = r.temperature
m_dot = r.flow_rate
cp = self.fluid.get_cp(temp)
cp = self.fluid.cp(temp)
sum_mdot_cp_temp += m_dot * cp * temp
sum_mdot += m_dot
sum_cp += cp
Expand Down
10 changes: 5 additions & 5 deletions glhe/topology/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def calc_transit_time(self, flow_rate: float, temperature: float) -> float:
:param temperature: temperature, C
:return: transit time, s
"""
v_dot = flow_rate / self.fluid.get_rho(temperature)
v_dot = flow_rate / self.fluid.rho(temperature)
return self.fluid_vol / v_dot

def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
Expand Down Expand Up @@ -136,7 +136,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
tau_0 = tau - num_cells * tau_n

# volume flow rate
v_dot = m_dot / self.fluid.get_rho(inlet_temp)
v_dot = m_dot / self.fluid.rho(inlet_temp)

# volume for ideal-mixed cells
v_n = tau_n * v_dot
Expand Down Expand Up @@ -238,7 +238,7 @@ def m_dot_to_re(self, flow_rate, temp) -> float:
:param temp: temperature, C
:return: Reynolds number
"""
self.re = 4 * flow_rate / (self.fluid.get_mu(temp) * pi * self.inner_diameter)
self.re = 4 * flow_rate / (self.fluid.mu(temp) * pi * self.inner_diameter)
return self.re

def calc_friction_factor(self, re: float) -> float:
Expand Down Expand Up @@ -305,7 +305,7 @@ def calc_conv_resist(self, flow_rate: float, temperature: float):
nu = (1 - sigma) * nu_low + sigma * nu_high
else:
nu = self.turbulent_nusselt(re, temperature)
self.resist_conv = 1 / (nu * pi * self.fluid.get_k(temperature))
self.resist_conv = 1 / (nu * pi * self.fluid.k(temperature))
return self.resist_conv

def calc_resist(self, flow_rate: float, temperature: float):
Expand Down Expand Up @@ -344,7 +344,7 @@ def turbulent_nusselt(self, re: float, temperature: float):
"""

f = self.calc_friction_factor(re)
pr = self.fluid.get_pr(temperature)
pr = self.fluid.pr(temperature)
return (f / 8) * (re - 1000) * pr / (1 + 12.7 * (f / 8) ** 0.5 * (pr ** (2 / 3) - 1))

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions glhe/topology/single_u_tube_grouted_borehole.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def calc_bh_effective_resistance_uhf(self, temperature: float,
self.calc_bh_average_resistance(temperature, flow_rate, pipe_resist)

pt_1 = 1 / (3 * self.resist_bh_total_internal)
pt_2 = (self.h / (self.fluid.get_cp(temperature) * flow_rate)) ** 2
pt_2 = (self.h / (self.fluid.cp(temperature) * flow_rate)) ** 2
resist_short_circuiting = pt_1 * pt_2

self.resist_bh_effective = self.resist_bh_ave + resist_short_circuiting
Expand Down Expand Up @@ -337,7 +337,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
# update report variables
self.inlet_temperature = inlet_temp
self.outlet_temperature = self.pipe_2.outlet_temperature
cp = self.fluid.get_cp(inlet_temp)
cp = self.fluid.cp(inlet_temp)
self.heat_rate = flow_rate * cp * (inlet_temp - self.outlet_temperature)
self.heat_rate_bh = self.get_heat_rate_bh()

Expand Down
4 changes: 2 additions & 2 deletions glhe/topology/single_u_tube_grouted_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def simulate_time_step(self, time_step: float, inputs: TimeStepStructure) -> np.
self.boundary_temp = inputs.boundary_temp
self.bh_resist = inputs.bh_resist
self.dc_resist = inputs.dc_resist
self.fluid_cp = self.fluid.get_cp(self.inlet_temp_1)
self.fluid_heat_capacity = self.fluid.get_rho(self.inlet_temp_1) * self.fluid_cp
self.fluid_cp = self.fluid.cp(self.inlet_temp_1)
self.fluid_heat_capacity = self.fluid.rho(self.inlet_temp_1) * self.fluid_cp

solver = RK45(self.right_hand_side, 0, self.y, time_step)
while solver.status != 'finished':
Expand Down
2 changes: 1 addition & 1 deletion glhe/topology/swedish_heat_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse:
self.hp_rtf = self.wtr_htg_rtf + self.htg_rtf
self.heat_extraction = -self.wtr_htg_heat_extraction - self.htg_heat_extraction

cp = self.fluid.get_cp(inlet_temp)
cp = self.fluid.cp(inlet_temp)
outlet_temp = inlet_temp + self.heat_extraction / (flow_rate * cp)
response = SimulationResponse(time, dt, flow_rate, outlet_temp, hp_src_heat_rate=self.heat_extraction)

Expand Down
6 changes: 3 additions & 3 deletions unit_tests/glhe/input_processor/test_input_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def test_validate_fluid(self):

self.run_validate(d)

d = {'fluid': {'fluid-type': 'EA', 'concentration': 100}}
d = {'fluid': {'fluid-type': 'EA', 'concentration': 60}}

self.run_validate(d)

d = {'fluid': {'fluid-type': 'EG', 'concentration': 100}}
d = {'fluid': {'fluid-type': 'EG', 'concentration': 60}}

self.run_validate(d)

d = {'fluid': {'fluid-type': 'PG', 'concentration': 100}}
d = {'fluid': {'fluid-type': 'PG', 'concentration': 60}}

self.run_validate(d)

Expand Down
Loading

0 comments on commit b64b69d

Please sign in to comment.