From bcdd40b687f5459e2637375527c4e5be067d9de4 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Mon, 24 May 2021 18:51:29 -0400 Subject: [PATCH] Ensures compatibility with archetypal --- tests/conftest.py | 11 +++++---- umitemplatedb/core.py | 10 ++++---- umitemplatedb/mongodb_schema.py | 41 +++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5abd450..354b61d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,6 +21,7 @@ MassRatio, StructureInformation, WindowSetting, + GasLayer, ) @@ -172,7 +173,7 @@ def airlayer(air): Args: air: """ - return MaterialLayer(Material=air, Thickness=0.01) + return GasLayer(Material=air, Thickness=0.01) @pytest.fixture() @@ -183,7 +184,9 @@ def windowconstruction(windowlayer, airlayer): airlayer: """ return WindowConstruction( - Name="A Window Construction", Layers=[windowlayer, airlayer, windowlayer] + Name="A Window Construction", + Layers=[windowlayer, airlayer, windowlayer], + Category="double", ).save() @@ -217,8 +220,8 @@ def conset(construction): @pytest.fixture() -def intmass(): - return OpaqueConstruction(Name="OpaqueConstruction").save() +def intmass(materiallayer): + return OpaqueConstruction(Name="InternalMass", Layers=[materiallayer]).save() @pytest.fixture() diff --git a/umitemplatedb/core.py b/umitemplatedb/core.py index 013d9d0..2b202dd 100644 --- a/umitemplatedb/core.py +++ b/umitemplatedb/core.py @@ -1,6 +1,7 @@ import logging from enum import Enum +from archetypal.umi_template import traverse from mongoengine import EmbeddedDocument from tqdm import tqdm @@ -37,7 +38,7 @@ def recursive(umibase, **metaattributes): if isinstance( value, ( - archetypal.template.UmiBase, + archetypal.template.umi_base.UmiBase, archetypal.template.schedule.YearSchedulePart, ), ): @@ -48,10 +49,11 @@ def recursive(umibase, **metaattributes): if isinstance( value, ( - archetypal.template.UmiBase, + archetypal.template.umi_base.UmiBase, archetypal.template.schedule.YearSchedulePart, - archetypal.template.MaterialLayer, - archetypal.template.MassRatio, + archetypal.template.materials.material_layer.MaterialLayer, + archetypal.template.materials.gas_layer.GasLayer, + archetypal.template.structure.MassRatio, ), ): instance_attr[key].append(recursive(value)) diff --git a/umitemplatedb/mongodb_schema.py b/umitemplatedb/mongodb_schema.py index 8bd11e5..d10aafc 100644 --- a/umitemplatedb/mongodb_schema.py +++ b/umitemplatedb/mongodb_schema.py @@ -49,6 +49,7 @@ def failed(self, event): "microseconds".format(event) ) + # Uncomment next line to register the logger # monitoring.register(CommandLogger()) @@ -121,7 +122,7 @@ class GlazingMaterial(Material): class OpaqueMaterial(Material): - SpecificHeat = FloatField(default=0) + SpecificHeat = FloatField(default=100, min_value=100) SolarAbsorptance = FloatField(default=0.7) ThermalEmittance = FloatField(default=0.9) VisibleAbsorptance = FloatField(default=0.7) @@ -139,13 +140,28 @@ class OpaqueMaterial(Material): ) -class MaterialLayer(EmbeddedDocument): +class _Layer(EmbeddedDocument): + """Parent class of MaterialLayer & GasLayer to use in EmbeddedDocumentListField.""" + + pass + + meta = {"allow_inheritance": True} + + +class MaterialLayer(_Layer): Material = ReferenceField(Material, required=True) Thickness = FloatField(required=True) meta = {"allow_inheritance": True, "strict": False} +class GasLayer(_Layer): + Material = ReferenceField(GasMaterial, required=True) + Thickness = FloatField(required=True) + + meta = {"allow_inheritance": True, "strict": False} + + class ConstructionBase(UmiBase): # Type = IntField(choices=range(0, 5)) @@ -157,13 +173,13 @@ class ConstructionBase(UmiBase): class OpaqueConstruction(ConstructionBase): - Layers = EmbeddedDocumentListField(MaterialLayer) + Layers = EmbeddedDocumentListField(_Layer) meta = {"allow_inheritance": True} class WindowConstruction(ConstructionBase): - Layers = EmbeddedDocumentListField(MaterialLayer) + Layers = EmbeddedDocumentListField(_Layer) class MassRatio(EmbeddedDocument): @@ -302,6 +318,15 @@ class ZoneDefinition(UmiBase): Loads = ReferenceField(ZoneLoad, required=True) Ventilation = ReferenceField(VentilationSetting, required=True) + zone_surfaces = ListField() + is_part_of_conditioned_floor_area = BooleanField(default=True) + volume = FloatField() + multiplier = IntField(min_value=1) + occupants = FloatField() + is_part_of_total_floor_area = BooleanField(default=True) + area = FloatField() + is_core = BooleanField() + class WindowSetting(UmiBase): AfnDischargeC = FloatField(default=0.65, min_value=0, max_value=1) @@ -393,7 +418,13 @@ def recursive(document, idf, bar): for value in document[key]: if isinstance( value, - (UmiBase, YearSchedulePart, MaterialLayer, MassRatio,), + ( + UmiBase, + YearSchedulePart, + MaterialLayer, + GasLayer, + MassRatio, + ), ): instance_attr[key].append(recursive(value, idf, bar)) else: