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  
18  package org.orekit.estimation;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.bodies.CelestialBody;
23  import org.orekit.bodies.GeodeticPoint;
24  import org.orekit.bodies.OneAxisEllipsoid;
25  import org.orekit.estimation.measurements.GroundStation;
26  import org.orekit.forces.gravity.potential.UnnormalizedSphericalHarmonicsProvider;
27  import org.orekit.frames.TopocentricFrame;
28  import org.orekit.models.earth.displacement.StationDisplacement;
29  import org.orekit.orbits.CartesianOrbit;
30  import org.orekit.orbits.Orbit;
31  import org.orekit.orbits.PositionAngleType;
32  import org.orekit.propagation.analytical.BrouwerLyddanePropagator;
33  import org.orekit.propagation.conversion.BrouwerLyddanePropagatorBuilder;
34  import org.orekit.time.TimeScale;
35  import org.orekit.time.UT1Scale;
36  import org.orekit.utils.IERSConventions;
37  import org.orekit.utils.PVCoordinates;
38  
39  import java.util.List;
40  import java.util.Map;
41  
42  public class BrouwerLyddaneContext implements StationDataProvider {
43  
44      public IERSConventions                        conventions;
45      public OneAxisEllipsoid                       earth;
46      public CelestialBody                          sun;
47      public CelestialBody                          moon;
48      public UnnormalizedSphericalHarmonicsProvider gravity;
49      public TimeScale                              utc;
50      public UT1Scale                               ut1;
51      public Orbit                                  initialOrbit;
52      public StationDisplacement[]                  displacements;
53      public List<GroundStation>                    stations;
54      // Stations for turn-around range
55      // Map entry = primary station
56      // Map value = secondary station associated
57      public Map<GroundStation, GroundStation>     TARstations;
58  
59      public BrouwerLyddanePropagatorBuilder createBuilder(final PositionAngleType angleType, final boolean perfectStart, final double dP) {
60  
61          final Orbit startOrbit;
62          if (perfectStart) {
63              // orbit estimation will start from a perfect orbit
64              startOrbit = initialOrbit;
65          } else {
66              // orbit estimation will start from a wrong point
67              final Vector3D initialPosition = initialOrbit.getPosition();
68              final Vector3D initialVelocity = initialOrbit.getPVCoordinates().getVelocity();
69              final Vector3D wrongPosition   = initialPosition.add(new Vector3D(1000.0, 0, 0));
70              final Vector3D wrongVelocity   = initialVelocity.add(new Vector3D(0, 0, 0.01));
71              startOrbit                     = new CartesianOrbit(new PVCoordinates(wrongPosition, wrongVelocity),
72                                                                  initialOrbit.getFrame(),
73                                                                  initialOrbit.getDate(),
74                                                                  initialOrbit.getMu());
75          }
76  
77          // Initialize builder
78          return new BrouwerLyddanePropagatorBuilder(startOrbit, gravity, angleType, dP, BrouwerLyddanePropagator.M2);
79  
80      }
81  
82      GroundStation createStation(double latitudeInDegrees, double longitudeInDegrees,
83                                  double altitude, String name) {
84          final GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(latitudeInDegrees),
85                                                     FastMath.toRadians(longitudeInDegrees),
86                                                     altitude);
87          return new GroundStation(new TopocentricFrame(earth, gp, name), ut1.getEOPHistory(), displacements);
88      }
89  
90      @Override
91      public List<GroundStation> getStations() {
92          return stations;
93      }
94  
95  }