Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/parents lookup #372

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions archetypal/template/building_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class BuildingTemplate(UmiBase):

.. image:: ../images/template/buildingtemplate.png
"""
_CREATED_OBJECTS = []

__slots__ = (
"_partition_ratio",
Expand Down Expand Up @@ -116,7 +115,7 @@ def __init__(
self.Version = Version

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

@property
def Perimeter(self):
Expand Down Expand Up @@ -658,6 +657,13 @@ def __eq__(self, other):
]
)

@property
def ParentTemplates(self):
"""Bails out of Parent Templates recursive call from UmiBase
And returns array of self for concatenation
"""
return {self}

@property
def children(self):
return self.Core, self.Perimeter, self.Structure, self.Windows
5 changes: 3 additions & 2 deletions archetypal/template/conditioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class ZoneConditioning(UmiBase):

.. image:: ../images/template/zoninfo-conditioning.png
"""
_CREATED_OBJECTS = []

_POSSIBLE_PARENTS = [("ZoneDefinition", ["Conditioning"])]

__slots__ = (
"_cooling_setpoint",
Expand Down Expand Up @@ -287,7 +288,7 @@ def __init__(
self.area = area

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

@property
def area(self):
Expand Down
7 changes: 5 additions & 2 deletions archetypal/template/constructions/opaque_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class OpaqueConstruction(LayeredConstruction):
* solar_reflectance_index
"""

_CREATED_OBJECTS = []
_POSSIBLE_PARENTS = [
("ZoneDefinition", ["InternalMassConstruction"]),
("ZoneConstructionSet", ["Facade", "Slab", "Ground", "Partition", "Roof"]),
]

__slots__ = ("area",)

Expand All @@ -48,7 +51,7 @@ def __init__(self, Name, Layers, **kwargs):
self.area = 1

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

@property
def r_value(self):
Expand Down
5 changes: 2 additions & 3 deletions archetypal/template/constructions/window_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ class WindowConstruction(LayeredConstruction):
.. image:: ../images/template/constructions-window.png
"""

_CREATED_OBJECTS = []

_POSSIBLE_PARENTS = [("WindowSetting", ["Construction"])]
_CATEGORIES = ("single", "double", "triple", "quadruple")

__slots__ = ("_category",)
Expand All @@ -88,7 +87,7 @@ 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)
self.CREATED_OBJECTS.append(self)

@property
def Category(self):
Expand Down
5 changes: 3 additions & 2 deletions archetypal/template/dhw.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class DomesticHotWaterSetting(UmiBase):

.. image:: ../images/template/zoneinfo-dhw.png
"""
_CREATED_OBJECTS = []

_POSSIBLE_PARENTS = [("ZoneDefinition", ["DomesticHotWater"])]

__slots__ = (
"_flow_rate_per_floor_area",
Expand Down Expand Up @@ -63,7 +64,7 @@ def __init__(
self.area = area

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

@property
def FlowRatePerFloorArea(self):
Expand Down
5 changes: 3 additions & 2 deletions archetypal/template/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ZoneLoad(UmiBase):

.. image:: ../images/template/zoneinfo-loads.png
"""
_CREATED_OBJECTS = []

_POSSIBLE_PARENTS = [("ZoneDefinition", ["Loads"])]

__slots__ = (
"_dimming_type",
Expand Down Expand Up @@ -133,7 +134,7 @@ def __init__(
self.volume = volume

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

@property
def DimmingType(self):
Expand Down
3 changes: 1 addition & 2 deletions archetypal/template/materials/gas_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class GasMaterial(MaterialBase):

.. image:: ../images/template/materials-gas.png
"""
_CREATED_OBJECTS = []

__slots__ = ("_type", "_conductivity", "_density")

Expand All @@ -41,7 +40,7 @@ def __init__(
self.Density = Density

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

@property
def Name(self):
Expand Down
3 changes: 1 addition & 2 deletions archetypal/template/materials/glazing_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class GlazingMaterial(MaterialBase):
.. image:: ../images/template/materials-glazing.png

"""
_CREATED_OBJECTS = []

__slots__ = (
"_ir_emissivity_back",
Expand Down Expand Up @@ -106,7 +105,7 @@ def __init__(
self.SolarTransmittance = SolarTransmittance

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

@property
def Conductivity(self):
Expand Down
21 changes: 21 additions & 0 deletions archetypal/template/materials/material_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ class MaterialBase(UmiBase):
-cycle-impact
"""

_POSSIBLE_PARENTS = [
(
"WindowConstruction",
lambda parent: [
(i, layer.Material) for i, layer in enumerate(parent.Layers)
],
),
(
"OpaqueConstruction",
lambda parent: [
(i, layer.Material) for i, layer in enumerate(parent.Layers)
],
),
(
"StructureInformation",
lambda parent: [
(i, ratio.Material) for i, ratio in enumerate(parent.MassRatios)
],
),
]

__slots__ = (
"_cost",
"_embodied_carbon",
Expand Down
4 changes: 1 addition & 3 deletions archetypal/template/materials/nomass_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
class NoMassMaterial(MaterialBase):
"""Use this component to create a custom no mass material."""

_CREATED_OBJECTS = []

_ROUGHNESS_TYPES = (
"VeryRough",
"Rough",
Expand Down Expand Up @@ -80,7 +78,7 @@ def __init__(
self.MoistureDiffusionResistance = MoistureDiffusionResistance

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

@property
def r_value(self):
Expand Down
4 changes: 1 addition & 3 deletions archetypal/template/materials/opaque_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class OpaqueMaterial(MaterialBase):
.. image:: ../images/template/materials-opaque.png
"""

_CREATED_OBJECTS = []

_ROUGHNESS_TYPES = (
"VeryRough",
"Rough",
Expand Down Expand Up @@ -124,7 +122,7 @@ def __init__(
# TODO: replace when NoMass and AirGap when properly is supported

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

@property
def Conductivity(self):
Expand Down
47 changes: 44 additions & 3 deletions archetypal/template/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

class UmiSchedule(Schedule, UmiBase):
"""Class that handles Schedules."""
_CREATED_OBJECTS = []

__slots__ = ("_quantity",)

Expand All @@ -33,7 +32,7 @@ def __init__(self, Name, quantity=None, **kwargs):
self.quantity = quantity

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

@property
def quantity(self):
Expand Down Expand Up @@ -503,6 +502,10 @@ def __hash__(self):
class DaySchedule(UmiSchedule):
"""Superclass of UmiSchedule that handles daily schedules."""

_POSSIBLE_PARENTS = [
("WeekSchedule", lambda parent: [(i, day) for i, day in enumerate(parent.Days)])
]

__slots__ = ("_values",)

def __init__(self, Name, Values, Category="Day", **kwargs):
Expand All @@ -517,6 +520,7 @@ def __init__(self, Name, Values, Category="Day", **kwargs):
super(DaySchedule, self).__init__(
Category=Category, Name=Name, Values=Values, **kwargs
)
self.CREATED_OBJECTS.append(self)

@property
def all_values(self) -> np.ndarray:
Expand Down Expand Up @@ -719,6 +723,12 @@ def to_epbunch(self, idf):
class WeekSchedule(UmiSchedule):
"""Superclass of UmiSchedule that handles weekly schedules."""

_POSSIBLE_PARENTS = [
(
"YearSchedule",
lambda parent: [(i, p.Schedule) for i, p in enumerate(parent.Parts)],
)
]
__slots__ = ("_days", "_values")

def __init__(self, Name, Days=None, Category="Week", **kwargs):
Expand All @@ -730,6 +740,7 @@ def __init__(self, Name, Days=None, Category="Week", **kwargs):
"""
super(WeekSchedule, self).__init__(Name, Category=Category, **kwargs)
self.Days = Days
self.CREATED_OBJECTS.append(self)

@property
def Days(self):
Expand Down Expand Up @@ -912,6 +923,35 @@ def children(self):
class YearSchedule(UmiSchedule):
"""Superclass of UmiSchedule that handles yearly schedules."""

_POSSIBLE_PARENTS = [
(
"WindowSetting",
[
"AfnWindowAvailability",
"ShadingSystemAvailabilitySchedule",
"ZoneMixingAvailabilitySchedule",
],
),
("VentilationSetting", ["NatVentSchedule", "ScheduledVentilationSchedule"]),
(
"ZoneLoad",
[
"EquipmentAvailabilitySchedule",
"LightsAvailabilitySchedule",
"OccupancySchedule",
],
),
("DomesticHotWaterSetting", ["WaterSchedule"]),
(
"ZoneConditioning",
[
"CoolingSchedule",
"HeatingSchedule",
"MechVentSchedule",
],
),
]

def __init__(self, Name, Type="Fraction", Parts=None, Category="Year", **kwargs):
"""Initialize a YearSchedule object with parameters.

Expand All @@ -930,6 +970,7 @@ def __init__(self, Name, Type="Fraction", Parts=None, Category="Year", **kwargs)
super(YearSchedule, self).__init__(
Name=Name, Type=Type, schType="Schedule:Year", Category=Category, **kwargs
)
self.CREATED_OBJECTS.append(self)

def __eq__(self, other):
"""Assert self is equivalent to other."""
Expand Down Expand Up @@ -1068,7 +1109,7 @@ def _get_parts(self, epbunch):
next(
(
x
for x in self._CREATED_OBJECTS
for x in self.CREATED_OBJECTS
if x.Name == week_day_schedule_name
and type(x).__name__ == "WeekSchedule"
)
Expand Down
4 changes: 2 additions & 2 deletions archetypal/template/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class StructureInformation(ConstructionBase):
.. image:: ../images/template/constructions-structure.png
"""

_CREATED_OBJECTS = []
_POSSIBLE_PARENTS = [("BuildingTemplate", ["Structure"])]

__slots__ = ("_mass_ratios",)

Expand All @@ -154,7 +154,7 @@ def __init__(self, Name, MassRatios, **kwargs):
self.MassRatios = MassRatios

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

@property
def MassRatios(self):
Expand Down
Loading