Esempio n. 1
0
    def history_update(self, insn):
        time_slow = self.var_time_level[insn.slow_arg]
        time_fast = self.var_time_level[insn.fast_arg]

        assert abs(time_slow - time_fast) < 1e-10, str(
            (abs(time_slow - time_fast), self.stepper.method_name,
             self.stepper.substep_count, self.insn_counter))

        t = (self.t_start +
             self.stepper.large_dt * time_slow / self.stepper.substep_count)

        rhs = self.rhss[HIST_NAMES.index(insn.which)]

        hist = self.stepper.histories[insn.which]
        hist.pop()
        hist.insert(
            0, rhs(t, self.context[insn.fast_arg],
                   self.context[insn.slow_arg]))

        if self.stepper.hist_is_fast[insn.which]:
            self.hist_head_time_level[insn.which] += 1
        else:
            self.hist_head_time_level[insn.which] += self.stepper.substep_count

        MRABProcessor.history_update(self, insn)
Esempio n. 2
0
    def integrate_in_time(self, insn):
        from hedge.timestep.multirate_ab.methods import CO_FAST
        from hedge.timestep.multirate_ab.methods import HIST_F2F, HIST_S2F, HIST_F2S, HIST_S2S

        if insn.component == CO_FAST:
            self_hn, cross_hn = HIST_F2F, HIST_S2F
        else:
            self_hn, cross_hn = HIST_S2S, HIST_F2S

        start_time_level = self.eval_expr(insn.start)
        end_time_level = self.eval_expr(insn.end)

        self_coefficients = self.stepper.get_coefficients(
            self.stepper.hist_is_fast[self_hn],
            self.hist_head_time_level[self_hn],
            start_time_level,
            end_time_level,
            self.stepper.orders[self_hn],
        )
        cross_coefficients = self.stepper.get_coefficients(
            self.stepper.hist_is_fast[cross_hn],
            self.hist_head_time_level[cross_hn],
            start_time_level,
            end_time_level,
            self.stepper.orders[cross_hn],
        )

        if start_time_level == 0 or (insn.result_name not in self.context):
            my_y = self.last_y[insn.component]
            assert start_time_level == 0
        else:
            my_y = self.context[insn.result_name]()
            assert start_time_level == self.var_time_level[insn.result_name]

        hists = self.stepper.histories
        self_history = hists[self_hn][:]
        cross_history = hists[cross_hn][:]
        if False:
            my_integrated_y = memoize(
                lambda: my_y
                + self.stepper.large_dt
                * (_linear_comb(self_coefficients, self_history) + _linear_comb(cross_coefficients, cross_history))
            )
        else:
            my_new_y = my_y + self.stepper.large_dt * (
                _linear_comb(self_coefficients, self_history) + _linear_comb(cross_coefficients, cross_history)
            )
            my_integrated_y = lambda: my_new_y

        self.context[insn.result_name] = my_integrated_y
        self.var_time_level[insn.result_name] = end_time_level

        MRABProcessor.integrate_in_time(self, insn)
Esempio n. 3
0
    def integrate_in_time(self, insn):
        from hedge.timestep.multirate_ab.methods import CO_FAST
        from hedge.timestep.multirate_ab.methods import \
                HIST_F2F, HIST_S2F, HIST_F2S, HIST_S2S

        if insn.component == CO_FAST:
            self_hn, cross_hn = HIST_F2F, HIST_S2F
        else:
            self_hn, cross_hn = HIST_S2S, HIST_F2S

        start_time_level = self.eval_expr(insn.start)
        end_time_level = self.eval_expr(insn.end)

        self_coefficients = self.stepper.get_coefficients(
            self.stepper.hist_is_fast[self_hn],
            self.hist_head_time_level[self_hn], start_time_level,
            end_time_level, self.stepper.orders[self_hn])
        cross_coefficients = self.stepper.get_coefficients(
            self.stepper.hist_is_fast[cross_hn],
            self.hist_head_time_level[cross_hn], start_time_level,
            end_time_level, self.stepper.orders[cross_hn])

        if start_time_level == 0 or (insn.result_name not in self.context):
            my_y = self.last_y[insn.component]
            assert start_time_level == 0
        else:
            my_y = self.context[insn.result_name]()
            assert start_time_level == \
                    self.var_time_level[insn.result_name]

        hists = self.stepper.histories
        self_history = hists[self_hn][:]
        cross_history = hists[cross_hn][:]
        if False:
            my_integrated_y = memoize(lambda: my_y + self.stepper.large_dt * (
                _linear_comb(self_coefficients, self_history) + _linear_comb(
                    cross_coefficients, cross_history)))
        else:
            my_new_y = my_y + self.stepper.large_dt * (
                _linear_comb(self_coefficients, self_history) +
                _linear_comb(cross_coefficients, cross_history))
            my_integrated_y = lambda: my_new_y

        self.context[insn.result_name] = my_integrated_y
        self.var_time_level[insn.result_name] = end_time_level

        MRABProcessor.integrate_in_time(self, insn)
Esempio n. 4
0
    def __init__(self, stepper, y, t, rhss):
        MRABProcessor.__init__(self, stepper.method, stepper.substep_count)

        self.stepper = stepper

        self.t_start = t

        self.context = {}
        self.var_time_level = {}

        self.rhss = rhss

        y_fast, y_slow = y
        from hedge.timestep.multirate_ab.methods import CO_FAST, CO_SLOW
        self.last_y = {CO_FAST: y_fast, CO_SLOW: y_slow}

        self.hist_head_time_level = dict((hn, 0) for hn in HIST_NAMES)
Esempio n. 5
0
    def __init__(self, stepper, y, t, rhss):
        MRABProcessor.__init__(self, stepper.method, stepper.substep_count)

        self.stepper = stepper

        self.t_start = t

        self.context = {}
        self.var_time_level = {}

        self.rhss = rhss

        y_fast, y_slow = y
        from hedge.timestep.multirate_ab.methods import CO_FAST, CO_SLOW

        self.last_y = {CO_FAST: y_fast, CO_SLOW: y_slow}

        self.hist_head_time_level = dict((hn, 0) for hn in HIST_NAMES)
Esempio n. 6
0
    def history_update(self, insn):
        time_slow = self.var_time_level[insn.slow_arg]
        time_fast = self.var_time_level[insn.fast_arg]

        assert abs(time_slow - time_fast) < 1e-10, str(
            (abs(time_slow - time_fast), self.stepper.method_name, self.stepper.substep_count, self.insn_counter)
        )

        t = self.t_start + self.stepper.large_dt * time_slow / self.stepper.substep_count

        rhs = self.rhss[HIST_NAMES.index(insn.which)]

        hist = self.stepper.histories[insn.which]
        hist.pop()
        hist.insert(0, rhs(t, self.context[insn.fast_arg], self.context[insn.slow_arg]))

        if self.stepper.hist_is_fast[insn.which]:
            self.hist_head_time_level[insn.which] += 1
        else:
            self.hist_head_time_level[insn.which] += self.stepper.substep_count

        MRABProcessor.history_update(self, insn)