예제 #1
0
 def solver_hook(solve_expr, unknown, solver_id, guess):
     from dagrt.expression import match, substitute
     pieces = match(
         "k - <func>rhs(time, y + dt * (c0 + c1 * k))",
         solve_expr,
         pre_match={"k": unknown})
     return substitute("-10 * (dt * c0 + y) / (10 * dt * c1 + 1)", pieces)
예제 #2
0
def solver_hook(solve_expr, solve_var, solver_id, guess):
    from dagrt.expression import match, substitute

    pieces = match("unk - <func>rhs(t=t, y=sub_y + coeff*unk)",
                   solve_expr,
                   pre_match={"unk": solve_var})
    pieces["guess"] = guess
    return substitute("<func>solver(t, sub_y, coeff, guess)", pieces)
예제 #3
0
def solver_hook(solve_expr, solve_var, solver_id, guess):
    from dagrt.expression import match, substitute

    pieces = match("unk + (-1)*<func>impl_y(y=sub_y + coeff*unk, t=t)",
                   solve_expr,
                   pre_match={"unk": solve_var})
    pieces["guess"] = guess
    return substitute("<func>solver(sub_y, coeff)", pieces)
예제 #4
0
def am_solver_hook(solve_expr, solve_var, solver_id, guess):
    from dagrt.expression import match, substitute

    pieces = match(
        "unk + (-1)*<func>f(t=t, fast=sub_fast + coeff*unk, "
        "slow=sub_slow)",
        solve_expr,
        pre_match={"unk": solve_var})
    pieces["guess"] = guess
    return substitute("<func>solver(sub_fast, sub_slow, " "coeff, t)", pieces)
예제 #5
0
def solver_hook(solve_expr, solve_var, solver_id, guess):
    from dagrt.expression import match, substitute

    pieces = match("unk - <func>rhs(t=t, y=<state>y + sub_y + coeff*unk)",
                   solve_expr,
                   bound_variable_names=["<state>y"],
                   pre_match={"unk": solve_var})

    pieces["guess"] = guess

    return substitute("<func>solver(t, <state>y, sub_y, coeff)", pieces)
예제 #6
0
def test_substitute():
    f, a = declare("f", "a")

    from dagrt.expression import substitute
    assert substitute("f(<state>y)", {"<state>y": a}) == f(a)
예제 #7
0
def solver_hook(expr, var, solver_id, guess):
    from dagrt.expression import match, substitute
    pieces = match("unk-y-h*<func>f(t=t,y=unk)", expr, pre_match={"unk": var})
    pieces["guess"] = guess
    return substitute("<func>solver(t,h,y,guess)", pieces)