Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHW-related verification items development #46

Merged
4 changes: 4 additions & 0 deletions constrain/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
from .G36ReheatTerminalBoxHeatingAirflowSetpoint import *
from .G36ReheatTerminalBoxDeadbandAirflowSetpoint import *
from .G36TerminalBoxCoolingMinimumAirflow import *
from .hpwh_sizing import *
from .dhw_tank_temperature import *

__all__ = [
"AutomaticOADamperControl",
Expand Down Expand Up @@ -110,4 +112,6 @@
"G36ReheatTerminalBoxHeatingAirflowSetpoint",
"G36ReheatTerminalBoxDeadbandAirflowSetpoint",
"G36TerminalBoxCoolingMinimumAirflow",
"HPWH_sizing",
"DHW_tank_temperature",
]
23 changes: 23 additions & 0 deletions constrain/library/dhw_tank_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from constrain.checklib import RuleCheckBase


class DHW_tank_temperature(RuleCheckBase):
yunjoonjung-PNNL marked this conversation as resolved.
Show resolved Hide resolved
points = ["T_dhw", "T_dhw_deadband", "T_dhw_design_parameter"]

def check_dhw_temperature(self, data):
if (
abs(data["T_dhw"] - data["T_dhw_design_parameter"])
<= 0.5 * data["T_dhw_deadband"]
):
return True
else:
return False

def verify(self):
self.result = self.df.apply(lambda d: self.check_dhw_temperature(d), axis=1)

def check_bool(self):
if len(self.result[self.result == False] > 0):
return False
else:
return True
50 changes: 50 additions & 0 deletions constrain/library/hpwh_sizing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from constrain.checklib import RuleCheckBase
import numpy as np


class HPWH_sizing(RuleCheckBase):
points = [
"T_amb",
"HeatingRate_dx_coil",
"HeatingRate_waterheater1",
"HeatingRate_waterheater2",
"T_amb_parameter",
"HPWH_output_target_percent",
"tol_p",
]

def verify(self):
self.df["total_hpwh_load"] = (
self.df["HeatingRate_dx_coil"]
+ self.df["HeatingRate_waterheater1"]
+ self.df["HeatingRate_waterheater2"]
)

self.df["HPWH_output"] = np.where(
self.df["total_hpwh_load"] != 0.0,
self.df["HeatingRate_dx_coil"] / self.df["total_hpwh_load"],
0.0,
)

min_hpwh_output = self.df[
(self.df["T_amb"] > self.df["T_amb_parameter"])
& (self.df["HPWH_output"] > 0.0)
]["HPWH_output"].min()
min_hpwh_output = 0.0 if min_hpwh_output is np.nan else min_hpwh_output

HPWH_output_target_percent = self.df["HPWH_output_target_percent"].iloc[0]
tol_p = self.df["tol_p"].iloc[0]

self.df["result"] = (
True
if abs(min_hpwh_output - HPWH_output_target_percent) <= tol_p
else False
)

self.result = self.df["result"]

def check_bool(self):
if len(self.result[self.result == False] > 0):
return False
else:
return True
49 changes: 49 additions & 0 deletions schema/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -1556,5 +1556,54 @@
" pass",
"end"
]
},
"HPWH_sizing": {
"library_item_id": 68,
"description_brief": "The algorithm verifies whether hpwh DX coil can achieve 100% heating rate at every time step.",
"description_index": [
"N/A"
],
"description_datapoints": {
"T_amb": "outdoor ambient temperature",
"HeatingRate_dx_coil": "HPWH coil's total water heating rate",
"HeatingRate_waterheater1": "HPWH 1 heating rate",
"HeatingRate_waterheater2": "HPWH 2 heating rate",
"T_amb_parameter": "outdoor ambient temperature parameter",
"HPWH_output_target_percent": "HPWH output target in percent",
"tol_p": "percent tolerance"
},
"description_verification_type": "rule-based",
"assertions_type": "pass",
"description_assertions": [
"total_hpwh_load = HeatingRate_dx_coil + HeatingRate_waterheater1 + HeatingRate_waterheater2",
"HPWH_output = np.where(df['total_hpwh_load'] != 0.0, df['HeatingRate_dx_coil'] / df['total_hpwh_load'] * 100, 0.0)",
"min_hpwh_output = df[(df['T_amb'] > df['T_amb_parameter']) & (df['HPWH_output'] > 0.0)]['HPWH_output'].min()",
"if abs(min_hpwh_output - HPWH_output_target_percent) <= tol_p: ",
" pass",
"else: ",
" fail",
"end"
]
},
"DHW_tank_temperature": {
"library_item_id": 69,
"description_brief": "The algorithm verifies whether water temperature in the domestic hot water tank is within the deadband.",
"description_index": [
"N/A"
],
"description_datapoints": {
"T_dhw": "Water temperature in DHW tank",
"T_dhw_deadband": "DHW tank temperature deadband",
"T_dhw_design_parameter": "DHW tank design temperature"
},
"description_verification_type": "rule-based",
"assertions_type": "pass",
"description_assertions": [
"if abs(T_dhw - T_dhw_design_parameter) <= 0.5 * T_dhw_deadband:",
" pass",
"else: ",
" fail",
"end"
]
}
}
33 changes: 33 additions & 0 deletions tests/test_dhw_tank_temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys
import unittest

