def getStateVector(fileName): import orbitTools from scipy.interpolate import UnivariateSpline from scipy import interpolate import orbitProp as op import sys sys.path.append('../PythonScripts') import AtmosProfile as AP import matplotlib.pyplot as plt planetModel = 0 omegaE = 2.*np.pi/(86164.0906) inputs = readInput(fileName) [lon0,lat0,h0] = inputs[0] thetag = inputs[10] ispList = inputs[9] [x0,y0,z0] = orbitTools.latlonalt2ECI(lat0,lon0,h0,thetag,planetModel) #SEZ2ECI(lat,lon,hs,Vsouth,Veast,Vzenith,inertial,thetag,planetModel) V0 = orbitTools.SEZ2ECI(lat0,lon0,h0,0,0,0,0,thetag,planetModel) Vx0 = V0[0] Vy0 = V0[1] Vz0 = V0[2] massList = inputs[1] m0Vec = massList[0] mfVec = massList[1] SrefList = inputs[2] MinfCDlist = inputs[3] CDList = inputs[4] atmosoption = inputs[5] atmoFile = inputs[6] timelist = inputs[7] thrustList = inputs[8] retTrajs = [] #atmosoption = 2 if atmosoption>0: print 'using given atmo data' altitudeList,densityMeanList,uMeanList,vMeanList,wMeanList,densitySDList,uSDList,vSDList,wSDList,nPoints= AP.readGramAtmos(atmoFile) else: altitudeList = [0] densityMeanList = [0] uMeanList = [0] vMeanList = [0] wMeanList = [0] densitylist = densityMeanList ulist = uMeanList vlist = vMeanList wlist = wMeanList dtinterval = inputs[12] cloption = 0 cl = [0] loverd = 0 minfcl = [1] geoptions = 1 fileGE = 'trajProp' thrustoffangledeg =[0,0] mass_time_alt_opt = 1 dtinterval = 0.01 stateVectors = [] for index in range(0,len(m0Vec)): mass = m0Vec[index] mf = mfVec[index] initialstate = [x0,y0,z0,Vx0,Vy0,Vz0] thrust = thrustList[index] Tx = thrust[0] Ty = thrust[1] Tz = thrust[2] timeVec = timelist[index] ''' fTx = UnivariateSpline(timeVec,Tx) fTy = UnivariateSpline(timeVec,Ty) fTz = UnivariateSpline(timeVec,Tz) timeVec = np.linspace(timeVec[0],timeVec[-1],1000) Tx = fTx(timeVec) Ty = fTy(timeVec) Tz = fTz(timeVec) ''' cd0 = CDList[index] minfcd0 = MinfCDlist[index] sref = SrefList[index] fcd0 = UnivariateSpline(minfcd0,cd0) isp = ispList[index] minfcd = np.linspace(minfcd0[0],minfcd0[-1],100) cd = fcd0(minfcd) Tlist = np.array([Tx,Ty,Tz]).T#np.concatenate([[Tx],[Ty],[Tz]],axis=1) ndtinterval = int(np.ceil(2*timeVec[-1]/dtinterval)) ntime = len(timeVec) #finalconditions,derivVals = op.propagate(initialstate,mass,mf,sref,minfcd,cd,cloption,minfcl,cl,loverd,atmosoption,altitudeList,densitylist,ulist,vlist,wlist,Tlist,timeVec,isp,geoptions,fileGE,planetModel,dtinterval,ndtinterval,thetag,1,ncd=len(minfcd),ncl=len(minfcl),ntime=ntime,nlist=len(altitudeList)) #finalconditions,finalderivs = propagate(initialstate,mass,mass_time_alt_final,sref,minfcd,cd,cloption,minfcl,cl,loverd,atmosoption,altitudelist,densitylist,ulist,vlist,wlist,tlist,timelist,isp,geoptions,filename,planetmodel,dtinterval,ndtinterval,thetag,mass_time_alt_opt,thrustoffangledeg,ncd=len(minfcd),ncl=len(minfcl),ntime=shape(tlist,0),nlist=len(altitudelist)) if index == len(m0Vec)-1: mass_time_alt_opt = 2 fcond = timeVec[-1] else: fcond = mf finalconditions,finalderivs = op.propagate(initialstate,mass,fcond,sref,minfcd,cd,cloption,minfcl,cl,loverd,atmosoption,altitudeList,densitylist,ulist,vlist,wlist,Tlist,timeVec,isp,geoptions,fileGE+str(1+index),planetModel,dtinterval,ndtinterval,thetag,mass_time_alt_opt) newIndex = finalconditions[:,10]>=0.0 newfinalConditions = finalconditions[newIndex,:] stateVectors.append(newfinalConditions) x0 = newfinalConditions[-1,0] y0 = newfinalConditions[-1,1] z0 = newfinalConditions[-1,2] Vx0 = newfinalConditions[-1,3] Vy0 = newfinalConditions[-1,4] Vz0 = newfinalConditions[-1,5] massCheck = newfinalConditions[-1,9] timeCheck = newfinalConditions[-1,7] thetag = thetag + omegaE*newfinalConditions[-1,10] retTrajs.append(newfinalConditions)
cloption = 0 # if 1, then ignore loverd and use CL profile. Doesnt change drag profile usage Vup = Vmag*np.sin(FPA*np.pi/180.) Vplane = Vmag*np.cos(FPA*np.pi/180.) Veast = Vplane*np.cos(beta*np.pi/180.) Vsouth = -Vplane*np.sin(beta*np.pi/180.) r_eci = orbitTools.latlonalt2ECI(latitude,longitude,altitude,thetagRef,planetModel) v_eci = orbitTools.SEZ2ECI(latitude,longitude,altitude,Vsouth,Veast,Vup,inertial,thetagRef,planetModel) #print r_eci #print v_eci
def generateRandomMultiTrajMalFunc(missionList,tLaunchDesired,dt,timeMalfunc,deltatfail,TOffset,ThrustOffsetAngDegMalFunc,atmProfile): # this function generates entire trajectories import numpy as np #calculating ECI coordinates for launch import orbitTools # library for coordinate transformation import orbitProp as op # trajectory propagation routine import data2GE import copy if len(atmProfile)>0: atmosoption =1 [altitudelist,densitylist,ulist,vlist,wlist] = atmProfile else: atmosoption = 0 densitylist = [0] ulist = [0] vlist = [0] wlist = [0] altitudelist = [0] mission0 = missionList[0]# getting mission parameters for current mission omegaE = getAngVelEarth(mission0)# planet's angular velocity retList = [] latitude,longitude,height = latlonaltFromMission(mission0) planetmodel = 0# 0 for Circ ...1 for ellipt trajList,thetag0 = interpolateTrajectories(missionList,tLaunchDesired,dt) r0 = orbitTools.latlonalt2ECI(latitude,longitude,height,thetag0,planetmodel) Rearth = getRfromMission(mission0) omega = getAngVelEarth(mission0) nEvents = getNumberOfStages(mission0) cloption = 1 cl = 0. minfcl = [1] loverd = 0.0 geoptions = 0 dtinterval = dt ndtinterval = 20000 fileList = [] currentTime = 0.0 retList= [] malFuncBool = False for indexEvent in range(nEvents): ThrustOffsetAngDeg= [0,0]#ThrustOffsetAngDegMalFunc if indexEvent ==0 : #first stage...setting initial conditions for rest of cases [vS0,vE0,vZ0] = [0,0,0] # initial velocity in SEZ frame inertial = 0 thetag = copy.deepcopy(thetag0) # inertial = 1. input velocities are inertial velocities in SEZ frame # inertial =0. input velocities are local velocities (earth rotation not accounted) #Veci0 = orbitTools.SEZ2ECI(latitude,longitude,r0,vS0,vE0,vZ0,inertial,thetag) Veci0 = orbitTools.SEZ2ECI(latitude,longitude,height,vS0,vE0,vZ0,inertial,thetag,planetmodel) initialstate = np.array([r0[0],r0[1],r0[2],Veci0[0],Veci0[1],Veci0[2]]) m0,Fmax,isp,minfcd,cd,sref = vehicleParamFromMission(mission0,indexEvent) massf = getFinalMassFromMission(mission0,indexEvent)# m0[-1] Fmax = TOffset*Fmax etaMin = getEtaMinFromMission(mission0,indexEvent) filename = 'pTraj'+str(indexEvent)+'.txt' fileList.append(filename) if etaMin>=0: propOption = 1 currTraj = trajList[indexEvent] [indexEvent,tfit,uxFit,uyFit,uzFit,etaFit] = currTraj # ensuring that unit vector is actually a unit vector (due to interpolation) uMag = (uxFit**2 + uyFit**2 + uzFit**2)**.5 uxetaFit = np.array([etaFit*uxFit/uMag]).T uyetaFit = np.array([etaFit*uyFit/uMag]).T uzetaFit = np.array([etaFit*uzFit/uMag]).T uetaMat = np.concatenate((uxetaFit,uyetaFit,uzetaFit),1) Fmat = Fmax*uetaMat timelist = tfit propCond = massf ntime = len(timelist) finalconditions,finalderivs = op.propagate(initialstate, m0, propCond,sref,minfcd,cd,cloption, minfcl,cl,loverd,atmosoption, altitudelist,densitylist,ulist,vlist ,wlist,Fmat,timelist,isp,geoptions,filename,planetmodel,dtinterval,ndtinterval,thetag,propOption,ThrustOffsetAngDeg,ncd=len(minfcd),ncl=len(minfcl),ntime=ntime,nlist=len(altitudelist)) tfTemp = fixPropagateResultsGetTime(finalconditions) if timeMalfunc<=tfTemp[-1]: geoptions=0 #print 'TOff',ThrustOffsetAngDegMalFunc finalconditions,finalderivs = malFunc.propagate(initialstate,m0,propCond,sref,minfcd,cd,cloption,minfcl,cl,loverd,atmosoption,altitudelist,densitylist,ulist,vlist,wlist,Fmat,timeMalfunc,deltatfail,timelist,isp,geoptions,filename,planetmodel,dtinterval,ndtinterval,thetag,propOption,ThrustOffsetAngDegMalFunc) malFuncBool = True xc,yc,zc,Vxc,Vyc,Vzc,mc,tc,newfinalConditions = fixPropagateResults(finalconditions) #print 'FC',newfinalConditions[-1] #print 'new',newfinalConditions[-1] # print 'tc',tc,currentTime tc = tc + currentTime initialstate = np.array([xc[-1],yc[-1],zc[-1],Vxc[-1],Vyc[-1],Vzc[-1]]) mass0 = mc[-1] currentTime = tc[-1] # updating time thetagVector = omegaE*tc + thetag0 thetag = omegaE*currentTime + thetag0 # updating thetag for next event elif etaMin<0: propOption = 2 currTraj = trajList[indexEvent] [indexEvent,tffit] = currTraj dtlocal = tffit/5. Tmax = 0.0 uetaMat = np.array([[1,1,1]]) Fmat = Fmax*uetaMat timelist = [tffit] propCond = tffit ntime = len(timelist) finalconditions,finalderivs = op.propagate(initialstate, mass0, propCond,sref,minfcd,cd,cloption, minfcl,cl,loverd,atmosoption, altitudelist,densitylist,ulist,vlist ,wlist,Fmat,timelist,isp,geoptions,filename,planetmodel,dtlocal,ndtinterval,thetag,propOption,ThrustOffsetAngDeg,ncd=len(minfcd),ncl=len(minfcl),ntime=ntime,nlist=len(altitudelist)) xc,yc,zc,Vxc,Vyc,Vzc,mc,tc,newfinalConditions = fixPropagateResults(finalconditions) tc = tc + currentTime mass0 = mc[-1] currentTime = tc[-1] # updating time thetagVector = omegaE*tc + thetag0 thetag = omegaE*currentTime + thetag0# updating thetag for next event retList.append([xc,yc,zc,Vxc,Vyc,Vzc,mc,tc,thetagVector,indexEvent]) if malFuncBool==True: break return retList