def add_detailed_construction(idf: IDF,
                              construction: LayeredConstructionProtocol,
                              ureg: pint.UnitRegistry,
                              is_window=False) -> str:
    """
    Adds a construction to the idf.

    Note that in cesarp.model each layer of a construction or window construction is modelled with a separate
    Layer object having a thickness and material, whereas in the IDF definition a material object has a specific
    thickness, thus a construction has directly materials assigned without an intermediate layer object.
    """
    idf_obj_name = construction.name
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.construction, idf_obj_name):
        # assert construction.external_layer_index == 0, \
        #    "external/outside layer of a construction is expected as layer 0. Either change your initialization " \
        #    "of the construction or add some code handling reverse layer order in idf_writer_construction"
        idf_constr = idf.newidfobject(idf_strings.IDFObjects.construction)
        idf_constr.Name = idf_obj_name
        idf_constr.Outside_Layer = add_layer(idf=idf,
                                             layer=construction.layers[0],
                                             ureg=ureg,
                                             is_window_layer=is_window)
        for idx in range(1, len(construction.layers)):
            mat_idf_name = add_layer(idf=idf,
                                     layer=construction.layers[idx],
                                     ureg=ureg,
                                     is_window_layer=is_window)
            idf_constr[f"Layer_{idx+1}"] = mat_idf_name

    return idf_obj_name
def add_window_glazing_material(idf: IDF, idf_obj_name: str,
                                mat_def: TransparentMaterial,
                                thickness: pint.Quantity,
                                ureg: pint.UnitRegistry) -> None:

    idf_obj_type = idf_strings.IDFObjects.win_material_glazing
    if not idf_writing_helpers.exists_in_idf(idf, idf_obj_type, idf_obj_name):
        win_glazing = idf.newidfobject(idf_obj_type)
        win_glazing.Name = idf_obj_name
        win_glazing.Thickness = thickness.to(ureg.m).m
        win_glazing.Optical_Data_Type = idf_strings.WindowMatGlazing.optical_data_type
        win_glazing.Solar_Transmittance_at_Normal_Incidence = mat_def.solar_transmittance.to(
            ureg.dimensionless).m
        win_glazing.Front_Side_Solar_Reflectance_at_Normal_Incidence = mat_def.front_side_solar_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Back_Side_Solar_Reflectance_at_Normal_Incidence = mat_def.back_side_solar_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Visible_Transmittance_at_Normal_Incidence = mat_def.visible_transmittance.to(
            ureg.dimensionless).m
        win_glazing.Front_Side_Visible_Reflectance_at_Normal_Incidence = mat_def.front_side_visible_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Back_Side_Visible_Reflectance_at_Normal_Incidence = mat_def.back_side_visible_reflectance.to(
            ureg.dimensionless).m
        win_glazing.Infrared_Transmittance_at_Normal_Incidence = mat_def.infrared_transmittance.to(
            ureg.dimensionless).m
        win_glazing.Front_Side_Infrared_Hemispherical_Emissivity = mat_def.front_side_infrared_hemispherical_emissivity.to(
            ureg.dimensionless).m
        win_glazing.Back_Side_Infrared_Hemispherical_Emissivity = mat_def.back_side_infrared_hemispherical_emissivity.to(
            ureg.dimensionless).m
        win_glazing.Conductivity = mat_def.conductivity.to(ureg.W /
                                                           (ureg.m * ureg.K)).m
        win_glazing.Dirt_Correction_Factor_for_Solar_and_Visible_Transmittance = mat_def.dirt_correction_factor.to(
            ureg.dimensionless).m
