-
Notifications
You must be signed in to change notification settings - Fork 0
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
ConStrain Supply Air Temperature Reset Verification Measure #14
Open
jslane-h
wants to merge
12
commits into
master
Choose a base branch
from
constrain_supply_air_temperature_reset_verification
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3a96e41
WIP: Added contrain supply air temperature reset verification measure
jslane-h 96371a9
Added file arguments to measure
jslane-h 2b87e31
Added xml and README for measure
jslane-h 885d5bd
Fixed verification case path in generated workflow
jslane-h e4a3ad9
Updated verification case filename
jslane-h 93fa349
Merge remote-tracking branch 'origin/master' into constrain_supply_ai…
jslane-h 416d3a2
Update verification case measure
jslane-h 20c8ffe
Correct comments.
lymereJ 35df8e8
Update licenses.
lymereJ 0c1f377
Create output directory if it does not yet exist
jslane-h bf0ac3c
Remove test output.
lymereJ 1f011fd
Merge branch 'constrain_supply_air_temperature_reset_verification' of…
lymereJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
lib/measures/ConstrainSupplyAirTemperatureResetVerification/LICENSE.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
BSD 2-Clause License | ||
|
||
Generate ConStrain Supply Air Temperature Reset Verification Case Copyright (c) 2024, Battelle Memorial Institute | ||
All rights reserved. | ||
1. Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity lawfully obtaining a copy of this software and associated documentation files (hereinafter “the Software”) to redistribute and use the Software in source and binary forms, with or without modification. Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and may permit others to do so, subject to the following conditions: | ||
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. | ||
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
- Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any form whatsoever without the express written consent of Battelle. | ||
2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 changes: 26 additions & 0 deletions
26
lib/measures/ConstrainSupplyAirTemperatureResetVerification/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generate ConStrain Supply Air Temperature Reset Verification Case | ||
## Description | ||
This is a ModelMeasure that generates a ConStrain Supply Air Temperature Reset Verification Case. | ||
## Modeler Description | ||
## Measure Type | ||
ModelMeasure | ||
## Taxonomy | ||
## Arguments | ||
**Type:** string, | ||
**Required:** true | ||
### Output Dataset Path | ||
**Name:** output_dataset_path, | ||
**Type:** string, | ||
**Required:** true | ||
### Output Directory | ||
**Name:** output_dir, | ||
**Type:** string, | ||
**Required:** true | ||
### Air Loop Name | ||
**Name:** air_loop_name, | ||
**Type:** string, | ||
**Required:** true | ||
### Design Zone Cooling Air Temp | ||
**Name:** design_zone_cooling_air_temp, | ||
**Type:** string, | ||
**Required:** true |
273 changes: 273 additions & 0 deletions
273
lib/measures/ConstrainSupplyAirTemperatureResetVerification/measure.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,273 @@ | ||
import openstudio | ||
import logging | ||
import datetime | ||
import json | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ConstrainSupplyAirTemperatureResetVerification(openstudio.measure.ModelMeasure): | ||
def name(self): | ||
""" | ||
Return the human readable name. | ||
Measure name should be the title case of the class name. | ||
""" | ||
return "Supply Air Temperature Reset Verification" | ||
|
||
def description(self): | ||
""" | ||
Human readable description | ||
""" | ||
return "Verifies supply air temperature reset for a specified AirLoopHVAC." | ||
|
||
def modeler_description(self): | ||
""" | ||
Human readable description of the modeling approach | ||
""" | ||
return "Verifies supply air temperature reset for a specified AirLoopHVAC." | ||
|
||
def arguments(self, model): | ||
""" | ||
Define arguments | ||
""" | ||
args = openstudio.measure.OSArgumentVector() | ||
|
||
output_dataset_path = openstudio.measure.OSArgument.makeStringArgument( | ||
"output_dataset_path", True | ||
) | ||
output_dir = openstudio.measure.OSArgument.makeStringArgument( | ||
"output_dir", True | ||
) | ||
|
||
air_loop_name = openstudio.measure.OSArgument.makeStringArgument( | ||
"air_loop_name", True | ||
) | ||
|
||
design_zone_cooling_air_temp = openstudio.measure.OSArgument.makeDoubleArgument( | ||
"design_zone_cooling_air_temp", True | ||
) | ||
|
||
args.append(air_loop_name) | ||
args.append(design_zone_cooling_air_temp) | ||
args.append(output_dataset_path) | ||
args.append(output_dir) | ||
|
||
return args | ||
|
||
def get_workflow(self, output_dataset_path, output_dir): | ||
workflow = { | ||
"workflow_name": "Supply Air Temperature Reset Verification", | ||
"meta": { | ||
"author": "None", | ||
"date": datetime.datetime.now().strftime("%m/%d/%Y"), | ||
"version": "1.0", | ||
"description": "Supply Air Temperature Reset Verification", | ||
}, | ||
"imports": ["numpy as np", "pandas as pd", "datetime", "glob"], | ||
"states": { | ||
"load_data": { | ||
"Type": "MethodCall", | ||
"MethodCall": "DataProcessing", | ||
"Parameters": { | ||
"data_path": output_dataset_path, | ||
"data_source": "EnergyPlus", | ||
}, | ||
"Payloads": {"data_processing_obj": "$"}, | ||
"Start": "True", | ||
"Next": "load_verification_case", | ||
} | ||
}, | ||
"load_verification_case": { | ||
"Type": "MethodCall", | ||
"MethodCall": "VerificationCase", | ||
"Parameters": {"json_case_path": f"{output_dir}/supply_air_temperature_verification_case.json"}, | ||
"Payloads": { | ||
"verification_case_obj": "$", | ||
}, | ||
"Next": "validate_case", | ||
}, | ||
"validate_cases": { | ||
"Type": "Choice", | ||
"Choices": [ | ||
{ | ||
"Value": "Payloads['verification_case_obj'].validate()", | ||
"Equals": "True", | ||
"Next": "setup_verification", | ||
} | ||
], | ||
"Default": "Report Error in Workflow", | ||
}, | ||
"configure verification runner": { | ||
"Type": "MethodCall", | ||
"MethodCall": "Payloads['verification_obj'].configure", | ||
"Parameters": { | ||
"output_path": f"{output_dir}", | ||
"lib_items_path": "./schema/library.json", | ||
"plot_option": "+x None", | ||
"fig_size": "+x (6, 5)", | ||
"num_threads": 1, | ||
"preprocessed_data": "Payloads['data_processing_obj']", | ||
}, | ||
"Payloads": {}, | ||
"Next": "run verification", | ||
}, | ||
"run verification": { | ||
"Type": "MethodCall", | ||
"MethodCall": "Payloads['verification_obj'].run", | ||
"Parameters": {}, | ||
"Payloads": {"verification_return": "$"}, | ||
"Next": "check results", | ||
}, | ||
"setup verification": { | ||
"Type": "MethodCall", | ||
"MethodCall": "Verification", | ||
"Parameters": {"verifications": "Payloads['verification_case_obj']"}, | ||
"Payloads": {"verification_obj": "$"}, | ||
"Next": "configure verification runner", | ||
}, | ||
"check results": { | ||
"Type": "MethodCall", | ||
"MethodCall": "glob.glob", | ||
"Parameters": [f"{output_dir}/*_md.json"], | ||
"Payloads": {"length_of_mdjson": "len($)"}, | ||
"Next": "check number of result files", | ||
}, | ||
"check number of result files": { | ||
"Type": "Choice", | ||
"Choices": [ | ||
{ | ||
"Value": "Payloads['length_of_mdjson']", | ||
"Equals": "1", | ||
"Next": "reporting_object_instantiation", | ||
} | ||
], | ||
"Default": "Report Error in workflow", | ||
}, | ||
"reporting_object_instantiation": { | ||
"Type": "MethodCall", | ||
"MethodCall": "Reporting", | ||
"Parameters": { | ||
"verification_json": f"{output_dir}/*_md.json", | ||
"result_md_name": "report_summary.md", | ||
"report_format": "markdown", | ||
}, | ||
"Payloads": {"reporting_obj": "$"}, | ||
"Next": "report_cases", | ||
}, | ||
"report_cases": { | ||
"Type": "MethodCall", | ||
"MethodCall": "Payloads['reporting_obj'].report_multiple_cases", | ||
"Parameters": {}, | ||
"Payloads": {}, | ||
"Next": "Success", | ||
}, | ||
"Success": { | ||
"Type": "MethodCall", | ||
"MethodCall": "print", | ||
"Parameters": [ | ||
"Congratulations! The supply air temperature reset verification workflow is executed with expected results and no error!" | ||
], | ||
"End": "True", | ||
}, | ||
"Report Error in workflow": { | ||
"Type": "MethodCall", | ||
"MethodCall": "logging.error", | ||
"Parameters": ["Something is wrong in the workflow execution"], | ||
"End": "True", | ||
}, | ||
} | ||
|
||
return workflow | ||
|
||
def get_verification_case( | ||
self, | ||
output_dataset_path, | ||
supply_outlet_node, | ||
air_loop, | ||
design_zone_cooling_air_temp, | ||
): | ||
supply_air_temperature_reset_verification_case = { | ||
"no": 1, | ||
"run_simulation": False, | ||
"expected_result": "pass", | ||
"simulation_IO": {"output": output_dataset_path}, | ||
"datapoints_source": { | ||
"idf_output_variables": { | ||
"T_sa_set": { | ||
"subject": supply_outlet_node.nameString(), | ||
"variable": f"{air_loop.nameString()} Supply Outlet Temperature", | ||
"frequency": "detailed", | ||
} | ||
}, | ||
"parameters": {"T_z_coo": design_zone_cooling_air_temp}, | ||
}, | ||
"verification_class": "SupplyAirTempReset", | ||
} | ||
|
||
return {"cases": [supply_air_temperature_reset_verification_case]} | ||
|
||
def run( | ||
self, | ||
model: openstudio.model.Model, | ||
runner: openstudio.measure.OSRunner, | ||
user_arguments: openstudio.measure.OSArgumentMap, | ||
): | ||
""" | ||
Define what happens when the measure is run | ||
""" | ||
super().run(model, runner, user_arguments) | ||
|
||
if not (runner.validateUserArguments(self.arguments(model), user_arguments)): | ||
return False | ||
|
||
air_loop_name = runner.getStringArgumentValue("air_loop_name", user_arguments) | ||
design_zone_cooling_air_temp = runner.getDoubleArgumentValue( | ||
"design_zone_cooling_air_temp", user_arguments | ||
) | ||
output_dataset_path = runner.getStringArgumentValue( | ||
"output_dataset_path", user_arguments | ||
) | ||
output_dir = runner.getStringArgumentValue("output_dir", user_arguments) | ||
|
||
runner.registerInitialCondition("Init") | ||
|
||
air_loop = model.getAirLoopHVACByName(air_loop_name) | ||
if not air_loop.get(): | ||
runner.registerError( | ||
f"AirLoopHVAC '{air_loop_name}' not found in the model" | ||
) | ||
return False | ||
|
||
air_loop = air_loop.get() | ||
|
||
supply_outlet_node = air_loop.supplyOutletNode() | ||
|
||
output_variable = openstudio.model.OutputVariable( | ||
"System Node Temperature", model | ||
) | ||
output_variable.setName(f"{air_loop.name().get()} Supply Outlet Temperature") | ||
output_variable.setKeyValue(f"{supply_outlet_node.name().get()}") | ||
|
||
runner.registerInfo("Added OutputVariable for supply outlet node temperature") | ||
|
||
verification_cases = self.get_verification_case( | ||
output_dataset_path, | ||
supply_outlet_node, | ||
air_loop, | ||
design_zone_cooling_air_temp, | ||
) | ||
|
||
os.makedirs(output_dir, exist_ok=True) | ||
with open(f"{output_dir}/supply_air_temperature_reset_verification_case.json", "w") as f: | ||
json.dump(verification_cases, f, indent=2) | ||
|
||
workflow = self.get_workflow(output_dataset_path, output_dir) | ||
with open(f"{output_dir}/constrain_workflow.json", "w") as f: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comments here. |
||
json.dump(workflow, f, indent=2) | ||
|
||
runner.registerFinalCondition("Done") | ||
return True | ||
|
||
|
||
ConstrainSupplyAirTemperatureResetVerification().registerWithApplication() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the supply_air_temperature_reset_verification_case.json exists all the time?
If not, suggest adding a file exist check first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added line 261 to handle this. open's "w" mode will create a new file if it doesn't exist, but it won't create any directories.