Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wan, Hanlong committed Sep 26, 2024
1 parent c25cdfc commit 9c26f37
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
27 changes: 13 additions & 14 deletions copper/unitarydirectexpansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def __init__(
"capacity_fraction": 1.0,
},
},
infdoor_fan_curve_coef={
indoor_fan_curve_coef={
"type": "cubic",
"1": 0.63 * 0.0408,
"2": 0.63 * 0.088,
"3": -0.63 * 0.0729,
"4": 0.63 * 0.9437,
},
indoor_fan_speeds=1,
indoor_fan_curve=0,
indoor_fan_curve=None,
fan_power_unit="kW",
):
global log_fan
Expand Down Expand Up @@ -161,7 +161,7 @@ def __init__(
self.indoor_fan_speeds_mapping = indoor_fan_speeds_mapping
self.indoor_fan_speeds = indoor_fan_speeds
self.indoor_fan_power = indoor_fan_power
self.infdoor_fan_curve_coef = infdoor_fan_curve_coef
self.indoor_fan_curve_coef = indoor_fan_curve_coef
self.fan_power_unit = fan_power_unit
self.indoor_fan_curve = indoor_fan_curve
# Define rated temperatures
Expand Down Expand Up @@ -213,20 +213,22 @@ def __init__(

# default fan curve
self.default_fan_curve = Curve(
eqp=self, c_type=self.infdoor_fan_curve_coef["type"]
eqp=self, c_type=self.indoor_fan_curve_coef["type"]
)
self.default_fan_curve.coeff1 = self.infdoor_fan_curve_coef["1"]
self.default_fan_curve.coeff2 = self.infdoor_fan_curve_coef["2"]
self.default_fan_curve.coeff3 = self.infdoor_fan_curve_coef["3"]
self.default_fan_curve.coeff4 = self.infdoor_fan_curve_coef["4"]
self.default_fan_curve.coeff1 = self.indoor_fan_curve_coef["1"]
self.default_fan_curve.coeff2 = self.indoor_fan_curve_coef["2"]
self.default_fan_curve.coeff3 = self.indoor_fan_curve_coef["3"]
self.default_fan_curve.coeff4 = self.indoor_fan_curve_coef["4"]

def calc_fan_power(self, capacity_ratio):
# Full flow/power
ratio = capacity_ratio
flow_fraction = (
capacity_ratio # we assume flow_fraction = 1*capacity_ratio as default
)
if capacity_ratio == 1 or self.indoor_fan_speeds == 1:
return self.indoor_fan_power
else:
if self.indoor_fan_curve == 0:
if self.indoor_fan_curve == None:
capacity_ratios = []
fan_power_fractions = []
for speed_info in self.indoor_fan_speeds_mapping.values():
Expand All @@ -253,13 +255,10 @@ def calc_fan_power(self, capacity_ratio):
b = fan_power_fractions[i] - a * capacity_ratios[i]
return self.indoor_fan_power * (a * capacity_ratio + b)
else: # using curve
defualt_coef = 1 # can update this coef later
default_min_fan_power = (
self.indoor_fan_power * 0.25
) # default min fan power
power_factor = self.default_fan_curve.evaluate(
x=defualt_coef * ratio, y=0
) # x:ff factor
power_factor = self.default_fan_curve.evaluate(x=flow_fraction, y=0)
if self.indoor_fan_power * power_factor > default_min_fan_power:
return self.indoor_fan_power * power_factor
else:
Expand Down
29 changes: 22 additions & 7 deletions tests/test_unitarydirectexpansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ def test_multi_speed(self):
== 0.65
)

def test_multi_speed_with_curve(self):
# Two-speed fan unit
dx_unit_multi_speed = self.dx_unit_dft
dx_unit_multi_speed.indoor_fan_curve = 1
dx_unit_multi_speed.indoor_fan_speeds = 2
assert (
dx_unit_multi_speed.calc_fan_power(capacity_ratio=0.5)
/ dx_unit_multi_speed.indoor_fan_power
== 0.25
)
assert (
dx_unit_multi_speed.calc_fan_power(capacity_ratio=1.0)
/ dx_unit_multi_speed.indoor_fan_power
== 1.0
)
assert (
dx_unit_multi_speed.calc_fan_power(capacity_ratio=0.75)
/ dx_unit_multi_speed.indoor_fan_power
< 0.7
)


def test_generation(self):
# Define equipment characteristics
dx_unit = self.dx_unit_dft
Expand Down Expand Up @@ -258,10 +280,3 @@ def test_get_ranges(self):
ranges = self.dx_unit_dft.get_ranges()
assert isinstance(ranges, dict)
assert len(ranges) == 5


# Run the tests
import unittest

if __name__ == "__main__":
unittest.main()

0 comments on commit 9c26f37

Please sign in to comment.