def add_opaque_material(idf: IDF, idf_obj_name: str, mat_def: OpaqueMaterial,
                        thickness: pint.Quantity,
                        ureg: pint.UnitRegistry) -> None:
    """
    For materials without mass specified (e.g. vapour barriers) thickness is not
    :param idf:
    :param idf_obj_name:
    :param mat_def:
    :param thickness:
    :param ureg:
    :return:
    """
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.material, idf_obj_name):
        assert mat_def.is_mass_fully_specified(
        ), f"trying to add opaque material {mat_def.name}, but no mass properties specified"
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.material)
        idf_mat.Name = idf_obj_name
        idf_mat.Roughness = get_idf_roughness_string_for(mat_def.roughness)
        idf_mat.Thickness = thickness.to(ureg.m).m
        idf_mat.Conductivity = mat_def.conductivity.to(ureg.W /
                                                       (ureg.m * ureg.K)).m
        # checking for mass properties at begin, thus ignore type warning due to Optional[] declaration
        idf_mat.Density = mat_def.density.to(ureg.kg /
                                             ureg.m**3).m  # type: ignore
        idf_mat.Specific_Heat = mat_def.specific_heat.to(
            ureg.J / (ureg.kg * ureg.K)).m  # type: ignore
        idf_mat.Thermal_Absorptance = mat_def.thermal_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Solar_Absorptance = mat_def.solar_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Visible_Absorptance = mat_def.visible_absorptance.to(
            ureg.dimensionless).m
def add_material_no_mass(idf: IDF, idf_obj_name: str, mat_def: OpaqueMaterial,
                         thermal_resistance: pint.Quantity,
                         ureg: pint.UnitRegistry) -> None:
    """
    For materials without mass specified (e.g. vapour barriers)
    :param idf:
    :param idf_obj_name:
    :param mat_def:
    :param thermal_resistance:
    :param ureg:
    :return:
    """
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.material_no_mass, idf_obj_name):
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.material_no_mass)
        idf_mat.Name = idf_obj_name
        idf_mat.Roughness = get_idf_roughness_string_for(mat_def.roughness)
        idf_mat.Thermal_Resistance = thermal_resistance.to(
            (ureg.m**2 * ureg.K) / ureg.W).m
        idf_mat.Thermal_Absorptance = mat_def.thermal_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Solar_Absorptance = mat_def.solar_absorptance.to(
            ureg.dimensionless).m
        idf_mat.Visible_Absorptance = mat_def.visible_absorptance.to(
            ureg.dimensionless).m
Пример #5
0
def _add_shading_mat(idf, shading_mat_model: WindowShadingMaterial):
    shade_mat_idf_name = shading_mat_model.name
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.win_shade_material,
            shade_mat_idf_name):
        window_shading_mat = idf.newidfobject(
            idf_strings.IDFObjects.win_shade_material)
        window_shading_mat.Name = shade_mat_idf_name
        window_shading_mat.Solar_Transmittance = shading_mat_model.solar_transmittance.to(
            "solar_transmittance").m
        window_shading_mat.Solar_Reflectance = shading_mat_model.solar_reflectance.to(
            "solar_reflectance").m
        window_shading_mat.Visible_Transmittance = shading_mat_model.visible_transmittance.to(
            "visible_transmittance").m
        window_shading_mat.Visible_Reflectance = shading_mat_model.visible_reflectance.to(
            "visible_reflectance").m
        window_shading_mat.Infrared_Hemispherical_Emissivity = shading_mat_model.infrared_hemispherical_emissivity.to(
            "infrared_hemispherical_emissivity").m
        window_shading_mat.Infrared_Transmittance = shading_mat_model.infrared_transmittance.to(
            "infrared_transmittance").m
        window_shading_mat.Thickness = shading_mat_model.thickness.to("m").m
        window_shading_mat.Conductivity = shading_mat_model.conductivity.to(
            "W/(m*K)").m
        window_shading_mat.Shade_to_Glass_Distance = shading_mat_model.shade_to_glass_distance.to(
            "m").m
        window_shading_mat.Top_Opening_Multiplier = shading_mat_model.top_opening_multiplier
        window_shading_mat.Bottom_Opening_Multiplier = shading_mat_model.bottom_opening_multiplier
        window_shading_mat.LeftSide_Opening_Multiplier = shading_mat_model.leftside_opening_multiplier
        window_shading_mat.RightSide_Opening_Multiplier = shading_mat_model.rightside_opening_multiplier
        window_shading_mat.Airflow_Permeability = shading_mat_model.airflow_permeability
    return shade_mat_idf_name
