Spaces:
Sleeping
Sleeping
Update utils/cooling_load.py
Browse files- utils/cooling_load.py +100 -17
utils/cooling_load.py
CHANGED
@@ -15,7 +15,7 @@ from data.ashrae_tables import ASHRAETables
|
|
15 |
from utils.heat_transfer import HeatTransferCalculations
|
16 |
from utils.psychrometrics import Psychrometrics
|
17 |
from app.component_selection import Wall, Roof, Window, Door, Skylight, Orientation
|
18 |
-
from data.drapery import Drapery
|
19 |
|
20 |
# Set up logging
|
21 |
logging.basicConfig(level=logging.INFO)
|
@@ -662,7 +662,9 @@ class CoolingLoadCalculator:
|
|
662 |
hour: int,
|
663 |
latitude: str,
|
664 |
shading_coefficient: float,
|
665 |
-
adjusted_shgc: Optional[float] = None
|
|
|
|
|
666 |
) -> Dict[str, float]:
|
667 |
"""
|
668 |
Calculate cooling load for a window (conduction and solar).
|
@@ -677,6 +679,8 @@ class CoolingLoadCalculator:
|
|
677 |
latitude: Latitude (e.g., '24N')
|
678 |
shading_coefficient: Default shading coefficient
|
679 |
adjusted_shgc: Adjusted SHGC from external drapery calculation (optional)
|
|
|
|
|
680 |
|
681 |
Returns:
|
682 |
Dictionary with conduction, solar, and total loads in Watts
|
@@ -686,17 +690,55 @@ class CoolingLoadCalculator:
|
|
686 |
month = self.validate_month(month)
|
687 |
hour = self.validate_hour(hour)
|
688 |
if self.debug_mode:
|
689 |
-
logger.debug(f"calculate_window_cooling_load: latitude={latitude}, month={month}, hour={hour}, orientation={window.orientation.value}")
|
690 |
|
691 |
-
#
|
692 |
-
|
693 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
694 |
|
695 |
# Determine shading coefficient
|
696 |
effective_shading_coefficient = adjusted_shgc if adjusted_shgc is not None else shading_coefficient
|
697 |
if adjusted_shgc is None and hasattr(window, 'drapery') and window.drapery and window.drapery.enabled:
|
698 |
try:
|
699 |
-
effective_shading_coefficient = window.drapery.get_shading_coefficient(
|
700 |
if self.debug_mode:
|
701 |
logger.debug(f"Using drapery shading coefficient: {effective_shading_coefficient}")
|
702 |
except Exception as e:
|
@@ -720,11 +762,11 @@ class CoolingLoadCalculator:
|
|
720 |
logger.warning("Using default SCL=100 W/m²")
|
721 |
scl = 100.0
|
722 |
|
723 |
-
solar_load = window.area *
|
724 |
|
725 |
total_load = conduction_load + solar_load
|
726 |
if self.debug_mode:
|
727 |
-
logger.debug(f"Window load: conduction={conduction_load}, solar={solar_load}, total={total_load}, effective_shading_coefficient={effective_shading_coefficient}")
|
728 |
|
729 |
return {
|
730 |
'conduction': max(conduction_load, 0.0),
|
@@ -746,7 +788,9 @@ class CoolingLoadCalculator:
|
|
746 |
hour: int,
|
747 |
latitude: str,
|
748 |
shading_coefficient: float,
|
749 |
-
adjusted_shgc: Optional[float] = None
|
|
|
|
|
750 |
) -> Dict[str, float]:
|
751 |
"""
|
752 |
Calculate cooling load for a skylight (conduction and solar).
|
@@ -761,6 +805,8 @@ class CoolingLoadCalculator:
|
|
761 |
latitude: Latitude (e.g., '24N')
|
762 |
shading_coefficient: Default shading coefficient
|
763 |
adjusted_shgc: Adjusted SHGC from external drapery calculation (optional)
|
|
|
|
|
764 |
|
765 |
Returns:
|
766 |
Dictionary with conduction, solar, and total loads in Watts
|
@@ -770,17 +816,54 @@ class CoolingLoadCalculator:
|
|
770 |
month = self.validate_month(month)
|
771 |
hour = self.validate_hour(hour)
|
772 |
if self.debug_mode:
|
773 |
-
logger.debug(f"calculate_skylight_cooling_load: latitude={latitude}, month={month}, hour={hour}, orientation=Horizontal")
|
774 |
|
775 |
-
#
|
776 |
-
|
777 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
778 |
|
779 |
# Determine shading coefficient
|
780 |
effective_shading_coefficient = adjusted_shgc if adjusted_shgc is not None else shading_coefficient
|
781 |
if adjusted_shgc is None and hasattr(skylight, 'drapery') and skylight.drapery and skylight.drapery.enabled:
|
782 |
try:
|
783 |
-
effective_shading_coefficient = skylight.drapery.get_shading_coefficient(
|
784 |
if self.debug_mode:
|
785 |
logger.debug(f"Using drapery shading coefficient: {effective_shading_coefficient}")
|
786 |
except Exception as e:
|
@@ -804,11 +887,11 @@ class CoolingLoadCalculator:
|
|
804 |
logger.warning("Using default SCL=100 W/m²")
|
805 |
scl = 100.0
|
806 |
|
807 |
-
solar_load = skylight.area *
|
808 |
|
809 |
total_load = conduction_load + solar_load
|
810 |
if self.debug_mode:
|
811 |
-
logger.debug(f"Skylight load: conduction={conduction_load}, solar={solar_load}, total={total_load}, effective_shading_coefficient={effective_shading_coefficient}")
|
812 |
|
813 |
return {
|
814 |
'conduction': max(conduction_load, 0.0),
|
|
|
15 |
from utils.heat_transfer import HeatTransferCalculations
|
16 |
from utils.psychrometrics import Psychrometrics
|
17 |
from app.component_selection import Wall, Roof, Window, Door, Skylight, Orientation
|
18 |
+
from data.drapery import Drapery, GlazingType, FrameType, WINDOW_U_FACTORS, WINDOW_SHGC, SKYLIGHT_U_FACTORS, SKYLIGHT_SHGC, CLTDCalculator
|
19 |
|
20 |
# Set up logging
|
21 |
logging.basicConfig(level=logging.INFO)
|
|
|
662 |
hour: int,
|
663 |
latitude: str,
|
664 |
shading_coefficient: float,
|
665 |
+
adjusted_shgc: Optional[float] = None,
|
666 |
+
glazing_type: Optional[str] = None,
|
667 |
+
frame_type: Optional[str] = None
|
668 |
) -> Dict[str, float]:
|
669 |
"""
|
670 |
Calculate cooling load for a window (conduction and solar).
|
|
|
679 |
latitude: Latitude (e.g., '24N')
|
680 |
shading_coefficient: Default shading coefficient
|
681 |
adjusted_shgc: Adjusted SHGC from external drapery calculation (optional)
|
682 |
+
glazing_type: Glazing type (e.g., 'Single Clear', 'Double Tinted') (optional)
|
683 |
+
frame_type: Frame type (e.g., 'Aluminum without Thermal Break') (optional)
|
684 |
|
685 |
Returns:
|
686 |
Dictionary with conduction, solar, and total loads in Watts
|
|
|
690 |
month = self.validate_month(month)
|
691 |
hour = self.validate_hour(hour)
|
692 |
if self.debug_mode:
|
693 |
+
logger.debug(f"calculate_window_cooling_load: latitude={latitude}, month={month}, hour={hour}, orientation={window.orientation.value}, glazing_type={glazing_type}, frame_type={frame_type}")
|
694 |
|
695 |
+
# Initialize CLTDCalculator
|
696 |
+
cltd_calculator = CLTDCalculator(
|
697 |
+
indoor_temp=indoor_temp,
|
698 |
+
outdoor_max_temp=outdoor_temp,
|
699 |
+
outdoor_daily_range=11.7, # Default from drapery.py
|
700 |
+
latitude=latitude,
|
701 |
+
month=month
|
702 |
+
)
|
703 |
+
|
704 |
+
# Determine U-factor and SHGC
|
705 |
+
u_value = window.u_value
|
706 |
+
shgc = window.shgc
|
707 |
+
if glazing_type and frame_type:
|
708 |
+
try:
|
709 |
+
glazing_enum = next(g for g in GlazingType if g.value == glazing_type)
|
710 |
+
frame_enum = next(f for f in FrameType if f.value == frame_type)
|
711 |
+
u_value = WINDOW_U_FACTORS.get((glazing_enum, frame_enum), window.u_value)
|
712 |
+
shgc = WINDOW_SHGC.get((glazing_enum, frame_enum), window.shgc)
|
713 |
+
if self.debug_mode:
|
714 |
+
logger.debug(f"Using table values: u_value={u_value}, shgc={shgc} for glazing_type={glazing_type}, frame_type={frame_type}")
|
715 |
+
except StopIteration:
|
716 |
+
if self.debug_mode:
|
717 |
+
logger.warning(f"Invalid glazing_type={glazing_type} or frame_type={frame_type}. Using default u_value={u_value}, shgc={shgc}")
|
718 |
+
|
719 |
+
# Conduction load using CLTD
|
720 |
+
try:
|
721 |
+
glazing_key = glazing_type if glazing_type in ['Single Clear', 'Double Tinted', 'Low-E', 'Reflective'] else 'SingleClear'
|
722 |
+
cltd = cltd_calculator.get_cltd_window(
|
723 |
+
glazing_type=glazing_key,
|
724 |
+
orientation=window.orientation.value,
|
725 |
+
hour=hour
|
726 |
+
)
|
727 |
+
if self.debug_mode:
|
728 |
+
logger.debug(f"CLTD from CLTDCalculator: {cltd} for glazing_type={glazing_key}")
|
729 |
+
except Exception as e:
|
730 |
+
if self.debug_mode:
|
731 |
+
logger.error(f"get_cltd_window failed for glazing_type={glazing_key}: {str(e)}")
|
732 |
+
logger.warning("Using default CLTD=8.0°C")
|
733 |
+
cltd = 8.0
|
734 |
+
|
735 |
+
conduction_load = u_value * window.area * cltd
|
736 |
|
737 |
# Determine shading coefficient
|
738 |
effective_shading_coefficient = adjusted_shgc if adjusted_shgc is not None else shading_coefficient
|
739 |
if adjusted_shgc is None and hasattr(window, 'drapery') and window.drapery and window.drapery.enabled:
|
740 |
try:
|
741 |
+
effective_shading_coefficient = window.drapery.get_shading_coefficient(shgc)
|
742 |
if self.debug_mode:
|
743 |
logger.debug(f"Using drapery shading coefficient: {effective_shading_coefficient}")
|
744 |
except Exception as e:
|
|
|
762 |
logger.warning("Using default SCL=100 W/m²")
|
763 |
scl = 100.0
|
764 |
|
765 |
+
solar_load = window.area * shgc * effective_shading_coefficient * scl
|
766 |
|
767 |
total_load = conduction_load + solar_load
|
768 |
if self.debug_mode:
|
769 |
+
logger.debug(f"Window load: conduction={conduction_load}, solar={solar_load}, total={total_load}, u_value={u_value}, shgc={shgc}, cltd={cltd}, effective_shading_coefficient={effective_shading_coefficient}")
|
770 |
|
771 |
return {
|
772 |
'conduction': max(conduction_load, 0.0),
|
|
|
788 |
hour: int,
|
789 |
latitude: str,
|
790 |
shading_coefficient: float,
|
791 |
+
adjusted_shgc: Optional[float] = None,
|
792 |
+
glazing_type: Optional[str] = None,
|
793 |
+
frame_type: Optional[str] = None
|
794 |
) -> Dict[str, float]:
|
795 |
"""
|
796 |
Calculate cooling load for a skylight (conduction and solar).
|
|
|
805 |
latitude: Latitude (e.g., '24N')
|
806 |
shading_coefficient: Default shading coefficient
|
807 |
adjusted_shgc: Adjusted SHGC from external drapery calculation (optional)
|
808 |
+
glazing_type: Glazing type (e.g., 'Single Clear', 'Double Tinted') (optional)
|
809 |
+
frame_type: Frame type (e.g., 'Aluminum without Thermal Break') (optional)
|
810 |
|
811 |
Returns:
|
812 |
Dictionary with conduction, solar, and total loads in Watts
|
|
|
816 |
month = self.validate_month(month)
|
817 |
hour = self.validate_hour(hour)
|
818 |
if self.debug_mode:
|
819 |
+
logger.debug(f"calculate_skylight_cooling_load: latitude={latitude}, month={month}, hour={hour}, orientation=Horizontal, glazing_type={glazing_type}, frame_type={frame_type}")
|
820 |
|
821 |
+
# Initialize CLTDCalculator
|
822 |
+
cltd_calculator = CLTDCalculator(
|
823 |
+
indoor_temp=indoor_temp,
|
824 |
+
outdoor_max_temp=outdoor_temp,
|
825 |
+
outdoor_daily_range=11.7, # Default from drapery.py
|
826 |
+
latitude=latitude,
|
827 |
+
month=month
|
828 |
+
)
|
829 |
+
|
830 |
+
# Determine U-factor and SHGC
|
831 |
+
u_value = skylight.u_value
|
832 |
+
shgc = skylight.shgc
|
833 |
+
if glazing_type and frame_type:
|
834 |
+
try:
|
835 |
+
glazing_enum = next(g for g in GlazingType if g.value == glazing_type)
|
836 |
+
frame_enum = next(f for f in FrameType if f.value == frame_type)
|
837 |
+
u_value = SKYLIGHT_U_FACTORS.get((glazing_enum, frame_enum), skylight.u_value)
|
838 |
+
shgc = SKYLIGHT_SHGC.get((glazing_enum, frame_enum), skylight.shgc)
|
839 |
+
if self.debug_mode:
|
840 |
+
logger.debug(f"Using table values: u_value={u_value}, shgc={shgc} for glazing_type={glazing_type}, frame_type={frame_type}")
|
841 |
+
except StopIteration:
|
842 |
+
if self.debug_mode:
|
843 |
+
logger.warning(f"Invalid glazing_type={glazing_type} or frame_type={frame_type}. Using default u_value={u_value}, shgc={shgc}")
|
844 |
+
|
845 |
+
# Conduction load using CLTD
|
846 |
+
try:
|
847 |
+
glazing_key = glazing_type if glazing_type in ['Single Clear', 'Double Tinted', 'Low-E', 'Reflective'] else 'SingleClear'
|
848 |
+
cltd = cltd_calculator.get_cltd_skylight(
|
849 |
+
glazing_type=glazing_key,
|
850 |
+
hour=hour
|
851 |
+
)
|
852 |
+
if self.debug_mode:
|
853 |
+
logger.debug(f"CLTD from CLTDCalculator: {cltd} for glazing_type={glazing_key}")
|
854 |
+
except Exception as e:
|
855 |
+
if self.debug_mode:
|
856 |
+
logger.error(f"get_cltd_skylight failed for glazing_type={glazing_key}: {str(e)}")
|
857 |
+
logger.warning("Using default CLTD=8.0°C")
|
858 |
+
cltd = 8.0
|
859 |
+
|
860 |
+
conduction_load = u_value * skylight.area * cltd
|
861 |
|
862 |
# Determine shading coefficient
|
863 |
effective_shading_coefficient = adjusted_shgc if adjusted_shgc is not None else shading_coefficient
|
864 |
if adjusted_shgc is None and hasattr(skylight, 'drapery') and skylight.drapery and skylight.drapery.enabled:
|
865 |
try:
|
866 |
+
effective_shading_coefficient = skylight.drapery.get_shading_coefficient(shgc)
|
867 |
if self.debug_mode:
|
868 |
logger.debug(f"Using drapery shading coefficient: {effective_shading_coefficient}")
|
869 |
except Exception as e:
|
|
|
887 |
logger.warning("Using default SCL=100 W/m²")
|
888 |
scl = 100.0
|
889 |
|
890 |
+
solar_load = skylight.area * shgc * effective_shading_coefficient * scl
|
891 |
|
892 |
total_load = conduction_load + solar_load
|
893 |
if self.debug_mode:
|
894 |
+
logger.debug(f"Skylight load: conduction={conduction_load}, solar={solar_load}, total={total_load}, u_value={u_value}, shgc={shgc}, cltd={cltd}, effective_shading_coefficient={effective_shading_coefficient}")
|
895 |
|
896 |
return {
|
897 |
'conduction': max(conduction_load, 0.0),
|