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.leastsquares;
18  
19  import java.util.List;
20  
21  import org.orekit.estimation.measurements.ObservedMeasurement;
22  import org.orekit.orbits.Orbit;
23  import org.orekit.propagation.MatricesHarvester;
24  import org.orekit.propagation.PropagationType;
25  import org.orekit.propagation.Propagator;
26  import org.orekit.propagation.SpacecraftState;
27  import org.orekit.propagation.conversion.OrbitDeterminationPropagatorBuilder;
28  import org.orekit.propagation.semianalytical.dsst.DSSTHarvester;
29  import org.orekit.propagation.semianalytical.dsst.DSSTJacobiansMapper;
30  import org.orekit.propagation.semianalytical.dsst.DSSTPropagator;
31  import org.orekit.utils.ParameterDriversList;
32  
33  /** Bridge between {@link ObservedMeasurement measurements} and {@link
34   * org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem
35   * least squares problems}.
36   * <p>
37   * This class is an adaption of the {@link BatchLSModel} class
38   * but for the {@link DSSTPropagator DSST propagator}.
39   * </p>
40   * @author Luc Maisonobe
41   * @author Bryan Cazabonne
42   * @since 10.0
43   *
44   */
45  public class DSSTBatchLSModel extends AbstractBatchLSModel {
46  
47      /** Name of the State Transition Matrix state. */
48      private static final String STM_NAME = DSSTBatchLSModel.class.getName() + "-derivatives";
49  
50      /** Type of the orbit used for the propagation.*/
51      private PropagationType propagationType;
52  
53      /** Type of the elements used to define the orbital state.*/
54      private PropagationType stateType;
55  
56      /** Simple constructor.
57       * @param propagatorBuilders builders to use for propagation
58       * @param measurements measurements
59       * @param estimatedMeasurementsParameters estimated measurements parameters
60       * @param observer observer to be notified at model calls
61       * @param propagationType type of the orbit used for the propagation (mean or osculating)
62       * @param stateType type of the elements used to define the orbital state (mean or osculating)
63       */
64      public DSSTBatchLSModel(final OrbitDeterminationPropagatorBuilder[] propagatorBuilders,
65                              final List<ObservedMeasurement<?>> measurements,
66                              final ParameterDriversList estimatedMeasurementsParameters,
67                              final ModelObserver observer,
68                              final PropagationType propagationType,
69                              final PropagationType stateType) {
70          // call super constructor
71          super(propagatorBuilders, measurements, estimatedMeasurementsParameters, observer);
72          this.propagationType = propagationType;
73          this.stateType       = stateType;
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      protected MatricesHarvester configureHarvester(final Propagator propagator) {
79          return propagator.setupMatricesComputation(STM_NAME, null, null);
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      @Deprecated
85      protected DSSTJacobiansMapper configureDerivatives(final Propagator propagator) {
86  
87          final org.orekit.propagation.semianalytical.dsst.DSSTPartialDerivativesEquations partials =
88                          new org.orekit.propagation.semianalytical.dsst.DSSTPartialDerivativesEquations(STM_NAME, (DSSTPropagator) propagator, propagationType);
89  
90          // add the derivatives to the initial state
91          final SpacecraftState rawState = propagator.getInitialState();
92          final SpacecraftState stateWithDerivatives = partials.setInitialJacobians(rawState);
93          ((DSSTPropagator) propagator).setInitialState(stateWithDerivatives, stateType);
94  
95          return partials.getMapper();
96  
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     protected Orbit configureOrbits(final MatricesHarvester harvester, final Propagator propagator) {
102         // Cast
103         final DSSTPropagator dsstPropagator = (DSSTPropagator) propagator;
104         final DSSTHarvester  dsstHarvester  = (DSSTHarvester) harvester;
105         // Mean orbit
106         final SpacecraftState initial = dsstPropagator.initialIsOsculating() ?
107                        DSSTPropagator.computeMeanState(dsstPropagator.getInitialState(), dsstPropagator.getAttitudeProvider(), dsstPropagator.getAllForceModels()) :
108                        dsstPropagator.getInitialState();
109         dsstHarvester.initializeFieldShortPeriodTerms(initial);
110         // Compute short period derivatives at the beginning of the iteration
111         if (propagationType == PropagationType.OSCULATING) {
112             dsstHarvester.updateFieldShortPeriodTerms(initial);
113             dsstHarvester.setReferenceState(initial);
114         }
115         // Compute short period derivatives at the beginning of the iteration
116         harvester.setReferenceState(initial);
117         return initial.getOrbit();
118     }
119 
120 }