Skip to content

Commit

Permalink
feat(constructions): Add support for Material Color
Browse files Browse the repository at this point in the history
- Support custom material colors for WUFI-Passive export
- Update all tests
  • Loading branch information
ed-p-may committed Mar 6, 2024
1 parent 3a70bfc commit 03fd78f
Show file tree
Hide file tree
Showing 11 changed files with 9,115 additions and 8,888 deletions.
39 changes: 37 additions & 2 deletions PHX/from_HBJSON/create_assemblies.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
WindowConstructionPhProperties,
)
from honeybee_energy_ph.construction.window import PhWindowGlazing, PhWindowFrame
from honeybee_ph_utils import iso_10077_1
from honeybee_energy_ph.properties.materials.opaque import EnergyMaterialPhProperties
from honeybee_ph_utils import iso_10077_1, color

from PHX.model import constructions, project, shades

Expand All @@ -37,6 +38,25 @@ def _conductivity_from_r_value(_r_value: float, _thickness: float) -> float:
return conductivity


def create_phx_color_from_hbph_color(_hbph_color: Optional[color.PhColor]) -> constructions.PhxColor:
"""Create a new PHX-Color from a Honeybee-PH-Utils PhColor.
Arguments:
----------
* _hbph_color (Optional[color.PhColor]): The Honeybee-PH-Utils Color to use as the source.
Returns:
--------
* (constructions.PhxColor): The new PHX-Color object.
"""
new_color = constructions.PhxColor()
if _hbph_color:
new_color.alpha = int(_hbph_color.a)
new_color.red = int(_hbph_color.r)
new_color.green = int(_hbph_color.g)
new_color.blue = int(_hbph_color.b)
return new_color

def build_phx_material_from_hb_EnergyMaterial(
_hb_material: EnergyMaterial,
) -> constructions.PhxMaterial:
Expand All @@ -57,7 +77,15 @@ def build_phx_material_from_hb_EnergyMaterial(
new_mat.conductivity = _hb_material.conductivity
new_mat.density = _hb_material.density
new_mat.heat_capacity = _hb_material.specific_heat
new_mat.percentage_of_assembly = _hb_material.properties.ph.percentage_of_assembly # type: ignore

_prop_ph = _hb_material.properties.ph # type: EnergyMaterialPhProperties # type: ignore
new_mat.percentage_of_assembly = _prop_ph.percentage_of_assembly

try:
hbph_color = _prop_ph.ph_color
except AttributeError:
hbph_color = None
new_mat.argb_color = create_phx_color_from_hbph_color(hbph_color)

# -- Defaults
new_mat.porosity = 0.95
Expand Down Expand Up @@ -89,6 +117,13 @@ def build_phx_material_from_hb_EnergyMaterialNoMass(
new_mat.density = _hb_material.mass_area_density
new_mat.heat_capacity = _hb_material.area_heat_capacity

_prop_ph = _hb_material.properties.ph # type: EnergyMaterialPhProperties # type: ignore
try:
hbph_color = _prop_ph.ph_color
except AttributeError:
hbph_color = None
new_mat.argb_color = create_phx_color_from_hbph_color(hbph_color)

# -- Defaults
new_mat.water_vapor_resistance = 1.0
new_mat.porosity = 0.95
Expand Down
8 changes: 8 additions & 0 deletions PHX/model/constructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
from dataclasses import dataclass, field
import uuid

@dataclass
class PhxColor:
# Default color is white
alpha: int = 255
red: int = 255
green: int = 255
blue: int = 255

@dataclass
class PhxMaterial:
Expand All @@ -19,6 +26,7 @@ class PhxMaterial:
water_vapor_resistance: float = 0.0
reference_water: float = 0.0
percentage_of_assembly: float = 1.0
argb_color: PhxColor = field(default_factory=PhxColor)


@dataclass
Expand Down
8 changes: 8 additions & 0 deletions PHX/to_WUFI_XML/xml_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,16 @@ def _PhxMaterial(_m: constructions.PhxMaterial) -> List[xml_writable]:
XML_Node("HeatCapacity", _m.heat_capacity),
XML_Node("WaterVaporResistance", _m.water_vapor_resistance),
XML_Node("ReferenceWaterContent", _m.reference_water),
XML_Object("Color", _m.argb_color, _schema_name="_PhxColor"),
]

def _PhxColor(_c: constructions.PhxColor) -> List[xml_writable]:
return [
XML_Node("Alpha", _c.alpha),
XML_Node("Red", _c.red),
XML_Node("Green", _c.green),
XML_Node("Blue", _c.blue),
]

def _PhxConstructionWindow(
_wt: constructions.PhxConstructionWindow,
Expand Down
76 changes: 74 additions & 2 deletions tests/_reference_xml/Default_Model_Single_Zone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
<Components count="3">
<Component index="0">
<IdentNr>5</IdentNr>
<Name>Room_1_bfb7b23e..Face4</Name>
<Name>Room_1_95f6e17f..Face4</Name>
<Visual>true</Visual>
<Type>1</Type>
<IdentNrColorI>12</IdentNrColorI>
Expand All @@ -218,7 +218,7 @@
</Component>
<Component index="1">
<IdentNr>6</IdentNr>
<Name>Room_1_bfb7b23e..Face5</Name>
<Name>Room_1_95f6e17f..Face5</Name>
<Visual>true</Visual>
<Type>1</Type>
<IdentNrColorI>7</IdentNrColorI>
Expand Down Expand Up @@ -586,6 +586,12 @@
<HeatCapacity>790.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="1">
Expand All @@ -598,6 +604,12 @@
<HeatCapacity>840.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="2">
Expand All @@ -610,6 +622,12 @@
<HeatCapacity>1210.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="3">
Expand All @@ -622,6 +640,12 @@
<HeatCapacity>1000.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="4">
Expand All @@ -634,6 +658,12 @@
<HeatCapacity>1090.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
</Layers>
Expand All @@ -654,6 +684,12 @@
<HeatCapacity>1210.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="1">
Expand All @@ -666,6 +702,12 @@
<HeatCapacity>900.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
</Layers>
Expand All @@ -686,6 +728,12 @@
<HeatCapacity>1460.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="1">
Expand All @@ -698,6 +746,12 @@
<HeatCapacity>1210.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="2">
Expand All @@ -710,6 +764,12 @@
<HeatCapacity>840.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="3">
Expand All @@ -722,6 +782,12 @@
<HeatCapacity>1000.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
<Layer index="4">
Expand All @@ -734,6 +800,12 @@
<HeatCapacity>590.0</HeatCapacity>
<WaterVaporResistance>1.0</WaterVaporResistance>
<ReferenceWaterContent>0.0</ReferenceWaterContent>
<Color>
<Alpha>255</Alpha>
<Red>255</Red>
<Green>255</Green>
<Blue>255</Blue>
</Color>
</Material>
</Layer>
</Layers>
Expand Down
Loading

0 comments on commit 03fd78f

Please sign in to comment.