示例#1
0
文件: test_ksp.py 项目: jgrot/grotlib
def T2DS1ME() :
    
    print("Testing traj2d with one stage with mixed engines (T2DS1ME)")
    
    tname = "T2DS1ME"
    tfile = ksp.pthut(tname + ".pkl")
    do_generate = not os.access(tfile, os.F_OK)

    stage_1 = ksp.Stage()
    stage_1.loadJSON(ksp.pthut(tname + "_stage1.json"))
    # stage_1.dumpInfo( )

    def fthrottle( t, y ) :
        return 1.0
    def falpha( t, y, flyer ) :
        m, r, th, vr, om = y
        vth = om/r
        if r < (flyer.R+7.5E3) :
            n = (1.0, 0.0)
        elif vth == 0.0 :
            n = (1.0, 0.0)
        else :
            v,n = mpm.v_and_dir(y)
        return n
    
    flyer = ksp.FlyingStage(stage_1, "Stage 1", "Kerbin", fthrottle, falpha)
    flyer.launch( )
    # Fly until crash
    flyer.flyTo( 30000 )

    if do_generate :
        with open( tfile, 'wb' ) as f :
            pickle.dump( flyer.soln, f )
    else :
        with open( tfile, 'rb' ) as f :
            soln_compare = pickle.load( f )
            cmp.compare_datasets(flyer.soln, soln_compare, tolfrac=1E-8)
        print("SUCCESS")

    if True :
        import matplotlib
        import matplotlib.pyplot as plt

        fig, ax = plt.subplots()

        plots = [flyer.sample()]
        plot_opts = [{"marker":"o"}]

        bbox = mpt.square_plot_bounds(plots)
        
        plots.append(mpt.sample_circle(flyer.R, 100))
        plot_opts.append(None)
        plots.append(mpt.sample_circle(flyer.R+70, 100))
        plot_opts.append(None)

        mpt.square_plots(ax, plots, bbox, plot_opts)
        
        plt.show()

        flyer.dumpTraj( )    
示例#2
0
文件: run.py 项目: jgrot/grotlib
        n = (1.0, 0.0)
        #else :
        #    v,n = mpm.v_and_dir(y)
        return n

    flyer = ksp.FlyingStage(s1, "Stage 1", "Kerbin", fthrottle, falpha)
    flyer.launch()
    # Fly until crash
    flyer.flyTo(30000)

    import matplotlib
    import matplotlib.pyplot as plt

    fig, ax = plt.subplots()

    plots = [flyer.sample()]
    plot_opts = [{"marker": "o"}]

    bbox = mpt.square_plot_bounds(plots)

    plots.append(mpt.sample_circle(flyer.R, 100))
    plot_opts.append(None)
    plots.append(mpt.sample_circle(flyer.R + 70, 100))
    plot_opts.append(None)

    mpt.square_plots(ax, plots, bbox, plot_opts)

    plt.show()

    flyer.dumpTraj()
