コード例 #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
import mpl_tools as mpt

if __name__ == "__main__":
    import matplotlib
    import matplotlib.pyplot as plt

    ksp.augmentBodyDbs()
    ksp.processBodyDbs()

    rw = ct.RowWriter([40])

    plots = []
    plot_opts = []

    # Stage we will be flying
    s1 = ksp.Stage()
    s1.loadJSON("TestLFE1.json")
    s1.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)
        #else :
        #    v,n = mpm.v_and_dir(y)
        return n
コード例 #3
0
ファイル: optim_dd.py プロジェクト: jgrot/grotlib
    cmd_test.add_argument("case_file", help="Name of the case file")

    args = parser.parse_args()

    if args.command == "inst":
        for line in instructions:
            print(line)
        exit(0)

    if args.command == "test":

        case_data = None
        with open(args.case_file, "rt") as f:
            case_data = json.load(f)

        stage = ksp.Stage()
        stage.loadJSON(ksp.pthdat("drag_tests/" + case_data["stage file"]))
        flyer = ksp.FlyingStage(stage, "stage", "Kerbin", fthrottle, falpha)

        htarget = case_data["htarget"]
        crash_time = case_data["crash time"]

        itrial = 1

        def trial(X):
            global itrial

            if X[0] < 1.0 or \
               X[0] > 10.0 or \
               X[1] < 5.0 or \
               X[1] > 200.0 or \
コード例 #4
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()
コード例 #5
0
ファイル: run.py プロジェクト: jgrot/grotlib
import mks_polar_motion as mpm
import mpl_tools as mpt

if __name__ == "__main__":
    import matplotlib
    import matplotlib.pyplot as plt

    ksp.augmentBodyDbs()
    ksp.processBodyDbs()

    rw = ct.RowWriter([40])

    plots = []
    plot_opts = []

    s1 = ksp.Stage()
    s1.loadJSON("minmus_express_2_s1.json")
    s1.dumpInfo()

    s2 = ksp.Stage()
    s2.loadJSON("minmus_express_2_s2.json")
    s2.dumpInfo()

    s3 = ksp.Stage()
    s3.loadJSON("minmus_express_2_s3.json")
    s3.dumpInfo()

    t1 = 300.0
    t2 = 400.0
    t3 = 10000.0
コード例 #6
0
import mpl_tools as mpt

if __name__ == "__main__":
    import matplotlib
    import matplotlib.pyplot as plt

    ksp.augmentBodyDbs()
    ksp.processBodyDbs()

    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