Skip to content

Commit

Permalink
Clean up model-specific kwargs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nealkruis committed Aug 1, 2022
1 parent eeca1dc commit a2b3f34
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 45 deletions.
6 changes: 5 additions & 1 deletion chiller/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ class ChillerModel:
def __init__(self):
self.system = None
self.allowed_kwargs = []
self.required_kwargs = []

def set_system(self, system):
self.system = system
for kwarg in system.kwargs:
if kwarg not in self.allowed_kwargs:
if kwarg not in self.allowed_kwargs and kwarg not in self.required_kwargs:
raise Exception(f"Unrecognized key word argument: {kwarg}")
for kwarg in self.required_kwargs:
if kwarg not in system.kwargs:
raise Exception(f"Required key word argument not provided: {kwarg}")

def net_evaporator_capacity(self, conditions):
raise NotImplementedError()
Expand Down
38 changes: 21 additions & 17 deletions chiller/models/energyplus_eir.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,43 @@
class EnergyPlusEIR(ChillerModel):
def __init__(self):
super().__init__()
self.allowed_kwargs += [
"eir_f_t",
"eir_f_plr",
"cap_f_t",
"min_plr",
"min_unload"
self.required_kwargs += [
"eir_temperature_coefficients",
"eir_part_load_ratio_coefficients",
"capacity_temperature_coefficients",
"minimum_part_load_ratio",
"minimum_unloading_ratio"
]

def set_system(self, system):
super().set_system(system)
# set kwarg variables
self.capacity_temperature_coefficients = self.system.kwargs["capacity_temperature_coefficients"]
self.eir_temperature_coefficients = self.system.kwargs["eir_temperature_coefficients"]
self.eir_part_load_ratio_coefficients = self.system.kwargs["eir_part_load_ratio_coefficients"]
self.minimum_part_load_ratio = self.system.kwargs["minimum_part_load_ratio"]
self.minimum_unloading_ratio = self.system.kwargs["minimum_unloading_ratio"]
if self.system.number_of_compressor_speeds is None:
self.system.number_of_compressor_speeds = 4
if self.system.rated_net_condenser_capacity is None:
self.system.rated_net_condenser_capacity = self.system.rated_net_evaporator_capacity*(1./self.system.rated_cop + 1.)

def net_evaporator_capacity(self, conditions):
coeffs = self.system.kwargs["cap_f_t"]
cap_f_t = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(conditions.condenser_inlet.T,"°C"))
return self.system.rated_net_evaporator_capacity*cap_f_t*self.part_load_ratio(conditions)
coeffs = self.capacity_temperature_coefficients
capacity_temperature_multiplier = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(conditions.condenser_inlet.T,"°C"))
return self.system.rated_net_evaporator_capacity*capacity_temperature_multiplier*self.part_load_ratio(conditions)

def input_power(self, conditions):
cap = self.net_evaporator_capacity(conditions)
coeffs = self.system.kwargs["eir_f_t"]
eir_f_t = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(conditions.condenser_inlet.T,"°C"))
coeffs = self.eir_temperature_coefficients
eir_temperature_multplier = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(conditions.condenser_inlet.T,"°C"))
plr = self.part_load_ratio(conditions)
if plr < self.system.kwargs["min_unload"]:
effective_plr = self.system.kwargs["min_unload"]
if plr < self.minimum_unloading_ratio:
effective_plr = self.minimum_unloading_ratio
else:
effective_plr = plr
eir_f_plr = calc_cubic(self.system.kwargs["eir_f_plr"], effective_plr)
eir = eir_f_t*eir_f_plr/self.system.rated_cop
eir_part_load_ratio_multiplier = calc_cubic(self.eir_part_load_ratio_coefficients, effective_plr)
eir = eir_temperature_multplier*eir_part_load_ratio_multiplier/self.system.rated_cop
return eir*cap/self.part_load_ratio(conditions)*effective_plr

