예제 #1
0
    def simulate(self):
        """
        More docs to come...
        """

        PrintClass.my_print("Beginning simulation")

        # calculate g-functions if not present
        if not self.g_func_present:
            PrintClass.my_print("G-functions not present", 'warn')
            self.calc_g_func()

        # pre-load hourly g-functions
        for hour in range(self.agg_load_intervals[0] +
                          self.min_hourly_history):
            ln_t_ts = np.log((hour + 1) * 3600 / self.ts)
            self.g_func_hourly.append(self.g_func(ln_t_ts))

        # set aggregate load container max length
        len_hourly_loads = self.min_hourly_history + self.agg_load_intervals[0]
        self.hourly_loads = deque([0] * len_hourly_loads,
                                  maxlen=len_hourly_loads)

        agg_hour = 0
        sim_hour = 0

        for year in range(self.sim_years):
            for month in range(ConstantClass.months_in_year):

                PrintClass.my_print("....Year/Month: %d/%d" %
                                    (year + 1, month + 1))

                for hour in range(ConstantClass.hours_in_month):

                    agg_hour += 1
                    sim_hour += 1

                    # get raw hourly load and append to hourly list
                    curr_index = month * ConstantClass.hours_in_month + hour
                    self.hourly_loads.append(self.sim_loads[curr_index])
                    curr_flow_rate = self.total_flow_rate[curr_index]

                    # update borehole flow rate
                    self.borehole.pipe.fluid.update_fluid_state(
                        new_flow_rate=curr_flow_rate)

                    # calculate borehole resistance
                    self.borehole.calc_bh_resistance()

                    # calculate borehole temp
                    # hourly effects
                    temp_bh_hourly = []
                    temp_mft_hourly = []
                    start_hourly = len(self.hourly_loads) - 1
                    end_hourly = start_hourly - agg_hour
                    g_func_index = -1
                    for i in range(start_hourly, end_hourly, -1):
                        g_func_index += 1
                        q_curr = self.hourly_loads[i]
                        q_prev = self.hourly_loads[i - 1]
                        g = self.g_func_hourly[g_func_index]
                        # calculate average bh temp
                        delta_q = (q_curr - q_prev) / \
                                  (2 * np.pi * self.borehole.soil.conductivity *
                                   self.total_bh_length)
                        temp_bh_hourly.append(delta_q * g)

                        # calculate mean fluid temp
                        g_rb = g + self.borehole.resist_bh

                        if g_rb < 0:
                            g = -self.borehole.resist_bh * 2 * np.pi * self.borehole.soil.conductivity
                            g_rb = g + self.borehole.resist_bh

                        temp_mft_hourly.append(delta_q * g_rb)

                    # aggregated load effects
                    temp_bh_agg = []
                    temp_mft_agg = []
                    if self.agg_loads_flag:
                        for i in range(len(self.agg_load_objects)):
                            if i == 0:
                                continue
                            curr_obj = self.agg_load_objects[i]
                            prev_obj = self.agg_load_objects[i - 1]

                            t_agg = sim_hour - curr_obj.time()
                            ln_t_ts = np.log(t_agg * 3600 / self.ts)
                            g = self.g_func(ln_t_ts)
                            # calculate the average borehole temp
                            delta_q = (curr_obj.q - prev_obj.q) / (
                                2 * np.pi * self.borehole.soil.conductivity *
                                self.total_bh_length)
                            temp_bh_agg.append(delta_q * g)

                            # calculate the mean fluid temp
                            g_rb = g + self.borehole.resist_bh

                            if g_rb < 0:
                                g = -self.borehole.resist_bh * 2 * np.pi * self.borehole.soil.conductivity
                                g_rb = g + self.borehole.resist_bh

                            temp_mft_agg.append(delta_q * g_rb)

                        # aggregate load
                        if agg_hour == self.agg_load_intervals[
                                0] + self.min_hourly_history - 1:
                            # this has one extra value for comparative purposes
                            # need to get rid of it here
                            self.hourly_loads.popleft()

                            # create new aggregated load object
                            self.aggregate_load()

                            # reset aggregation hour to '0'
                            agg_hour -= self.agg_load_intervals[0]

                    # final bh temp
                    self.temp_bh.append(self.borehole.soil.undisturbed_temp +
                                        sum(temp_bh_hourly) + sum(temp_bh_agg))

                    # final mean fluid temp
                    self.temp_mft.append(self.borehole.soil.undisturbed_temp +
                                         sum(temp_mft_hourly) +
                                         sum(temp_mft_agg))

                    # update borehole temperature
                    self.borehole.pipe.fluid.update_fluid_state(
                        new_temp=self.temp_mft[-1])

        self.generate_output_reports()

        PrintClass.my_print("Simulation complete", "success")
        PrintClass.my_print("Simulation time: %0.3f sec" %
                            (timeit.default_timer() - self.timer_start))

        PrintClass.write_log_file()
