DSSTPropagatorBuilder.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.conversion;

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

  21. import org.orekit.annotation.DefaultDataContext;
  22. import org.orekit.attitudes.Attitude;
  23. import org.orekit.attitudes.AttitudeProvider;
  24. import org.orekit.data.DataContext;
  25. import org.orekit.estimation.leastsquares.DSSTBatchLSModel;
  26. import org.orekit.estimation.leastsquares.ModelObserver;
  27. import org.orekit.estimation.measurements.ObservedMeasurement;
  28. import org.orekit.estimation.sequential.CovarianceMatrixProvider;
  29. import org.orekit.estimation.sequential.DSSTKalmanModel;
  30. import org.orekit.orbits.EquinoctialOrbit;
  31. import org.orekit.orbits.Orbit;
  32. import org.orekit.orbits.OrbitType;
  33. import org.orekit.orbits.PositionAngle;
  34. import org.orekit.propagation.PropagationType;
  35. import org.orekit.propagation.Propagator;
  36. import org.orekit.propagation.SpacecraftState;
  37. import org.orekit.propagation.integration.AdditionalEquations;
  38. import org.orekit.propagation.semianalytical.dsst.DSSTPropagator;
  39. import org.orekit.propagation.semianalytical.dsst.forces.DSSTForceModel;
  40. import org.orekit.propagation.semianalytical.dsst.forces.DSSTNewtonianAttraction;
  41. import org.orekit.utils.ParameterDriver;
  42. import org.orekit.utils.ParameterDriversList;

  43. /** Builder for DSST propagator.
  44.  * @author Bryan Cazabonne
  45.  * @since 10.0
  46.  */
  47. public class DSSTPropagatorBuilder extends AbstractPropagatorBuilder implements IntegratedPropagatorBuilder {

  48.     /** First order integrator builder for propagation. */
  49.     private final ODEIntegratorBuilder builder;

  50.     /** Force models used during the extrapolation of the orbit. */
  51.     private final List<DSSTForceModel> forceModels;

  52.     /** Current mass for initial state (kg). */
  53.     private double mass;

  54.     /** Type of the orbit used for the propagation.*/
  55.     private PropagationType propagationType;

  56.     /** Type of the elements used to define the orbital state.*/
  57.     private PropagationType stateType;

  58.     /** Build a new instance.
  59.      * <p>
  60.      * The reference orbit is used as a model to {@link
  61.      * #createInitialOrbit() create initial orbit}. It defines the
  62.      * inertial frame, the central attraction coefficient, and is also used together
  63.      * with the {@code positionScale} to convert from the {@link
  64.      * ParameterDriver#setNormalizedValue(double) normalized} parameters used by the
  65.      * callers of this builder to the real orbital parameters.
  66.      * </p>
  67.      *
  68.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  69.      *
  70.      * @param referenceOrbit reference orbit from which real orbits will be built
  71.      * @param builder first order integrator builder
  72.      * @param positionScale scaling factor used for orbital parameters normalization
  73.      * (typically set to the expected standard deviation of the position)
  74.      * @param propagationType type of the orbit used for the propagation (mean or osculating)
  75.      * @param stateType type of the elements used to define the orbital state (mean or osculating)
  76.      * @see #DSSTPropagatorBuilder(Orbit, ODEIntegratorBuilder, double, PropagationType,
  77.      * PropagationType, AttitudeProvider)
  78.      */
  79.     @DefaultDataContext
  80.     public DSSTPropagatorBuilder(final Orbit referenceOrbit,
  81.                                  final ODEIntegratorBuilder builder,
  82.                                  final double positionScale,
  83.                                  final PropagationType propagationType,
  84.                                  final PropagationType stateType) {
  85.         this(referenceOrbit, builder, positionScale, propagationType, stateType,
  86.                 Propagator.getDefaultLaw(DataContext.getDefault().getFrames()));
  87.     }

  88.     /** Build a new instance.
  89.      * <p>
  90.      * The reference orbit is used as a model to {@link
  91.      * #createInitialOrbit() create initial orbit}. It defines the
  92.      * inertial frame, the central attraction coefficient, and is also used together
  93.      * with the {@code positionScale} to convert from the {@link
  94.      * ParameterDriver#setNormalizedValue(double) normalized} parameters used by the
  95.      * callers of this builder to the real orbital parameters.
  96.      * </p>
  97.      * @param referenceOrbit reference orbit from which real orbits will be built
  98.      * @param builder first order integrator builder
  99.      * @param positionScale scaling factor used for orbital parameters normalization
  100.      * (typically set to the expected standard deviation of the position)
  101.      * @param propagationType type of the orbit used for the propagation (mean or osculating)
  102.      * @param stateType type of the elements used to define the orbital state (mean or osculating)
  103.      * @param attitudeProvider attitude law.
  104.      * @since 10.1
  105.      */
  106.     public DSSTPropagatorBuilder(final Orbit referenceOrbit,
  107.                                  final ODEIntegratorBuilder builder,
  108.                                  final double positionScale,
  109.                                  final PropagationType propagationType,
  110.                                  final PropagationType stateType,
  111.                                  final AttitudeProvider attitudeProvider) {
  112.         super(referenceOrbit, PositionAngle.MEAN, positionScale, true, attitudeProvider);
  113.         this.builder           = builder;
  114.         this.forceModels       = new ArrayList<DSSTForceModel>();
  115.         this.mass              = Propagator.DEFAULT_MASS;
  116.         this.propagationType   = propagationType;
  117.         this.stateType         = stateType;
  118.     }

  119.     /** Create a copy of a DSSTPropagatorBuilder object.
  120.      * @return Copied version of the DSSTPropagatorBuilder
  121.      */
  122.     public DSSTPropagatorBuilder copy() {
  123.         final DSSTPropagatorBuilder copyBuilder =
  124.                         new DSSTPropagatorBuilder((EquinoctialOrbit) OrbitType.EQUINOCTIAL.convertType(createInitialOrbit()),
  125.                                                   builder,
  126.                                                   getPositionScale(),
  127.                                                   propagationType,
  128.                                                   stateType,
  129.                                                   getAttitudeProvider());
  130.         copyBuilder.setMass(mass);
  131.         for (DSSTForceModel model : forceModels) {
  132.             copyBuilder.addForceModel(model);
  133.         }
  134.         return copyBuilder;
  135.     }

  136.     /** Get the integrator builder.
  137.      * @return the integrator builder
  138.      */
  139.     public ODEIntegratorBuilder getIntegratorBuilder()
  140.     {
  141.         return builder;
  142.     }

  143.     /** Get the list of all force models.
  144.      * @return the list of all force models
  145.      */
  146.     public List<DSSTForceModel> getAllForceModels()
  147.     {
  148.         return Collections.unmodifiableList(forceModels);
  149.     }

  150.     /** Get the mass.
  151.      * @return the mass
  152.      */
  153.     public double getMass()
  154.     {
  155.         return mass;
  156.     }

  157.     /** Set the initial mass.
  158.      * @param mass the mass (kg)
  159.      */
  160.     public void setMass(final double mass) {
  161.         this.mass = mass;
  162.     }

  163.     /** Add a force model to the global perturbation model.
  164.      * <p>If this method is not called at all, the integrated orbit will follow
  165.      * a Keplerian evolution only.</p>
  166.      * @param model perturbing {@link DSSTForceModel} to add
  167.      */
  168.     public void addForceModel(final DSSTForceModel model) {
  169.         if (model instanceof DSSTNewtonianAttraction) {
  170.             // we want to add the central attraction force model
  171.             if (hasNewtonianAttraction()) {
  172.                 // there is already a central attraction model, replace it
  173.                 forceModels.set(forceModels.size() - 1, model);
  174.             } else {
  175.                 // there are no central attraction model yet, add it at the end of the list
  176.                 forceModels.add(model);
  177.             }
  178.         } else {
  179.             // we want to add a perturbing force model
  180.             if (hasNewtonianAttraction()) {
  181.                 // insert the new force model before Newtonian attraction,
  182.                 // which should always be the last one in the list
  183.                 forceModels.add(forceModels.size() - 1, model);
  184.             } else {
  185.                 // we only have perturbing force models up to now, just append at the end of the list
  186.                 forceModels.add(model);
  187.             }
  188.         }

  189.         for (final ParameterDriver driver : model.getParametersDrivers()) {
  190.             addSupportedParameter(driver);
  191.         }
  192.     }

  193.     /** {@inheritDoc} */
  194.     public DSSTPropagator buildPropagator(final double[] normalizedParameters) {

  195.         setParameters(normalizedParameters);
  196.         final EquinoctialOrbit orbit    = (EquinoctialOrbit) OrbitType.EQUINOCTIAL.convertType(createInitialOrbit());
  197.         final Attitude         attitude = getAttitudeProvider().getAttitude(orbit, orbit.getDate(), getFrame());
  198.         final SpacecraftState  state    = new SpacecraftState(orbit, attitude, mass);

  199.         final DSSTPropagator propagator = new DSSTPropagator(
  200.                 builder.buildIntegrator(orbit, OrbitType.EQUINOCTIAL),
  201.                 propagationType,
  202.                 getAttitudeProvider());

  203.         // Configure force models
  204.         if (!hasNewtonianAttraction()) {
  205.             // There are no central attraction model yet, add it at the end of the list
  206.             addForceModel(new DSSTNewtonianAttraction(orbit.getMu()));
  207.         }
  208.         for (DSSTForceModel model : forceModels) {
  209.             propagator.addForceModel(model);
  210.         }

  211.         propagator.setInitialState(state, stateType);

  212.         // Add additional equations to the propagator
  213.         for (AdditionalEquations equation: getAdditionalEquations()) {
  214.             propagator.addAdditionalEquations(equation);
  215.         }

  216.         return propagator;
  217.     }

  218.     /** {@inheritDoc} */
  219.     public DSSTBatchLSModel buildLSModel(final IntegratedPropagatorBuilder[] builders,
  220.                                 final List<ObservedMeasurement<?>> measurements,
  221.                                 final ParameterDriversList estimatedMeasurementsParameters,
  222.                                 final ModelObserver observer) {
  223.         return new DSSTBatchLSModel(builders,
  224.                                     measurements,
  225.                                     estimatedMeasurementsParameters,
  226.                                     observer,
  227.                                     propagationType, stateType);
  228.     }

  229.     /** {@inheritDoc} */
  230.     @Deprecated
  231.     public DSSTKalmanModel buildKalmanModel(final List<IntegratedPropagatorBuilder> propagatorBuilders,
  232.                                   final List<CovarianceMatrixProvider> covarianceMatricesProviders,
  233.                                   final ParameterDriversList estimatedMeasurementsParameters) {
  234.         return new DSSTKalmanModel(propagatorBuilders,
  235.                                    covarianceMatricesProviders,
  236.                                    estimatedMeasurementsParameters,
  237.                                    propagationType, stateType);
  238.     }

  239.     /** {@inheritDoc} */
  240.     @Override
  241.     public DSSTKalmanModel buildKalmanModel(final List<IntegratedPropagatorBuilder> propagatorBuilders,
  242.                                   final List<CovarianceMatrixProvider> covarianceMatricesProviders,
  243.                                   final ParameterDriversList estimatedMeasurementsParameters,
  244.                                   final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  245.         return new DSSTKalmanModel(propagatorBuilders, covarianceMatricesProviders,
  246.                                    estimatedMeasurementsParameters, measurementProcessNoiseMatrix,
  247.                                    propagationType, stateType);
  248.     }

  249.     /** Check if Newtonian attraction force model is available.
  250.      * <p>
  251.      * Newtonian attraction is always the last force model in the list.
  252.      * </p>
  253.      * @return true if Newtonian attraction force model is available
  254.      */
  255.     private boolean hasNewtonianAttraction() {
  256.         final int last = forceModels.size() - 1;
  257.         return last >= 0 && forceModels.get(last) instanceof DSSTNewtonianAttraction;
  258.     }

  259. }