Exemplo n.º 1
0
    def test_di_integrator_pure_with_complete_guess(self):

        # solve Problem for the first time
        first_guess = {'seed': 20}
        S1 = TransitionProblem(rhs_di,
                               a=0.0,
                               b=2.0,
                               xa=xa_di,
                               xb=xb_di,
                               ua=0,
                               ub=0,
                               show_ir=False,
                               ierr=None,
                               first_guess=first_guess,
                               use_chains=False)
        S1.solve()
        assert S1.reached_accuracy

        first_guess2 = {
            'complete_guess':
            S1.eqs.sol,
            'n_spline_parts':
            aux.Container(x=S1.eqs.trajectories.n_parts_x,
                          u=S1.eqs.trajectories.n_parts_u)
        }
        S2 = S1.create_new_TP(first_guess=first_guess2)
        S2.solve()

        assert S2.reached_accuracy

        # now test changed boundary conditions

        S3 = S2.create_new_TP(first_guess=first_guess2, xb=[1.5, 0.0])
        S3.solve()
        assert S3.reached_accuracy
S.solve()

N = 20
i = 0
di = 1
while i <= N:
    S_old = S

    # new final value
    xb = xb_0 + i*1.0/N*(xb_des - xb_0)

    first_guess2 = {'complete_guess': S.eqs.sol,
                    'n_spline_parts': aux.Container(x=S.eqs.trajectories.n_parts_x,
                                                    u=S.eqs.trajectories.n_parts_u)}
    S = S.create_new_TP(first_guess=first_guess2, xb=xb)
    S.solve()

    if S.reached_accuracy:
        print "{}: i={};  Successed!\n".format(time.ctime(), i)
    else:
        print "i={};  Failed!".format(i)
        IPS()
    # if S.eqs.trajectories.n_parts_x > 80:
    #     # the last step was too big,
    #     # try again with smaller step
    #     # roll back
    #     i -= di
    #
    #     # change di
    #     di *= .5