def net_condenser_capacity(self, conditions):
Expand All @@ -50,7 +55,6 @@ def auxiliary_heat(self, conditions):
return 0.0

def part_load_ratio(self, conditions):
min_plr = self.system.kwargs["min_plr"]
min_speed = self.system.number_of_compressor_speeds - 1
return min_plr + (1.0 - min_plr)*(min_speed - conditions.compressor_speed)/min_speed
return self.minimum_part_load_ratio + (1.0 - self.minimum_part_load_ratio)*(min_speed - conditions.compressor_speed)/min_speed

20 changes: 10 additions & 10 deletions chiller/models/energyplus_reformulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ def net_evaporator_capacity(self, conditions):

def input_power(self, conditions):
cap = self.net_evaporator_capacity(conditions)
coeffs = self.system.kwargs["eir_f_t"]
eir_f_t = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(self.condenser_leaving_temperature,"°C"))
coeffs = self.eir_temperature_coefficients
eir_temperature_multiplier = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(self.condenser_leaving_temperature,"°C"))
plr = self.part_load_ratio(conditions)
eir_f_plr = calc_bicubic(self.system.kwargs["eir_f_plr"], to_u(self.condenser_leaving_temperature,"°C"), plr)
eir = eir_f_t*eir_f_plr/self.system.rated_cop
eir_part_load_ratio_multiplier = calc_bicubic(self.eir_part_load_ratio_coefficients, to_u(self.condenser_leaving_temperature,"°C"), plr)
eir = eir_temperature_multiplier*eir_part_load_ratio_multiplier/self.system.rated_cop
return eir*cap

def calculate_evaporator_capacity(self, conditions, condenser_leaving_temperature):
cap_f_t = calc_biquad(self.system.kwargs["cap_f_t"], to_u(conditions.evaporator_outlet.T,"°C"), to_u(condenser_leaving_temperature,"°C"))
return self.system.rated_net_evaporator_capacity*cap_f_t*self.part_load_ratio(conditions)
capacity_temperature_multiplier = calc_biquad(self.capacity_temperature_coefficients, to_u(conditions.evaporator_outlet.T,"°C"), to_u(condenser_leaving_temperature,"°C"))
return self.system.rated_net_evaporator_capacity*capacity_temperature_multiplier*self.part_load_ratio(conditions)

def calculate_condenser_capacity(self, conditions, condenser_leaving_temperature):
evaporator_capacity = self.calculate_evaporator_capacity(conditions, condenser_leaving_temperature)
coeffs = self.system.kwargs["eir_f_t"]
eir_f_t = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(condenser_leaving_temperature,"°C"))
coeffs = self.eir_temperature_coefficients
eir_temperature_multiplier = calc_biquad(coeffs, to_u(conditions.evaporator_outlet.T,"°C"), to_u(condenser_leaving_temperature,"°C"))
plr = self.part_load_ratio(conditions)
eir_f_plr = calc_bicubic(self.system.kwargs["eir_f_plr"], to_u(condenser_leaving_temperature,"°C"), plr)
eir = eir_f_t*eir_f_plr/self.system.rated_cop
eir_part_load_ratio_multiplier = calc_bicubic(self.eir_part_load_ratio_coefficients, to_u(condenser_leaving_temperature,"°C"), plr)
eir = eir_temperature_multiplier*eir_part_load_ratio_multiplier/self.system.rated_cop
power = eir*evaporator_capacity
return evaporator_capacity + power

Expand Down
1 change: 1 addition & 0 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def task_examples():
return {
'actions': [
(create_folder, [OUTPUT_PATH]),
'python examples/generate.py',
'python examples/baseline_chillers.py'],
'clean': True
}
15 changes: 8 additions & 7 deletions examples/baseline_chillers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"min_size": float(row[4]),
"max_size": None if row[5] == "" else float(row[5]),
"cop": float(row[6]),
"eir_f_t": [float(c) for c in row[12:18]],
"cap_f_t": [float(c) for c in row[18:24]],
"eir_f_plr": [float(c) for c in row[24:28]]
"eir_temperature_coefficients": [float(c) for c in row[12:18]],
"capacity_temperature_coefficients": [float(c) for c in row[18:24]],
"eir_part_load_ratio_coefficients": [float(c) for c in row[24:28]]
}
)