sys.path.append("./constrain")
import pandas as pd
from lib_unit_test_runner import *


class TestDHWTankTemperature(unittest.TestCase):
def test_dhw_tank_temperature(self):
points = [
"T_dhw",
"T_dhw_deadband",
"T_dhw_design_parameter",
]

data = [
[50, 2.0, 49], # Pass - dhw tank temp is within the deadband range
[50, 2.0, 51], # Pass - dhw tank temp is within the deadband range
[50, 2.0, 47], # Fail - dhw tank temp is out of the deadband range
[50, 2.0, 53], # Fail - dhw tank temp is out of the deadband range
]

df = pd.DataFrame(data, columns=points)

verification_obj = run_test_verification_with_data("DHW_tank_temperature", df)

results = pd.Series(list(verification_obj.result))
expected_results = pd.Series([True, True, False, False])
self.assertTrue(results.equals(expected_results))

binary_result = verification_obj.check_bool()
self.assertFalse(binary_result)
147 changes: 147 additions & 0 deletions tests/test_hpwh_sizing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import sys
import unittest

sys.path.append("./constrain")
import datetime

import pandas as pd
from lib_unit_test_runner import *


class TestHPWHSizing(unittest.TestCase):
def test_HPWH_sizing_pass(self):
points = [
"T_amb",
"HeatingRate_dx_coil",
"HeatingRate_waterheater1",
"HeatingRate_waterheater2",
"T_amb_parameter",
"HPWH_output_target_percent",
"tol_p",
]

timestamp = [
datetime(2024, 1, 1, 12, 0, 0),
datetime(2024, 1, 1, 13, 0, 0),
datetime(2024, 1, 1, 14, 0, 0),
datetime(2024, 1, 1, 15, 0, 0),
]

data = [
[3.0, 50, 0, 50, 2.7, 0.5, 0.01],
[3.0, 60, 0, 60, 2.7, 0.5, 0.01],
[5.0, 60, 10, 30, 2.7, 0.5, 0.01],
[5.0, 80, 40, 40, 2.7, 0.5, 0.01],
]

df = pd.DataFrame(data, columns=points, index=timestamp)

verification_obj = run_test_verification_with_data("HPWH_sizing", df)

results = pd.Series(list(verification_obj.result))
expected_results = pd.Series(
[
True,
True,
True,
True,
]
)
self.assertTrue(results.equals(expected_results))

binary_result = verification_obj.check_bool()
self.assertTrue(binary_result)

def test_HPWH_sizing_fail(self):
points = [
"T_amb",
"HeatingRate_dx_coil",
"HeatingRate_waterheater1",
"HeatingRate_waterheater2",
"T_amb_parameter",
"HPWH_output_target_percent",
"tol_p",
]

timestamp = [
datetime(2024, 1, 1, 12, 0, 0),
datetime(2024, 1, 1, 13, 0, 0),
datetime(2024, 1, 1, 14, 0, 0),
datetime(2024, 1, 1, 15, 0, 0),
]

data = [
[3.0, 50, 0, 50, 2.7, 0.5, 0.01],
[3.0, 60, 0, 60, 2.7, 0.5, 0.01],
[5.0, 60, 10, 30, 2.7, 0.5, 0.01],
[
5.0,
30,
40,
40,
2.7,
0.4,
0.01,
], # fail because of this line (e.g., 30 / (30+40+40) < 0.4)
]

df = pd.DataFrame(data, columns=points, index=timestamp)

verification_obj = run_test_verification_with_data("HPWH_sizing", df)

results = pd.Series(list(verification_obj.result))
expected_results = pd.Series(
[
False,
False,
False,
False,
]
)
self.assertTrue(results.equals(expected_results))

binary_result = verification_obj.check_bool()
self.assertFalse(binary_result)

def test_HPWH_sizing_fail_all_temps_less_than_temp_param(self):
points = [
"T_amb",
"HeatingRate_dx_coil",
"HeatingRate_waterheater1",
"HeatingRate_waterheater2",
"T_amb_parameter",
"HPWH_output_target_percent",
"tol_p",
]

timestamp = [
datetime(2024, 1, 1, 12, 0, 0),
datetime(2024, 1, 1, 13, 0, 0),
datetime(2024, 1, 1, 14, 0, 0),
datetime(2024, 1, 1, 15, 0, 0),
]

data = [
[1.0, 50, 0, 50, 2.7, 0.5, 0.01],
[1.0, 60, 0, 60, 2.7, 0.5, 0.01],
[2.0, 60, 10, 30, 2.7, 0.5, 0.01],
[2.0, 30, 40, 40, 2.7, 0.5, 0.01],
]

df = pd.DataFrame(data, columns=points, index=timestamp)

verification_obj = run_test_verification_with_data("HPWH_sizing", df)

results = pd.Series(list(verification_obj.result))
expected_results = pd.Series(
[
False,
False,
False,
False,
]
)
self.assertTrue(results.equals(expected_results))

binary_result = verification_obj.check_bool()
self.assertFalse(binary_result)
Loading