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
2 changes: 1 addition & 1 deletion EMS/Building infiltration.idf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! EMS script for calculating total building infiltration
! Calculates total building infiltration

! Output:Variable,*,Zone Infiltration Current Density Volume Flow Rate,hourly; !- HVAC Average [m3/s]

Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# db-scripts
DesignBuilder functionality may be extended via scripts or plugins.
This repository works as a library to store various examples.

DesignBuilder functionality may be extended via scripts or plugins.
This repository works as a library to store various scripting examples.

There are three different languages to customize simulations:

- EMS: EnergyPlus runtime scripting
- C#: standard C# code can be executed at various hookpoints
- Python: standard Python code can be executed at various hookpoints
- C#: C# code can be executed at various hookpoints
- Python: Python code can be executed at various hookpoints

More on scripting can be found in DesignBuilder help page:
https://designbuilder.co.uk/helpv7.0/#Scripting.htm
More on scripting can be found at:
[DesignBuilder Extensibility](https://designbuilder.co.uk/helpv2025.1/#Extensibility.htm)
218 changes: 109 additions & 109 deletions cs/addCentralDOAS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,79 +21,79 @@ namespace DB.Extensibility.Scripts
{
public class IdfFindAndReplace : ScriptBase, IScript
{
public override void BeforeEnergySimulation()
{
IdfReader idfReader = new IdfReader(
ApiEnvironment.EnergyPlusInputIdfPath,
ApiEnvironment.EnergyPlusInputIddPath
);
public override void BeforeEnergySimulation()
{
IdfReader idfReader = new IdfReader(
ApiEnvironment.EnergyPlusInputIdfPath,
ApiEnvironment.EnergyPlusInputIddPath
);

DoasIdfHandler idfHandler = new DoasIdfHandler(idfReader);
DoasIdfHandler idfHandler = new DoasIdfHandler(idfReader);

List<string> doas1AirLoops = new List<string> { "AIRLOOP1" }; // specify air loops connected to the central DOAS
string chwLoopName = "CHW Loop"; // specify chw loop connected to the central DOAS cooling coil
string hwLoopName = "HW Loop"; // specify hw loop connected to the central DOAS heating coil
string doasName = "DOAS1";
double supplyAirTemperature = 17.5; // supply air temperature in degrees of Celsius
bool includeHX = true;
List<string> doas1AirLoops = new List<string> { "AIRLOOP1" }; // specify air loops connected to the central DOAS
string chwLoopName = "CHW Loop"; // specify chw loop connected to the central DOAS cooling coil
string hwLoopName = "HW Loop"; // specify hw loop connected to the central DOAS heating coil
string doasName = "DOAS1";
double supplyAirTemperature = 17.5; // supply air temperature in degrees of Celsius
bool includeHX = true;

DoasSpecs doas1 = new DoasSpecs(doasName, doas1AirLoops, hwLoopName, chwLoopName, includeHX, supplyAirTemperature);
DoasSpecs doas1 = new DoasSpecs(doasName, doas1AirLoops, hwLoopName, chwLoopName, includeHX, supplyAirTemperature);

// display doas specification (comment out to disable the message box pop-up)
MessageBox.Show(doas1.GetInfo());
// display doas specification (comment out to disable the message box pop-up)
MessageBox.Show(doas1.GetInfo());

idfHandler.LoadDoas(doas1);
}
idfHandler.LoadDoas(doas1);
}
}

public class DoasSpecs
{
public string Name;
public List<string> ChildAirLoops;
public string HwLoopName;
public string ChwLoopName;
public bool IncludeHX;
public double SupplyTemperature;

public DoasSpecs() {}

public DoasSpecs(string name, List<string> childAirLoops, string hwLoopName, string chwLoopName, bool includeHX, double supplyTemperature)
{
Name = name;
ChildAirLoops = childAirLoops;
HwLoopName = hwLoopName;
ChwLoopName = chwLoopName;
IncludeHX = includeHX;
SupplyTemperature = supplyTemperature;
}

public string HwBranchName { get { return this.Name + " DOAS Heating Coil HW Loop Demand Side Branch"; } }
public string ChwBranchName { get { return this.Name + " DOAS Cooling Coil CHW Loop Demand Side Branch"; } }
public string FanName { get { return this.Name + "DOAS OA Supply Fan"; } }
public string HxName { get { return this.Name + " DOAS Heat Recovery Device"; } }
public string OffScheduleName { get { return this.Name + " ALWAYS_OFF"; } }


public string GetInfo()
{
string childLoopNames = String.Join("\n - ", this.ChildAirLoops);
string text = @"DOAS: {0}
public string Name;
public List<string> ChildAirLoops;
public string HwLoopName;
public string ChwLoopName;
public bool IncludeHX;
public double SupplyTemperature;

public DoasSpecs() { }

public DoasSpecs(string name, List<string> childAirLoops, string hwLoopName, string chwLoopName, bool includeHX, double supplyTemperature)
{
Name = name;
ChildAirLoops = childAirLoops;
HwLoopName = hwLoopName;
ChwLoopName = chwLoopName;
IncludeHX = includeHX;
SupplyTemperature = supplyTemperature;
}

public string HwBranchName { get { return this.Name + " DOAS Heating Coil HW Loop Demand Side Branch"; } }
public string ChwBranchName { get { return this.Name + " DOAS Cooling Coil CHW Loop Demand Side Branch"; } }
public string FanName { get { return this.Name + "DOAS OA Supply Fan"; } }
public string HxName { get { return this.Name + " DOAS Heat Recovery Device"; } }
public string OffScheduleName { get { return this.Name + " ALWAYS_OFF"; } }


public string GetInfo()
{
string childLoopNames = String.Join("\n - ", this.ChildAirLoops);
string text = @"DOAS: {0}
HW loop: {1}
CHW loop: {2}
HX included: {3}
Supply temperature: {4}
Child air loops:
- {5}";
return string.Format(text, this.Name, this.HwLoopName, this.ChwLoopName, this.IncludeHX, this.SupplyTemperature, childLoopNames);
}

public string GetIDFObjects()
{
string airLoops = String.Join(",\n", this.ChildAirLoops);
int airLoopCount = this.ChildAirLoops.Count;
string airLoopInlets = String.Join(",\n", this.ChildAirLoops.Select(x => x + " AHU Outdoor Air Inlet"));
string airLoopOutlets = String.Join(",\n", this.ChildAirLoops.Select(x => x + " AHU Relief Air Outlet"));
string idfObjects = @"
return string.Format(text, this.Name, this.HwLoopName, this.ChwLoopName, this.IncludeHX, this.SupplyTemperature, childLoopNames);
}

public string GetIDFObjects()
{
string airLoops = String.Join(",\n", this.ChildAirLoops);
int airLoopCount = this.ChildAirLoops.Count;
string airLoopInlets = String.Join(",\n", this.ChildAirLoops.Select(x => x + " AHU Outdoor Air Inlet"));
string airLoopOutlets = String.Join(",\n", this.ChildAirLoops.Select(x => x + " AHU Relief Air Outlet"));
string idfObjects = @"
!- =========== ALL OBJECTS IN CLASS: SCHEDULE:COMPACT ===========

Schedule:Compact,
Expand Down Expand Up @@ -346,60 +346,60 @@ public string GetIDFObjects()
Controller:WaterCoil,
{0} DOAS Heating Coil Controller;";

return String.Format(idfObjects, this.Name, airLoopCount, airLoops, airLoopOutlets, airLoopInlets, this.SupplyTemperature, this.ChwBranchName, this.HwBranchName);
}
return String.Format(idfObjects, this.Name, airLoopCount, airLoops, airLoopOutlets, airLoopInlets, this.SupplyTemperature, this.ChwBranchName, this.HwBranchName);
}
}

public class DoasIdfHandler
{
public IdfReader Reader;

public DoasIdfHandler(){}

public DoasIdfHandler(IdfReader idfReader)
{
Reader = idfReader;
}

public IdfObject FindObject(string objectType, string objectName)
{
try
{
return this.Reader[objectType].First(c => c[0] == objectName);
}
catch(Exception e)
{
throw new Exception(String.Format("Cannot find object: {0}, type: {1}", objectName, objectType));
}
}

private void AddBranch(string loopName, string branchName)
{
IdfObject branchList = FindObject("branchList", loopName + " Demand Side Branches");
branchList.InsertField(branchList.Count - 1, branchName);

IdfObject splitter = FindObject("Connector:Splitter", loopName + " Demand Splitter");
splitter.InsertField(splitter.Count - 1, branchName);

IdfObject mixer = FindObject( "Connector:Mixer", loopName + " Demand Mixer");
mixer.InsertField(mixer.Count - 1, branchName);
}

public void LoadDoas(DoasSpecs doasSpecs)
{
string doasIdfObjects = doasSpecs.GetIDFObjects();
this.Reader.Load(doasIdfObjects);

AddBranch(doasSpecs.HwLoopName, doasSpecs.HwBranchName);
AddBranch(doasSpecs.ChwLoopName, doasSpecs.ChwBranchName);

if (!doasSpecs.IncludeHX)
{
IdfObject hx = FindObject("HeatExchanger:AirToAir:SensibleAndLatent", doasSpecs.HxName);
hx[1].Value = doasSpecs.OffScheduleName;
}

this.Reader.Save();
}
public IdfReader Reader;

public DoasIdfHandler() { }

public DoasIdfHandler(IdfReader idfReader)
{
Reader = idfReader;
}

public IdfObject FindObject(string objectType, string objectName)
{
try
{
return this.Reader[objectType].First(c => c[0] == objectName);
}
catch (Exception e)
{
throw new Exception(String.Format("Cannot find object: {0}, type: {1}", objectName, objectType));
}
}

private void AddBranch(string loopName, string branchName)
{
IdfObject branchList = FindObject("branchList", loopName + " Demand Side Branches");
branchList.InsertField(branchList.Count - 1, branchName);

IdfObject splitter = FindObject("Connector:Splitter", loopName + " Demand Splitter");
splitter.InsertField(splitter.Count - 1, branchName);

IdfObject mixer = FindObject("Connector:Mixer", loopName + " Demand Mixer");
mixer.InsertField(mixer.Count - 1, branchName);
}

public void LoadDoas(DoasSpecs doasSpecs)
{
string doasIdfObjects = doasSpecs.GetIDFObjects();
this.Reader.Load(doasIdfObjects);

AddBranch(doasSpecs.HwLoopName, doasSpecs.HwBranchName);
AddBranch(doasSpecs.ChwLoopName, doasSpecs.ChwBranchName);

if (!doasSpecs.IncludeHX)
{
IdfObject hx = FindObject("HeatExchanger:AirToAir:SensibleAndLatent", doasSpecs.HxName);
hx[1].Value = doasSpecs.OffScheduleName;
}

this.Reader.Save();
}
}
}
77 changes: 39 additions & 38 deletions cs/addNodeOutputs.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DB.Extensibility.Contracts;
using EpNet;

namespace DB.Extensibility.Scripts

/*
Reporting all node outputs can be difficult as output files tend to be enormous due to
huge amount of data (especially for bigger models).

This script adds requested output ariables only for 'supply side outlet' nodes.
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"

Default variables are:
- System Node Temperature
- System Node Mass Flow Rate

Additional outputs (below) can be added to 'variables' list.

System Node Temperature
System Node Mass Flow Rate
System Node Humidity Ratio
System Node Setpoint Temperature
System Node Setpoint High Temperature
System Node Setpoint Low Temperature
System Node Setpoint Humidity Ratio
System Node Setpoint Minimum Humidity Ratio
System Node Setpoint Maximum Humidity Ratio
System Node Relative Humidity
System Node Pressure
System Node Standard Density Volume Flow Rate
System Node Current Density Volume Flow Rate
System Node Current Density
System Node Specific Heat
System Node Enthalpy
System Node Minimum Temperature
System Node Maximum Temperature
System Node Minimum Limit Mass Flow Rate
System Node Maximum Limit Mass Flow Rate
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
System Node Temperature
System Node Mass Flow Rate

Additional outputs (below) can be added to 'variables' list:
System Node Temperature
System Node Mass Flow Rate
System Node Humidity Ratio
System Node Setpoint Temperature
System Node Setpoint High Temperature
System Node Setpoint Low Temperature
System Node Setpoint Humidity Ratio
System Node Setpoint Minimum Humidity Ratio
System Node Setpoint Maximum Humidity Ratio
System Node Relative Humidity
System Node Pressure
System Node Standard Density Volume Flow Rate
System Node Current Density Volume Flow Rate
System Node Current Density
System Node Specific Heat
System Node Enthalpy
System Node Minimum Temperature
System Node Maximum Temperature
System Node Minimum Limit Mass Flow Rate
System Node Maximum Limit Mass Flow Rate
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
*/

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
{
Expand Down
Loading