示例#3
0
文件: test_ksp.py 项目: jgrot/grotlib
def T2DS2ME() :
    # KSP Flight
    #
    # 50s stage
    # 30km track orbit
    #
    # Max alt:
    # Crash Time:
    #
    print("Testing traj2d with two stages with mixed engines (T2DS2ME)")
    
    tname = "T2DS2ME"
    tfile = ksp.pthut(tname + ".pkl")
    do_generate = not os.access(tfile, os.F_OK)

    stage_1 = ksp.Stage()
    stage_1.loadJSON(ksp.pthut(tname + "_stage1.json"))
    # stage_1.dumpInfo( )

    stage_2 = ksp.Stage()
    stage_2.loadJSON(ksp.pthut(tname + "_stage2.json"))
    # stage_2.dumpInfo( )
    
    def fthrottle( t, y ) :
        return 1.0
    def falpha( t, y, flyer ) :
        r = y[1]
        if r < (flyer.R+30.0E3) :
            n = (1.0, 0.0)
        else :
            v, n = mpm.v_and_dir(y)
        return n
    
    fly_s1 = ksp.FlyingStage( stage_1, "Stage 1", "Kerbin", fthrottle, falpha )
    fly_s1.launch( )
    fly_s1.flyTo( 84.00 )

    fly_s2 = ksp.FlyingStage( stage_2, "Stage 2",  "Kerbin", fthrottle, falpha )
    fly_s2.launch( sm1 = fly_s1, t0 = 84.00 )
    fly_s2.flyTo( 30000 )

    t = 0.0
    DV = []
    while t <= fly_s2.solnt[-1] :
        Y, crashed, flyer = fly_s2.flyTo( t )
        m, r, th, vr, om = Y
        craft_asl_dvremain = flyer.dv_at_m( m, ksp.C_p0 )
        craft_dvremain = flyer.dv_at_m( m, flyer.fpress.call(r-flyer.R)[0] )
        stage_asl_dvremain = flyer.stage.dv_at_m( m, ksp.C_p0 )
        DV.append( (craft_asl_dvremain, craft_dvremain, stage_asl_dvremain) )
        t += 10
    
    if do_generate :
        with open( tfile, 'wb' ) as f :
            data = {
                "stage1" : fly_s1.soln,
                "stage2" : fly_s2.soln,
                "DV"     : DV
            }
            pickle.dump( data, f )
    else :
        with open( tfile, 'rb' ) as f :
            soln_compare = pickle.load( f )
            cmp.compare_datasets( fly_s1.soln, soln_compare["stage1"], tolfrac=1E-3 )
            cmp.compare_datasets( fly_s2.soln, soln_compare["stage2"], tolfrac=1E-3 )
            cmp.compare_datasets( DV, soln_compare["DV"], tolfrac=1E-3 )
        print("SUCCESS")

    if True :
        import matplotlib
        import matplotlib.pyplot as plt

        fig, ax = plt.subplots()
        
        plots = [fly_s2.sample(t0=0.0, dt=10.0)]
        plot_opts = [{"marker":"o"}]
        
        bbox = mpt.square_plot_bounds(plots)
        
        plots.append(mpt.sample_circle(fly_s2.R, 100))
        plot_opts.append(None)
        plots.append(mpt.sample_circle(fly_s2.R+70, 100))
        plot_opts.append(None)

        mpt.square_plots(ax, plots, bbox, plot_opts)
        
        plt.show()

        flyer.dumpTraj()
示例#4
0
    rw = ct.RowWriter([40])

    plots = []
    plot_opts = []

    # Stage we will be flying
    s2 = ksp.Stage()
    s2.loadJSON("stage_2.json")
    s2.dumpInfo()

    rw.print("Analysis...")

    # Mun
    mun_r_m = ksp.dInterp("R('Mun')")
    # Plot Mun
    mun_XY = mpt.sample_circle(mun_r_m, 10000)
    plots.append(mun_XY)
    plot_opts.append(None)

    # A FlyingStage is used when there are non-central forces acting on the stage.
    def fthrottle(t, y):
        m, r, th, vr, om = y

        v, n = mpm.v_and_dir(y)

        h = r - 200E3

        vtarget = h / 10.0

        if t < 5.0:
            # Initial kick out of circ orbit
示例#5
0
    s2.loadJSON("stage_2.json")
    s2.dumpInfo()

    rw.print("Analysis...")

    # Available stage DV at start
    dv_stage = s2.dv_at_m(s2.m0_kg, 0.0)
    dv.append(dv_stage)
    dv_desc.append("Initial")
    rw.write("Initial stage DV", dv_stage)

    # Kerbin
    GMkerbin, GMkerbinu = ksp.bodies_db["Kerbin"]["GM"]
    rw.write("GM Kerbin", GMkerbin)
    # Plot Kerbin
    plots.append(mpt.sample_circle(6E5, 100))
    plot_opts.append(None)

    # Mun
    mun_th = math.pi
    mun_d = ksp.dInterp("D('Kerbin','Mun')")
    mun_r = ksp.dInterp("R('Mun')")
    mun_XY = mpt.sample_circle(mun_r, 100)
    mun_x, mun_y = mpm.xy_at_rth(mun_d, mun_th)
    mun_XY = mpt.offset_xy(mun_XY, mun_x, mun_y)
    # Plot Mun
    plots.append(mun_XY)
    plot_opts.append(None)
    # Mun SOI
    mun_soi_r, mun_soi_ru = ksp.bodies_db["Mun"]["SOI"]
    mun_soi_r *= ksp.uconv(ksp.dist_db, mun_soi_ru, "m")