def __init__(self, storage_on, Qc_tank_charging_limit_W,
              T_tank_fully_charged_K, T_tank_fully_discharged_K, T_tank_K,
              T_ground_average_K):
     self.storage_on = storage_on
     self.T_ground_average_K = T_ground_average_K
     self.T_tank_K = T_tank_K
     self.Qc_tank_charging_limit_W = Qc_tank_charging_limit_W
     self.T_tank_fully_charged_K = T_tank_fully_charged_K
     self.T_tank_fully_discharged_K = T_tank_fully_discharged_K
     self.Q_from_storage_W = 0.0
     self.V_tank_m3 = storage_tank.calc_storage_tank_volume(
         self.Qc_tank_charging_limit_W, self.T_tank_fully_charged_K,
         self.T_tank_fully_discharged_K)
     self.Area_tank_surface_m2 = storage_tank.calc_tank_surface_area(
         self.V_tank_m3)
     self.Q_from_storage_W = 0.0
     self.Q_current_storage_empty_capacity_W = self.Qc_tank_charging_limit_W  # start with an empty tank
     self.Q_current_storage_filled_capacity_W = 0.0  # start with an empty tank
def calc_DH_ww_with_tank_losses(T_ext_C, T_int_C, Qww, Vww, Qww_dis_ls_r,
                                Qww_dis_ls_nr):
    """
    Calculates the heat flows within a fully mixed water storage tank for HOURS_IN_YEAR time-steps.
    :param T_ext_C: external temperature in [C]
    :param T_int_C: room temperature in [C]
    :param Qww: hourly DHW demand in [Wh]
    :param Vww: hourly DHW demand in [m3]
    :param Qww_dis_ls_r: recoverable loss in distribution in [Wh]
    :param Qww_dis_ls_nr: non-recoverable loss in distribution in [Wh]
    :type T_ext_C: ndarray
    :type T_int_C: ndarray
    :type Qww: ndarray
    :type Vww: ndarray
    :type Qww_dis_ls_r: ndarray
    :type Qww_dis_ls_nr: ndarray
    :return:
    """
    Qww_sys = np.zeros(HOURS_IN_YEAR)
    Qww_st_ls = np.zeros(HOURS_IN_YEAR)
    Tww_tank_C = np.zeros(HOURS_IN_YEAR)
    Qd = np.zeros(HOURS_IN_YEAR)
    # calculate DHW tank size [in m3] based on the peak DHW demand in the building
    V_tank_m3 = Vww.max()  # size the tank with the highest flow rate
    T_tank_start_C = TWW_SETPOINT  # assume the tank temperature at timestep 0 is at the dhw set point

    if V_tank_m3 > 0:
        for k in range(HOURS_IN_YEAR):
            area_tank_surface_m2 = storage_tank.calc_tank_surface_area(
                V_tank_m3)
            Q_tank_discharged_W = Qww[k] + Qww_dis_ls_r[k] + Qww_dis_ls_nr[k]
            Qww_st_ls[k], Qd[k], Qww_sys[
                k] = storage_tank.calc_dhw_tank_heat_balance(
                    T_int_C[k], T_ext_C[k], T_tank_start_C, V_tank_m3,
                    Q_tank_discharged_W, area_tank_surface_m2)
            Tww_tank_C[k] = storage_tank.calc_tank_temperature(
                T_tank_start_C, Qww_st_ls[k], Qd[k], Qww_sys[k], V_tank_m3,
                'hot_water')
            T_tank_start_C = Tww_tank_C[
                k]  # update the tank temperature at the beginning of the next time step
    else:
        for k in range(HOURS_IN_YEAR):
            Tww_tank_C[k] = np.nan
    return Tww_tank_C, Qww_sys