1   /* Contributed in the public domain.
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  import org.hamcrest.MatcherAssert;
20  import org.hamcrest.core.IsInstanceOf;
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.junit.jupiter.api.Assertions;
23  import org.junit.jupiter.api.BeforeAll;
24  import org.junit.jupiter.api.Test;
25  import org.orekit.Utils;
26  import org.orekit.bodies.CelestialBody;
27  import org.orekit.bodies.CelestialBodyFactory;
28  import org.orekit.time.AbsoluteDate;
29  import org.orekit.time.TimeScale;
30  import org.orekit.time.TimeScalesFactory;
31  import org.orekit.utils.Constants;
32  import org.orekit.utils.IERSConventions;
33  
34  
35  /** Unit tests for {@link EclipticProvider}. */
36  public class EclipticProviderTest {
37  
38      /** Set the orekit data to include ephemerides. */
39      @BeforeAll
40      public static void setUpBefore() {
41          Utils.setDataRoot("regular-data");
42      }
43  
44      /**
45       * Check the Ecliptic frame defined from IERS mean obliquity equations against the
46       * position of Sun and Earth from the JPL 406 ephemerides.
47       *
48       * @throws Exception on error
49       */
50      @Test
51      public void testAgreementWith406Ephemerides() throws Exception {
52          TimeScale utc = TimeScalesFactory.getUTC();
53  
54          //time spans we have test data sets for.
55          checkAlignment(new AbsoluteDate(1969, 5, 27, utc), new AbsoluteDate(1969, 9, 20, utc));
56          checkAlignment(new AbsoluteDate(1969, 12, 5, utc), new AbsoluteDate(1970, 4, 1, utc));
57          checkAlignment(new AbsoluteDate(1970, 6, 15, utc), new AbsoluteDate(1970, 8, 1, utc));
58          checkAlignment(new AbsoluteDate(2002, 12, 16, utc), new AbsoluteDate(2004, 2, 3, utc));
59  
60          checkAlignment(new AbsoluteDate(1999, 11, 22, utc), new AbsoluteDate(2000, 5, 21, utc));
61      }
62  
63      /**
64       * Check alignment of ecliptic +z with Earth-Moon barycenter angular momentum. Angular
65       * difference will be checked every month.
66       *
67       * @param start start date of check.
68       * @param end   en date of check.
69       */
70      private void checkAlignment(AbsoluteDate start, AbsoluteDate end) {
71          //setup
72          CelestialBody sun = CelestialBodyFactory.getSun();
73          CelestialBody emb = CelestialBodyFactory.getEarthMoonBarycenter();
74          Frame heliocentric = sun.getInertiallyOrientedFrame();
75          //subject under test
76          Frame ecliptic = FramesFactory.getEcliptic(IERSConventions.IERS_2010);
77  
78          //verify
79          //precise definition is +z is parallel to Earth-Moon barycenter's angular momentum
80          //over date range of ephemeris, a season at a time
81          double preciseTol = 0.50 * Constants.ARC_SECONDS_TO_RADIANS;
82          for (AbsoluteDate date = start;
83               date.compareTo(end) < 0;
84               date = date.shiftedBy(Constants.JULIAN_YEAR / 12.0)) {
85  
86              Transform heliocentricToEcliptic = heliocentric.getTransformTo(ecliptic, date);
87              Vector3D momentum = emb.getPVCoordinates(date, heliocentric).getMomentum();
88              Vector3D actual = heliocentricToEcliptic.transformVector(momentum);
89              double angle = Vector3D.angle(
90                      Vector3D.PLUS_K,
91                      actual
92              );
93              Assertions.assertEquals(0, angle, preciseTol,"Agrees with ephemerides to within " + preciseTol);
94  
95          }
96  
97      }
98  
99      /**
100      * Check frame has the right name.
101      */
102     @Test
103     public void testGetName() {
104         Assertions.assertEquals("Ecliptic/1996",
105                             FramesFactory.getEcliptic(IERSConventions.IERS_1996).getName());
106         Assertions.assertEquals("Ecliptic/2003",
107                             FramesFactory.getEcliptic(IERSConventions.IERS_2003).getName());
108         Assertions.assertEquals("Ecliptic/2010",
109                             FramesFactory.getEcliptic(IERSConventions.IERS_2010).getName());
110     }
111 
112     /**
113      * Check the parent frame is MOD.
114      */
115     @Test
116     public void testGetParent() {
117         //setup
118         Frame frame = FramesFactory.getEcliptic(IERSConventions.IERS_2003);
119 
120         //action + verify
121         MatcherAssert.assertThat(frame.getParent().getTransformProvider(),
122                           IsInstanceOf.instanceOf(MODProvider.class));
123     }
124 
125 }