1   /* Copyright 2002-2021 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.PropagationType;
24  import org.orekit.propagation.Propagator;
25  import org.orekit.propagation.SpacecraftState;
26  import org.orekit.propagation.conversion.OrbitDeterminationPropagatorBuilder;
27  import org.orekit.propagation.integration.AbstractJacobiansMapper;
28  import org.orekit.propagation.semianalytical.dsst.DSSTJacobiansMapper;
29  import org.orekit.propagation.semianalytical.dsst.DSSTPartialDerivativesEquations;
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      /** Type of the orbit used for the propagation.*/
48      private PropagationType propagationType;
49  
50      /** Type of the elements used to define the orbital state.*/
51      private PropagationType stateType;
52  
53      /** Simple constructor.
54       * @param propagatorBuilders builders to use for propagation
55       * @param measurements measurements
56       * @param estimatedMeasurementsParameters estimated measurements parameters
57       * @param observer observer to be notified at model calls
58       * @param propagationType type of the orbit used for the propagation (mean or osculating)
59       * @param stateType type of the elements used to define the orbital state (mean or osculating)
60       */
61      public DSSTBatchLSModel(final OrbitDeterminationPropagatorBuilder[] propagatorBuilders,
62                              final List<ObservedMeasurement<?>> measurements,
63                              final ParameterDriversList estimatedMeasurementsParameters,
64                              final ModelObserver observer,
65                              final PropagationType propagationType,
66                              final PropagationType stateType) {
67          // call super constructor
68          super(propagatorBuilders, measurements, estimatedMeasurementsParameters,
69                new DSSTJacobiansMapper[propagatorBuilders.length], observer);
70          this.propagationType = propagationType;
71          this.stateType       = stateType;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      protected DSSTJacobiansMapper configureDerivatives(final Propagator propagator) {
77  
78          final String equationName = DSSTBatchLSModel.class.getName() + "-derivatives";
79  
80          final DSSTPartialDerivativesEquations partials = new DSSTPartialDerivativesEquations(equationName, (DSSTPropagator) propagator, propagationType);
81  
82          // add the derivatives to the initial state
83          final SpacecraftState rawState = propagator.getInitialState();
84          final SpacecraftState stateWithDerivatives = partials.setInitialJacobians(rawState);
85          ((DSSTPropagator) propagator).setInitialState(stateWithDerivatives, stateType);
86  
87          return partials.getMapper();
88  
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      protected Orbit configureOrbits(final AbstractJacobiansMapper mapper,
94                                      final Propagator propagator) {
95          // Cast
96          final DSSTPropagator dsstPropagator = (DSSTPropagator) propagator;
97          // Mean orbit
98          final SpacecraftState initial = dsstPropagator.initialIsOsculating() ?
99                         DSSTPropagator.computeMeanState(dsstPropagator.getInitialState(), dsstPropagator.getAttitudeProvider(), dsstPropagator.getAllForceModels()) :
100                        dsstPropagator.getInitialState();
101         // Compute short period derivatives at the beginning of the iteration
102         ((DSSTJacobiansMapper) mapper).setShortPeriodJacobians(initial);
103         return initial.getOrbit();
104     }
105 
106 }