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.estimation;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.hipparchus.geometry.euclidean.threed.Vector3D;
23  import org.hipparchus.util.FastMath;
24  import org.hipparchus.util.Pair;
25  import org.orekit.bodies.CelestialBody;
26  import org.orekit.bodies.GeodeticPoint;
27  import org.orekit.bodies.OneAxisEllipsoid;
28  import org.orekit.estimation.measurements.GroundStation;
29  import org.orekit.forces.drag.DragSensitive;
30  import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
31  import org.orekit.forces.radiation.RadiationSensitive;
32  import org.orekit.frames.TopocentricFrame;
33  import org.orekit.models.earth.displacement.StationDisplacement;
34  import org.orekit.orbits.CartesianOrbit;
35  import org.orekit.orbits.Orbit;
36  import org.orekit.orbits.OrbitType;
37  import org.orekit.orbits.PositionAngle;
38  import org.orekit.propagation.conversion.DormandPrince853IntegratorBuilder;
39  import org.orekit.propagation.conversion.NumericalPropagatorBuilder;
40  import org.orekit.time.TimeScale;
41  import org.orekit.time.UT1Scale;
42  import org.orekit.utils.IERSConventions;
43  import org.orekit.utils.PVCoordinates;
44  
45  public class Context implements StationDataProvider {
46      public IERSConventions                      conventions;
47      public OneAxisEllipsoid                     earth;
48      public CelestialBody                        sun;
49      public CelestialBody                        moon;
50      public RadiationSensitive                   radiationSensitive;
51      public DragSensitive                        dragSensitive;
52      public NormalizedSphericalHarmonicsProvider gravity;
53      public TimeScale                            utc;
54      public UT1Scale                             ut1;
55      public Orbit                                initialOrbit;
56      public StationDisplacement[]                displacements;
57      public List<GroundStation>                  stations;
58      // Stations for turn-around range
59      // Map entry = primary station
60      // Map value = secondary station associated
61      public Map<GroundStation, GroundStation>     TARstations;
62      // Stations for bistatic range rate
63      // key/first    = emitter station
64      // value/second = receiver station
65      public Pair<GroundStation, GroundStation>    BRRstations;
66      // Stations for TDOA
67      // key/first    = primary station that dates the measurement
68      // value/second = secondary station associated
69      public Pair<GroundStation, GroundStation>    TDOAstations;
70  
71      public NumericalPropagatorBuilder createBuilder(final OrbitType orbitType, final PositionAngle positionAngle,
72                                                      final boolean perfectStart,
73                                                      final double minStep, final double maxStep, final double dP,
74                                                      final Force... forces) {
75  
76          final Orbit startOrbit;
77          if (perfectStart) {
78              // orbit estimation will start from a perfect orbit
79              startOrbit = initialOrbit;
80          } else {
81              // orbit estimation will start from a wrong point
82              final Vector3D initialPosition = initialOrbit.getPVCoordinates().getPosition();
83              final Vector3D initialVelocity = initialOrbit.getPVCoordinates().getVelocity();
84              final Vector3D wrongPosition   = initialPosition.add(new Vector3D(1000.0, 0, 0));
85              final Vector3D wrongVelocity   = initialVelocity.add(new Vector3D(0, 0, 0.01));
86              startOrbit                     = new CartesianOrbit(new PVCoordinates(wrongPosition, wrongVelocity),
87                                                                  initialOrbit.getFrame(),
88                                                                  initialOrbit.getDate(),
89                                                                  initialOrbit.getMu());
90          }
91          final NumericalPropagatorBuilder propagatorBuilder =
92                          new NumericalPropagatorBuilder(orbitType.convertType(startOrbit),
93                                                         new DormandPrince853IntegratorBuilder(minStep, maxStep, dP),
94                                                         positionAngle, dP);
95          for (Force force : forces) {
96              propagatorBuilder.addForceModel(force.getForceModel(this));
97          }
98  
99          return propagatorBuilder;
100 
101     }
102 
103     GroundStation createStation(double latitudeInDegrees, double longitudeInDegrees,
104                                 double altitude, String name) {
105         final GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(latitudeInDegrees),
106                                                    FastMath.toRadians(longitudeInDegrees),
107                                                    altitude);
108         return new GroundStation(new TopocentricFrame(earth, gp, name),
109                                  ut1.getEOPHistory(), displacements);
110     }
111 
112     @Override
113     public List<GroundStation> getStations() {
114         return stations;
115     }
116 
117 }