def add_airgap(idf: IDF, idf_obj_name: str, thermal_resistance: pint.Quantity,
               ureg: pint.UnitRegistry) -> None:
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.material_air_gap, idf_obj_name):
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.material_air_gap)
        idf_mat.Name = idf_obj_name
        idf_mat.Thermal_Resistance = thermal_resistance.to(ureg.m**2 * ureg.K /
                                                           ureg.W).m
def add_window_material_gas(idf: IDF, idf_obj_name: str,
                            thickness: pint.Quantity, mat_def: Gas,
                            ureg: pint.UnitRegistry) -> None:
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.win_material_gas, idf_obj_name):
        idf_mat = idf.newidfobject(idf_strings.IDFObjects.win_material_gas)
        idf_mat.Name = idf_obj_name
        idf_mat.Gas_Type = get_gas_type(mat_def.name)
        idf_mat.Thickness = thickness.to(ureg.m).m
Пример #8
0
def _add_shading_control_EP8(idf: IDF, shade_ctrl_idf_name: str,
                             shade_mat_idf_name: str,
                             shading_ctrl_model: WindowShadingControl) -> str:
    if not idf_writing_helpers.exists_in_idf(
            idf, idf_strings.IDFObjects.win_shading_ctrl_ep8,
            shade_ctrl_idf_name):
        window_shading_control = idf.newidfobject(
            idf_strings.IDFObjects.win_shading_ctrl_ep8)
        window_shading_control.Name = shade_ctrl_idf_name
        window_shading_control.Shading_Type = _get_shading_type_str(
            shading_ctrl_model.is_exterior)
        window_shading_control.Shading_Control_Type = shading_ctrl_model.shading_control_type
        window_shading_control.Setpoint = shading_ctrl_model.radiation_min_setpoint.to(
            "W/m2").m
        window_shading_control.Shading_Device_Material_Name = shade_mat_idf_name
    return shade_ctrl_idf_name
Пример #9
0
def _adding_the_schedule(idf: IDF, start_hour: str, end_hour: str):
    schedule_name = "night_vent_schedule"
    if not exists_in_idf(idf, idf_strings.IDFObjects.schedule_compact,
                         schedule_name):
        idf_type_lim_name = add_type_limits(
            idf, cesarp.common.ScheduleTypeLimits.FRACTION())
        schedule_night_vent_obj = idf.newidfobject(
            idf_strings.IDFObjects.schedule_compact)
        schedule_night_vent_obj.Name = schedule_name
        schedule_night_vent_obj.Schedule_Type_Limits_Name = idf_type_lim_name

        schedule_night_vent_obj.Field_1 = "Through: 12 / 31"
        schedule_night_vent_obj.Field_2 = "For: AllDays"
        schedule_night_vent_obj.Field_3 = "Until: " + end_hour
        schedule_night_vent_obj.Field_4 = 1
        schedule_night_vent_obj.Field_5 = "until: " + start_hour
        schedule_night_vent_obj.Field_6 = 0
        schedule_night_vent_obj.Field_7 = "until: " + "24:00"
        schedule_night_vent_obj.Field_8 = 1
    return schedule_name
