def fitness(self, x): obj1 = 0 transfer = hodographicShaping( self.scStateDep, self.scStateArr, departureDate=self.depDate, tof=self.tof, N=self.N, departureBody=self.depBody, arrivalBody=self.target, rShape='CPowPow2_scaled', thetaShape='CPowPow2_scaled', zShape='CosR5P3CosR5P3SinR5_scaled', rShapeFree='PSin05PCos05_scaled', thetaShapeFree='PSin05PCos05_scaled', zShapeFree='P4CosR5P4SinR5_scaled', rFreeC=[x[0], x[1]], thetaFreeC=[x[2], x[3]], zFreeC=[x[4], x[5]], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.evaluate(evalThrust=False) obj1 = transfer.deltaV return [ obj1, ]
def boundaryConditionComparison(): # trajectory settings depMjd = 3421 tof = 349 N = 1 arrMjd = depMjd + tof depBody = '3' arrBody = '4' ephems = 'spice' # departure and arrival states: rendezvous scStateDep, __, __ = ephemeris(depBody, depMjd, mode=ephems) scStateArr, __, __ = ephemeris(arrBody, arrMjd, mode=ephems) transfer = hodographicShaping(scStateDep, scStateArr) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.checkBoundaryConditions() if transfer.velCompare == True and transfer.posCompare == True: print('OK\tBoundary conditions comparison (built-in)') else: print('ERROR\tBoundary conditions comparison (built-in)')
def fullTest2(rtol = 1e-3, atol = 1e-2): # trajectory settings depMjd = 10025 tof = 1050 N = 2 arrMjd = depMjd + tof depBody = 'earth' arrBody = 'mars' # departure and arrival states: rendezvous scStateDep, __, __ = ephemeris(depBody, depMjd) scStateArr, __, __ = ephemeris(arrBody, arrMjd) transfer = hodographicShaping(scStateDep, scStateArr, departureDate=depMjd, tof=tof, N=N, departureBody = depBody, arrivalBody = arrBody, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [0, 0], thetaFreeC = [0, 0], zFreeC = [0, 0], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.checkBoundaryConditions() transfer.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) testPoints = [transfer.psiTransfer, transfer.deltaV, transfer.maxThrust] # print(testPoints) knownPoints = [2.573118029750549, 6338.852298544599, 0.00015143346642256032] test = np.allclose(testPoints, knownPoints, rtol, atol) if test == True: print('OK\tFull test 2 (earth-mars, departureDate=10025,', 'tof=1050, N=2)') else: print('ERROR\tFull test 2 (earth-mars, departureDate=10025,', 'tof=1050, N=2)') print('\tComputed: ', testPoints) print('\tExpected: ', knownPoints)
def fullTest3(rtol = 1e-3, atol = 1e-2): # trajectory settings depMjd = 12000 tof = 300 N = 1 arrMjd = depMjd + tof depBody = 'earth' arrBody = 'venus' # departure and arrival states: rendezvous scStateDep, __, __ = ephemeris(depBody, depMjd) scStateArr, __, __ = ephemeris(arrBody, arrMjd) transfer = hodographicShaping(scStateDep, scStateArr, departureDate=depMjd, tof=tof, N=N, departureBody = depBody, arrivalBody = arrBody, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CPowPow2_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [2, 20000], thetaFreeC = [173, 3460], zFreeC = [1990, 3333], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.checkBoundaryConditions() transfer.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) testPoints = [transfer.psiTransfer, transfer.deltaV, transfer.maxThrust] # print(testPoints) knownPoints = [0.71804214972971, 22535.748458173402, 0.0012091070214979359] test = np.allclose(testPoints, knownPoints, rtol, atol) if test == True: print('OK\tFull test 3 (earth-venus, departureDate=12000,', 'tof=300, N=1)') else: print('ERROR\tFull test 3 (earth-venus, departureDate=12000,', 'tof=300, N=1)') print('\tComputed: ', testPoints) print('\tExpected: ', knownPoints)
def fitness(self, x): obj = 0 transfer = hodographicShaping('earth', 'mars', departureDate=x[0], tof=x[1], N=x[2]) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.evaluate(evalThrust=False) obj = transfer.deltaV return [ obj, ]
def fitness(self, x): obj1, obj2 = 0, 0 transfer = hodographicShaping('earth', 'mars', departureDate=x[0], tof=x[1], N=x[2]) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() # transfer.checkBoundaryConditions() transfer.evaluate(evalThrust=True) obj1 = transfer.deltaV obj2 = transfer.maxThrust return [obj1, obj2]
def boundaryConditionTestPos(rtol = 1e-3, atol = 1e-2): # trajectory settings depMjd = 10025 tof = 1050 N = 2 arrMjd = depMjd + tof depBody = 'earth' arrBody = 'mars' ephems = 'jpl' # departure and arrival states: rendezvous scStateDep, __, __ = ephemeris(depBody, depMjd, mode=ephems) scStateArr, __, __ = ephemeris(arrBody, arrMjd, mode=ephems) transfer = hodographicShaping(scStateDep, scStateArr, departureDate=depMjd, tof=tof, N=N, departureBody = depBody, arrivalBody = arrBody, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [0, 0], thetaFreeC = [0, 0], zFreeC = [0, 0], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() testPoints = [transfer.r(transfer.tofSec), transfer.t(transfer.tofSec), # 0, transfer.z(transfer.tofSec)] # print(testPoints) knownPoints = [219832470724.13513, 13.418874318624699, -77456667.88140798] test = np.allclose(testPoints, knownPoints, rtol, atol) if test == True: print('OK\tBoundary conditions position test') else: print('ERROR\tBoundary conditions position test') print('\tComputed: ', testPoints) print('\tExpected: ', knownPoints)
def fullTest4(rtol = 1e-3, atol = 1e-2): # trajectory settings depMjd = 9453 tof = 844 N = 1 arrMjd = depMjd + tof depBody = '3' arrBody = '4' ephems = 'spice' # departure and arrival states: rendezvous scStateDep, __, __ = ephemeris(depBody, depMjd, mode=ephems) scStateArr, __, __ = ephemeris(arrBody, arrMjd, mode=ephems) transfer = hodographicShaping(scStateDep, scStateArr, departureDate=depMjd, tof=tof, N=N, departureBody = depBody, arrivalBody = arrBody, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [137, 178], thetaFreeC = [100, 1364], zFreeC = [32, 283], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.checkBoundaryConditions() transfer.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) testPoints = [transfer.psiTransfer, transfer.deltaV, transfer.maxThrust] knownPoints = [5.213985160376169, 45508.713465061395, 0.0010283457257095393] test = np.allclose(testPoints, knownPoints, rtol, atol) if test == True: print('OK\tFull test 4 (3-4, departureDate=9453, tof=844, N=1)') else: print('ERROR\tFull test 4 (3-4, departureDate=9453, tof=844, N=1)') print('\tComputed: ', testPoints) print('\tExpected: ', knownPoints)
def boundaryConditionTestVel(rtol = 1e-3, atol = 1e-2): # trajectory settings depMjd = 10025 tof = 1050 N = 2 arrMjd = depMjd + tof depBody = 'earth' arrBody = 'mars' ephems = 'jpl' # departure and arrival states: rendezvous scStateDep, __, __ = ephemeris(depBody, depMjd, mode=ephems) scStateArr, __, __ = ephemeris(arrBody, arrMjd, mode=ephems) transfer = hodographicShaping(scStateDep, scStateArr, departureDate=depMjd, tof=tof, N=N, departureBody = depBody, arrivalBody = arrBody, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [0, 0], thetaFreeC = [0, 0], zFreeC = [0, 0], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() testPoints = [transfer.rDot(transfer.tofSec), transfer.tDot(transfer.tofSec), transfer.zDot(transfer.tofSec)] # print(testPoints) knownPoints = [2161.3061456572896, 24897.147647368587, 802.1571912246434] test = np.allclose(testPoints, knownPoints, rtol, atol) if test == True: print('OK\tBoundary conditions velocity test') else: print('ERROR\tBoundary conditions velocity test') print('\tComputed: ', testPoints) print('\tExpected: ', knownPoints)
def fullTest1(rtol = 1e-3, atol = 1e-2): depMjd = 8002 tof = 1500 N = 3 arrMjd = depMjd + tof depBody = 'earth' arrBody = 'mars' scStateDep, __, __ = ephemeris(depBody, depMjd) scStateArr, __, __ = ephemeris(arrBody, arrMjd) transfer = hodographicShaping(scStateDep, scStateArr, departureBody='earth', arrivalBody='mars', departureDate=8002, tof=1500, N=3, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [137, 178], thetaFreeC = [100, 1364], zFreeC = [32, 283], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.checkBoundaryConditions() transfer.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) testPoints = [transfer.psiTransfer, transfer.deltaV, transfer.maxThrust] # print(testPoints) knownPoints = [3.858953628300317, 273559.833321966, 0.003146874363948356] test = np.allclose(testPoints, knownPoints, rtol, atol) if test == True: print('OK\tFull test 1 (earth-mars, departureDate=8002, tof=1500, N=3)') else: print('ERROR\tFull test 1 (earth-mars, departureDate=8002,', 'tof=1500, N=3)') print('\tComputed: ', testPoints) print('\tExpected: ', knownPoints)
def main(folder = 'graveyard'): """ Evaluate patched low thrust trajectories For explicit conditions resembling the Dawn mission: Launch from Earth -> impulsive shot -> low-thrust to Mars -> swingby -> low-thrust to Vesta -> rendezvous All state vectors at this level are in cylindrical coordinates: [radius, phi, z, v_r, vTheta, v_z]] the only exception is the flyby computation, see below """ ############################################################################ # Initialization # output folder: Contents are overwritten each run! outputFolder = os.path.join('output', folder) checkFolder(outputFolder) # reduce precision of printed numpy values np.set_printoptions(precision=3) # load spice kernels ephems = 'spice' loadSpiceKernels() ############################################################################ # Free parameters # set up the problem: fixed parameters ephems = 'spice' # bodies depBody = '3' # earth arrBody = '4' # mars arrBody2 = '2000004' # Vesta arrBody4 = '2000001' # Ceres # number of revolutions N = 0 N2 = 1 N4 = 0 # orbit insertion (tangential inpulsive shot) injectionDeltaV = [0, 2.42e3, 0] # flyby parameters swingbyPlanet = pk.planet.jpl_lp('mars') arrVelMars = [-2.21e3, 2.17e4, -6.37e1] flybyPlane = 2.71 flybyAltitude = 471e3 # dates depMjd = 2782.2 tof = 407.6 # Earth - Mars tof2 = 1099.1 # Mars- Vesta tof3 = 559.2 # stay at Vesta tof4 = 912.7 # transfer Vesta - Ceres ############################################################################ # Derived parameters # Earth - Mars arrMjd = depMjd + tof planetStateDep, __, __ = ephemeris(depBody, depMjd, mode=ephems) planetStateArr, plArCart, __ = ephemeris(arrBody, arrMjd, mode=ephems) print('Mars arrival date', arrMjd) print('Mars state cyl', planetStateArr) print('Mars state cart', plArCart) injectionDeltaVabs = np.linalg.norm(injectionDeltaV) scStateDep = applyDeltaV(planetStateDep, injectionDeltaV) scStateArr = np.array((planetStateArr[0:3], arrVelMars)).reshape(6,) # swingby scStateArrCart = stateCyl2cart(scStateArr) # convert state to Cartesian # Mars - Vesta depMjd2 = arrMjd arrMjd2 = depMjd2 + tof2 depBody2 = arrBody scStateArr2, __, __ = ephemeris(arrBody2, arrMjd2, mode=ephems) # stay at Vesta depMjd3 = arrMjd2 arrMjd3 = depMjd3 + tof3 body = arrBody2 # Vesta - Ceres depMjd4 = arrMjd3 arrMjd4 = depMjd4 + tof4 depBody4 = body scStateDep4, __, __ = ephemeris(depBody4, depMjd4, mode=ephems) scStateArr4, __, __ = ephemeris(arrBody4, arrMjd4, mode=ephems) ############################################################################ # Computations # low-thrust transfer to Mars prob = pg.problem(myProblemShapingSingle(scStateDep, scStateArr, depDate=depMjd, tof=tof, N=N, depBody=depBody, target=arrBody)) pop, algo, initialGuess = optimizationSetup(prob) print('Run Nelder-Mead to find good shape coefficients.') start = time.process_time() pop = algo.evolve(pop) optiTime = time.process_time() - start DeltaV1, c1 = getShapingResults(pop, algo, optiTime, initialGuess) # flyby scStateNewCart, swingbyDeltaV = flyby(scStateArrCart, 'mars', flybyAltitude, flybyPlane, mode='jpl', mjd=arrMjd, folder=outputFolder, makePlot=True, save=True, show=True) scStateDep2 = stateCart2cyl(scStateNewCart) # convert back to Cylindrical # low-thrust to Vesta prob = pg.problem(myProblemShapingSingle(scStateDep2, scStateArr2, depDate=depMjd2, tof=tof2, N=N2, depBody=depBody2, target=arrBody2)) pop, algo, initialGuess = optimizationSetup(prob) start = time.process_time() print('Run Nelder-Mead to find good shape coefficients.') pop = algo.evolve(pop) optiTime = time.process_time() - start DeltaV2, c2 = getShapingResults(pop, algo, optiTime, initialGuess) # stay at Vesta transfer3 = orbitFollowing(startDate=depMjd3, tof=tof3, body=body, ephemSource=ephems) # low-thrust to Ceres prob = pg.problem(myProblemShapingSingle(scStateDep4, scStateArr4, depDate=depMjd4, tof=tof4, N=N4, depBody=depBody4, target=arrBody4)) pop, algo, initialGuess = optimizationSetup(prob) start = time.process_time() print('Run Nelder-Mead to find good shape coefficients.') pop = algo.evolve(pop) optiTime = time.process_time() - start DeltaV4, c4 = getShapingResults(pop, algo, optiTime, initialGuess) # compute the total DeltaV totalDeltaV = np.squeeze(DeltaV1 + DeltaV2 + DeltaV4) ############################################################################ # Result outputs # compute the individual transfers again for detailed results and plotting details = False print('Detailed results for each leg') transfer = hodographicShaping(scStateDep, scStateArr, departureDate=depMjd, tof=tof, N=N, departureBody = depBody, arrivalBody = arrBody, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [c1[0], c1[1]], thetaFreeC = [c1[2], c1[3]], zFreeC = [c1[4], c1[5]], ) transfer.shapingRadial() transfer.shapingVertical() transfer.shapingTransverse() transfer.assembleThrust() transfer.checkBoundaryConditions() transfer.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) if details: transfer.status(printBC=False) transfer2 = hodographicShaping(scStateDep2, scStateArr2, departureDate=depMjd2, tof=tof2, N=N2, departureBody = depBody2, arrivalBody = arrBody2, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [c2[0], c2[1]], thetaFreeC = [c2[2], c2[3]], zFreeC = [c2[4], c2[5]], ) transfer2.shapingRadial() transfer2.shapingVertical() transfer2.shapingTransverse() transfer2.assembleThrust() transfer2.checkBoundaryConditions() transfer2.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) if details: transfer2.status(printBC=True) transfer4 = hodographicShaping(scStateDep4, scStateArr4, departureDate=depMjd4, tof=tof4, N=N4, departureBody = depBody4, arrivalBody = arrBody4, rShape = 'CPowPow2_scaled', thetaShape = 'CPowPow2_scaled', zShape = 'CosR5P3CosR5P3SinR5_scaled', rShapeFree = 'PSin05PCos05_scaled', thetaShapeFree = 'PSin05PCos05_scaled', zShapeFree = 'P4CosR5P4SinR5_scaled', rFreeC = [c4[0], c4[1]], thetaFreeC = [c4[2], c4[3]], zFreeC = [c4[4], c4[5]], ) transfer4.shapingRadial() transfer4.shapingVertical() transfer4.shapingTransverse() transfer4.assembleThrust() transfer4.checkBoundaryConditions() transfer4.evaluate(evalThrust='Grid', printTime=False, nEvalPoints = 1000) if details: transfer4.status(printBC=True) # print overal results print('###################################################################') print(f'Results of patched trajectory computation') print(f'Orbit injection impulse:\t{(injectionDeltaVabs)/1e3:>9.2f} km/s') print(f'DeltaV Earth -> Mars:\t\t{np.squeeze(DeltaV1)/1e3:>9.2f} km/s') print(f'Swingby DeltaV:\t\t\t{swingbyDeltaV/1e3:>9.2f} km/s') print(f'DeltaV Mars -> Vesta:\t\t{np.squeeze(DeltaV2)/1e3:>9.2f} km/s') print(f'DeltaV Vesta -> Ceres:\t\t{np.squeeze(DeltaV4)/1e3:>9.2f} km/s') print(f'Total low-thrust DeltaV:\t{totalDeltaV/1e3:>9.2f} km/s') print('###################################################################') # generate combined plots awesomePlotWonderland = patchedPlots( [transfer, transfer2, transfer3, transfer4], samples=1000, folder=outputFolder, save=True, show=True, addBody=[]) # awesomePlotWonderland.planetSystem(plotSOI=True, scaling=False) awesomePlotWonderland.trajectory2D() awesomePlotWonderland.trajectory3D(scaling=False)