Expand All @@ -39,10 +39,11 @@
new_chiller = Chiller(
rated_net_evaporator_capacity=size,
rated_cop=chiller["cop"],
min_plr=0.25,
cap_f_t=chiller["cap_f_t"],
eir_f_t=chiller["eir_f_t"],
eir_f_plr=chiller["eir_f_plr"],
minimum_part_load_ratio=0.25,
minimum_unloading_ratio=0.25,
capacity_temperature_coefficients=chiller["capacity_temperature_coefficients"],
eir_temperature_coefficients=chiller["eir_temperature_coefficients"],
eir_part_load_ratio_coefficients=chiller["eir_part_load_ratio_coefficients"],
cycling_degradation_coefficient=0.0)

assert abs(new_chiller.cop() - chiller["cop"]) < 0.05
Expand Down
21 changes: 11 additions & 10 deletions examples/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
cop = 5.5
chiller_type = "Liquid-cooled"
subtype = " "
min_plr = 0.1
min_unload = 0.2
cap_f_t = [0.9061150, 0.0292277, -0.0003647, -0.0009709, -0.0000905, 0.0002527]
eir_f_t = [ 0.3617105, -0.0229833, -0.0009519, 0.0131889, 0.0003752, -0.0007059]
eir_f_plr = [ 4.602131E-02, 2.433945E-02, 6.394526E-05, -3.648563E-01, 1.854759E+00, -2.809346E-02, 0.000000E+00, -4.821515E-01, 0.000000E+00, 0.000000E+00,]
minimum_part_load_ratio = 0.1
minimum_unloading_ratio = 0.2
capacity_temperature_coefficients = [0.9061150, 0.0292277, -0.0003647, -0.0009709, -0.0000905, 0.0002527]
eir_temperature_coefficients = [ 0.3617105, -0.0229833, -0.0009519, 0.0131889, 0.0003752, -0.0007059]
eir_part_load_ratio_coefficients = [ 4.602131E-02, 2.433945E-02, 6.394526E-05, -3.648563E-01, 1.854759E+00, -2.809346E-02, 0.000000E+00, -4.821515E-01, 0.000000E+00, 0.000000E+00,]


my_chiller = Chiller(
model=EnergyPlusReformulatedEIR(),
rated_net_evaporator_capacity=fr_u(size_tons,"ton_ref"),
rated_cop=cop,
min_plr=min_plr,
cap_f_t=cap_f_t,
eir_f_t=eir_f_t,
eir_f_plr=eir_f_plr
minimum_part_load_ratio=minimum_part_load_ratio,
minimum_unloading_ratio=minimum_unloading_ratio,
capacity_temperature_coefficients=capacity_temperature_coefficients,
eir_temperature_coefficients=eir_temperature_coefficients,
eir_part_load_ratio_coefficients=eir_part_load_ratio_coefficients
)

assert abs(my_chiller.net_evaporator_capacity() - my_chiller.rated_net_evaporator_capacity) < 0.01*my_chiller.rated_net_evaporator_capacity
Expand All @@ -40,7 +41,7 @@
"data_model": "ASHRAE_205",
"schema": "RS0001",
"schema_version": "0.2.0",
"description": f"{size_tons:.1f} ton, {cop:.2f} COP {chiller_type}{subtype}Chiller based on ASHRAE 90.1-2019 Addendum 'bd' curve set '{chiller['set']}'",
"description": f"{size_tons:.1f} ton, {cop:.2f} COP {chiller_type}{subtype}Chiller",
"id": str(uuid.uuid4()),
"data_timestamp": f"{timestamp}Z",
"data_version": 1,
Expand Down

0 comments on commit a2b3f34

Please sign in to comment.