1   /* Copyright 2002-2020 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.orekit.bodies.CelestialBody;
25  import org.orekit.bodies.GeodeticPoint;
26  import org.orekit.bodies.OneAxisEllipsoid;
27  import org.orekit.estimation.measurements.GroundStation;
28  import org.orekit.forces.drag.DragSensitive;
29  import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
30  import org.orekit.forces.radiation.RadiationSensitive;
31  import org.orekit.frames.TopocentricFrame;
32  import org.orekit.models.earth.displacement.StationDisplacement;
33  import org.orekit.orbits.CartesianOrbit;
34  import org.orekit.orbits.Orbit;
35  import org.orekit.orbits.OrbitType;
36  import org.orekit.orbits.PositionAngle;
37  import org.orekit.propagation.conversion.DormandPrince853IntegratorBuilder;
38  import org.orekit.propagation.conversion.NumericalPropagatorBuilder;
39  import org.orekit.time.TimeScale;
40  import org.orekit.time.UT1Scale;
41  import org.orekit.utils.IERSConventions;
42  import org.orekit.utils.PVCoordinates;
43  
44  public class Context {
45      public IERSConventions                      conventions;
46      public OneAxisEllipsoid                     earth;
47      public CelestialBody                        sun;
48      public CelestialBody                        moon;
49      public RadiationSensitive                   radiationSensitive;
50      public DragSensitive                        dragSensitive;
51      public NormalizedSphericalHarmonicsProvider gravity;
52      public TimeScale                            utc;
53      public UT1Scale                             ut1;
54      public Orbit                                initialOrbit;
55      public StationDisplacement[]                displacements;
56      public List<GroundStation>                  stations;
57      // Stations for turn-around range
58      // Map entry = master station
59      // Map value = slave station associated
60      public Map<GroundStation, GroundStation>     TARstations;
61  
62      public NumericalPropagatorBuilder createBuilder(final OrbitType orbitType, final PositionAngle positionAngle,
63                                                      final boolean perfectStart,
64                                                      final double minStep, final double maxStep, final double dP,
65                                                      final Force... forces) {
66  
67          final Orbit startOrbit;
68          if (perfectStart) {
69              // orbit estimation will start from a perfect orbit
70              startOrbit = initialOrbit;
71          } else {
72              // orbit estimation will start from a wrong point
73              final Vector3D initialPosition = initialOrbit.getPVCoordinates().getPosition();
74              final Vector3D initialVelocity = initialOrbit.getPVCoordinates().getVelocity();
75              final Vector3D wrongPosition   = initialPosition.add(new Vector3D(1000.0, 0, 0));
76              final Vector3D wrongVelocity   = initialVelocity.add(new Vector3D(0, 0, 0.01));
77              startOrbit                     = new CartesianOrbit(new PVCoordinates(wrongPosition, wrongVelocity),
78                                                                  initialOrbit.getFrame(),
79                                                                  initialOrbit.getDate(),
80                                                                  initialOrbit.getMu());
81          }
82          final NumericalPropagatorBuilder propagatorBuilder =
83                          new NumericalPropagatorBuilder(orbitType.convertType(startOrbit),
84                                                         new DormandPrince853IntegratorBuilder(minStep, maxStep, dP),
85                                                         positionAngle, dP);
86          for (Force force : forces) {
87              propagatorBuilder.addForceModel(force.getForceModel(this));
88          }
89  
90          return propagatorBuilder;
91  
92      }
93  
94      GroundStation createStation(double latitudeInDegrees, double longitudeInDegrees,
95                                  double altitude, String name) {
96          final GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(latitudeInDegrees),
97                                                     FastMath.toRadians(longitudeInDegrees),
98                                                     altitude);
99          return new GroundStation(new TopocentricFrame(earth, gp, name),
100                                  ut1.getEOPHistory(), displacements);
101     }
102 
103 }