예제 #2
0
    def simulate(self):
        """
        More docs to come...
        """

        PrintClass.my_print("Beginning simulation")

        sim_hour = 0
        sim_hour_old = 0

        for year in range(self.sim_years):
            for month in range(ConstantClass.months_in_year):

                PrintClass.my_print("....Year/Month: %d/%d" %
                                    (year + 1, month + 1))

                temp_bh_hourly = []
                temp_mft_hourly = []

                for hour in range(ConstantClass.hours_in_month):
                    sim_hour += 1

                    # get raw hourly load and append to hourly list
                    load_index = month * ConstantClass.hours_in_month + hour
                    curr_load = self.sim_loads[load_index]

                    # aggregate energy in load blocks
                    energy = curr_load * (sim_hour - sim_hour_old) * ConstantClass.sec_in_hour
                    self.shift_loads(energy)

                    # get current data
                    curr_index = month * ConstantClass.hours_in_month + hour
                    curr_flow_rate = self.total_flow_rate[curr_index]

                    # update borehole flow rate
                    self.borehole.pipe.fluid.update_fluid_state(
                        new_flow_rate=curr_flow_rate)

                    # calculate borehole resistance
                    self.borehole.calc_bh_resistance()

                    for i, curr_obj in enumerate(self.agg_load_objects):

                        if curr_obj.num_loads == 0:
                            break

                        if i == 0:
                            q_curr = curr_obj.q
                            q_prev = 0
                        else:
                            prev_obj = self.agg_load_objects[i - 1]
                            q_curr = curr_obj.q
                            q_prev = prev_obj.q

                        # calculate average bh temp
                        delta_q = (q_curr - q_prev) / \
                                  (2 * np.pi * self.borehole.soil.conductivity *
                                   self.total_bh_length)

                        g = curr_obj.g_func
                        temp_bh_hourly.append(delta_q * g)

                        # calculate mean fluid temp
                        g_rb = g + self.borehole.resist_bh

                        if g_rb < 0:
                            g = -self.borehole.resist_bh * 2 * np.pi * self.borehole.soil.conductivity
                            g_rb = g + self.borehole.resist_bh

                        temp_mft_hourly.append(delta_q * g_rb)

                    # final bh temp
                    self.temp_bh.append(self.borehole.soil.undisturbed_temp + sum(temp_bh_hourly))

                    # final mean fluid temp
                    self.temp_mft.append(self.borehole.soil.undisturbed_temp + sum(temp_mft_hourly))

                    # update borehole temperature
                    self.borehole.pipe.fluid.update_fluid_state(new_temp=self.temp_mft[-1])

                    sim_hour_old = sim_hour

        self.generate_output_reports()

        PrintClass.my_print("Simulation complete", "success")
        PrintClass.my_print("Simulation time: %0.3f sec" %
                            (timeit.default_timer() - self.timer_start))

        PrintClass.write_log_file()