Exemplo n.º 1
0
    def _simplify_lower_order_moments(self, ac, moment_base, search_in_main_assignments):
        if self.cqe is None:
            return ac

        moment_symbols = [sq_sym(moment_base, e) for e in moments_up_to_order(1, dim=self.dim)]

        if search_in_main_assignments:
            f_to_cm_dict = ac.main_assignments_dict
            f_to_cm_dict_reduced = ac.new_without_subexpressions().main_assignments_dict
        else:
            f_to_cm_dict = ac.subexpressions_dict
            f_to_cm_dict_reduced = ac.new_without_subexpressions(moment_symbols).subexpressions_dict

        cqe_subs = self.cqe.new_without_subexpressions().main_assignments_dict
        for m in moment_symbols:
            m_eq = fast_subs(fast_subs(f_to_cm_dict_reduced[m], cqe_subs), cqe_subs)
            m_eq = m_eq.expand().cancel()
            for cqe_sym, cqe_exp in cqe_subs.items():
                m_eq = subs_additive(m_eq, cqe_sym, cqe_exp)
            f_to_cm_dict[m] = m_eq

        if search_in_main_assignments:
            main_assignments = [Assignment(lhs, rhs) for lhs, rhs in f_to_cm_dict.items()]
            return ac.copy(main_assignments=main_assignments)
        else:
            subexpressions = [Assignment(lhs, rhs) for lhs, rhs in f_to_cm_dict.items()]
            return ac.copy(subexpressions=subexpressions)
Exemplo n.º 2
0
    def _compute_weights(self):
        replacements = self._conservedQuantityComputation.default_values
        ac = self.get_equilibrium(include_force_terms=False)
        ac = ac.new_with_substitutions(
            replacements,
            substitute_on_lhs=False).new_without_subexpressions()

        new_assignments = [
            Assignment(
                e.lhs,
                subs_additive(e.rhs,
                              sp.sympify(1),
                              sum(self.pre_collision_pdf_symbols),
                              required_match_replacement=1.0))
            for e in ac.main_assignments
        ]
        ac = ac.copy(new_assignments)

        weights = []
        for eq in ac.main_assignments:
            value = eq.rhs.expand()
            assert len(value.atoms(
                sp.Symbol)) == 0, "Failed to compute weights " + str(value)
            weights.append(value)
        return weights
Exemplo n.º 3
0
def subexpression_substitution_in_main_assignments(ac):
    """Replaces already existing subexpressions in the equations of the assignment_collection."""
    result = []
    for s in ac.main_assignments:
        new_rhs = s.rhs
        for sub_expr in ac.subexpressions:
            new_rhs = subs_additive(new_rhs, sub_expr.lhs, sub_expr.rhs, required_match_replacement=1.0)
        result.append(Assignment(s.lhs, new_rhs))
    return ac.copy(result)
Exemplo n.º 4
0
def subexpression_substitution_in_existing_subexpressions(ac):
    """Goes through the subexpressions list and replaces the term in the following subexpressions."""
    result = []
    for outer_ctr, s in enumerate(ac.subexpressions):
        new_rhs = s.rhs
        for inner_ctr in range(outer_ctr):
            sub_expr = ac.subexpressions[inner_ctr]
            new_rhs = subs_additive(new_rhs, sub_expr.lhs, sub_expr.rhs, required_match_replacement=1.0)
            new_rhs = new_rhs.subs(sub_expr.rhs, sub_expr.lhs)
        result.append(Assignment(s.lhs, new_rhs))

    return ac.copy(ac.main_assignments, result)
Exemplo n.º 5
0
    def _factor_backward_eqs_by_velocities(self, symbolic_rms, cm_to_rm_dict, required_match_replacement=0.75):
        velocity_by_occurences = dict()
        for rm, rm_eq in cm_to_rm_dict.items():
            velocity_by_occurences[rm] = sorted(self.equilibrium_velocity, key=rm_eq.count, reverse=True)
        for d in range(self.dim):
            for rm, rm_eq in cm_to_rm_dict.items():
                u_sorted = velocity_by_occurences[rm]
                cm_to_rm_dict[rm] = rm_eq.expand().collect(u_sorted[d])

            for i, rm1 in enumerate(symbolic_rms):
                for _, rm2 in enumerate(symbolic_rms[i + 1:]):
                    cm_to_rm_dict[rm2] = subs_additive(
                        cm_to_rm_dict[rm2], rm1, cm_to_rm_dict[rm1],
                        required_match_replacement=required_match_replacement)
        return cm_to_rm_dict
Exemplo n.º 6
0
 def _undo_remaining_cq_subexpressions(self, rm_to_cm_dict, cq_subs):
     for cm, cm_eq in rm_to_cm_dict.items():
         for rm, rm_subexp in cq_subs.items():
             cm_eq = subs_additive(cm_eq, rm, rm_subexp)
         rm_to_cm_dict[cm] = cm_eq
     return rm_to_cm_dict