An Implementation of Sgp4 in Non-Singular Variables Using a Functional Paradigm
Total Page:16
File Type:pdf, Size:1020Kb
AN IMPLEMENTATION OF SGP4 IN NON-SINGULAR VARIABLES USING A FUNCTIONAL PARADIGM Martín Lara∗ Pablo Pita Leira GRUCACI – Scientific Computation Group University of La Rioja [email protected] C/ Luis de Ulloa, s/n. Edificio Vives, 26004 Logroño, Spain ABSTRACT from his software. It is written in Scala and can be com- piled to run in the Java Virtual Machine or in the browser A new implementation of the SGP4 algorithm is pre- with the scala.js compiler backend. The SGP4Extensions sented, which allows for choosing different sets of vari- software however is designed differently to those versions ables in the computation of the periodic corrections. The from Vallado: project is implemented in Scala, a hybrid functional/ob- ject oriented programming language running in the Java 1. It is heavily influenced by the functional software Virtual Machine. Validation of the new implementations paradigm. is made by carrying out different tests based on Vallado’s results. Finally, applicability for massive data process- 2. Implementations using other variables and/or ex- ing tasks like prediction of orbital collision events and tra terms can be easily introduced to create new performance are discussed. propagation algorithms Index Terms— SGP4, Orbital Propagation, Scala, 3. Equations in the code have almost always the same Perturbation theory, non-singular variables notation as expressed in the papers to allow easy review 1. INTRODUCTION TO SGP4EXTENSIONS In particular, the usage of Lara’s non-singular variables The SGP4 (Simplified General Perturbations 4) orbit [9] is optional for all periodic corrections, in this way propagator is a widely used tool for the fast, short term avoiding the mixture of Lyddane’s and polar variables propagation of earth satellite orbits. The algorithms in used for the long- and short-period corrections, respec- which it is based are thoroughly described in the SPACE- tively, in the original implementation. TRACK report #3 [1], as well as in Vallado et al. up- In the current version of SGP4Extensions, only ex- date [2]. Current implementations of SGP4 are based tensions around SGP4 are implemented. The deep space on Brouwer’s gravity solution [3] and Lane atmospheric algorithm SDP4 is not implemented. model [4], but using Lyddane’s modifications for avoid- The project is hosted in ing loss of precision in the evaluation of the periodic cor- https://github.com/pleira/SGP4Extensions rections [5], which are, besides, notably simplified for and it is licensed with an open source Apache Version 2 improving evaluation efficiency. Different alternatives in license. the literature discuss other variable sets, either canonical or not, that can be used in the computation of periodic 2. SCALA FEATURES corrections (see, for instance, [6, 7, 8, 9]). Due to its popularity, there are numerous versions Scala has been created by Martin Odersky as an stati- of SGP4 in several programming languages. The most cally typed language fusing the object oriented and func- important implementation comes from David Vallado [2] tional paradigms [10]. It is designed with Java compati- who has done a comprehensive analysis of the algorithm. bility in mind. Users normally compile scala programs to Many other versions are derived from his work. The work Java byte code that will run in the Java Virtual Machine. presented in this paper, SGP4Extensions, also derives Scala fully supports the functional paradigm where ∗Funded by the Ministry of Economic Affairs and Competitive- functions are implemented in a referential transparent ness of Spain: Projects ESP2013-41634-P and ESP2014-57071-R. way, called pure functions with no side effects [11, p. 3]. There is a separation of the run time part, like for ex- For most of the methods, the following type classes are ample reading/writing from/to files, called generally the needed: interpreter, from a pure functional part, the description, • Field: provides for the sum, product and division which is just responsible to describe the algorithms that operation following associative laws. will be applied. The algorithms in the description just return new immutable structures with the calculations • Trig: provides trigonometric functions. carried out. In this implementation of SGP4, mutable state and side effects have been completely avoided in • NRoot: provides fractional exponents, square root the algorithm allowing easily to support software con- and nroots. cerns like testability and parallelism. • Order: type-safe equivalence and comparison func- Scala’s support for unicode to represent algebraic tions. equations has been explored in the literature [12]. Uni- code is used intensively in SGP4Extensions with some As example, the trigonometric series for the geopotential simplifications to alleviate the notation: no primes nor coefficients use these four type classes. overdots for derivatives have been done in the code. As The user has then a choice of a particular numeric example, equations 6 giving Lara’s long period correc- class to define a SGP4 propagator. The Double type tions in Sec.3.2 are so stated in the code in the scala has been used for testing SGP4Extensions as it is fast trait LaraFirstOrderCorrections: and sufficient for almost all cases. The @sp annotation is an alias for @specialized, and therefore, a version of val δψ = ϵ3 * (2*χ + (κ*χ - c*σ*ξ)/(1+c)) this method is created by the compiler using the prim- val δξ = ϵ3 * (2*`χ²` + κ*(1 - `ξ²`)) val δχ = -ϵ3 * (`c²`*σ + (2 + κ)*ξ*χ) itive representation of double in the Java Virtual Ma- val δr = ϵ3 * p * ξ chine avoiding the creation of objects. But the user has val δR = ϵ3 * (Θ/r) * (1 + κ) * χ a choice for other numeric types. As example, an exact val δΘ = ϵ3 * Θ * (κ*ξ - σ*χ) numeric type like Real could be used. A numeric type like Interval[Double] would allow for automatic calcula- Regarding optimizations, SGP4Extensions uses the tion of errors when those are defined as intervals. These @specialized annotation for the Double numeric type. numeric types can have uses in certain areas but their The usage of primitive types like Double comes with the execution times are several orders of magnitude slower cost of boxing/unboxing operations when working with than Double. unspecialized methods as the compiler creates wrapper Scalactic provides support for types expressing either objects for that, an operation called boxing. With @spe- the good result or an error message and for comparing cialized the compiler will support creating specialized Doubles with a certain tolerance. methods or classes for the declared primitive types that avoids creating the boxing objects. // final results in cartesians type SGPPropCtx[F] = (CartesianElems[F], CartesianElems[F], SpecialPolarNodal[F]) 2.1. Scala libraries used type SGPPropResult[F] = SGPPropCtx[F] Or ErrorMessage The current version of the SGP4Extensions code uses Scalatest is used to automatically check the results of the Scala libraries Spire [13], Scalactic [14] and Scalatest the different algorithms. [15]. Spire is a library that provides efficient numeric 2.2. Description of the types used types and mathematical functions. The implementation of most of the functions and methods in SGP4Exten- Several groups of types are defined to make clear the pro- sions are parameterized through Spire’s type classes. As cessing steps involved in this new SGP4 implementation. example, the algorithm to calculate Lane’s coefficients First, the coordinate types in the TEME (True Equator for atmospheric drag just needs Spire’s Field type class Mean Equinox) reference system and supporting classes as its operations are expressed via products and sums: for coordinate transformations: def calcLaneCoefs[@sp(Double) F : Field] • SGPElems: classical keplerian elements plus bStar (gcoefs : GeoPotentialCoefs[F]) : LaneCoefs[F] = { drag coefficient and julian day import gcoefs._ val `C1²` = C1*C1 • CartesianElems: orbital position and velocity ref- LaneCoefs( erence frame 3*C1/2, D2 + 2*`C1²`, • SpecialPolarNodal: polar nodal coordinates with (3*D3 + C1*(12*D2 + 10 * `C1²`))/4, (3*D4 + 12*C1*D3 + 6*D2*D2 + 15*`C1²`*(2*D2+`C1²`))/5) the inclination instead of the polar component of } the angular momentum • LaraNonSingular: non singular variables which should be obtained from the so called two line elements, or TLEs.2 From them, Delaunay elements • LyddaneElems 00 00 00 00 00 00 at epoch (`0 ; g0 ; h0 ;L0 ;G0 ;H0 ) are obtained from their Then, models for the corrections like BrouwerLaneSec- definition. The double prime notation is used for “sec- ularCorrections, LyddaneLongPeriodCorrections, Lyd- ular” elements. In fact, the Delaunay actions, viz. L, dane2ndOrderLongPeriodCorrections, LaraFirstOrder- G, and H, are never computed in SGP4, which uses p Corrections. For the resolution of the different Kepler n = µ2/L3, e = 1 − G2/L2, and I = arccos(H/G), equations because of the different coordinate systems, instead. there are SimpleKeplerEq and TwoTermsKeplerEq. From these initial elements, Brouwer’s theory pro- All those types are mixed in the SGP4 algorithm sub- vides the secular frequencies `_00, g_00, and h_ 00, due to the classes, like SGP4Vallado in Fig. (1) and SGP4Lara in earth’s gravitational potential, where the overdot means Fig. (2). time derivative. Each of these frequencies is a function of (n0; e0;I0), and remain constant for the evaluation of 3. SGP4 ALGORITHM DESCRIPTIONS the theory at different dates. Besides, the initialization process provides a series of coefficients needed to apply The SGP4 propagator is thoroughly described in the lit- drag secular corrections as computed from Lane’s theory erature [1, 2]. For completeness, we summarize it here, [4]. yet without mentioning anything related to the deep The code works with internal units of length LU space or atmospheric drag corrections. (units of earth’s radius R⊕ in km) and time TU (units First, we recall that Brouwer’s gravitational theory of the orbit’s period in min) such that µ = 1 LU3/TU2 relies on the canonical set of Delaunay variables in internal units.