1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.frames;
18  
19  
20  import java.io.ByteArrayInputStream;
21  import java.io.ByteArrayOutputStream;
22  import java.io.IOException;
23  import java.io.ObjectInputStream;
24  import java.io.ObjectOutputStream;
25  
26  import org.hipparchus.geometry.euclidean.threed.Vector3D;
27  import org.hipparchus.util.FastMath;
28  import org.junit.Assert;
29  import org.junit.Before;
30  import org.junit.Test;
31  import org.orekit.Utils;
32  import org.orekit.data.DataContext;
33  import org.orekit.time.AbsoluteDate;
34  import org.orekit.time.DateComponents;
35  import org.orekit.time.TimeComponents;
36  import org.orekit.time.TimeScalesFactory;
37  import org.orekit.utils.Constants;
38  import org.orekit.utils.IERSConventions;
39  import org.orekit.utils.PVCoordinates;
40  
41  
42  public class TEMEProviderTest {
43  
44      @Test
45      public void testValladoTEMEofDate() {
46  
47          // this reference test has been extracted from Vallado's book:
48          // Fundamentals of Astrodynamics and Applications
49          // David A. Vallado, Space Technology Library, 2007
50          AbsoluteDate t0 = new AbsoluteDate(new DateComponents(2000, 182),
51                                             new TimeComponents(0.78495062 * Constants.JULIAN_DAY),
52                                             TimeScalesFactory.getUTC());
53  
54          // TEME
55          PVCoordinates pvTEME =
56             new PVCoordinates(new Vector3D(-9060473.73569, 4658709.52502, 813686.73153),
57                               new Vector3D(-2232.832783, -4110.453490, -3157.345433));
58  
59          // reference position in EME2000
60          // note that Valado's book gives
61          //        PVCoordinates pvEME2000Ref =
62          //            new PVCoordinates(new Vector3D(-9059941.3786, 4659697.2000, 813958.8875),
63          //                              new Vector3D(-2233.348094, -4110.136162, -3157.394074));
64          // the values we use here are slightly different, they were computed using
65          // Vallado's C++ companion code to the book, using the teme_j2k function with
66          // all 106 nutation terms and the 2 corrections elements of the equation of the equinoxes
67          PVCoordinates pvEME2000Ref =
68              new PVCoordinates(new Vector3D(-9059941.5224999374914, 4659697.1225837596648, 813957.72947647583351),
69                                new Vector3D(-2233.3476939179299769, -4110.1362849403413335, -3157.3941963060194738));
70  
71          Transform t = FramesFactory.getTEME().getTransformTo(FramesFactory.getEME2000(), t0);
72  
73          PVCoordinates pvEME2000Computed = t.transformPVCoordinates(pvTEME);
74          PVCoordinates delta = new PVCoordinates(pvEME2000Computed, pvEME2000Ref);
75          Assert.assertEquals(0.0, delta.getPosition().getNorm(), 0.025);
76          Assert.assertEquals(0.0, delta.getVelocity().getNorm(), 1.0e-4);
77  
78      }
79  
80      @Test
81      public void testSerialization() throws IOException, ClassNotFoundException {
82          TEMEProvider provider = new TEMEProvider(IERSConventions.IERS_2010,
83                                                 FramesFactory.getEOPHistory(IERSConventions.IERS_2010, true),
84                                                 DataContext.getDefault().getTimeScales());
85  
86          ByteArrayOutputStream bos = new ByteArrayOutputStream();
87          ObjectOutputStream    oos = new ObjectOutputStream(bos);
88          oos.writeObject(provider);
89  
90          Assert.assertTrue(bos.size() > 295000);
91          Assert.assertTrue(bos.size() < 300000);
92  
93          ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
94          ObjectInputStream     ois = new ObjectInputStream(bis);
95          TEMEProvider deserialized  = (TEMEProvider) ois.readObject();
96          for (int i = 0; i < FastMath.min(100, provider.getEOPHistory().getEntries().size()); ++i) {
97              AbsoluteDate date = provider.getEOPHistory().getEntries().get(i).getDate();
98              Transform expectedIdentity = new Transform(date,
99                                                         provider.getTransform(date).getInverse(),
100                                                        deserialized.getTransform(date));
101             Assert.assertEquals(0.0, expectedIdentity.getTranslation().getNorm(), 1.0e-15);
102             Assert.assertEquals(0.0, expectedIdentity.getRotation().getAngle(),   1.0e-15);
103         }
104 
105     }
106 
107     @Before
108     public void setUp() {
109         Utils.setDataRoot("compressed-data");
110     }
111 
112 }