def _initial_guess_no_thrust(self): """Short summary. Returns ------- type Description of returned object. """ ''' Determine and store an initial guess for the parameters. Initial guess based on solution to no thrusting''' prob = self.prob r = self.rocket #set guess based on no thrusting x_guess = np.array([r.x_0 + r.vx_0*t for t in prob.time_all_section]) z_guess = np.array([r.z_0 + r.vz_0*t - 0.5*r.g*t**2 for t in prob.time_all_section]) vx_guess = np.array([r.vx_0 for t in prob.time_all_section]) vz_guess = np.array([r.vz_0 - r.g*t for t in prob.time_all_section]) m_guess = Guess.linear(prob.time_all_section, r.m_0 , 0.95*r.m_0) u1_guess = Guess.constant(prob.time_all_section, 0.01) u2_guess = Guess.constant(prob.time_all_section, 0) prob.set_states_all_section(0, x_guess) prob.set_states_all_section(1, z_guess) prob.set_states_all_section(2, vx_guess) prob.set_states_all_section(3, vz_guess) prob.set_states_all_section(4, m_guess) prob.set_controls_all_section(0, u1_guess) prob.set_controls_all_section(1, u2_guess) return
savefig_file = "04_Goddard/04_0knot_" # ------------------------ # set OpenGoddard class for algorithm determination prob = Problem(time_init, n, num_states, num_controls, max_iteration) # ------------------------ # create instance of operating object # Nondimensionalization of parameters obj = Rocket() # ======================== # Initial parameter guess # altitude profile H_init = Guess.cubic(prob.time_all_section, 1.0, 0.0, 1.010, 0.0) # Guess.plot(prob.time_all_section, H_init, "Altitude", "time", "Altitude") # if(flag_savefig):plt.savefig(savefig_file + "guess_alt" + ".png") # velocity V_init = Guess.linear(prob.time_all_section, 0.0, 0.0) # Guess.plot(prob.time_all_section, V_init, "Velocity", "time", "Velocity") # mass profile M_init = Guess.cubic(prob.time_all_section, 1.0, -0.6, 0.6, 0.0) # Guess.plot(prob.time_all_section, M_init, "Mass", "time", "Mass") # if(flag_savefig):plt.savefig(savefig_file + "guess_mass" + ".png") # thrust profile T_init = Guess.cubic(prob.time_all_section, 3.5, 0.0, 0.0, 0.0) # Guess.plot(prob.time_all_section, T_init, "Thrust Guess", "time", "Thrust")
tcontr = np.linspace(0, time_tot, int(varControls / Ncontrols)) '''values for reduction to unit''' unit_R = obj.Rtarget unit_theta = 1 unit_V = np.sqrt(obj.GMe / obj.Re) unit_m = obj.M0 unit_t = unit_R / unit_V unit_T = unit_m * unit_R / unit_t**2 states_unit = np.array((unit_R, unit_theta, unit_V, unit_V, unit_m)) controls_unit = np.array((unit_T, unit_T)) # ======================== # Initial parameter guess # altitude profile R_init = Guess.cubic(tnew, obj.Re, 0.0, obj.Rtarget, 0.0) theta_init = Guess.cubic(tnew, 0.0, 0.0, np.deg2rad(25.0), 0.0) # velocity Vr_init = Guess.linear(tnew, 0.0, 0.0) Vt_init = Guess.linear(tnew, 0.0, obj.Vtarget) # mass profile M_init = Guess.cubic(tnew, obj.M0, -0.6, obj.M0 - obj.Mp, 0.0) # thrust profile Tr_init = Guess.linear(tcontr, obj.Tmax / 2, 0.0) Tt_init = Guess.linear(tcontr, obj.Tmax / 2, 0.0) XGuess = np.array(
unit_R = obj.Re unit_v = np.sqrt(obj.GMe / obj.Re) unit_m = obj.M0 unit_t = unit_R / unit_v unit_T = unit_m * unit_R / unit_t**2 prob.set_unit_states_all_section(0, unit_R) prob.set_unit_states_all_section(1, unit_v) prob.set_unit_states_all_section(2, unit_m) prob.set_unit_controls_all_section(0, unit_T) prob.set_unit_time(unit_t) # ======================== # Initial parameter guess # altitude profile # Hinit = Guess.cubic(prob.time_all_section, y0, yprime0, yf1, yprimef) R_init = Guess.cubic(prob.time_all_section, obj.Re, 0.0, obj.Re + 50 * 1000, 0.0) # Guess.plot(prob.time_all_section, R_init, "Altitude", "time", "Altitude") # if(flag_savefig):plt.savefig(savefig_file + "guess_alt" + ".png") # velocity V_init = Guess.linear(prob.time_all_section, 0.0, 0.0) # Guess.plot(prob.time_all_section, V_init, "Velocity", "time", "Velocity") # mass profile M_init = Guess.cubic(prob.time_all_section, obj.M0, -0.6, obj.M0 * obj.Mc, 0.0) # Guess.plot(prob.time_all_section, M_init, "Mass", "time", "Mass") # if(flag_savefig):plt.savefig(savefig_file + "guess_mass" + ".png") # thrust profile T_init = Guess.cubic(prob.time_all_section, obj.max_thrust * obj.M0 * obj.g0, 0.0, 0.0, 0.0) # Guess.plot(prob.time_all_section, T_init, "Thrust Guess", "time", "Thrust") # if(flag_savefig):plt.savefig(savefig_file + "guess_mass" + ".png")
unit_t = unit_R / unit_V unit_T = unit_m * unit_R / unit_t**2 prob.set_unit_states_all_section(0, unit_R) prob.set_unit_states_all_section(1, unit_theta) prob.set_unit_states_all_section(2, unit_V) prob.set_unit_states_all_section(3, unit_V) prob.set_unit_states_all_section(4, unit_m) prob.set_unit_controls_all_section(0, unit_T) prob.set_unit_controls_all_section(1, unit_T) prob.set_unit_time(unit_t) # ======================== # Initial parameter guess # altitude profile R_init = Guess.cubic(prob.time_all_section, obj.Re, 0.0, obj.Rtarget, 0.0) # Guess.plot(prob.time_all_section, R_init, "Altitude", "time", "Altitude") # if(flag_savefig):plt.savefig(savefig_file + "guess_alt" + ".png") # theta theta_init = Guess.cubic(prob.time_all_section, 0.0, 0.0, np.deg2rad(25.0), 0.0) # velocity Vr_init = Guess.linear(prob.time_all_section, 0.0, 0.0) Vt_init = Guess.linear(prob.time_all_section, obj.V0, obj.Vtarget) # Guess.plot(prob.time_all_section, V_init, "Velocity", "time", "Velocity") # mass profile -0.6 M_init0 = Guess.cubic(prob.time_all_section, obj.Minit, 0.0, obj.Mdry[0] + obj.M0[1], 0.0) M_init1 = Guess.cubic(prob.time_all_section, obj.M0[1], 0.0, obj.Mdry[1], 0.0)
# ------------------------ # set OpenGoddard class for algorithm determination prob = Problem(time_init, n, num_states, num_controls, max_iteration) # ------------------------ # create instance of operating object obj = Rocket() prob.set_unit_states_all_section(0, 0.1) # ======================== # Initial parameter guess # altitude profile H_init = Guess.cubic(prob.time_all_section, 1.0, 0.0, 1.010, 0.0) # Guess.plot(prob.time_all_section, H_init, "Altitude", "time", "Altitude") # if(flag_savefig):plt.savefig(savefig_file + "guess_alt" + ".png") # velocity V_init = Guess.linear(prob.time_all_section, 0.0, 0.0) # Guess.plot(prob.time_all_section, V_init, "Velocity", "time", "Velocity") # mass profile M_init0 = Guess.linear(prob.time[0], 1.0, 0.6) M_init1 = Guess.linear(prob.time[1], 0.6, 0.6) M_init = np.hstack((M_init0, M_init1)) # Guess.plot(prob.time_all_section, M_init, "Mass", "time", "Mass") # if(flag_savefig):plt.savefig(savefig_file + "guess_mass" + ".png") # thrust profile
num_states = [3] num_controls = [4] max_iteration = 10 flag_savefig = True savefig_dir = "10_Low_Thrust_Orbit_Transfer/" # ------------------------ # set OpenGoddard class for algorithm determination prob = Problem(time_init, n, num_states, num_controls, max_iteration) obj = Orbiter() # ======================== # Initial parameter guess r_init = Guess.linear(prob.time_all_section, obj.r0, obj.rf) # Guess.plot(prob.time_all_section, r_init, "r", "time", "r") # if(flag_savefig):plt.savefig(savefig_dir + "guess_r" + savefig_add + ".png") vr_init = Guess.linear(prob.time_all_section, obj.vr0, obj.vrf) # Guess.plot(prob.time_all_section, vr_init, "vr", "time", "vr") # if(flag_savefig):plt.savefig(savefig_dir + "guess_vr" + savefig_add + ".png") vt_init = Guess.linear(prob.time_all_section, obj.vt0, obj.vtf) # Guess.plot(prob.time_all_section, theta_init, "vt", "time", "vt") # if(flag_savefig):plt.savefig(savefig_dir + "guess_vt" + savefig_add + ".png") ur1_init = Guess.linear(prob.time_all_section, obj.u_max, obj.u_max) # Guess.plot(prob.time_all_section, ur1_init, "ur1", "time", "ur1") # if(flag_savefig):plt.savefig(savefig_dir + "guess_ur1" + savefig_add + ".png")
num_states = [3] num_controls = [1] max_iteration = 30 flag_savefig = True savefig_dir = "01_Brachistochrone/normal_" # ------------------------ # set OpenGoddard class for algorithm determination prob = Problem(time_init, n, num_states, num_controls, max_iteration) obj = Ball() # ======================== # Initial parameter guess theta_init = Guess.linear(prob.time_all_section, np.deg2rad(30), np.deg2rad(30)) # Guess.plot(prob.time_all_section, theta_init, "gamma", "time", "gamma") # if(flag_savefig):plt.savefig(savefig_dir + "guess_gamma" + savefig_add + ".png") x_init = Guess.linear(prob.time_all_section, 0.0, obj.l) # Guess.plot(prob.time_all_section, x_init, "x", "time", "x") # if(flag_savefig):plt.savefig(savefig_dir + "guess_x" + savefig_add + ".png") y_init = Guess.linear(prob.time_all_section, 0.0, obj.l / np.sqrt(3)) # Guess.plot(prob.time_all_section, theta_init, "y", "time", "y") # if(flag_savefig):plt.savefig(savefig_dir + "guess_y" + savefig_add + ".png") prob.set_states_all_section(0, x_init) prob.set_states_all_section(1, y_init) prob.set_controls_all_section(0, theta_init)
# obj.make_scales() unit_x = 300000 unit_y = 100000 unit_t = 100 unit_v = unit_x / unit_t prob.set_unit_states_all_section(0, unit_x) prob.set_unit_states_all_section(1, unit_y) prob.set_unit_states_all_section(2, unit_v) prob.set_unit_controls_all_section(0, 1.0) prob.set_unit_time(unit_t) # ======================== # Initial parameter guess half_nodes = int(prob.nodes[0] / 2) theta_init = Guess.linear(prob.time_all_section, 0.0, np.pi) # Guess.plot(prob.time_all_section, theta_init, "gamma", "time", "gamma") # if(flag_savefig):plt.savefig(savefig_dir + "guess_gamma" + ".png") x_init = Guess.linear(prob.time_all_section, 0.0, obj.l) # Guess.plot(prob.time_all_section, x_init, "x", "time", "x") # if(flag_savefig):plt.savefig(savefig_dir + "guess_x" + ".png") # y_init = Guess.linear(prob.time_all_section, 0.0, obj.l / np.sqrt(3)) y_init0 = Guess.linear(prob.time_all_section[:half_nodes], 0, obj.h) y_init1 = Guess.linear(prob.time_all_section[half_nodes:], obj.h, 0) y_init = np.hstack((y_init0, y_init1)) # Guess.plot(prob.time_all_section, y_init, "y", "time", "y") # if(flag_savefig):plt.savefig(savefig_dir + "guess_y" + ".png") v_init0 = Guess.linear(prob.time_all_section[:half_nodes], 0, obj.h)
unit_t = unit_R / unit_V unit_T = unit_m * unit_R / unit_t**2 prob.set_unit_states_all_section(0, unit_R) prob.set_unit_states_all_section(1, unit_theta) prob.set_unit_states_all_section(2, unit_V) prob.set_unit_states_all_section(3, unit_V) prob.set_unit_states_all_section(4, unit_m) prob.set_unit_controls_all_section(0, unit_T) prob.set_unit_controls_all_section(1, unit_T) prob.set_unit_time(unit_t) # ======================== # Initial parameter guess # altitude profile R_init = Guess.cubic(prob.time_all_section, obj.Re, 0.0, obj.Rtarget, 0.0) # Guess.plot(prob.time_all_section, R_init, "Altitude", "time", "Altitude") # if(flag_savefig):plt.savefig(savefig_file + "guess_alt" + ".png") # theta theta_init = Guess.cubic(prob.time_all_section, 0.0, 0.0, np.deg2rad(25.0), 0.0) # velocity Vr_init = Guess.linear(prob.time_all_section, 0.0, 0.0) Vt_init = Guess.linear(prob.time_all_section, 0.0, obj.Vtarget) # Guess.plot(prob.time_all_section, V_init, "Velocity", "time", "Velocity") # mass profile M_init = Guess.cubic(prob.time_all_section, obj.M0, -0.6, obj.M0 - obj.Mp, 0.0) # Guess.plot(prob.time_all_section, M_init, "Mass", "time", "Mass") # if(flag_savefig):plt.savefig(savefig_file + "guess_mass" + ".png")