DSSTDSConverter.java

  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.propagation.semianalytical.dsst;

  18. import java.util.ArrayList;
  19. import java.util.List;

  20. import org.hipparchus.analysis.differentiation.DSFactory;
  21. import org.hipparchus.analysis.differentiation.DerivativeStructure;
  22. import org.orekit.attitudes.AttitudeProvider;
  23. import org.orekit.attitudes.FieldAttitude;
  24. import org.orekit.orbits.FieldEquinoctialOrbit;
  25. import org.orekit.orbits.FieldOrbit;
  26. import org.orekit.orbits.PositionAngle;
  27. import org.orekit.propagation.FieldSpacecraftState;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.propagation.integration.AbstractDSConverter;
  30. import org.orekit.propagation.semianalytical.dsst.forces.DSSTForceModel;
  31. import org.orekit.time.AbsoluteDate;
  32. import org.orekit.time.FieldAbsoluteDate;
  33. import org.orekit.utils.FieldAngularCoordinates;
  34. import org.orekit.utils.ParameterDriver;
  35. import org.orekit.utils.TimeStampedFieldAngularCoordinates;

  36. /** Converter for states and parameters arrays.
  37.  * @author Luc Maisonobe
  38.  * @author Bryan Cazabonne
  39.  * @since 10.0
  40.  * @deprecated as of 10.2, replace by {@link DSSTGradientConverter}
  41.  */
  42. @Deprecated
  43. class DSSTDSConverter extends AbstractDSConverter {

  44.     /** Fixed dimension of the state. */
  45.     private static final int FREE_STATE_PARAMETERS = 6;

  46.     /** States with various number of additional parameters for force models. */
  47.     private final List<FieldSpacecraftState<DerivativeStructure>> dsStates;

  48.     /** Simple constructor.
  49.      * @param state regular state
  50.      * @param provider provider to use if attitude needs to be recomputed
  51.      */
  52.     DSSTDSConverter(final SpacecraftState state, final AttitudeProvider provider) {

  53.         super(FREE_STATE_PARAMETERS);

  54.         // prepare derivation variables
  55.         final DSFactory factory = new DSFactory(FREE_STATE_PARAMETERS, 1);

  56.         // equinoctial parameters always has derivatives
  57.         final DerivativeStructure sma  = factory.variable(0, state.getA());
  58.         final DerivativeStructure ex   = factory.variable(1, state.getEquinoctialEx());
  59.         final DerivativeStructure ey   = factory.variable(2, state.getEquinoctialEy());
  60.         final DerivativeStructure hx   = factory.variable(3, state.getHx());
  61.         final DerivativeStructure hy   = factory.variable(4, state.getHy());
  62.         final DerivativeStructure l    = factory.variable(5, state.getLM());

  63.         final DerivativeStructure dsMu = factory.constant(state.getMu());

  64.         // date
  65.         final AbsoluteDate date = state.getDate();
  66.         final FieldAbsoluteDate<DerivativeStructure> dateField = new FieldAbsoluteDate<>(sma.getField(), date);

  67.         // mass never has derivatives
  68.         final DerivativeStructure dsM = factory.constant(state.getMass());

  69.         final FieldOrbit<DerivativeStructure> dsOrbit =
  70.                         new FieldEquinoctialOrbit<>(sma, ex, ey, hx, hy, l,
  71.                                                     PositionAngle.MEAN,
  72.                                                     state.getFrame(),
  73.                                                     dateField,
  74.                                                     dsMu);

  75.         final FieldAttitude<DerivativeStructure> dsAttitude;
  76.         // compute attitude partial derivatives
  77.         dsAttitude = provider.getAttitude(dsOrbit, dsOrbit.getDate(), dsOrbit.getFrame());

  78.         // initialize the list with the state having 0 force model parameters
  79.         dsStates = new ArrayList<>();
  80.         dsStates.add(new FieldSpacecraftState<>(dsOrbit, dsAttitude, dsM));

  81.     }

  82.     /** Get the state with the number of parameters consistent with force model.
  83.      * @param forceModel force model
  84.      * @return state with the number of parameters consistent with force model
  85.      */
  86.     public FieldSpacecraftState<DerivativeStructure> getState(final DSSTForceModel forceModel) {

  87.         // count the required number of parameters
  88.         int nbParams = 0;
  89.         for (final ParameterDriver driver : forceModel.getParametersDrivers()) {
  90.             if (driver.isSelected()) {
  91.                 ++nbParams;
  92.             }
  93.         }

  94.         // fill in intermediate slots
  95.         while (dsStates.size() < nbParams + 1) {
  96.             dsStates.add(null);
  97.         }

  98.         if (dsStates.get(nbParams) == null) {
  99.             // it is the first time we need this number of parameters
  100.             // we need to create the state
  101.             final DSFactory factory = new DSFactory(FREE_STATE_PARAMETERS + nbParams, 1);
  102.             final FieldSpacecraftState<DerivativeStructure> s0 = dsStates.get(0);

  103.             final FieldAbsoluteDate<DerivativeStructure> date = new FieldAbsoluteDate<>(extend(s0.getA(), factory).getField(),
  104.                                                                                         s0.getDate().toAbsoluteDate());
  105.             // orbit
  106.             final FieldOrbit<DerivativeStructure> dsOrbit =
  107.                             new FieldEquinoctialOrbit<>(extend(s0.getA(),             factory),
  108.                                                         extend(s0.getEquinoctialEx(), factory),
  109.                                                         extend(s0.getEquinoctialEy(), factory),
  110.                                                         extend(s0.getHx(),            factory),
  111.                                                         extend(s0.getHy(),            factory),
  112.                                                         extend(s0.getLM(),            factory),
  113.                                                         PositionAngle.MEAN,
  114.                                                         s0.getFrame(), date,
  115.                                                         extend(s0.getMu(),            factory));

  116.             // attitude
  117.             final FieldAngularCoordinates<DerivativeStructure> ac0 = s0.getAttitude().getOrientation();
  118.             final FieldAttitude<DerivativeStructure> dsAttitude =
  119.                             new FieldAttitude<>(s0.getAttitude().getReferenceFrame(),
  120.                                                 new TimeStampedFieldAngularCoordinates<>(dsOrbit.getDate(),
  121.                                                                                          extend(ac0.getRotation(),             factory),
  122.                                                                                          extend(ac0.getRotationRate(),         factory),
  123.                                                                                          extend(ac0.getRotationAcceleration(), factory)));

  124.             // mass
  125.             final DerivativeStructure dsM = extend(s0.getMass(), factory);

  126.             dsStates.set(nbParams, new FieldSpacecraftState<>(dsOrbit, dsAttitude, dsM));

  127.         }

  128.         return dsStates.get(nbParams);

  129.     }

  130.     /** Get the force model parameters.
  131.      * @param state state as returned by {@link #getState(DSSTForceModel)}
  132.      * @param forceModel force model associated with the parameters
  133.      * @return force model parameters
  134.      * @since 9.0
  135.      */
  136.     public DerivativeStructure[] getParameters(final FieldSpacecraftState<DerivativeStructure> state,
  137.                                                final DSSTForceModel forceModel) {
  138.         final DSFactory factory = state.getA().getFactory();
  139.         final ParameterDriver[] drivers = forceModel.getParametersDrivers();
  140.         final DerivativeStructure[] parameters = new DerivativeStructure[drivers.length];
  141.         int index = FREE_STATE_PARAMETERS;
  142.         for (int i = 0; i < drivers.length; ++i) {
  143.             parameters[i] = drivers[i].isSelected() ?
  144.                             factory.variable(index++, drivers[i].getValue()) :
  145.                             factory.constant(drivers[i].getValue());
  146.         }
  147.         return parameters;
  148.     }

  149. }