pyenergyplus / witheppy

Python packages built using eppy
MIT License
8 stars 2 forks source link

Functions to work with Energyplus Extensible fields #1

Closed santoshphilip closed 5 years ago

santoshphilip commented 5 years ago

Problem: Right now if you have branch list, it is difficult to remove an item from the middle of the list. The other items in the list have to move up to fill the gap made by the removed item. Usually this has to be done line by line.

Consider an example branch list

BranchList,
  Heating Supply Side Branches,  !- Name
  Heating Supply Inlet Branch,  !- Branch 1 Name
  Central Boiler Branch,   !- Branch 2 Name
  Heating Supply Bypass Branch,  !- Branch 3 Name
  Heating Supply Outlet Branch;  !- Branch 4 Name

If you want to remove the Central Boiler Branch (Branch 2 Name), the corresponding eppy code would look like:

branchlist.Branch_2_Name = "Heating Supply Bypass Branch"
branchlist.Branch_3_Name = "Heating Supply Outlet Branch"
branchlist.Branch_4_Name = ""

Actually there is no esy way to remove "Branch 4 Name"" :-(

You can manipulate values in the listbranchlist.fieldvalues. But you have to know what you are doing.

As similar issue occurs with vertices of a surface such as BuildingSurface:Detailed

You can see this when using idfEditor too. It is much easier to do this in the text editor.

There is a need for a function that makes it easy to add, insert, remove, find or pop an items in extensible fields.

Documentation of extensible fields from the idd file

!  \extensible:<#>  This object is dynamically extensible -- meaning, if you
!           change the IDD appropriately (if the object has a simple list
!           structure -- just add items to the list arguments (i.e. BRANCH
!           LIST). These will be automatically redimensioned and used during
!           the simulation. <#> should be entered by the developer to signify
!           how many of the last fields are needed to be extended (and EnergyPlus
!           will attempt to auto-extend the object).  The first field of the first
!           instance of the extensible field set is marked with \begin-extensible.
!
!  \begin-extensible  Marks the first field at which the object accepts an extensible
!                   field set.  A fixed number of fields from this marker define the
!                   extensible field set, see the object code \extensible for
!                   more information
santoshphilip commented 5 years ago

Solution: This problem can be resolved with two new functions

  1. extensiblefields2list(idfobject)
  2. list2extensiblefields(idfobject, newlist)

As an example:

points = extensiblefields2list(surface)

print(points)

>> [(2,3,4), (4,5,6), (6,4,3), (9,0,8)]

oldpoints = [(2,3,4), (4,5,6), (6,4,3), (9,0,8)]
newpoints = oldpoints + [(3,4,19)]

list2extensiblefields(surface, newpoints)

Similarly:

branches = extensiblefields2list(branchlist)
print(branches)
>> ["Branch1", "Branch2"]
branches.append("Branch3")
list2extensiblefields(branchlist, branches)
santoshphilip commented 5 years ago

from the pull request:

Problem: need and easy way to work with extensible fields in the idfobject Solution: new functions extensiblefields2list() and list2extensiblefields()

Limitation: both the functions work with flat lists. For the coordinates of a building surface it will return [2,3,4,22,33,44] instead of [(2,3,4),(22,33,44)]

All tests pass no complaints form lint

The pull request has been merged