EpNet .Net library online help
EpNet is a .Net library which provides very useful utilities to manipulate EnergyPlus files.
It makes very easy to modify idf files but it additionally allows to read and write EnergyPlus result eso files or extract data from csv table outputs.
EpNet is integrated in DesignBuilder Scripting module where scripts developed with EpNet are usually executed after idf generation and before simulation.
EpNet library is developed and mantained by Germán Campos, www.ecoeficiente.es.
Latest download link:
01 Sep 2024 - Download latest EpNet library.
And overwrite current EpNet.dll in *c:\Program Files (x86)\DesignBuilder\Lib* folder
Usage examples:
The easiest way to understand how to use EpNet library is to look at the following examples and use the Api Reference.
The class that reads the idf file and stores the list of idf objects is IdfReader.
So, first of all we have to create an IdfReader object:
var Idf = IdfReader();
After processing the Idf, the file must be saved:
Idf.Save();
Now, let's see some of the things we can do with the IdfReader object.
###Example 1 Get all the zones in the idf:
var zones = Idf["Zone"];
Get all the surfaces in the idf:
var surfaces = Idf["BuildingSurface:Detailed"];
zones and surfaces are now a List of IdfObjects
An IdfObject has [Fields](xref:EpNet.Field] and each field can have a value (Value or Number) and a Commment.
Fields can be accessed by its zero-based index or by their name (according to Energy+.idd).
Let's pick the first zone:
var zone = zones[0];
And change its name to "Zone1":
zone[0].Value = "Zone1";
Text values are accessed through Value property while numeric values are usually accessed through Number property (unless you want to treat them as a string value).
double zoneArea = zone[9].Number;
string zoneAreaValue = zone[9].Value;
zone[9].Number = zoneArea * 2; //Duplicate zone area.
zone[0].Value = zoneAreaValue + "sqm.Zone1"; //Include zone area in its name.
###Example 2 The following code updates simple glazing parameters to include the impact of a frame fraction.
var glass = Idf["WindowMaterial:SimpleGlazingSystem"];
var frameFrac= 0.15;
var frameU = 2.8;
var frameAbs = 0.9;
foreach (var g in glass)
{
var U = g[1].Number;
var SHGC = g[2].Number;
var t = g[3].Number;
g[1].Number = U*(1-frameFrac)+frameFrac*frameU;
g[2].Number = SHGC*(1-frameFrac)+0.04*frameAbs*frameU;
g[3].Number = t*(1-frameFrac);
}
###Example 3 Let's do something more complex. We will change the insulation material layer in the facades that belong to zones larger than 100 sqm.
We will use LINQ extension methods which are very useful and simplify the code when used with EpNet.
var zones = Idf["Zone"];
var surfaces = Idf["BuildingSurface:Detailed"];
//Load method can read an idf file or parse a text string in idf format.
//In this case, we use it to create a new insulation material named "XPS".
Idf.Load("Material,XPS,Smooth,0.05,0.04,80,1450,0.9,0.7,0.7;");
//We use "First" extension method to search the first construction whose name is "Facade".
var facade = Idf["Construction"].First(c => c["Name"] == "Facade");
//We make a copy of this construction.
var newFacade = facade.Clone();
//Change its name,
newFacade["Name"].Value = "New Facade";
//and search the first Field that contains "MW" and change its value to "XPS".
newFacade.First(f => f.Contains("MW")).Value = "XPS";
//Finally, we add it to the Idf.
Idf.Add(newFacade);
//We select all the zones with an area > 100
foreach (var zone in zones.Where(z => z["Floor Area"].Number > 100))
//and from all surfaces of type wall we choose those that belong to those zones
foreach (var surface in surfaces.Where(s => s["Surface Type"] == "Wall" && s["Zone Name"] == zone["Name"]))
surface["Construction Name"].Value = "New Facade"; //and change their construction to the new facade.
###Example 4 There are many things that can be done with EpNet, such as working with results. This example uses EsoReader to read eso results, select some, add them and get them translated to another time frequency and units.
var Eso = new EsoReader(); //Loads eplusout.eso from simulation folder.
//Let's select those hourly results referred to zones and with W as unit.
var zoneResults = Eso.Results
.Where(r => r.ReportType.StartsWith("Zone") && r.Frequency == Frequencies.Hourly && r.Units == "W")
.GroupBy(g => g.ReportType);
foreach (var zoneResult in zoneResults)
{
//Sum them and change component name to "Zone Total"
var zoneTotal = zoneResult.Sum().SetComponent("Zone Total");
//Average them and change component name to "Zone Average"
var zoneAverage = zoneResult.Average().SetComponent("Zone Average");
//Add them to the EsoReader
Eso.Add(zoneAverage);
Eso.Add(zoneTotal);
//Add zone totals but translated to monthly frequency and MBtu
Eso.Add(zoneTotal.ToFrequency(Frequencies.Monthly).SetUnits("MBtu")*3.412e-3);
}
Eso.Save(); //The eso file is overwritten with old and new results.
###Example 5 You can even set equipment efficiencies according to Ashrae 90.1 minimum efficiency requirement for LEED baseline models.
//Read EnergyPlus comma delimited result file.
var tablePath = @"eplustbl.csv";
var tableReader = new TableReader(tablePath);
//Get a dictionary<Key,Value> with column 0 as keys and column 2 as values from Coil:Cooling:DX:SingleSpeed table.
var coolingCoils = tableReader.GetTable("Coil:Cooling:DX:SingleSpeed").GetData(0, 2);
//Loop through the cooling coils and assign Ashrae minimum efficiency for a System 4 DX cooling coil.
foreach (var coil in coolingCoils)
{
Idf["Coil:Cooling:DX:SingleSpeed"].First(o => o[0].Equals(coil.Key))[4].Number = LEED.EER(4, coil.Value);
}
//Repeat for heating coils
var heatingCoils = tableReader.GetTable("Coil:Heating:DX:SingleSpeed").GetData(0, 2);
foreach (var coil in heatingCoils)
{
Idf["Coil:Heating:DX:SingleSpeed"].First(o => o[0].Equals(coil.Key))[3].Number = LEED.COP(4, coil.Value);
}
Or set fan power according to Ashrae procedure for baseline fans.
//Set system properties for System 4 airloops in the model.
var sP4 = new SystemProperties(4);
sP4.FullyDucted = true; //Configure the pressure loss in the system
sP4.Merv13to15 = true;
//Get airloop names (GetAirloopZones gets a dictionary with airloop as Keys and List of zones as Values)
var airloops = Idf.GetAirloopZones().Keys;
//Assign airloops that meet those properties.
sP4.Systems.AddRange(airloops);
//Set Fan Pressures for those system 4 airloop fans.
Idf.SetFanPressures(@"eplustbl.csv", sP4);
###Example 6 Finally, thanks to DesignBuilder API, C# (with or without EpNet) can be used to change DesignBuilder model as in this example:
//Get a dictionary with current names as Keys and updated names as Values
var zoneNames=Csv.GetData<string>(@"c:\temp\ZoneNames.csv");
//Get a reference to model site
var site = ApiEnvironment.Site;
//Loop through buildings and zones
foreach (var building in site.Buildings)
foreach (var block in building.BuildingsBlocks)
foreach (var zone in block.Zones)
{
//Get the name of the zone from DesignBuilder model
var name = zone.getAttribute("Title");
//If it is in the list of names to be updated
if (zoneNames.ContainsKey(name))
zone.setAttribute("Title", zoneNames[name]);//Update the name
}