Skip to content

Commit

Permalink
Supports Material:NoMass and Material:AirGap in OpaqueMaterial class (#…
Browse files Browse the repository at this point in the history
…274)

* Writes NoMassMaterial class like OpaqueMaterial

* Enables Conversion of OpaqueMaterial to Material:NoMass and Material:AirGap

* Fix version tests
  • Loading branch information
Samuel Letellier-Duchesne authored Jan 19, 2022
1 parent ff10b41 commit 04c7c57
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion archetypal/eplus_interface/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def valid_versions(self) -> set:
"""List the idd file version found on this machine."""
if not self.valid_idd_paths:
# Little hack in case E+ is not installed
_choices = set(settings.ep_version)
_choices = {settings.ep_version,}
else:
_choices = set(self.valid_idd_paths.keys())

Expand Down
2 changes: 1 addition & 1 deletion archetypal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ def set_weigth_attr(self, weight):
zone_weight = ZoneWeight(n=0)

# Latest version of EnergyPlus compatible with archetypal looks for ENERGYPLUS_VERSION in os.environ
ep_version = os.getenv("ENERGYPLUS_VERSION", "9-2-0").replace("-", ".")
ep_version = os.getenv("ENERGYPLUS_VERSION", "9-2-0")
2 changes: 1 addition & 1 deletion archetypal/template/constructions/opaque_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def from_epbunch(cls, epbunch, **kwargs):
**kwargs: keywords passed to the LayeredConstruction constructor.
"""
assert epbunch.key.lower() in ("internalmass", "construction", 'construction:internalsource'), (
f"Expected ('Internalmass', 'Construction', 'construction:internalsouce')." f"Got '{epbunch.key}'."
f"Expected ('Internalmass', 'Construction', 'construction:internalsource')." f"Got '{epbunch.key}'."
)
name = epbunch.Name

Expand Down
85 changes: 30 additions & 55 deletions archetypal/template/materials/nomass_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sigfig import round
from validator_collection import validators

from archetypal.template import GasMaterial
from archetypal.template.materials.material_base import MaterialBase
from archetypal.utils import log

Expand Down Expand Up @@ -119,7 +120,11 @@ def ThermalEmittance(self):

@ThermalEmittance.setter
def ThermalEmittance(self, value):
self._thermal_emittance = validators.float(value, minimum=0, maximum=1)
if value == "" or value is None:
value = 0.9
self._thermal_emittance = validators.float(
value, minimum=0, maximum=1, allow_empty=True
)

@property
def VisibleAbsorptance(self):
Expand All @@ -128,6 +133,8 @@ def VisibleAbsorptance(self):

@VisibleAbsorptance.setter
def VisibleAbsorptance(self, value):
if value == "" or value is None or value is None:
value = 0.7
self._visible_absorptance = validators.float(
value, minimum=0, maximum=1, allow_empty=True
)
Expand Down Expand Up @@ -299,7 +306,6 @@ def from_epbunch(cls, epbunch, **kwargs):
ThermalEmittance=epbunch.Thermal_Absorptance,
VisibleAbsorptance=epbunch.Visible_Absorptance,
Name=epbunch.Name,
idf=epbunch.theidf,
**kwargs,
)
elif epbunch.key.upper() == "MATERIAL:NOMASS":
Expand All @@ -313,41 +319,12 @@ def from_epbunch(cls, epbunch, **kwargs):
ThermalEmittance=epbunch.Thermal_Absorptance,
VisibleAbsorptance=epbunch.Visible_Absorptance,
Name=epbunch.Name,
idf=epbunch.theidf,
**kwargs,
)
elif epbunch.key.upper() == "MATERIAL:AIRGAP":
gas_prop = {
"AIR": dict(
Conductivity=0.02436,
Density=1.754,
SpecificHeat=1000,
ThermalEmittance=0.001,
),
"ARGON": dict(
Conductivity=0.016,
Density=1.784,
SpecificHeat=1000,
ThermalEmittance=0.001,
),
"KRYPTON": dict(
Conductivity=0.0088,
Density=3.749,
SpecificHeat=1000,
ThermalEmittance=0.001,
),
"XENON": dict(
Conductivity=0.0051,
Density=5.761,
SpecificHeat=1000,
ThermalEmittance=0.001,
),
"SF6": dict(
Conductivity=0.001345,
Density=6.17,
SpecificHeat=1000,
ThermalEmittance=0.001,
),
obj.Name.upper(): obj.mapping()
for obj in [GasMaterial(gas_name) for gas_name in GasMaterial._GASTYPES]
}
for gasname, properties in gas_prop.items():
if gasname.lower() in epbunch.Name.lower():
Expand All @@ -356,7 +333,6 @@ def from_epbunch(cls, epbunch, **kwargs):
Name=epbunch.Name,
Thickness=thickness,
**properties,
idf=epbunch.theidf,
)
else:
thickness = (
Expand All @@ -366,7 +342,6 @@ def from_epbunch(cls, epbunch, **kwargs):
Name=epbunch.Name,
Thickness=thickness,
**gas_prop["AIR"],
idf=epbunch.theidf,
)
else:
raise NotImplementedError(
Expand All @@ -386,6 +361,7 @@ def to_epbunch(self, idf):
"""
return idf.newidfobject(
"MATERIAL:NOMASS",
Name=self.Name,
Roughness=self.Roughness,
Thermal_Resistance=self.r_value,
Thermal_Absorptance=self.ThermalEmittance,
Expand Down Expand Up @@ -461,26 +437,25 @@ def __eq__(self, other):
if not isinstance(other, NoMassMaterial):
return NotImplemented
else:
return all(
[
self.r_value == other.r_value,
self.SolarAbsorptance == other.SolarAbsorptance,
self.ThermalEmittance == other.ThermalEmittance,
self.VisibleAbsorptance == other.VisibleAbsorptance,
self.Roughness == other.Roughness,
self.Cost == other.Cost,
self.MoistureDiffusionResistance
== self.MoistureDiffusionResistance,
self.EmbodiedCarbon == other.EmbodiedCarbon,
self.EmbodiedEnergy == other.EmbodiedEnergy,
self.TransportCarbon == other.TransportCarbon,
self.TransportDistance == other.TransportDistance,
self.TransportEnergy == other.TransportEnergy,
np.array_equal(
self.SubstitutionRatePattern, other.SubstitutionRatePattern
),
self.SubstitutionTimestep == other.SubstitutionTimestep,
]
return self.__key__() == other.__key__()

def __key__(self):
"""Get a tuple of attributes. Useful for hashing and comparing."""
return (
self.r_value,
self.SolarAbsorptance,
self.ThermalEmittance,
self.VisibleAbsorptance,
self.Roughness,
self.Cost,
self.MoistureDiffusionResistance,
self.EmbodiedCarbon,
self.EmbodiedEnergy,
self.TransportCarbon,
self.TransportDistance,
self.TransportEnergy,
self.SubstitutionRatePattern,
self.SubstitutionTimestep,
)

def __copy__(self):
Expand Down
49 changes: 37 additions & 12 deletions archetypal/template/materials/opaque_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OpaqueMaterial(MaterialBase):
"_moisture_diffusion_resistance",
"_conductivity",
"_density",
"_key"
)

def __init__(
Expand Down Expand Up @@ -117,6 +118,9 @@ def __init__(
self.VisibleAbsorptance = VisibleAbsorptance
self.MoistureDiffusionResistance = MoistureDiffusionResistance

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

@property
def Conductivity(self):
"""Get or set the conductivity of the material [W/m-K]."""
Expand Down Expand Up @@ -414,6 +418,7 @@ def from_epbunch(cls, epbunch, **kwargs):
ThermalEmittance=epbunch.Thermal_Absorptance,
VisibleAbsorptance=epbunch.Visible_Absorptance,
Name=epbunch.Name,
_key=epbunch.key.upper(),
**kwargs,
)
elif epbunch.key.upper() == "MATERIAL:AIRGAP":
Expand All @@ -429,6 +434,7 @@ def from_epbunch(cls, epbunch, **kwargs):
Name=epbunch.Name,
Thickness=thickness,
SpecificHeat=100.5,
_key=epbunch.key.upper(),
**properties,
)
else:
Expand All @@ -440,6 +446,7 @@ def from_epbunch(cls, epbunch, **kwargs):
Name=epbunch.Name,
Thickness=thickness,
SpecificHeat=100.5,
_key=epbunch.key.upper(),
**gas_prop["AIR"],
)
else:
Expand Down Expand Up @@ -472,18 +479,36 @@ def to_epbunch(self, idf, thickness) -> EpBunch:
Returns:
EpBunch: The EpBunch object added to the idf model.
"""
return idf.newidfobject(
"MATERIAL",
Name=self.Name,
Roughness=self.Roughness,
Thickness=thickness,
Conductivity=self.Conductivity,
Density=self.Density,
Specific_Heat=self.SpecificHeat,
Thermal_Absorptance=self.ThermalEmittance,
Solar_Absorptance=self.SolarAbsorptance,
Visible_Absorptance=self.VisibleAbsorptance,
)
if self._key == "MATERIAL:NOMASS":
# Special case for Material:NoMass
return idf.newidfobject(
"MATERIAL:NOMASS",
Name=self.Name,
Roughness=self.Roughness,
Thermal_Resistance=thickness / self.Conductivity,
Thermal_Absorptance=self.ThermalEmittance,
Solar_Absorptance=self.SolarAbsorptance,
Visible_Absorptance=self.VisibleAbsorptance,
)
elif self._key == "MATERIAL:AIRGAP":
return idf.newidfobject(
"MATERIAL:AIRGAP",
Name=self.Name,
Thermal_Resistance=thickness / self.Conductivity,
)
else:
return idf.newidfobject(
"MATERIAL",
Name=self.Name,
Roughness=self.Roughness,
Thickness=thickness,
Conductivity=self.Conductivity,
Density=self.Density,
Specific_Heat=self.SpecificHeat,
Thermal_Absorptance=self.ThermalEmittance,
Solar_Absorptance=self.SolarAbsorptance,
Visible_Absorptance=self.VisibleAbsorptance,
)

def validate(self):
"""Validate object and fill in missing values.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_idfclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def idf(self, request):

def test_init_version(self, idf):
"""Test creation of in-memory IDF file"""
assert idf.file_version.dot == settings.ep_version
assert idf.file_version.dash == settings.ep_version

# test another instance in this session with a different version number.
idf = IDF(as_version="8-9-0")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ def test_idd_on_missing_install(self):
idd_version = EnergyPlusVersion("9.2")
idd_version._valid_paths = {} # fakes not finding any versions on machine.

assert idd_version.valid_versions == {"9-2-0"}
assert idd_version.valid_versions == {"9-2-0",}

0 comments on commit 04c7c57

Please sign in to comment.