diff --git a/EMS/Building infiltration.idf b/EMS/Building infiltration.idf index 94699ca..6b28b21 100644 --- a/EMS/Building infiltration.idf +++ b/EMS/Building infiltration.idf @@ -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] diff --git a/README.md b/README.md index 72a6a9a..a1ff298 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file +More on scripting can be found at: +[DesignBuilder Extensibility](https://designbuilder.co.uk/helpv2025.1/#Extensibility.htm) diff --git a/cs/addCentralDOAS.cs b/cs/addCentralDOAS.cs index f232874..525cdde 100644 --- a/cs/addCentralDOAS.cs +++ b/cs/addCentralDOAS.cs @@ -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 doas1AirLoops = new List { "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 doas1AirLoops = new List { "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 ChildAirLoops; - public string HwLoopName; - public string ChwLoopName; - public bool IncludeHX; - public double SupplyTemperature; - - public DoasSpecs() {} - - public DoasSpecs(string name, List 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 ChildAirLoops; + public string HwLoopName; + public string ChwLoopName; + public bool IncludeHX; + public double SupplyTemperature; + + public DoasSpecs() { } + + public DoasSpecs(string name, List 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, @@ -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(); + } } } diff --git a/cs/addNodeOutputs.cs b/cs/addNodeOutputs.cs index b650fa3..1dda07c 100644 --- a/cs/addNodeOutputs.cs +++ b/cs/addNodeOutputs.cs @@ -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 { diff --git a/cs/addPipe.cs b/cs/addPipe.cs index 1248d4e..7ae41bd 100644 --- a/cs/addPipe.cs +++ b/cs/addPipe.cs @@ -1,7 +1,8 @@ /* -This C# script is designed to enhance the functionality by providing an option to add Pipe:Indoor and Pipe:Outdoor objects to an IDF file. - +This C# script is designed to enhance the functionality by providing an option to +add Pipe:Indoor and Pipe:Outdoor objects to an IDF file. */ + using System.Runtime; using System; using System.Linq; @@ -99,7 +100,8 @@ public void UpdatePlantLoopNode(IdfReader reader, string originalOutletNodeName, public string GetIndoorPipe(string name, string inletNodeName, string outletNodeName, string pipeConstructionName, string zoneName, double pipeInsideDiameter, double pipeLength) { - string pipe = @" Pipe:Indoor, + string pipe = @" +Pipe:Indoor, {0}, !- Name {1}, !- Construction Name {2}, !- Fluid Inlet Node Name @@ -115,7 +117,8 @@ public string GetIndoorPipe(string name, string inletNodeName, string outletNode public string GetOutdoorPipe(string name, string inletNodeName, string outletNodeName, string pipeConstructionName, double pipeInsideDiameter, double pipeLength) { - string pipe = @" Pipe:Outdoor, + string pipe = @" +Pipe:Outdoor, {0}, !- Construction Name {1}, !- Fluid Inlet Node Name {2}, !- Fluid Outlet Node Name @@ -124,7 +127,7 @@ public string GetOutdoorPipe(string name, string inletNodeName, string outletNod {4}, !- Pipe Inside Diameter {5}; !- pipe length - OutdoorAir:Node, +OutdoorAir:Node, {0} Outdoor Air Node; !- Name"; return String.Format(CultureInfo.InvariantCulture, pipe, name, pipeConstructionName, inletNodeName, outletNodeName, pipeInsideDiameter, pipeLength); } @@ -174,12 +177,13 @@ public void AddInsulatedPipe(IdfReader reader, string pipeConstructionName, doub { string pipeInsulationName = pipeConstructionName + " insulation"; string pipeSteelName = pipeConstructionName + " steel"; - string pipeConstructionTemplate = @" Construction, + string pipeConstructionTemplate = @" +Construction, {0}, !-Name {1}, !-Outside Layer {2}; !-Layer 2 - Material, +Material, {1}, !- Name VeryRough, !- Roughness {3}, !- Thickness m @@ -190,7 +194,7 @@ public void AddInsulatedPipe(IdfReader reader, string pipeConstructionName, doub 0.5, !- Solar Absorptance 0.5; !- Visible Absorptance - Material, +Material, {2}, !- Name Smooth, !- Roughness 3.00E-03, !- Thickness m @@ -200,7 +204,6 @@ public void AddInsulatedPipe(IdfReader reader, string pipeConstructionName, doub 0.9, !- Thermal Absorptance 0.5, !- Solar Absorptance 0.5; !- Visible Absorptance - "; string pipeConstruction = String.Format(CultureInfo.InvariantCulture, pipeConstructionTemplate, pipeConstructionName, pipeInsulationName, pipeSteelName, insulationThickness); reader.Load(pipeConstruction); diff --git a/cs/addReturnRegenerationCoil.cs b/cs/addReturnRegenerationCoil.cs index 845c12f..1c9040e 100644 --- a/cs/addReturnRegenerationCoil.cs +++ b/cs/addReturnRegenerationCoil.cs @@ -19,7 +19,8 @@ public class IdfFindAndReplace : ScriptBase, IScript { string[] airLoopNames = new string[] { "Air Loop" }; - string coilBoilerPlate = @"Coil:Heating:Electric, + string coilBoilerPlate = @" +Coil:Heating:Electric, {0}, !- Name {0} Availability, !- Availability Schedule Name 1.00, !- Efficiency (%) diff --git a/cs/addReturnStreamCooler.cs b/cs/addReturnStreamCooler.cs index 0ddfc6f..b178fec 100644 --- a/cs/addReturnStreamCooler.cs +++ b/cs/addReturnStreamCooler.cs @@ -19,7 +19,8 @@ public class IdfFindAndReplace : ScriptBase, IScript { string[] airLoopNames = new string[] { "Air Loop" }; - string coolerBoilerPlate = @"EvaporativeCooler:Direct:ResearchSpecial, + string coolerBoilerPlate = @" +EvaporativeCooler:Direct:ResearchSpecial, {0}, !- Name {0} Availability, !- Availability Schedule Name 0.7 , !- Cooler Design Effectiveness diff --git a/cs/addSolarTranspiredCollector.cs b/cs/addSolarTranspiredCollector.cs index b74e248..0a95f28 100644 --- a/cs/addSolarTranspiredCollector.cs +++ b/cs/addSolarTranspiredCollector.cs @@ -166,7 +166,8 @@ public SolarCollectorProperties(string name, public string GetIdfString() { - string solarCollectorTemplate = @" SurfaceProperty:OtherSideConditionsModel, + string solarCollectorTemplate = @" +SurfaceProperty:OtherSideConditionsModel, {0} Conditions Model, !- Name GapConvectionRadiation; !- Type of Modeling @@ -226,7 +227,7 @@ public string GetIdfString() ); } } - + public class SolarCollectorMultisystem { public string SolarCollectorName { get; set; } @@ -239,10 +240,12 @@ public SolarCollectorMultisystem(string solarCollectorName) public string GetIdfString() { - string template = @" SolarCollector:UnglazedTranspired:Multisystem, + string template = @" +SolarCollector:UnglazedTranspired:Multisystem, {0}, !- Solar Collector Name" + Environment.NewLine; - string nodesTemplate = @" {0}, !- Outdoor Air System {5} Collector Inlet Node + string nodesTemplate = @" + {0}, !- Outdoor Air System {5} Collector Inlet Node {1}, !- Outdoor Air System {5} Collector Outlet Node {2}, !- Outdoor Air System {5} Mixed Air Node {3}{4} !- Outdoor Air System {5} Zone Node" + Environment.NewLine; @@ -267,7 +270,8 @@ public string GetIdfString() public void AddFreeHeatingSetpointSchedule(string name, double setpoint) { - string template = @" Schedule:Compact, + string template = @" +Schedule:Compact, {0}, !- Name Temperature, !- Schedule Type Limits Name Through: 12/31, !- Field 1 @@ -351,7 +355,8 @@ public MultisystemNodeSpecification AddTranspiredCollectorToAirLoop(string solar public void AddSolarCollectorOutputs() { - string variables = @"Output:Variable,*,Solar Collector Heat Exchanger Effectiveness,hourly; !- HVAC Average [] + string variables = @" +Output:Variable,*,Solar Collector Heat Exchanger Effectiveness,hourly; !- HVAC Average [] Output:Variable,*,Solar Collector Leaving Air Temperature,hourly; !- HVAC Average [C] Output:Variable,*,Solar Collector Outside Face Suction Velocity,hourly; !- HVAC Average [m/s] Output:Variable,*,Solar Collector Surface Temperature,hourly; !- HVAC Average [C] diff --git a/cs/additionalCoolingOUtputs.cs b/cs/additionalCoolingOUtputs.cs index a5bbce8..4e23c1f 100644 --- a/cs/additionalCoolingOUtputs.cs +++ b/cs/additionalCoolingOUtputs.cs @@ -1,3 +1,13 @@ +/* + Adds additional EnergyPlus output variables to the cooling + simulation IDF. Actions performed by the script: + - Loads an Output:Variable for "People Latent Gain Rate" at Timestep + reporting frequency. + - Saves the modified IDF before the cooling simulation runs. + Usage: + - Attach this script to run before the cooling simulation. +*/ + using System.Runtime; using System.Collections.Generic; using DB.Extensibility.Contracts; diff --git a/cs/ahuNightVentilationManager.cs b/cs/ahuNightVentilationManager.cs index 12a1790..40bb26d 100644 --- a/cs/ahuNightVentilationManager.cs +++ b/cs/ahuNightVentilationManager.cs @@ -12,11 +12,12 @@ using EpNet; namespace DB.Extensibility.Scripts -{ - public class IdfFindAndReplace : ScriptBase, IScript +{ + public class IdfFindAndReplace : ScriptBase, IScript { // Define IDF templates - readonly string nightVentilationTemplate = @"AvailabilityManager:NightVentilation, + readonly string nightVentilationTemplate = @" +AvailabilityManager:NightVentilation, {0}, !- Name Night Ventilation Applicability Schedule, !- Applicability Schedule Name {1}, !- Fan Schedule Name @@ -26,7 +27,8 @@ public class IdfFindAndReplace : ScriptBase, IScript 0.5, !- Night Venting Flow Fraction {2}; !- Control Zone Name"; - readonly string commonObjects = @"Schedule:Compact, + readonly string commonObjects = @" +Schedule:Compact, Night Ventilation Setpoint Schedule, !- Name Any Number, !- Schedule Type Limits Name Through: 12/31, !- Field 1 @@ -107,7 +109,7 @@ public override void BeforeEnergySimulation() StringBuilder idfContent = new StringBuilder(); foreach (var pair in loopControlZonePairs) - { + { string airLoopName = pair.Key; string controlZoneName = pair.Value; diff --git a/cs/applyDesiccantDehumidifier.cs b/cs/applyDesiccantDehumidifier.cs index de6e118..4509652 100644 --- a/cs/applyDesiccantDehumidifier.cs +++ b/cs/applyDesiccantDehumidifier.cs @@ -21,7 +21,8 @@ namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript { - string dehumidifierBoilerplate = @" Dehumidifier:Desiccant:NoFans, + string dehumidifierBoilerplate = @" +Dehumidifier:Desiccant:NoFans, {0} Desiccant Dehumidifier,!- Name {0} Dehumidifier Schedule, !- Availability Schedule Name {1}, !- Process Air Inlet Node Name @@ -41,7 +42,8 @@ public class IdfFindAndReplace : ScriptBase, IScript OutdoorAir:Node,{0} Outside Air Inlet Node 2;"; - string dehumidifierFanBoilerplate = @" Fan:VariableVolume, + string dehumidifierFanBoilerplate = @" +Fan:VariableVolume, {0} Desiccant Regen Fan, !- Name {0} Dehumidifier Schedule, !- Availability Schedule Name 0.7, !- Fan Total Efficiency @@ -60,7 +62,8 @@ public class IdfFindAndReplace : ScriptBase, IScript {0} Outside Air Inlet Node 2,!- Air Inlet Node Name {0} Regen Fan Outlet Node; !- Air Outlet Node Name"; - string dehumidifierWaterCoilBoilerplate = @" Coil:Heating:Water, + string dehumidifierWaterCoilBoilerplate = @" +Coil:Heating:Water, {0} Desiccant Regen Coil, ! - Component name {0} Dehumidifier Schedule, ! - Availability schedule autosize, ! - U-factor times area value of coil (W/K) @@ -85,7 +88,8 @@ public class IdfFindAndReplace : ScriptBase, IScript {0} Desiccant Heating Coil Water Inlet Node, ! - Component 1 inlet node name {0} Desiccant Heating Coil Water Outlet Node; ! - Component 1 outlet node name"; - string dehumidifierCoilBoilerplate = @" Coil:Heating:Fuel, + string dehumidifierCoilBoilerplate = @" +Coil:Heating:Fuel, {0} Desiccant Regen Coil, !- Name {0} Dehumidifier Schedule, !- Availability Schedule Name NaturalGas, !- Fuel Type @@ -94,7 +98,8 @@ public class IdfFindAndReplace : ScriptBase, IScript {0} Regen Fan Outlet Node, !- Air Inlet Node Name {0} Desiccant Heating Coil Air Outlet Node; !- Air Outlet Node Name"; - string dehumidifierScheduleBoilerplate = @" Schedule:Compact, + string dehumidifierScheduleBoilerplate = @" +Schedule:Compact, {0} Dehumidifier Schedule,! Name Any Number, ! Type Through: 12/31, ! Type @@ -102,7 +107,9 @@ public class IdfFindAndReplace : ScriptBase, IScript Until: 24:00, ! All hours in day 1;"; - string dehumidifierSpmBoilerplate = @" SetpointManager:MultiZone:Humidity:Maximum, + string dehumidifierSpmBoilerplate = @" + +SetpointManager:MultiZone:Humidity:Maximum, {0} Humidity Setpoint Manager, ! - Component name {0}, ! - HVAC air loop name .005, ! - Minimum setpoint humidity ratio (kg/kg) @@ -128,7 +135,7 @@ public override void BeforeEnergySimulation() public void AddDesiccantDehumidifier( IdfReader idfReader, - string airLoopName, + string airLoopName, int position, int regenerationCoilCapacity, RegenerationCoilType regenerationCoilType = RegenerationCoilType.Fuel, @@ -142,7 +149,7 @@ public void AddDesiccantDehumidifier( // calculate index of the field set in the main branch int dehumidfierBranchIndex = 2 + (position - 1) * 4; - + // update component nodes string processInletNode = ahuMainBranch[dehumidfierBranchIndex - 1].Value; string processOutletNode = airLoopName + " Desiccant Process Outlet Node"; @@ -157,7 +164,7 @@ public void AddDesiccantDehumidifier( { IdfObject coil = FindObject(idfReader, nextComponent["Heating Coil Object Type"].Value, nextComponent["Heating Coil Name"].Value); coil["Air Inlet Node Name"].Value = processOutletNode; - } + } else if (nextComponentType.Equals("CoilSystem:Cooling:DX", StringComparison.OrdinalIgnoreCase)) { IdfObject coil = FindObject(idfReader, nextComponent["Cooling Coil Object Type"].Value, nextComponent["Cooling Coil Name"].Value); diff --git a/cs/applyDesiccantDehumidifierBalancedFlow.cs b/cs/applyDesiccantDehumidifierBalancedFlow.cs index 2524aa9..1441795 100644 --- a/cs/applyDesiccantDehumidifierBalancedFlow.cs +++ b/cs/applyDesiccantDehumidifierBalancedFlow.cs @@ -17,7 +17,8 @@ namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript { - string desiccantHxBoilerplate = @" HeatExchanger:Desiccant:BalancedFlow, + string desiccantHxBoilerplate = @" +HeatExchanger:Desiccant:BalancedFlow, {0}, !- Name ON 24/7, !- Availability Schedule Name {1}, !- Regeneration Air Inlet Node Name @@ -27,7 +28,7 @@ public class IdfFindAndReplace : ScriptBase, IScript HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, !- Heat Exchanger Performance Object Type HXDesPerf1; !- Heat Exchanger Performance Name - HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, +HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, HXDesPerf1, !- Name 1.90, !- Nominal Air Flow Rate m3/s 3.54, !- Nominal Air Face Velocity m/s diff --git a/cs/applyDesiccantDehumidifierOaSystem.cs b/cs/applyDesiccantDehumidifierOaSystem.cs index 25b32cb..663b2c6 100644 --- a/cs/applyDesiccantDehumidifierOaSystem.cs +++ b/cs/applyDesiccantDehumidifierOaSystem.cs @@ -18,7 +18,8 @@ namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript { - string dehumidifierBoilerplate = @" Dehumidifier:Desiccant:NoFans, + string dehumidifierBoilerplate = @" +Dehumidifier:Desiccant:NoFans, {0}, !- Name {1}, !- Availability Schedule Name {2}, !- Process Air Inlet Node Name @@ -38,7 +39,8 @@ public class IdfFindAndReplace : ScriptBase, IScript OutdoorAir:Node, Outside Air Inlet Node 2;"; - string dehumidifierFanBoilerplate = @" Fan:VariableVolume, + string dehumidifierFanBoilerplate = @" +Fan:VariableVolume, {0}, !- Name {1}, !- Availability Schedule Name 0.7, !- Fan Total Efficiency @@ -57,7 +59,8 @@ public class IdfFindAndReplace : ScriptBase, IScript {2}, !- Air Inlet Node Name Regen Fan Outlet Node; !- Air Outlet Node Name"; - string dehumidifierCoilBoilerplate = @" Coil:Heating:Electric, + string dehumidifierCoilBoilerplate = @" +Coil:Heating:Electric, {0}, !- Name {1}, !- Availability Schedule Name 1.0, !- Efficiency @@ -65,14 +68,16 @@ public class IdfFindAndReplace : ScriptBase, IScript Regen Fan Outlet Node, !- Air Inlet Node Name Desiccant Heating Coil Air Outlet Node; !- Air Outlet Node Name"; - string dehumidifierScheduleBoilerplate = @" Schedule:Compact, {0}, ! Name + string dehumidifierScheduleBoilerplate = @" +Schedule:Compact, {0}, ! Name Any Number, ! Type Through: 12/31, ! Type For: AllDays, ! All days in year Until: 24:00, ! All hours in day 1;"; - string dehumidifierSpmBoilerplate = @" SetpointManager:MultiZone:Humidity:Maximum, + string dehumidifierSpmBoilerplate = @" +SetpointManager:MultiZone:Humidity:Maximum, Humidity Setpoint Manager, ! - Component name {0}, ! - HVAC air loop name .005, ! - Minimum setpoint humidity ratio (kg/kg) @@ -124,7 +129,7 @@ public void AddDesiccantDehumifierToOaSystem(IdfReader reader, string airLoopNam // Define the regeneration inlet node, this can be either the air loop relief or outdoor air node string regenerationInletNode = hxObject["Exhaust Air Outlet Node Name"].Value; - + // Load all desiccant dehumidifer related objects string scheduleName = airLoopName + " Desiccant unit schedule"; string dehumidifierSchedule = String.Format(dehumidifierScheduleBoilerplate, scheduleName); @@ -139,13 +144,13 @@ public void AddDesiccantDehumifierToOaSystem(IdfReader reader, string airLoopNam string dehumidifier = String.Format( dehumidifierBoilerplate, - desiccantDehumidifierName, + desiccantDehumidifierName, scheduleName, processInletNode, processOutletNode, dehumidifierCoilType, - regenerationInletNode, - dehumidifierCoilName, + regenerationInletNode, + dehumidifierCoilName, dehumidiferFanName ); diff --git a/cs/applyDesiccantSystemDehumidifier.cs b/cs/applyDesiccantSystemDehumidifier.cs index ea9d1b2..8d51fdf 100644 --- a/cs/applyDesiccantSystemDehumidifier.cs +++ b/cs/applyDesiccantSystemDehumidifier.cs @@ -21,7 +21,8 @@ namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript { - string dehumidifierBoilerplate = @" Dehumidifier:Desiccant:System, + string dehumidifierBoilerplate = @" +Dehumidifier:Desiccant:System, {0} Desiccant Dehumidifier,!- Name {0} Dehumidifier Schedule, !- Availability Schedule Name HeatExchanger:Desiccant:BalancedFlow, !- Desiccant Heat Exchanger Object Type @@ -41,7 +42,7 @@ public class IdfFindAndReplace : ScriptBase, IScript 50, !- Exhaust Fan Maximum Power W {0} ExhaustFanPerfCurve; !- Exhaust Fan Power Curve Name - HeatExchanger:Desiccant:BalancedFlow, +HeatExchanger:Desiccant:BalancedFlow, {0} Desiccant Heat Exchanger, !- Name {0} Dehumidifier Schedule, !- Availability Schedule Name {0} Regen Fan Outlet Node,!- Regeneration Air Inlet Node Name @@ -51,7 +52,7 @@ public class IdfFindAndReplace : ScriptBase, IScript HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, !- Heat Exchanger Performance Object Type HXDesPerf1; !- Heat Exchanger Performance Name - Fan:SystemModel, +Fan:SystemModel, {0} Desiccant Regen Fan, !- Name {0} Dehumidifier Schedule, !- Availability Schedule Name {0} Outside Air Inlet Node 3,!- Air Inlet Node Name @@ -69,7 +70,7 @@ public class IdfFindAndReplace : ScriptBase, IScript 0.7, !- Fan Total Efficiency {0} FanPerfCurve; ! - Electric Power Function of Flow Fraction Curve Name - Curve:Quartic, +Curve:Quartic, {0} FanPerfCurve, ! Curve Name 0, ! CoefficientC1 1, ! CoefficientC2 @@ -81,7 +82,7 @@ public class IdfFindAndReplace : ScriptBase, IScript 0, ! Minimum Curve Output 1; ! Maximum Curve Output - Curve:Cubic, +Curve:Cubic, {0} ExhaustFanPerfCurve, !- Name 0, !- Coefficient1 Constant 1, !- Coefficient2 x @@ -93,7 +94,7 @@ public class IdfFindAndReplace : ScriptBase, IScript OutdoorAir:Node,{0} Outside Air Inlet Node 2; OutdoorAir:Node,{0} Outside Air Inlet Node 3; - Schedule:Compact, +Schedule:Compact, {0} Dehumidifier Schedule,! Name Any Number, ! Type Through: 12/31, ! Type @@ -101,14 +102,15 @@ public class IdfFindAndReplace : ScriptBase, IScript Until: 24:00, ! All hours in day 1; - SetpointManager:MultiZone:Humidity:Maximum, +SetpointManager:MultiZone:Humidity:Maximum, {0} Humidity Setpoint Manager, ! - Component name {0}, ! - HVAC air loop name .005, ! - Minimum setpoint humidity ratio (kg/kg) .012, ! - Maximum setpoint humidity ratio (kg/kg) {2}; ! - Setpoint node list"; - string desiccantHeatExchangerPerf = @" HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, + string desiccantHeatExchangerPerf = @" +HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, HXDesPerf1, !- Name 1.05, !- Nominal Air Flow Rate {m3/s} 3.25, !- Nominal Air Face Velocity {m/s} diff --git a/cs/applyDesiccantSystemDehumidifierOaSystem.cs b/cs/applyDesiccantSystemDehumidifierOaSystem.cs index 54d04bb..b8bc11c 100644 --- a/cs/applyDesiccantSystemDehumidifierOaSystem.cs +++ b/cs/applyDesiccantSystemDehumidifierOaSystem.cs @@ -21,7 +21,8 @@ namespace DB.Extensibility.Scripts { public class DesiccantDehumidifierOaSystemScript : ScriptBase, IScript { - string dehumidifierBoilerplate = @" Dehumidifier:Desiccant:System, + string dehumidifierBoilerplate = @" +Dehumidifier:Desiccant:System, {0} Desiccant Dehumidifier,!- Name {0} Dehumidifier Schedule, !- Availability Schedule Name HeatExchanger:Desiccant:BalancedFlow, !- Desiccant Heat Exchanger Object Type @@ -41,7 +42,7 @@ public class DesiccantDehumidifierOaSystemScript : ScriptBase, IScript 50, !- Exhaust Fan Maximum Power W {0} ExhaustFanPerfCurve; !- Exhaust Fan Power Curve Name - HeatExchanger:Desiccant:BalancedFlow, +HeatExchanger:Desiccant:BalancedFlow, {0} Desiccant Heat Exchanger, !- Name {0} Dehumidifier Schedule, !- Availability Schedule Name {0} Regen Fan Outlet Node,!- Regeneration Air Inlet Node Name @@ -51,7 +52,7 @@ public class DesiccantDehumidifierOaSystemScript : ScriptBase, IScript HeatExchanger:Desiccant:BalancedFlow:PerformanceDataType1, !- Heat Exchanger Performance Object Type HXDesPerf1; !- Heat Exchanger Performance Name - Fan:SystemModel, +Fan:SystemModel, {0} Desiccant Regen Fan, !- Name {0} Dehumidifier Schedule, !- Availability Schedule Name {0} Outside Air Inlet Node 3,!- Air Inlet Node Name @@ -69,7 +70,7 @@ public class DesiccantDehumidifierOaSystemScript : ScriptBase, IScript 0.7, !- Fan Total Efficiency {0} FanPerfCurve; ! - Electric Power Function of Flow Fraction Curve Name - Curve:Quartic, +Curve:Quartic, {0} FanPerfCurve, ! Curve Name 0, ! CoefficientC1 1, ! CoefficientC2 @@ -81,7 +82,7 @@ public class DesiccantDehumidifierOaSystemScript : ScriptBase, IScript 0, ! Minimum Curve Output 1; ! Maximum Curve Output - Curve:Cubic, +Curve:Cubic, {0} ExhaustFanPerfCurve, !- Name 0, !- Coefficient1 Constant 1, !- Coefficient2 x diff --git a/cs/applyDesuperheaterGenericAhu.cs b/cs/applyDesuperheaterGenericAhu.cs index e5bf54a..609f5bd 100644 --- a/cs/applyDesuperheaterGenericAhu.cs +++ b/cs/applyDesuperheaterGenericAhu.cs @@ -15,81 +15,82 @@ The AHU needs to contain DX cooling coil and use "desuperheater" string in its n namespace DB.Extensibility.Scripts { - public class IdfFindAndReplace : ScriptBase, IScript - { + public class IdfFindAndReplace : ScriptBase, IScript + { - private IdfObject FindObject(IdfReader reader, string objectType, string objectName) { - return reader[objectType].First(c => c[0] == objectName); - } + private IdfObject FindObject(IdfReader reader, string objectType, string objectName) + { + return reader[objectType].First(c => c[0] == objectName); + } - private void UpdateBranches(IdfReader idfReader) - { - IEnumerable branches = idfReader["Branch"]; - foreach (IdfObject branch in branches) - { - if (branch[0].Value.Contains("desuperheater") && branch[0].Value.Contains("AHU Main Branch")) - { - UpdateBranch(idfReader, branch); - } - } - } + private void UpdateBranches(IdfReader idfReader) + { + IEnumerable branches = idfReader["Branch"]; + foreach (IdfObject branch in branches) + { + if (branch[0].Value.Contains("desuperheater") && branch[0].Value.Contains("AHU Main Branch")) + { + UpdateBranch(idfReader, branch); + } + } + } - private void UpdateBranch(IdfReader reader, IdfObject branch) - { - const string DesuperHeaterObject = "Coil:Heating:Desuperheater"; - const string ElectricCoilObject = "Coil:Heating:Electric"; - const string DxSystemObjectName = "CoilSystem:Cooling:DX"; - IdfObject DxCoil = new IdfObject(); - bool DxIncluded = false; + private void UpdateBranch(IdfReader reader, IdfObject branch) + { + const string DesuperHeaterObject = "Coil:Heating:Desuperheater"; + const string ElectricCoilObject = "Coil:Heating:Electric"; + const string DxSystemObjectName = "CoilSystem:Cooling:DX"; + IdfObject DxCoil = new IdfObject(); + bool DxIncluded = false; - foreach (int i in Enumerable.Range(1, (branch.Count - 2))) - { - Field ThisField = branch.Fields[i]; - Field NextField = branch.Fields[i + 1]; - if (ThisField.Value.Contains(DxSystemObjectName)) - { - MessageBox.Show("DX Coil System included " + branch[0]); - DxIncluded = true; - IdfObject CoilSystem = FindObject(reader, DxSystemObjectName, NextField.Value); - DxCoil = FindObject(reader, CoilSystem["Cooling Coil Object Type"], CoilSystem["Cooling Coil Name"]); - - } + foreach (int i in Enumerable.Range(1, (branch.Count - 2))) + { + Field ThisField = branch.Fields[i]; + Field NextField = branch.Fields[i + 1]; + if (ThisField.Value.Contains(DxSystemObjectName)) + { + MessageBox.Show("DX Coil System included " + branch[0]); + DxIncluded = true; + IdfObject CoilSystem = FindObject(reader, DxSystemObjectName, NextField.Value); + DxCoil = FindObject(reader, CoilSystem["Cooling Coil Object Type"], CoilSystem["Cooling Coil Name"]); - if (DxIncluded && ThisField.Comment.ToLower().Contains("object type") && ThisField.Value.ToLower() == ElectricCoilObject.ToLower()) - { - IdfObject ElectricCoil = FindObject(reader, ElectricCoilObject, NextField.Value); - ThisField.Value = DesuperHeaterObject; - AddDesuperheater(reader, ElectricCoil, DxCoil); - MessageBox.Show("Replacing electric heating coil: " + ElectricCoil[0] + " with desuperheater coil." ); - reader.Remove(ElectricCoil); - break; - } - } - } - private void AddDesuperheater(IdfReader reader, IdfObject electricCoil, IdfObject dxCoil) - { - string name = electricCoil[0].Value; - string availability = electricCoil[1].Value; - string inlet = electricCoil[4].Value; - string outlet = electricCoil[5].Value; - string dxClass = dxCoil.IdfClass; - string dxName = dxCoil[0].Value; - string tempNode = electricCoil[6].Value; - double efficiency = 0.3; - - string desuperheater = String.Format("Coil:Heating:Desuperheater,{0},{1},{2},{3},{4},{5},{6},{7},0;", name, availability, efficiency, inlet, outlet, dxClass, dxName, tempNode); + } - reader.Load(desuperheater); - } - public override void BeforeEnergySimulation() - { - IdfReader idfReader = new IdfReader( - ApiEnvironment.EnergyPlusInputIdfPath, - ApiEnvironment.EnergyPlusInputIddPath); - - UpdateBranches(idfReader); + if (DxIncluded && ThisField.Comment.ToLower().Contains("object type") && ThisField.Value.ToLower() == ElectricCoilObject.ToLower()) + { + IdfObject ElectricCoil = FindObject(reader, ElectricCoilObject, NextField.Value); + ThisField.Value = DesuperHeaterObject; + AddDesuperheater(reader, ElectricCoil, DxCoil); + MessageBox.Show("Replacing electric heating coil: " + ElectricCoil[0] + " with desuperheater coil."); + reader.Remove(ElectricCoil); + break; + } + } + } + private void AddDesuperheater(IdfReader reader, IdfObject electricCoil, IdfObject dxCoil) + { + string name = electricCoil[0].Value; + string availability = electricCoil[1].Value; + string inlet = electricCoil[4].Value; + string outlet = electricCoil[5].Value; + string dxClass = dxCoil.IdfClass; + string dxName = dxCoil[0].Value; + string tempNode = electricCoil[6].Value; + double efficiency = 0.3; - idfReader.Save(); - } - } + string desuperheater = String.Format("Coil:Heating:Desuperheater,{0},{1},{2},{3},{4},{5},{6},{7},0;", name, availability, efficiency, inlet, outlet, dxClass, dxName, tempNode); + + reader.Load(desuperheater); + } + public override void BeforeEnergySimulation() + { + IdfReader idfReader = new IdfReader( + ApiEnvironment.EnergyPlusInputIdfPath, + ApiEnvironment.EnergyPlusInputIddPath); + + UpdateBranches(idfReader); + + idfReader.Save(); + } + } } diff --git a/cs/applyDesuperheaterGenericUnitaryAhu.cs b/cs/applyDesuperheaterGenericUnitaryAhu.cs index 937ec34..9fa1c1f 100644 --- a/cs/applyDesuperheaterGenericUnitaryAhu.cs +++ b/cs/applyDesuperheaterGenericUnitaryAhu.cs @@ -32,7 +32,8 @@ public IdfObject FindObject(string objectType, string objectName) private string GetDesuperheaterCoil(string name, string coolingCoilType, string coolingCoilName, IdfObject reheatCoil) { - string template = @"Coil:Heating:Desuperheater, + string template = @" +Coil:Heating:Desuperheater, {0}, !- Coil Name {1}, !- Availability Schedule 0.3, !- Heat Reclaim Recovery Efficiency diff --git a/cs/applyDesuperheaterUnitaryHeatCool.cs b/cs/applyDesuperheaterUnitaryHeatCool.cs index 50009e3..6bf93ab 100644 --- a/cs/applyDesuperheaterUnitaryHeatCool.cs +++ b/cs/applyDesuperheaterUnitaryHeatCool.cs @@ -32,7 +32,8 @@ public IdfObject FindObject(string objectType, string objectName) private string GetDesuperheaterCoil(string name, string coolingCoilType, string coolingCoilName, IdfObject reheatCoil) { - string template = @"Coil:Heating:Desuperheater, + string template = @" +Coil:Heating:Desuperheater, {0}, !- Coil Name {1}, !- Availability Schedule 0.3, !- Heat Reclaim Recovery Efficiency @@ -43,12 +44,12 @@ private string GetDesuperheaterCoil(string name, string coolingCoilType, string {6}, !- Coil Temperature Setpoint Node Name 0.1; !- Parasitic Electric Load W"; return string.Format( - template, - name, - reheatCoil["Availability Schedule Name"].Value, + template, + name, + reheatCoil["Availability Schedule Name"].Value, reheatCoil["Air Inlet Node Name"].Value, - reheatCoil["Air Outlet Node Name"].Value, - coolingCoilType, + reheatCoil["Air Outlet Node Name"].Value, + coolingCoilType, coolingCoilName, reheatCoil["Temperature Setpoint Node Name"].Value); } @@ -70,7 +71,7 @@ private void AddDesuperheaterToUnitary(IdfObject unitary) } IdfObject reheatCoil = FindObject(reheatCoilType, reheatCoilName); - + string desuperheaterName = unitaryName + " Desuperheater Coil"; string desuperheater = GetDesuperheaterCoil(desuperheaterName, coolingCoilType, coolingCoilName, reheatCoil); diff --git a/cs/applyLoopReturnSpm.cs b/cs/applyLoopReturnSpm.cs index 9524162..e657f07 100644 --- a/cs/applyLoopReturnSpm.cs +++ b/cs/applyLoopReturnSpm.cs @@ -21,7 +21,8 @@ namespace DB.Extensibility.Scripts { public class ApplyLoopReturnSpm : ScriptBase, IScript { - private string hwReturnSpmTemplate = @"SetpointManager:ReturnTemperature:HotWater, + private string hwReturnSpmTemplate = @" +SetpointManager:ReturnTemperature:HotWater, {0}, !- Name {1}, !- Plant Loop Supply Outlet Node {2}, !- Plant Loop Supply Inlet Node @@ -31,7 +32,8 @@ public class ApplyLoopReturnSpm : ScriptBase, IScript , !- Return Temperature Setpoint Constant Value ; !- Return Temperature Setpoint Schedule Name"; - private string chwReturnSpmTemplate = @"SetpointManager:ReturnTemperature:ChilledWater, + private string chwReturnSpmTemplate = @" +SetpointManager:ReturnTemperature:ChilledWater, {0}, !- Name {1}, !- Plant Loop Supply Outlet Node {2}, !- Plant Loop Supply Inlet Node @@ -79,7 +81,8 @@ private void ApplyReturnSpms(IdfReader reader, string chwKey, string hwKey) if (name.IndexOf(chwKey, StringComparison.OrdinalIgnoreCase) >= 0) { template = chwReturnSpmTemplate; - } else if (name.IndexOf(hwKey, StringComparison.OrdinalIgnoreCase) >= 0) + } + else if (name.IndexOf(hwKey, StringComparison.OrdinalIgnoreCase) >= 0) { template = hwReturnSpmTemplate; } @@ -93,7 +96,7 @@ private void ApplyReturnSpms(IdfReader reader, string chwKey, string hwKey) } private string GetReturnSpm(IdfReader reader, IdfObject spm, string template) - { + { string nodeListName = spm[3].Value; IdfObject nodeList = FindObject(reader, "NodeList", nodeListName); string supplySideOutletNodeName = nodeList[1].Value; diff --git a/cs/applyMixedAirTerminal.cs b/cs/applyMixedAirTerminal.cs index 1b44158..f231cb6 100644 --- a/cs/applyMixedAirTerminal.cs +++ b/cs/applyMixedAirTerminal.cs @@ -47,7 +47,8 @@ public string ZoneInletNodeListName } // Boilerplate for new Mixer terminal - string terminalBoilerPlate = @"AirTerminal:SingleDuct:Mixer, + string terminalBoilerPlate = @" +AirTerminal:SingleDuct:Mixer, {0}, !- Name {1}, !- ZoneHVAC Unit Object Type {2}, !- ZoneHVAC Unit Object Name diff --git a/cs/applyNightCycleFCUs.cs b/cs/applyNightCycleFCUs.cs index e7edff1..8610d63 100644 --- a/cs/applyNightCycleFCUs.cs +++ b/cs/applyNightCycleFCUs.cs @@ -19,7 +19,8 @@ namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript { - string nightCycleObjects = @"AvailabilityManagerAssignmentList, + string nightCycleObjects = @" +AvailabilityManagerAssignmentList, {0}, !- Name AvailabilityManager:NightCycle, !- Availability Manager 1 Object Type {1} Night Cycle Operation; !- Availability Manager 1 Name @@ -34,17 +35,17 @@ public class IdfFindAndReplace : ScriptBase, IScript 3600, !- Cycling Run Time s {2}; !- Control zone name"; - public IdfObject FindObject(IdfReader reader, string objectType, string objectName) - { - try - { - return reader[objectType].First(c => c[0] == objectName); - } - catch(Exception e) - { - throw new Exception(String.Format("Cannot find object: {0}, type: {1}", objectName, objectType)); - } - } + public IdfObject FindObject(IdfReader reader, string objectType, string objectName) + { + try + { + return reader[objectType].First(c => c[0] == objectName); + } + catch (Exception e) + { + throw new Exception(String.Format("Cannot find object: {0}, type: {1}", objectName, objectType)); + } + } public override void BeforeEnergySimulation() { @@ -59,7 +60,7 @@ public override void BeforeEnergySimulation() { // Add assignment list and nigt cycle manager to the idf string fanCoilName = fanCoil["Name"].Value; - string name = fanCoilName + " Assignment List"; + string name = fanCoilName + " Assignment List"; string zoneName = fanCoilName.Replace(" Fan Coil Unit", ""); fanCoil.AddField(name, "! - Availability Manager List Name"); fanCoil["Availability Schedule Name"].Value = "On 24/7"; diff --git a/cs/checkProposed.cs b/cs/checkProposed.cs index 422496d..9fd1571 100644 --- a/cs/checkProposed.cs +++ b/cs/checkProposed.cs @@ -16,7 +16,7 @@ namespace DB.Extensibility.Scripts public class CheckProposed : ScriptBase, IScript { private bool IsCurrentProposed() - { + { string ashraeType = ActiveBuilding.GetAttribute("ASHRAE901Type"); return ashraeType == "1-Proposed"; } diff --git a/cs/dlControloff.cs b/cs/dlControloff.cs index ef50635..1342306 100644 --- a/cs/dlControloff.cs +++ b/cs/dlControloff.cs @@ -14,8 +14,8 @@ public class IdfFindAndReplace : ScriptBase, IScript private void UpdateDlSchedule() { IdfReader idfReader = new IdfReader( - ApiEnvironment.EnergyPlusInputIdfPath, - ApiEnvironment.EnergyPlusInputIddPath); + ApiEnvironment.EnergyPlusInputIdfPath, + ApiEnvironment.EnergyPlusInputIddPath); IEnumerable dlControls = idfReader["Daylighting:Controls"]; diff --git a/cs/energyRecoveryVentilator.cs b/cs/energyRecoveryVentilator.cs index 8432bb7..d8aa156 100644 --- a/cs/energyRecoveryVentilator.cs +++ b/cs/energyRecoveryVentilator.cs @@ -17,7 +17,8 @@ namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript { - string ervBoilerPlate = @"ZoneHVAC:EnergyRecoveryVentilator, + string ervBoilerPlate = @" +ZoneHVAC:EnergyRecoveryVentilator, {0}, !- Name {1}, !- Availability Schedule Name {0} OA Heat Recovery, !- Heat Exchanger Name @@ -27,7 +28,7 @@ public class IdfFindAndReplace : ScriptBase, IScript {0} Exhaust Fan, !- Exhaust Air Fan Name {0} OA Controller; !- Controller Name - ZoneHVAC:EnergyRecoveryVentilator:Controller, +ZoneHVAC:EnergyRecoveryVentilator:Controller, {0} OA Controller, !- Name , !- Temperature High Limit , !- Temperature Low Limit @@ -42,7 +43,7 @@ public class IdfFindAndReplace : ScriptBase, IScript , !- High Humidity Outdoor Air Flow Ratio No; !- Control High Indoor Humidity Based on Outdoor Humidity Ratio - Fan:SystemModel, +Fan:SystemModel, {0} Supply Fan, !- Name {1}, !- Availability Schedule Name {0} Heat Recovery Outlet Node, !- Air Inlet Node Name @@ -59,7 +60,7 @@ public class IdfFindAndReplace : ScriptBase, IScript , !- Electric Power Per Unit Flow Rate Per Unit Pressure 0.50; !- Fan Total Efficiency - Fan:SystemModel, +Fan:SystemModel, {0} Exhaust Fan, !- Name {1}, !- Availability Schedule Name {0} Heat Recovery Secondary Outlet Node, !- Air Inlet Node Name @@ -76,7 +77,7 @@ public class IdfFindAndReplace : ScriptBase, IScript , !- Electric Power Per Unit Flow Rate Per Unit Pressure 0.50; !- Fan Total Efficiency - HeatExchanger:AirToAir:SensibleAndLatent, +HeatExchanger:AirToAir:SensibleAndLatent, {0} OA Heat Recovery, !- Name {1}, !- Availability Schedule Name {2}, !- Nominal Supply Air Flow Rate @@ -98,7 +99,8 @@ public class IdfFindAndReplace : ScriptBase, IScript MinimumExhaustTemperature, !- Frost Control Type 1.7; !- Threshold Temperature"; - string spmBoilerPlate = @"SetpointManager:Scheduled, + string spmBoilerPlate = @" +SetpointManager:Scheduled, Heat Exchanger Supply Air Temp Manager, !- Name Temperature, !- Control Variable Heat Exchanger Supply Air Temp Sch, !- Schedule Name @@ -107,7 +109,7 @@ public class IdfFindAndReplace : ScriptBase, IScript NodeList, {0}; !- Name - Schedule:Compact, +Schedule:Compact, Heat Exchanger Supply Air Temp Sch, !- Name Temperature, !- Schedule Type Limits Name Through: 12/31, !- Field 1 @@ -226,9 +228,9 @@ public override void BeforeEnergySimulation() string nodeListName = "ERV HR Outlets"; string spmObjects = String.Format(spmBoilerPlate, nodeListName); - idfReader.Load(spmObjects); + idfReader.Load(spmObjects); List outletNodes = FindNodes(idfReader, "HeatExchanger:AirToAir:SensibleAndLatent", "Supply Air Outlet Node Name"); - + IdfObject ervNodeList = FindObject(idfReader, "NodeList", nodeListName); ervNodeList.AddFields(outletNodes.ToArray()); diff --git a/cs/flatPlateHeatExchanger.cs b/cs/flatPlateHeatExchanger.cs index b16237e..1765338 100644 --- a/cs/flatPlateHeatExchanger.cs +++ b/cs/flatPlateHeatExchanger.cs @@ -17,7 +17,8 @@ namespace DB.Extensibility.Scripts public class IdfFindAndReplace : ScriptBase, IScript { string[] objectNames = new string[] { "Air Loop AHU Heat Recovery Device" }; - string hxBoilerPlate = @"HeatExchanger:AirToAir:FlatPlate, + string hxBoilerPlate = @" +HeatExchanger:AirToAir:FlatPlate, {0}, !- Name {1}, !- Availability Schedule Name CounterFlow, !- Flow Arrangement Type diff --git a/cs/gasFiredChiller.cs b/cs/gasFiredChiller.cs index 0dfdeaf..8b357ca 100644 --- a/cs/gasFiredChiller.cs +++ b/cs/gasFiredChiller.cs @@ -31,9 +31,9 @@ public override void BeforeEnergySimulation() const string districtCoolingName = "District Cooling"; ApplyDirectFiredChiller( - chillerName, - hwLoopName, - chwLoopName, + chillerName, + hwLoopName, + chwLoopName, districtHeatingName, districtCoolingName); @@ -81,7 +81,8 @@ public void ApplyDirectFiredChiller( public string GetChillerHeaterIdfObjects(string chillerName, string hwInletNode, string hwOutletNode, string chwInletNode, string chwOutletNode) { - string template = @"ChillerHeater:Absorption:DirectFired, + string template = @" +ChillerHeater:Absorption:DirectFired, {0}, !- Name Autosize, !- Nominal Cooling Capacity W 0.8, !- Heating to Cooling Capacity Ratio @@ -120,7 +121,7 @@ public string GetChillerHeaterIdfObjects(string chillerName, string hwInletNode, OutdoorAir:Nodelist, {0} Chiller OA Node; ! - Outside air node - Curve:Biquadratic, +Curve:Biquadratic, {0} GasAbsFlatBiQuad, !- Name 1.000000000, !- Coefficient1 Constant 0.000000000, !- Coefficient2 x @@ -133,7 +134,7 @@ public string GetChillerHeaterIdfObjects(string chillerName, string hwInletNode, 0., !- Minimum Value of y 50.; !- Maximum Value of y - Curve:Quadratic, +Curve:Quadratic, {0} GasAbsFlatQuad, !- Name 1.000000000, !- Coefficient1 Constant 0.000000000, !- Coefficient2 x @@ -141,7 +142,7 @@ public string GetChillerHeaterIdfObjects(string chillerName, string hwInletNode, 0., !- Minimum Value of x 50.; !- Maximum Value of x - Curve:Quadratic, +Curve:Quadratic, {0} GasAbsLinearQuad, !- Name 0.000000000, !- Coefficient1 Constant 1.000000000, !- Coefficient2 x @@ -149,7 +150,7 @@ public string GetChillerHeaterIdfObjects(string chillerName, string hwInletNode, 0., !- Minimum Value of x 50.; !- Maximum Value of x - Curve:Quadratic, +Curve:Quadratic, {0} GasAbsInvLinearQuad, !- Name 1.000000000, !- Coefficient1 Constant -1.000000000, !- Coefficient2 x diff --git a/cs/headeredPumps.cs b/cs/headeredPumps.cs index ac93c13..65c84b9 100644 --- a/cs/headeredPumps.cs +++ b/cs/headeredPumps.cs @@ -36,7 +36,7 @@ public IdfObject FindObject(IdfReader reader, string objectType, string objectNa { return reader[objectType].First(c => c[0] == objectName); } - catch(Exception e) + catch (Exception e) { throw new Exception(String.Format("Cannot find object: {0}, type: {1}", objectName, objectType)); } @@ -56,7 +56,9 @@ public void ReplacePump(IdfReader reader, string pumpType, string pumpName, int { headeredPump = GetConstantPump(pump, nPumpsInBank); ReplaceObjectTypeInList(reader, "Branch", "Pump:ConstantSpeed", pumpName, "HeaderedPumps:ConstantSpeed", pumpName); - } else { + } + else + { throw new Exception(String.Format("Invalid pump type {0}", pumpType)); } reader.Load(headeredPump); @@ -65,7 +67,8 @@ public void ReplacePump(IdfReader reader, string pumpType, string pumpName, int public string GetConstantPump(IdfObject pump, int nPumpsInBank) { - string headeredPump = @"HeaderedPumps:ConstantSpeed, + string headeredPump = @" +HeaderedPumps:ConstantSpeed, {0}, !- Name {1}, !- Inlet Node Name {2}, !- Outlet Node Name @@ -77,12 +80,13 @@ public string GetConstantPump(IdfObject pump, int nPumpsInBank) {7}, !- Motor Efficiency {8}, !- Fraction of Motor Inefficiencies to Fluid Stream {9}; !- Pump Control Type"; - return String.Format(headeredPump, pump[0].Value, pump[1].Value, pump[2].Value, pump[3].Value, nPumpsInBank.ToString(), pump[4].Value, pump[5].Value, pump[6].Value, pump[7].Value, pump[8].Value); + return String.Format(headeredPump, pump[0].Value, pump[1].Value, pump[2].Value, pump[3].Value, nPumpsInBank.ToString(), pump[4].Value, pump[5].Value, pump[6].Value, pump[7].Value, pump[8].Value); } public string GetVariablePump(IdfObject pump, int nPumpsInBank) { - string headeredPump = @"HeaderedPumps:VariableSpeed, + string headeredPump = @" +HeaderedPumps:VariableSpeed, {0}, !- Name {1}, !- Inlet Node Name {2}, !- Outlet Node Name @@ -101,7 +105,7 @@ public string GetVariablePump(IdfObject pump, int nPumpsInBank) {14}; !- Pump Control Type"; - return String.Format(headeredPump, pump[0].Value, pump[1].Value, pump[2].Value, pump[3].Value, nPumpsInBank, pump[4].Value, pump[5].Value, pump[6].Value, pump[7].Value, pump[8].Value, pump[9].Value, pump[10].Value, pump[11].Value, pump[12].Value, pump[13].Value); + return String.Format(headeredPump, pump[0].Value, pump[1].Value, pump[2].Value, pump[3].Value, nPumpsInBank, pump[4].Value, pump[5].Value, pump[6].Value, pump[7].Value, pump[8].Value, pump[9].Value, pump[10].Value, pump[11].Value, pump[12].Value, pump[13].Value); } private void ReplaceObjectTypeInList(IdfReader idfReader, string listName, string oldObjectType, string oldObjectName, string newObjectType, string newObjectName) diff --git a/cs/multispeedUnitaryUnit.cs b/cs/multispeedUnitaryUnit.cs index e283d7e..03bbd5a 100644 --- a/cs/multispeedUnitaryUnit.cs +++ b/cs/multispeedUnitaryUnit.cs @@ -37,6 +37,7 @@ How to Use 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.Runtime; using System.Linq; using System.Collections.Generic; @@ -112,7 +113,7 @@ public struct FourSpeedSpecification public void LoadCurves() { string curves = @" - Curve:Quadratic, +Curve:Quadratic, PSZ-AC_CoolCLennoxStandard10Ton_TGA120S2B_CapFF, !- Name 0.77136, !- Coefficient1 Constant 0.34053, !- Coefficient2 x @@ -120,7 +121,7 @@ public void LoadCurves() 0.75918, !- Minimum Value of x 1.13877; !- Maximum Value of x - Curve:Quadratic, +Curve:Quadratic, PSZ-AC_CoolCLennoxStandard10Ton_TGA120S2B_EIRFFF, !- Name 1.20550, !- Coefficient1 Constant -0.32953, !- Coefficient2 x @@ -128,7 +129,7 @@ public void LoadCurves() 0.75918, !- Minimum Value of x 1.13877; !- Maximum Value of x - Curve:Quadratic, +Curve:Quadratic, PSZ-AC_CoolCLennoxStandard10Ton_TGA120S2B_PLR, !- Name 0.77100, !- Coefficient1 Constant 0.22900, !- Coefficient2 x @@ -136,7 +137,7 @@ public void LoadCurves() 0.0, !- Minimum Value of x 1.0; !- Maximum Value of x - Curve:Biquadratic, +Curve:Biquadratic, PSZ-AC_CoolCLennoxStandard10Ton_TGA120S2B_CapFT, !- Name 0.42415, !- Coefficient1 Constant 0.04426, !- Coefficient2 x @@ -149,7 +150,7 @@ public void LoadCurves() 29.00000, !- Minimum Value of y 46.00000; !- Maximum Value of y - Curve:Biquadratic, +Curve:Biquadratic, PSZ-AC_CoolCLennoxStandard10Ton_TGA120S2B_EIRFT, !- Name 1.23649, !- Coefficient1 Constant -0.02431, !- Coefficient2 x @@ -323,7 +324,8 @@ public string Apply4SpeedSpec(string multispeedSpecName, IdfObject unitarySystem public string Get2SMultispeedSpecification(string multispeedSpecName, string unitName, TwoSpeedSpecification spec) { - string template = @" UnitarySystemPerformance:Multispeed, + string template = @" +UnitarySystemPerformance:Multispeed, {0}, !- Name 2, !- Number of Speeds for Heating 2, !- Number of Speeds for Cooling @@ -338,7 +340,8 @@ public string Get2SMultispeedSpecification(string multispeedSpecName, string uni public string Get4SMultispeedSpecification(string multispeedSpecName, string unitName, FourSpeedSpecification spec) { - string template = @" UnitarySystemPerformance:Multispeed, + string template = @" +UnitarySystemPerformance:Multispeed, {0}, !- Name 4, !- Number of Speeds for Heating 4, !- Number of Speeds for Cooling @@ -362,7 +365,8 @@ public string Get2SFan(IdfObject fan, TwoSpeedSpecification spec) throw new Exception( "Cannot get fan performance, the required placeholder object is Fan:VariableVolume., fan: " + fan["Name"].Value); } - string newFanTemplate = @" Fan:SystemModel, + string newFanTemplate = @" +Fan:SystemModel, {0}, !- Name {1}, !- Availability Schedule Name {2}, !- Air Inlet Node Name @@ -413,7 +417,8 @@ public string Get4SFan(IdfObject fan, FourSpeedSpecification spec) throw new Exception( "Cannot get fan performance, the required placeholder object is Fan:VariableVolume., fan: " + fan["Name"].Value); } - string newFanTemplate = @" Fan:SystemModel, + string newFanTemplate = @" +Fan:SystemModel, {0}, !- Name {1}, !- Availability Schedule Name {2}, !- Air Inlet Node Name @@ -479,7 +484,7 @@ public string Get2SCoolingCoil(IdfObject coil, TwoSpeedSpecification spec) string shr = coil["Gross Rated Sensible Heat Ratio"].Value; string template = @" - Coil:Cooling:DX:MultiSpeed, +Coil:Cooling:DX:MultiSpeed, {0}, !- Name {1}, !- Availability Schedule Name {2}, !- Air Inlet Node Name @@ -574,7 +579,8 @@ public string Get4SCoolingCoil(IdfObject coil, FourSpeedSpecification spec) string shr = coil["Gross Rated Sensible Heat Ratio"].Value; string template = @" - Coil:Cooling:DX:MultiSpeed, + +Coil:Cooling:DX:MultiSpeed, {0}, !- Name {1}, !- Availability Schedule Name {2}, !- Air Inlet Node Name diff --git a/cs/optimisationUpdateHeatingCoolingCop.cs b/cs/optimisationUpdateHeatingCoolingCop.cs index a7ee424..6337003 100644 --- a/cs/optimisationUpdateHeatingCoolingCop.cs +++ b/cs/optimisationUpdateHeatingCoolingCop.cs @@ -1,3 +1,18 @@ +/* + Reads optimisation variables from the "OptimisationVariables" table + (expected keys: "heatingCOP" and "coolingEER") and updates the EnergyPlus + IDF accordingly. Actions performed by the script: + - Sets the "Rated COP" field on the + Coil:WaterHeating:AirToWaterHeatPump:Pumped object named + "HP Water Heater HP Water Heating Coil" when a valid heating COP is present. + - Sets the "Reference COP" field on Chiller:Electric:EIR objects when a valid cooling EER is present. + Behavior: + - If a variable value equals "UNKNOWN", a MessageBox is shown and that value is not applied. + - The IDF is saved after modifications. + Usage: + - Ensure the `OptimisationVariables` table contains the current values before running this script. +*/ + using System.Windows.Forms; using System.Collections.Generic; using DB.Extensibility.Contracts; @@ -5,7 +20,6 @@ using DB.Api; using System.Windows.Forms; - namespace DB.Extensibility.Scripts { public class IdfFindAndReplace : ScriptBase, IScript @@ -16,7 +30,7 @@ public override void BeforeEnergySimulation() Table table = site.GetTable("OptimisationVariables"); Record recordHeating = table.Records["heatingCOP"]; string heatingCop = recordHeating["VariableCurrentValue"]; - + IdfReader idfReader = new IdfReader( ApiEnvironment.EnergyPlusInputIdfPath, ApiEnvironment.EnergyPlusInputIddPath); @@ -26,9 +40,12 @@ public override void BeforeEnergySimulation() { if (coil["Name"].Equals("HP Water Heater HP Water Heating Coil")) { - if (heatingCop.Equals("UNKNOWN")) { + if (heatingCop.Equals("UNKNOWN")) + { MessageBox.Show("Cannot set heating COP, UNKNOWN value in OptimisationVariables table. "); - } else { + } + else + { coil["Rated COP"].Value = heatingCop; } } @@ -40,10 +57,13 @@ public override void BeforeEnergySimulation() IEnumerable chillers = idfReader["Chiller:Electric:EIR"]; foreach (IdfObject chiller in chillers) { - if (coolingEer.Equals("UNKNOWN")) { - MessageBox.Show("Cannot set cooling COP, UNKNOWN value in OptimisationVariables table. "); - } else { - chiller["Reference COP"].Value = coolingEer; + if (coolingEer.Equals("UNKNOWN")) + { + MessageBox.Show("Cannot set cooling COP, UNKNOWN value in OptimisationVariables table. "); + } + else + { + chiller["Reference COP"].Value = coolingEer; } } idfReader.Save(); diff --git a/cs/overridePeopleRadiantFraction.cs b/cs/overridePeopleRadiantFraction.cs index 286d11a..3f2a642 100644 --- a/cs/overridePeopleRadiantFraction.cs +++ b/cs/overridePeopleRadiantFraction.cs @@ -1,7 +1,7 @@ /* Override radiant heat gain by people. -DesignBuilder always apply default 0.3. +DesignBuilder always applies default 0.3. */ diff --git a/cs/slinky.cs b/cs/slinky.cs index d619534..6711ea0 100644 --- a/cs/slinky.cs +++ b/cs/slinky.cs @@ -18,7 +18,8 @@ namespace DB.Extensibility.Scripts public class IdfFindAndReplace : ScriptBase, IScript { string objectName = "Ground Heat Exchanger"; - string slinkyBoilerPlate = @"GroundHeatExchanger:Slinky, + string slinkyBoilerPlate = @" +GroundHeatExchanger:Slinky, {0}, !- Name {1}, !- Inlet Node {2}, !- Outlet Node @@ -42,7 +43,8 @@ public class IdfFindAndReplace : ScriptBase, IScript KATemps, !- Name of Undisturbed Ground Temperature Object 10; !- Maximum length of simulation [years]"; - string ground = @" Site:GroundTemperature:Undisturbed:KusudaAchenbach, + string ground = @" +Site:GroundTemperature:Undisturbed:KusudaAchenbach, KATemps, !- Name 1.8, !- Soil Thermal Conductivity {W/m-K} 920, !- Soil Density {kg/m3} @@ -94,7 +96,7 @@ public override void BeforeEnergySimulation() string newObjectType = "GroundHeatExchanger:Slinky"; IdfObject groundHX = FindObject(idfReader, oldObjectType, objectName); - + ReplaceObjectTypeInList(idfReader, "CondenserEquipmentList", oldObjectType, objectName, newObjectType, objectName); ReplaceObjectTypeInList(idfReader, "Branch", oldObjectType, objectName, newObjectType, objectName); @@ -110,4 +112,9 @@ public override void BeforeEnergySimulation() idfReader.Save(); } } -} \ No newline at end of file +} + + + + + diff --git a/cs/steamHumidifier.cs b/cs/steamHumidifier.cs index d519dcd..2d7288c 100644 --- a/cs/steamHumidifier.cs +++ b/cs/steamHumidifier.cs @@ -18,42 +18,43 @@ namespace DB.Extensibility.Scripts public class IdfFindAndReplace : ScriptBase, IScript { - private IdfObject FindObject(IdfReader reader, string objectType, string objectName) { - return reader[objectType].First(c => c[0] == objectName); + private IdfObject FindObject(IdfReader reader, string objectType, string objectName) + { + return reader[objectType].First(c => c[0] == objectName); } private void UpdateBranches(IdfReader idfReader) { - IEnumerable branches = idfReader["Branch"]; - foreach (IdfObject branch in branches) - { - if (branch[0].Value.Contains("steamgas") && branch[0].Value.Contains("AHU Main Branch")) - { - UpdateBranch(idfReader, branch); - } - } + IEnumerable branches = idfReader["Branch"]; + foreach (IdfObject branch in branches) + { + if (branch[0].Value.Contains("steamgas") && branch[0].Value.Contains("AHU Main Branch")) + { + UpdateBranch(idfReader, branch); + } + } } private void UpdateBranch(IdfReader reader, IdfObject branch) { - const string GasHumidifierObject = "Humidifier:Steam:Gas"; - const string EleHumidifierObject = "Humidifier:Steam:Electric"; + const string GasHumidifierObject = "Humidifier:Steam:Gas"; + const string EleHumidifierObject = "Humidifier:Steam:Electric"; - foreach (int i in Enumerable.Range(1, (branch.Count - 2))) - { - Field ThisField = branch.Fields[i]; - Field NextField = branch.Fields[i + 1]; - if (ThisField.Comment.ToLower().Contains("object type") && ThisField.Value.ToLower() == EleHumidifierObject.ToLower()) - { - IdfObject EleHumidifier = FindObject(reader, EleHumidifierObject, NextField.Value); - ThisField.Value = GasHumidifierObject; - string humidifierText = GetHumidifierIdfText(EleHumidifier, GasHumidifierObject); - reader.Load(humidifierText); - MessageBox.Show("Replacing electric humidifier: " + EleHumidifier[0] + " with gas humidifier." ); - reader.Remove(EleHumidifier); - break; - } - } + foreach (int i in Enumerable.Range(1, (branch.Count - 2))) + { + Field ThisField = branch.Fields[i]; + Field NextField = branch.Fields[i + 1]; + if (ThisField.Comment.ToLower().Contains("object type") && ThisField.Value.ToLower() == EleHumidifierObject.ToLower()) + { + IdfObject EleHumidifier = FindObject(reader, EleHumidifierObject, NextField.Value); + ThisField.Value = GasHumidifierObject; + string humidifierText = GetHumidifierIdfText(EleHumidifier, GasHumidifierObject); + reader.Load(humidifierText); + MessageBox.Show("Replacing electric humidifier: " + EleHumidifier[0] + " with gas humidifier."); + reader.Remove(EleHumidifier); + break; + } + } } private string GetHumidifierIdfText(IdfObject EleHumidifier, string GasHumidifier) { @@ -78,7 +79,7 @@ private void AddOutputs(IdfReader reader) reader.Load("Output:Variable,*,Humidifier NaturalGas Rate,Runperiod;"); } - public override void BeforeEnergySimulation() + public override void BeforeEnergySimulation() { IdfReader idfReader = new IdfReader( ApiEnvironment.EnergyPlusInputIdfPath, diff --git a/cs/temperatureSourceReplaceDistrictHeating.cs b/cs/temperatureSourceReplaceDistrictHeating.cs index 3e08604..191b369 100644 --- a/cs/temperatureSourceReplaceDistrictHeating.cs +++ b/cs/temperatureSourceReplaceDistrictHeating.cs @@ -18,7 +18,8 @@ namespace DB.Extensibility.Scripts public class IdfFindAndReplace : ScriptBase, IScript { - string boilerplate = @"PlantComponent:TemperatureSource, + string boilerplate = @" +PlantComponent:TemperatureSource, {0}, !- Name {1}, !- Inlet Node {2}, !- Outlet Node diff --git a/cs/temperatureSourceReplaceGroundHX.cs b/cs/temperatureSourceReplaceGroundHX.cs index 2c0f13b..9dd6c07 100644 --- a/cs/temperatureSourceReplaceGroundHX.cs +++ b/cs/temperatureSourceReplaceGroundHX.cs @@ -18,7 +18,8 @@ namespace DB.Extensibility.Scripts public class IdfFindAndReplace : ScriptBase, IScript { - string boilerplate = @"PlantComponent:TemperatureSource, + string boilerplate = @" +PlantComponent:TemperatureSource, {0}, !- Name {1}, !- Inlet Node {2}, !- Outlet Node diff --git a/cs/warmestTemperatureFlow.cs b/cs/warmestTemperatureFlow.cs index 7714d64..0fb4ad5 100644 --- a/cs/warmestTemperatureFlow.cs +++ b/cs/warmestTemperatureFlow.cs @@ -18,23 +18,24 @@ namespace DB.Extensibility.Scripts public class IdfFindAndReplace : ScriptBase, IScript { - private IdfObject FindObject(IdfReader reader, string objectType, string objectName) { - return reader[objectType].First(c => c[0] == objectName); + private IdfObject FindObject(IdfReader reader, string objectType, string objectName) + { + return reader[objectType].First(c => c[0] == objectName); } private void ReplaceWarmest(IdfReader idfReader, string strategy, float turnDownRatio) { - IEnumerable spms = idfReader["SetpointManager:Warmest"]; - foreach (IdfObject spm in spms) - { - if (spm[0].Value.ToLower().Contains("warmesttemperatureflow")) - { - string newSpm = GetSpmText(spm, strategy, turnDownRatio); - MessageBox.Show("Replacing Warmest spm: " + spm[0].Value + " with WarmestTemperatureFlow spm." ); - idfReader.Load(newSpm); - idfReader.Remove(spm); - } - } + IEnumerable spms = idfReader["SetpointManager:Warmest"]; + foreach (IdfObject spm in spms) + { + if (spm[0].Value.ToLower().Contains("warmesttemperatureflow")) + { + string newSpm = GetSpmText(spm, strategy, turnDownRatio); + MessageBox.Show("Replacing Warmest spm: " + spm[0].Value + " with WarmestTemperatureFlow spm."); + idfReader.Load(newSpm); + idfReader.Remove(spm); + } + } } private string GetSpmText(IdfObject warmestSpm, string strategy, float turnDownRatio) @@ -50,7 +51,7 @@ private string GetSpmText(IdfObject warmestSpm, string strategy, float turnDownR return String.Join(",", fields) + ";"; } - public override void BeforeEnergySimulation() + public override void BeforeEnergySimulation() { IdfReader idfReader = new IdfReader( ApiEnvironment.EnergyPlusInputIdfPath, diff --git a/db-scripts.csproj b/db-scripts.csproj deleted file mode 100644 index 23c5b9c..0000000 --- a/db-scripts.csproj +++ /dev/null @@ -1,140 +0,0 @@ - - - Debug - AnyCPU - {B6C1BF30-066F-455B-BB0B-82FD4F5C5C9C} - Library - false - ClassLibrary - v4.0 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - db_scripts - - - - ..\..\..\..\..\Program Files (x86)\DesignBuilder\Lib\DB.Api.dll - - - ..\..\..\..\..\Program Files (x86)\DesignBuilder\Lib\DB.Extensibility.Contracts.dll - - - ..\..\..\..\..\Program Files (x86)\DesignBuilder\Lib\EpNet.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/db-scripts.csproj.user b/db-scripts.csproj.user deleted file mode 100644 index 0b07de1..0000000 --- a/db-scripts.csproj.user +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/py/custom_KPI_1_db_eplusout_reader.py b/py/custom_KPI_1_db_eplusout_reader.py index e7873dd..1a7c563 100644 --- a/py/custom_KPI_1_db_eplusout_reader.py +++ b/py/custom_KPI_1_db_eplusout_reader.py @@ -7,7 +7,7 @@ """ from db_eplusout_reader import Variable, get_results -from db_eplusout_reader.constants import * +from db_eplusout_reader.constants import RP # ensure that SQLite outputs are generated diff --git a/py/custom_KPI_2_htm_EUI.py b/py/custom_KPI_2_htm_EUI.py index 748af90..e608946 100644 --- a/py/custom_KPI_2_htm_EUI.py +++ b/py/custom_KPI_2_htm_EUI.py @@ -19,7 +19,9 @@ def after_energy_simulation(): table_path = api_environment.EnergyPlusFolder + "eplustbl.htm" if path.exists(table_path): with open(table_path, "r") as filehandle: - eui_table = fasthtml.tablebyname(filehandle, "EAp2-17a. Energy Use Intensity - Electricity") + eui_table = fasthtml.tablebyname( + filehandle, "EAp2-17a. Energy Use Intensity - Electricity" + ) eui_table_content = eui_table[1] eui = str(eui_table_content[8][1]) diff --git a/py/custom_KPI_4_TM52.py b/py/custom_KPI_4_TM52.py index 06c9e3b..94c7cfc 100644 --- a/py/custom_KPI_4_TM52.py +++ b/py/custom_KPI_4_TM52.py @@ -79,7 +79,12 @@ def after_energy_simulation(): except ZeroDivisionError: raise NoResults("No TM52 results found!") - show_message("Results TM52", "{}% fails, total_area {}m2, fail_area: {}m2".format(percentage_area_fail, total_area, fail_area)) + show_message( + "Results TM52", + "{}% fails, total_area {}m2, fail_area: {}m2".format( + percentage_area_fail, total_area, fail_area + ), + ) table = site.GetTable("ParamResultsTmp") record = table.AddRecord() diff --git a/py/custom_KPI_5_TM59.py b/py/custom_KPI_5_TM59.py index 3409494..e89cfd2 100644 --- a/py/custom_KPI_5_TM59.py +++ b/py/custom_KPI_5_TM59.py @@ -69,7 +69,12 @@ def after_energy_simulation(): except ZeroDivisionError: raise NoResults("No TM59 results found!") - show_message("Results TM59", "{}% fails, total_area {}m2, fail_area: {}m2".format(percentage_area_fail, total_area, fail_area)) + show_message( + "Results TM59", + "{}% fails, total_area {}m2, fail_area: {}m2".format( + percentage_area_fail, total_area, fail_area + ), + ) table = site.GetTable("ParamResultsTmp") record = table.AddRecord() diff --git a/py/custom_variable_mech_vent_ach.py b/py/custom_variable_mech_vent_ach.py index ce105e5..6facc62 100644 --- a/py/custom_variable_mech_vent_ach.py +++ b/py/custom_variable_mech_vent_ach.py @@ -10,12 +10,11 @@ """ - MECH_VENT_ACH_ATTR = "MechanicalVentilationValue" def filter_zones(building, *args): - """ Retrieve zones within a building where the zone title contains a specific key. """ + """Retrieve zones within a building where the zone title contains a specific key.""" for zone in (zone for block in building.BuildingBlocks for zone in block.Zones): zone_name = zone.GetAttribute("title") if any(key.lower() in zone_name.lower() for key in args): diff --git a/py/optimisation_TM59_split_AB.py b/py/optimisation_TM59_split_AB.py index fe64b2f..9489095 100644 --- a/py/optimisation_TM59_split_AB.py +++ b/py/optimisation_TM59_split_AB.py @@ -21,7 +21,7 @@ import os from db_eplusout_reader import Variable, get_results -from db_eplusout_reader.constants import * +from db_eplusout_reader.constants import RP from db_eplusout_reader.exceptions import NoResults THRESHOLD_A = 3 diff --git a/py/optimisation_constant_openable_area.py b/py/optimisation_constant_openable_area.py index 6816890..bfd672b 100644 --- a/py/optimisation_constant_openable_area.py +++ b/py/optimisation_constant_openable_area.py @@ -8,6 +8,7 @@ openable area constant (default 1m2). """ + import ctypes @@ -33,5 +34,14 @@ def before_energy_idf_generation(): openable_percentage = str(min(openable_area / area * 100, 100)) opening.SetAttribute(percantage_area_opens, openable_percentage) name = opening.GetAttribute("SSEPObjectNameInOP") - openings_summary += ("\nOpening: " + name + "\n\t" + "Area: " + str(area) + "\n\t" + "Percentage: " + openable_percentage) + openings_summary += ( + "\nOpening: " + + name + + "\n\t" + + "Area: " + + str(area) + + "\n\t" + + "Percentage: " + + openable_percentage + ) show_message("Summary", openings_summary) diff --git a/py/optimisation_heating_cooling_efficiency.py b/py/optimisation_heating_cooling_efficiency.py index 44cfe23..890241b 100644 --- a/py/optimisation_heating_cooling_efficiency.py +++ b/py/optimisation_heating_cooling_efficiency.py @@ -15,6 +15,7 @@ - 'CoolingCOP' (chiller reference COP) """ + import ctypes from eppy import modeleditor @@ -45,8 +46,10 @@ def before_energy_simulation(): if heating_eff != "UNKNOWN": boiler.Nominal_Thermal_Efficiency = heating_eff else: - show_message("ERROR", - "Cannot set heating COP, unknown value in table OptimisationVariables") + show_message( + "ERROR", + "Cannot set heating COP, unknown value in table OptimisationVariables", + ) chillers = idf_file.idfobjects["Chiller:Electric:EIR".upper()] cooling_cop_row = table.Records["CoolingCOP"] @@ -59,7 +62,9 @@ def before_energy_simulation(): if cooling_cop != "UNKNOWN": chiller.Reference_COP = cooling_cop else: - show_message("ERROR", - "Cannot set cooling COP, unknown value in table OptimisationVariables") + show_message( + "ERROR", + "Cannot set cooling COP, unknown value in table OptimisationVariables", + ) - idf_file.save() \ No newline at end of file + idf_file.save()