Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 77 additions & 38 deletions cs/addNodeOutputs.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
/*
Reporting all node outputs can be difficult as output files tend to be enormous due to
huge amount of data (especially for bigger models).
Targeted Node Output Variable Request Script

This script adds requested output ariables only for defined nodes:
"Supply Side Outlet Node Names"
"Plant Side Outlet Node Name"
"Condenser Side Outlet Node Name"
This DesignBuilder C# script adds Output:Variable objects for a limited set of node names to help avoid extremely large output files that can occur when reporting variables for all nodes in large models.

Default variables are:
System Node Temperature
System Node Mass Flow Rate
Purpose
The script reduces output size by requesting only selected node output variables for outlet nodes referenced by:
- AirLoopHVAC: "Supply Side Outlet Node Names"
- PlantLoop: "Plant Side Outlet Node Name"
- CondenserLoop: "Condenser Side Outlet Node Name"

Main Steps
1) Load the EnergyPlus IDF using EpNet IdfReader.
2) Collect outlet node names from AirLoopHVAC, PlantLoop and CondenserLoop objects.
- If a node name ends with "List", it is assumed to reference a NodeList object, and the script uses the first node entry in that NodeList.
3) For each requested variable name, add Output:Variable objects for each collected node.
4) Save the modified IDF before the EnergyPlus simulation runs.

Additional outputs (below) can be added to 'variables' list:
How to Use

Configuration
- requestedVariables:
Add/remove entries using the exact EnergyPlus variable names you want to request:
System Node Temperature
System Node Mass Flow Rate
System Node Humidity Ratio
Expand All @@ -36,48 +45,68 @@ System Node Minimum Available Mass Flow Rate
System Node Maximum Available Mass Flow Rate
System Node Setpoint Mass Flow Rate
System Node Requested Mass Flow Rate
- reportingFrequency:
Set to a valid Output:Variable reporting frequency string.

Prerequisites
Base model must contain the required objects/fields:
- AirLoopHVAC objects (Supply Side Outlet Node Names)
- PlantLoop objects (Plant Side Outlet Node Name)
- CondenserLoop objects (Condenser Side Outlet Node Name)
If any of these fields reference a NodeList, the NodeList object must exist in the IDF.

DISCLAIMER: This script is provided as-is without warranty. DesignBuilder takes no responsibility for simulation results, accuracy, or any issues arising from the use of this script. Users are responsible for validating all outputs and ensuring the script meets their specific modeling requirements.
*/

using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DB.Extensibility.Contracts;
using EpNet;

namespace DB.Extensibility.Scripts
{
public class IdfFindAndReplace : ScriptBase, IScript
// Adds Output:Variable requests for specific node variables and specific outlet nodes only.
public class AddTargetedNodeOutputVariables : ScriptBase, IScript
{
private List<string> FindNodes(IdfReader idfReader, string objectName, string fieldName)
// Collect node names from a given IDF object type and field name.
// If a value ends with "List", it is treated as a NodeList reference and the first node entry is used.
private List<string> CollectOutletNodeNames(IdfReader idfReader, string idfObjectType, string nodeFieldName)
{
List<string> nodes = new List<string>();
IEnumerable<IdfObject> idfObjects = idfReader[objectName];
var nodeNames = new List<string>();
IEnumerable<IdfObject> objectsOfType = idfReader[idfObjectType];

foreach (IdfObject idfObject in idfObjects)
foreach (IdfObject obj in objectsOfType)
{
string nodeName = idfObject[fieldName];
string nodeOrListName = obj[nodeFieldName];

if (nodeName.EndsWith("List"))
if (nodeOrListName.EndsWith("List"))
{
IdfObject nodeList = idfReader["NodeList"].First(item => item[0] == nodeName);
nodeName = nodeList[1];
IdfObject nodeList = idfReader["NodeList"].First(item => item[0] == nodeOrListName);
nodeOrListName = nodeList[1];
}
nodes.Add(nodeName);

nodeNames.Add(nodeOrListName);
}
return nodes;

return nodeNames;
}

private void AddOuputVariable(IdfReader idfReader, string key, string name, string frequency)
private void AddOutputVariable(IdfReader idfReader, string nodeName, string variableName, string reportingFrequency)
{
string outputVariable = string.Format("Output:Variable, {0}, {1}, {2};", key, name, frequency);
idfReader.Load(outputVariable);
string outputVariableObject = string.Format(
"Output:Variable, {0}, {1}, {2};",
nodeName,
variableName,
reportingFrequency);

idfReader.Load(outputVariableObject);
}

private void AddNodeVariables(IdfReader idfReader, List<string> nodes, string name, string frequency)
private void AddVariablesForNodes(IdfReader idfReader, List<string> nodeNames, string variableName, string reportingFrequency)
{
foreach (string node in nodes)
foreach (string nodeName in nodeNames)
{
AddOuputVariable(idfReader, node, name, frequency);
AddOutputVariable(idfReader, nodeName, variableName, reportingFrequency);
}
}

Expand All @@ -87,19 +116,29 @@ public override void BeforeEnergySimulation()
ApiEnvironment.EnergyPlusInputIdfPath,
ApiEnvironment.EnergyPlusInputIddPath);

List<string> airLoopNodes = FindNodes(idfReader, "AirLoopHVAC", "Supply Side Outlet Node Names");
List<string> plantLoopNodes = FindNodes(idfReader, "PlantLoop", "Plant Side Outlet Node Name");
List<string> condenserLoopNodes = FindNodes(idfReader, "CondenserLoop", "Condenser Side Outlet Node Name");
// Collect outlet nodes from the three loop types (Air, Plant, Condenser)
List<string> airLoopOutletNodes = CollectOutletNodeNames(idfReader, "AirLoopHVAC", "Supply Side Outlet Node Names");
List<string> plantLoopOutletNodes = CollectOutletNodeNames(idfReader, "PlantLoop", "Plant Side Outlet Node Name");
List<string> condenserLoopOutletNodes = CollectOutletNodeNames(idfReader, "CondenserLoop", "Condenser Side Outlet Node Name");

// ----------------------------
// USER CONFIGURATION SECTION
// ----------------------------
// Add additional EnergyPlus Output:Variable names to the list below as required.
List<string> requestedVariables = new List<string>
{
"System Node Temperature",
"System Node Mass Flow Rate"
};

// Request node variables (listed in description above) by adding them into list below
List<string> variables = new List<string> { "System Node Temperature", "System Node Mass Flow Rate" };
const string frequency = "hourly";
// Add desired reporting frequency
const string reportingFrequency = "hourly";

foreach (string variable in variables)
foreach (string variableName in requestedVariables)
{
AddNodeVariables(idfReader, plantLoopNodes, variable, frequency);
AddNodeVariables(idfReader, airLoopNodes, variable, frequency);
AddNodeVariables(idfReader, condenserLoopNodes, variable, frequency);
AddVariablesForNodes(idfReader, plantLoopOutletNodes, variableName, reportingFrequency);
AddVariablesForNodes(idfReader, airLoopOutletNodes, variableName, reportingFrequency);
AddVariablesForNodes(idfReader, condenserLoopOutletNodes, variableName, reportingFrequency);
}

idfReader.Save();
Expand Down
Loading