Skip to content

Commit

Permalink
Added the ability to specify which type of Umi object should be uniqu…
Browse files Browse the repository at this point in the history
…e in an UmiTemplateLibrary (#348)

* Adds "children" property to each UmiBase subclasses

It is simply better to specify the actual children if these umi components instead of relying on their type in DFS traverse algorit

* Updates tests

* Updated repr for YearSchedulePart

* introduces different traversal algorithm

* Missing typing class

* Adds Name validation for GasMaterial

* Fix test

* missing children

* Adds __getitem__

* improvements to GasLayer class

* Changes the hash method of umi objects to their id

* Updates tests for that change

* Fixes an issue where the __add__ method would mess things up for GasMaterials

Improves traversal and graph creation with hashable objects that behave better

* children all return tuples instead of a generator

* Fixes an issue where reduced component names would look like <io_

* Fixes an issue where UmiTemplateLibrary.save() could produce a template library with missing Schedules

* adds quantity to develop

* Errors are logged when UmiTemplateLibrary.from_idf_files() fails on some file

* Fixes missing import

* fix test

* try fix test

* Attempt to fix an issue when the initialization of subclasses of UmiBase fails

The object should not be kept in UmiBase.CREATED_OBJECTS
  • Loading branch information
Samuel Letellier-Duchesne committed Jul 28, 2022
1 parent 937cfa6 commit 577ac65
Show file tree
Hide file tree
Showing 30 changed files with 10,175 additions and 293 deletions.
2 changes: 1 addition & 1 deletion archetypal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def transition(idf, to_version, cores, yes):

# Save results to file (overwriting if True)
file_list = []
for idf in results:
for idf in results.values():
if isinstance(idf, IDF):
if overwrite:
file_list.append(idf.original_idfname)
Expand Down
13 changes: 9 additions & 4 deletions archetypal/template/building_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def __init__(
self.AuthorEmails = AuthorEmails if AuthorEmails else []
self.Version = Version

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def Perimeter(self):
"""Get or set the perimeter ZoneDefinition."""
Expand Down Expand Up @@ -353,7 +356,7 @@ def from_idf(cls, idf, **kwargs):
**kwargs:
"""
# initialize empty BuildingTemplate
name = kwargs.pop("Name", Path(idf.idfname).basename().splitext()[0])
name = kwargs.pop("Name", Path(idf.name).stem)

epbunch_zones = idf.idfobjects["ZONE"]
zones = [
Expand Down Expand Up @@ -628,9 +631,7 @@ def get_ref(self, ref):

def __hash__(self):
"""Return the hash value of self."""
return hash(
(self.__class__.__name__, getattr(self, "Name", None), self.DataSource)
)
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand All @@ -655,3 +656,7 @@ def __eq__(self, other):
self.Version == other.Version,
]
)

@property
def children(self):
return self.Core, self.Perimeter, self.Structure, self.Windows
11 changes: 8 additions & 3 deletions archetypal/template/conditioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def __init__(

self.area = area

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def area(self):
"""Get or set the area of the zone associated to this object [m²]."""
Expand Down Expand Up @@ -1583,9 +1586,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash(
(self.__class__.__name__, getattr(self, "Name", None), self.DataSource)
)
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down Expand Up @@ -1624,3 +1625,7 @@ def __eq__(self, other):
def __copy__(self):
"""Create a copy of self."""
return self.__class__(**self.mapping(validate=False))

@property
def children(self):
return self.CoolingSchedule, self.HeatingSchedule, self.MechVentSchedule
4 changes: 4 additions & 0 deletions archetypal/template/constructions/base_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,7 @@ def __eq__(self, other):
return isinstance(other, LayeredConstruction) and all(
[self.Layers == other.Layers]
)

@property
def children(self):
return tuple(l.Material for l in self.Layers)
5 changes: 4 additions & 1 deletion archetypal/template/constructions/opaque_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def __init__(self, Name, Layers, **kwargs):
super(OpaqueConstruction, self).__init__(Name, Layers, **kwargs)
self.area = 1

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def r_value(self):
"""Get or set the thermal resistance [K⋅m2/W] (excluding air films).
Expand Down Expand Up @@ -535,7 +538,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash((self.__class__.__name__, getattr(self, "Name", None)))
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
5 changes: 4 additions & 1 deletion archetypal/template/constructions/window_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def __init__(self, Name, Layers, Category="Double", **kwargs):
)
self.Category = Category # set here for validators

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def Category(self):
"""Get or set the Category. Choices are ("single", "double", "triple")."""
Expand Down Expand Up @@ -557,7 +560,7 @@ def _layered_r_value_initial(

def __hash__(self):
"""Return the hash value of self."""
return hash((self.__class__.__name__, getattr(self, "Name", None)))
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
11 changes: 8 additions & 3 deletions archetypal/template/dhw.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def __init__(
self.WaterSchedule = WaterSchedule
self.area = area

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def FlowRatePerFloorArea(self):
"""Get or set the flow rate per flow area [m³/(hr·m²)]."""
Expand Down Expand Up @@ -504,9 +507,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash(
(self.__class__.__name__, getattr(self, "Name", None), self.DataSource)
)
return hash(self.id)

def __key__(self):
"""Get a tuple of attributes. Useful for hashing and comparing."""
Expand Down Expand Up @@ -536,6 +537,10 @@ def __copy__(self):
"""Create a copy of self."""
return self.__class__(**self.mapping(validate=False))

@property
def children(self):
return (self.WaterSchedule,)


def water_main_correlation(t_out_avg, max_diff):
"""Based on the correlation developed by Craig Christensen and Jay Burch.
Expand Down
15 changes: 12 additions & 3 deletions archetypal/template/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def __init__(
self.area = area
self.volume = volume

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def DimmingType(self):
"""Get or set the dimming type.
Expand Down Expand Up @@ -808,9 +811,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash(
(self.__class__.__name__, getattr(self, "Name", None), self.DataSource)
)
return hash(self.id)

def __key__(self):
"""Get a tuple of attributes. Useful for hashing and comparing."""
Expand All @@ -835,6 +836,14 @@ def __eq__(self, other):
else:
return self.__key__() == other.__key__()

@property
def children(self):
return (
self.EquipmentAvailabilitySchedule,
self.LightsAvailabilitySchedule,
self.OccupancySchedule,
)


def _resolve_dimming_type(zone, zone_ep):
"""Resolve the dimming type for the Zone object.
Expand Down
23 changes: 19 additions & 4 deletions archetypal/template/materials/gas_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math

from sigfig import round
from validator_collection import validators

from archetypal.utils import log

Expand Down Expand Up @@ -67,7 +68,7 @@ def resistivity(self):

@resistivity.setter
def resistivity(self, value):
self.Material.Conductivity = 1 / float(value)
self.Material.Conductivity = 1 / validators.float(value, minimum=0)

@property
def r_value(self):
Expand All @@ -80,7 +81,16 @@ def r_value(self):

@r_value.setter
def r_value(self, value):
self.Thickness = float(value) * self.Material.Conductivity
self.Thickness = validators.float(value, minimum=0) * self.Material.Conductivity

@property
def u_value(self):
"""Get or set the heat transfer coefficient [W/(m2⋅K)]."""
return 1 / self.r_value

@u_value.setter
def u_value(self, value):
self.r_value = 1 / validators.float(value, minimum=0)

@property
def heat_capacity(self):
Expand Down Expand Up @@ -322,9 +332,10 @@ def to_dict(self):
)

def to_epbunch(self, idf):
"""Convert self to an epbunch given an IDF model.
"""Convert self to an EpBunch given an IDF model.
Notes:
The object is added to the idf model.
The thickness is passed to the epbunch.
Args:
Expand All @@ -345,7 +356,7 @@ def get_unique(self):

def __hash__(self):
"""Return the hash value of self."""
return id(self)
return hash(id(self))

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand All @@ -372,3 +383,7 @@ def duplicate(self):
def __copy__(self):
"""Create a copy of self."""
return self.__class__(self.Material, self.Thickness)

@property
def children(self):
return (self.Material,)
5 changes: 4 additions & 1 deletion archetypal/template/materials/gas_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(
self.Conductivity = Conductivity
self.Density = Density

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def Name(self):
"""Get or set the name of the GasMaterial.
Expand Down Expand Up @@ -270,7 +273,7 @@ def conductivity_at_temperature(self, t_kelvin, pressure=101325):

def __hash__(self):
"""Return the hash value of self."""
return hash((self.__class__.__name__, getattr(self, "Name", None)))
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
5 changes: 4 additions & 1 deletion archetypal/template/materials/glazing_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def __init__(
self.SolarReflectanceFront = SolarReflectanceFront
self.SolarTransmittance = SolarTransmittance

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def Conductivity(self):
"""Get or set the conductivity of the material [W/m-K]."""
Expand Down Expand Up @@ -442,7 +445,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash((self.__class__.__name__, getattr(self, "Name", None)))
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
2 changes: 1 addition & 1 deletion archetypal/template/materials/material_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def TransportEnergy(self, value):

def __hash__(self):
"""Return the hash value of self."""
return hash((self.__class__.__name__, getattr(self, "Name", None)))
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
8 changes: 6 additions & 2 deletions archetypal/template/materials/material_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, Material, Thickness, **kwargs):
"""Initialize a MaterialLayer object with parameters.
Args:
Material (OpaqueMaterial, GlazingMaterial, GasMaterial):
Material (OpaqueMaterial, GlazingMaterial):
Thickness (float): The thickness of the material in the
construction.
"""
Expand Down Expand Up @@ -135,7 +135,7 @@ def get_unique(self):

def __hash__(self):
"""Return the hash value of self."""
return id(self)
return hash(id(self))

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand All @@ -162,3 +162,7 @@ def duplicate(self):
def __copy__(self):
"""Create a copy of self."""
return self.__class__(self.Material, self.Thickness)

@property
def children(self):
return (self.Material,)
5 changes: 4 additions & 1 deletion archetypal/template/materials/nomass_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def __init__(
self.VisibleAbsorptance = VisibleAbsorptance
self.MoistureDiffusionResistance = MoistureDiffusionResistance

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def r_value(self):
"""Get or set the thermal resistance [m2-K/W]."""
Expand Down Expand Up @@ -430,7 +433,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash((self.__class__.__name__, getattr(self, "Name", None)))
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
12 changes: 5 additions & 7 deletions archetypal/template/materials/opaque_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def __init__(
self.MoistureDiffusionResistance = MoistureDiffusionResistance

self._key: str = kwargs.get("_key", "")
# TODO: replace when NoMass and AirGap is properly supported
# TODO: replace when NoMass and AirGap when properly is supported

# Only at the end append self to CREATED_OBJECTS
self.CREATED_OBJECTS.append(self)

@property
def Conductivity(self):
Expand Down Expand Up @@ -573,12 +576,7 @@ def __add__(self, other):

def __hash__(self):
"""Return the hash value of self."""
return hash(
(
self.__class__.__name__,
getattr(self, "Name", None),
)
)
return hash(self.id)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down
Loading

0 comments on commit 577ac65

Please sign in to comment.