def add_win_frame_construction(idf: IDF, frame_constr: WindowFrameConstruction,
                               ureg: pint.UnitRegistry) -> Tuple[str, Any]:
    idf_obj_name = frame_constr.name
    # check if frame construction was alredy added. do throw exception if so, because we don't expect that due to special
    # case of window frame and divider idf object beeing mixed construction/geometry definition
    assert not idf_writing_helpers.exists_in_idf(
        idf, idf_strings.IDFObjects.window_property_frame_and_divider,
        idf_obj_name)
    f_and_d_idf_obj = idf.newidfobject(
        idf_strings.IDFObjects.window_property_frame_and_divider)
    f_and_d_idf_obj.Name = idf_obj_name
    f_and_d_idf_obj.Frame_Conductance = frame_constr.frame_conductance.to(
        ureg.W / ureg.m**2 / ureg.K).m
    f_and_d_idf_obj.Frame_Solar_Absorptance = frame_constr.frame_solar_absorptance.to(
        ureg.dimensionless).m
    f_and_d_idf_obj.Frame_Visible_Absorptance = frame_constr.frame_visible_absorptance.to(
        ureg.dimensionless).m
    f_and_d_idf_obj.Outside_Reveal_Solar_Absorptance = frame_constr.outside_reveal_solar_absorptance.to(
        ureg.dimensionless).m

    # make sure you add width of frame to this idf object!
    return (idf_obj_name, f_and_d_idf_obj)
Пример #11
0
def add_thermostat_template(idf, heating_setpoint_schedule,
                            cooling_setpoint_schedule, name_prefix: str):
    # calling add_schedule before checking if the thremostat template already exists only to have the schedule name to create thermostat template idf name,
    # which must be different in case different schedules for different zones shall be used...
    heating_sched_idf_name = idf_writing_helpers.add_schedule(
        idf,
        heating_setpoint_schedule,
        required_type=cesarp.common.ScheduleTypeLimits.TEMPERATURE())
    cooling_sched_idf_name = idf_writing_helpers.add_schedule(
        idf,
        cooling_setpoint_schedule,
        required_type=cesarp.common.ScheduleTypeLimits.TEMPERATURE())
    name = name_prefix + "_" + idf_strings.CustomObjNames.thermostat_template
    idf_obj_type = idf_strings.IDFObjects.hvac_template_thermostat
    if not idf_writing_helpers.exists_in_idf(idf, idf_obj_type, name):
        templ_thermostat_idf_obj = idf.newidfobject(idf_obj_type)
        templ_thermostat_idf_obj.Name = name
        templ_thermostat_idf_obj.Heating_Setpoint_Schedule_Name = heating_sched_idf_name
        templ_thermostat_idf_obj.Cooling_Setpoint_Schedule_Name = cooling_sched_idf_name
        templ_thermostat_idf_obj.Constant_Cooling_Setpoint = ""

    return name
Пример #12
0
def add_outdoor_air_sepc(idf, ventilation_schedule,
                         outdoor_air_flow_per_floor_area: pint.Quantity,
                         name_prefix: str, ureg):
    ventilation_sched_idf_name = idf_writing_helpers.add_schedule(
        idf,
        ventilation_schedule,
        required_type=cesarp.common.ScheduleTypeLimits.FRACTION())
    idf_obj_type = idf_strings.IDFObjects.design_specifictaion_outdoor_air
    name = name_prefix + "_" + idf_strings.CustomObjNames.outdoor_air_spec
    if not idf_writing_helpers.exists_in_idf(idf, idf_obj_type, name):
        outdoor_air_spec_idf_obj = idf.newidfobject(idf_obj_type)
        outdoor_air_spec_idf_obj.Name = name
        outdoor_air_spec_idf_obj.Outdoor_Air_Method = idf_strings.OutdoorAirCalcMethod.flow_per_area
        outdoor_air_spec_idf_obj.Outdoor_Air_Flow_per_Zone_Floor_Area = outdoor_air_flow_per_floor_area.to(
            ureg.m**3 / ureg.s / ureg.m**2).m
        # clean up default values: set to zero because calc method changed to flow/area
        outdoor_air_spec_idf_obj.Outdoor_Air_Flow_per_Person = 0
        if idf.idd_version[0] < 9 and idf.idd_version[1] < 6:
            outdoor_air_spec_idf_obj.Outdoor_Air_Flow_Rate_Fraction_Schedule_Name = ventilation_sched_idf_name
        else:
            outdoor_air_spec_idf_obj.Outdoor_Air_Schedule_Name = ventilation_sched_idf_name

    return name