1   /* Copyright 2002-2025 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.propagation.semianalytical.dsst.forces;
18  
19  import org.hipparchus.util.FastMath;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.BeforeEach;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.Utils;
24  import org.orekit.bodies.CelestialBodyFactory;
25  import org.orekit.frames.Frame;
26  import org.orekit.frames.FramesFactory;
27  import org.orekit.orbits.EquinoctialOrbit;
28  import org.orekit.orbits.Orbit;
29  import org.orekit.orbits.PositionAngleType;
30  import org.orekit.propagation.PropagationType;
31  import org.orekit.propagation.SpacecraftState;
32  import org.orekit.propagation.semianalytical.dsst.utilities.AuxiliaryElements;
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  
38  import java.io.IOException;
39  import java.text.ParseException;
40  import java.util.ArrayList;
41  import java.util.Arrays;
42  import java.util.Collection;
43  import java.util.List;
44  
45  class DSSTThirdBodyTest {
46  
47      private static final double eps  = 3.5e-25;
48  
49      @Test
50      void testGetMeanElementRate() throws IllegalArgumentException {
51  
52          final Frame earthFrame = FramesFactory.getEME2000();
53          final AbsoluteDate initDate = new AbsoluteDate(2003, 07, 01, 0, 0, 00.000, TimeScalesFactory.getUTC());
54  
55          final double mu = 3.986004415E14;
56          // a    = 42163393.0 m
57          // ex =  -0.25925449177598586
58          // ey =  -0.06946703170551687
59          // hx =   0.15995912655021305
60          // hy =  -0.5969755874197339
61          // lM   = 15.47576793123677 rad
62          final Orbit orbit = new EquinoctialOrbit(4.2163393E7,
63                                                   -0.25925449177598586,
64                                                   -0.06946703170551687,
65                                                   0.15995912655021305,
66                                                   -0.5969755874197339,
67                                                   15.47576793123677,
68                                                   PositionAngleType.TRUE,
69                                                   earthFrame,
70                                                   initDate,
71                                                   mu);
72  
73          final SpacecraftState state = new SpacecraftState(orbit, 1000.0);
74  
75          final AuxiliaryElements auxiliaryElements = new AuxiliaryElements(state.getOrbit(), 1);
76  
77          final DSSTForceModel moon = new DSSTThirdBody(CelestialBodyFactory.getMoon(), mu);
78  
79          // Force model parameters
80          final double[] parameters = moon.getParameters(orbit.getDate());
81  
82          // Initialize force model
83          moon.initializeShortPeriodTerms(auxiliaryElements, PropagationType.MEAN, parameters);
84  
85          final double[] elements = new double[7];
86          Arrays.fill(elements, 0.0);
87  
88          final double[] daidt = moon.getMeanElementRate(state, auxiliaryElements, parameters);
89          for (int i = 0; i < daidt.length; i++) {
90              elements[i] = daidt[i];
91          }
92  
93          Assertions.assertEquals(0.0,                    elements[0], eps);
94          Assertions.assertEquals(4.346622384804537E-10,  elements[1], eps);
95          Assertions.assertEquals(7.293879548440941E-10,  elements[2], eps);
96          Assertions.assertEquals(7.465699631747887E-11,  elements[3], eps);
97          Assertions.assertEquals(3.9170221137233836E-10, elements[4], eps);
98          Assertions.assertEquals(-3.178319341840074E-10, elements[5], eps);
99  
100     }
101 
102     @Test
103     void testShortPeriodTerms() throws IllegalArgumentException {
104         final SpacecraftState meanState = getGEOState();
105 
106         final DSSTForceModel moon = new DSSTThirdBody(CelestialBodyFactory.getMoon(), meanState.getOrbit().getMu());
107 
108         final Collection<DSSTForceModel> forces = new ArrayList<DSSTForceModel>();
109         forces.add(moon);
110 
111         //Create the auxiliary object
112         final AuxiliaryElements aux = new AuxiliaryElements(meanState.getOrbit(), 1);
113 
114         // Set the force models
115         final List<ShortPeriodTerms> shortPeriodTerms = new ArrayList<ShortPeriodTerms>();
116 
117         for (final DSSTForceModel force : forces) {
118             force.registerAttitudeProvider(null);
119             shortPeriodTerms.addAll(force.initializeShortPeriodTerms(aux, PropagationType.OSCULATING, force.getParameters(meanState.getDate())));
120             force.updateShortPeriodTerms(force.getParametersAllValues(), meanState);
121         }
122 
123         double[] y = new double[6];
124         for (final ShortPeriodTerms spt : shortPeriodTerms) {
125             final double[] shortPeriodic = spt.value(meanState.getOrbit());
126             for (int i = 0; i < shortPeriodic.length; i++) {
127                 y[i] += shortPeriodic[i];
128             }
129         }
130 
131         Assertions.assertEquals(-413.20633326933154,    y[0], 1.e-14);
132         Assertions.assertEquals(-1.8060137920197483E-5, y[1], 1.e-20);
133         Assertions.assertEquals(-2.8416367511811057E-5, y[2], 1.e-20);
134         Assertions.assertEquals(-2.791424363476855E-6,  y[3], 1.e-21);
135         Assertions.assertEquals(1.8817187527805853E-6,  y[4], 1.e-21);
136         Assertions.assertEquals(-3.423664701811889E-5,  y[5], 1.e-20);
137     }
138 
139     private SpacecraftState getGEOState() throws IllegalArgumentException {
140         // No shadow at this date
141         final AbsoluteDate initDate = new AbsoluteDate(new DateComponents(2003, 05, 21), new TimeComponents(1, 0, 0.),
142                                                        TimeScalesFactory.getUTC());
143         final Orbit orbit = new EquinoctialOrbit(42164000,
144                                                  10e-3,
145                                                  10e-3,
146                                                  FastMath.tan(0.001745329) * FastMath.cos(2 * FastMath.PI / 3),
147                                                  FastMath.tan(0.001745329) * FastMath.sin(2 * FastMath.PI / 3), 0.1,
148                                                  PositionAngleType.TRUE,
149                                                  FramesFactory.getEME2000(),
150                                                  initDate,
151                                                  3.986004415E14);
152         return new SpacecraftState(orbit);
153     }
154 
155     @BeforeEach
156     public void setUp() throws IOException, ParseException {
157         Utils.setDataRoot("regular-data");
158     }
159 
160 }