diff --git a/glhe/input_processor/input_processor.py b/glhe/input_processor/input_processor.py index bd33647a..00c67399 100644 --- a/glhe/input_processor/input_processor.py +++ b/glhe/input_processor/input_processor.py @@ -4,7 +4,9 @@ from jsonschema import SchemaError, ValidationError, validate -from glhe.properties.props_manager import PropsMGR +from glhe.ground_temps.ground_temp_factory import make_ground_temp_model +from glhe.properties.fluid_factory import get_fluid +from glhe.properties.base_properties import PropertiesBase from glhe.utilities.functions import load_json, lower_obj @@ -30,8 +32,20 @@ def __init__(self, json_input_path: Path): self.validate_inputs(self.input_dict) # load properties for later use - self.props_mgr = PropsMGR() - self.props_mgr.load_properties(self.input_dict) + try: + self.fluid = get_fluid(self.input_dict['fluid']) + except KeyError: + pass + + try: + self.soil = PropertiesBase(self.input_dict['soil']) + try: + self.soil.get_temp = make_ground_temp_model(self.input_dict['ground-temperature-model']).get_temp + except KeyError: + pass + + except KeyError: + pass @staticmethod def validate_inputs(input_dict: dict) -> None: diff --git a/glhe/profiles/constant_load.py b/glhe/profiles/constant_load.py index 0fbbac19..9db18998 100644 --- a/glhe/profiles/constant_load.py +++ b/glhe/profiles/constant_load.py @@ -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.cp(self.inlet_temp) + specific_heat = self.ip.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) diff --git a/glhe/profiles/external_load.py b/glhe/profiles/external_load.py index 64127fc5..40e2cfaf 100644 --- a/glhe/profiles/external_load.py +++ b/glhe/profiles/external_load.py @@ -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.cp(inlet_temp) + specific_heat = self.ip.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) diff --git a/glhe/profiles/pulse_load.py b/glhe/profiles/pulse_load.py index 595c5afd..448373d2 100644 --- a/glhe/profiles/pulse_load.py +++ b/glhe/profiles/pulse_load.py @@ -29,7 +29,7 @@ def simulate_time_step(self, inputs: SimulationResponse) -> SimulationResponse: inlet_temp = inputs.temperature - specific_heat = self.ip.props_mgr.fluid.cp(inlet_temp) + specific_heat = self.ip.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: diff --git a/glhe/profiles/sinusoid_load.py b/glhe/profiles/sinusoid_load.py index 9e900092..76ec5d1e 100644 --- a/glhe/profiles/sinusoid_load.py +++ b/glhe/profiles/sinusoid_load.py @@ -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.cp(inlet_temp) + specific_heat = self.ip.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) diff --git a/glhe/profiles/synthetic_load.py b/glhe/profiles/synthetic_load.py index be04fc97..3278af96 100644 --- a/glhe/profiles/synthetic_load.py +++ b/glhe/profiles/synthetic_load.py @@ -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.cp(inlet_temp) + specific_heat = self.ip.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) diff --git a/glhe/properties/props_manager.py b/glhe/properties/props_manager.py deleted file mode 100644 index 133a4d0c..00000000 --- a/glhe/properties/props_manager.py +++ /dev/null @@ -1,56 +0,0 @@ -from glhe.ground_temps.ground_temp_factory import make_ground_temp_model -from glhe.properties.base_properties import PropertiesBase -from glhe.properties.fluid_factory import get_fluid - - -class PropsMGR: - - def __init__(self): - self.fluid = None - self.soil = None - - def load_properties(self, inputs: dict): - # TODO: pull this into the init structure - - """ - Load all global properties - - :param inputs: input dictionary - """ - - # load properties first - for key in inputs: - if key == 'fluid': - self._add_fluid_props_inst(inputs[key]) - elif key == 'soil': - self._add_soil_props_inst(inputs[key]) - # tack ground temp model onto the soil class - try: - self._add_ground_temperature_model(inputs['ground-temperature-model']) - except KeyError: - pass - - def _add_fluid_props_inst(self, inputs: dict) -> None: - """ - Inits the fluid properties class - - :param inputs: fluid input dict - """ - self.fluid = get_fluid(inputs) - - def _add_soil_props_inst(self, inputs: dict) -> None: - """ - Inits the soil properties class - - :param inputs: soil input dict - """ - self.soil = PropertiesBase(inputs) - - def _add_ground_temperature_model(self, inputs: dict) -> None: - """ - Inits the ground temperature model - - :param inputs: ground temp model inputs dict - """ - gtm_cls = make_ground_temp_model(inputs) - self.soil.get_temp = gtm_cls.get_temp diff --git a/glhe/topology/ground_heat_exchanger_long_time_step.py b/glhe/topology/ground_heat_exchanger_long_time_step.py index 9900a6c6..5c46701c 100644 --- a/glhe/topology/ground_heat_exchanger_long_time_step.py +++ b/glhe/topology/ground_heat_exchanger_long_time_step.py @@ -21,8 +21,8 @@ def __init__(self, inputs: dict, ip: InputProcessor, op: OutputProcessor): self.op = op # props instances - self.fluid = ip.props_mgr.fluid - self.soil = ip.props_mgr.soil + self.fluid = ip.fluid + self.soil = ip.soil # geometry and other config parameters needed externally self.h = inputs['length'] diff --git a/glhe/topology/ground_heat_exchanger_short_time_step.py b/glhe/topology/ground_heat_exchanger_short_time_step.py index 8d620d8b..18f16ec1 100644 --- a/glhe/topology/ground_heat_exchanger_short_time_step.py +++ b/glhe/topology/ground_heat_exchanger_short_time_step.py @@ -29,8 +29,8 @@ def __init__(self, inputs: dict, ip: InputProcessor, op: OutputProcessor): self.op = op # props instances - self.fluid = ip.props_mgr.fluid - self.soil = ip.props_mgr.soil + self.fluid = ip.fluid + self.soil = ip.soil # init paths self.paths = [] diff --git a/glhe/topology/pipe.py b/glhe/topology/pipe.py index 45abf90b..023fa610 100644 --- a/glhe/topology/pipe.py +++ b/glhe/topology/pipe.py @@ -33,7 +33,7 @@ def __init__(self, inputs, ip, op): PropertiesBase.__init__(self, pipe_props) # local fluids reference - self.fluid = self.ip.props_mgr.fluid + self.fluid = self.ip.fluid # key geometric parameters self.inner_diameter = pipe_props["inner-diameter"] diff --git a/glhe/topology/single_u_tube_grouted_borehole.py b/glhe/topology/single_u_tube_grouted_borehole.py index 41423126..7a3010ce 100644 --- a/glhe/topology/single_u_tube_grouted_borehole.py +++ b/glhe/topology/single_u_tube_grouted_borehole.py @@ -26,8 +26,8 @@ def __init__(self, inputs, ip, op): self.ip = ip self.op = op - self.fluid = ip.props_mgr.fluid - self.soil = ip.props_mgr.soil + self.fluid = ip.fluid + self.soil = ip.soil # get borehole definition data if 'average-borehole' in inputs: diff --git a/glhe/topology/single_u_tube_grouted_segment.py b/glhe/topology/single_u_tube_grouted_segment.py index c7888f46..bbfb18a2 100644 --- a/glhe/topology/single_u_tube_grouted_segment.py +++ b/glhe/topology/single_u_tube_grouted_segment.py @@ -26,8 +26,8 @@ class SingleUTubeGroutedSegment: def __init__(self, inputs, ip, op): self.name = inputs['segment-name'] - self.fluid = ip.props_mgr.fluid - self.soil = ip.props_mgr.soil + self.fluid = ip.fluid + self.soil = ip.soil if 'average-pipe' in inputs: pipe_inputs = {'average-pipe': inputs['average-pipe'], 'length': inputs['length']} diff --git a/glhe/topology/swedish_heat_pump.py b/glhe/topology/swedish_heat_pump.py index 25ef61a4..b02b2ed1 100644 --- a/glhe/topology/swedish_heat_pump.py +++ b/glhe/topology/swedish_heat_pump.py @@ -29,7 +29,7 @@ def __init__(self, inputs, ip, op): self.op = op # local fluids reference - self.fluid = self.ip.props_mgr.fluid + self.fluid = self.ip.fluid # input data self.max_htg_set_point = inputs['max-heating-set-point'] diff --git a/unit_tests/glhe/properties/tests_props_manager.py b/unit_tests/glhe/properties/tests_props_manager.py deleted file mode 100644 index 67daf3ec..00000000 --- a/unit_tests/glhe/properties/tests_props_manager.py +++ /dev/null @@ -1,36 +0,0 @@ -import unittest - -from glhe.properties.base_properties import PropertiesBase -from glhe.properties.fluid_properties import Fluid -from glhe.properties.props_manager import PropsMGR - - -class TestPropsMGR(unittest.TestCase): - - @staticmethod - def add_instance(): - d = { - "fluid": { - "fluid-type": "water", - "concentration": 100}, - "soil": { - "name": "Some Rock", - "conductivity": 2.6, - "density": 2500, - "specific-heat": 880 - } - } - - props_mgr = PropsMGR() - props_mgr.load_properties(d) - return props_mgr - - def test_fluid_instance(self): - props_mgr = self.add_instance() - self.assertIsInstance(props_mgr.fluid, Fluid) - self.assertEqual(props_mgr.fluid.type, 'WATER') - - def test_soil_instance(self): - props_mgr = self.add_instance() - self.assertIsInstance(props_mgr.soil, PropertiesBase) - self.assertEqual(props_mgr.soil.name, 'Some Rock')