DSSTPropagatorBuilder.java

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

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

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

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

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

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

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

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

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

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

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

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

  132.     /** Get the integrator builder.
  133.      * @return the integrator builder
  134.      */
  135.     public ODEIntegratorBuilder getIntegratorBuilder()
  136.     {
  137.         return builder;
  138.     }

  139.     /** Get the list of all force models.
  140.      * @return the list of all force models
  141.      */
  142.     public List<DSSTForceModel> getAllForceModels()
  143.     {
  144.         return Collections.unmodifiableList(forceModels);
  145.     }

  146.     /** Get the mass.
  147.      * @return the mass
  148.      */
  149.     public double getMass()
  150.     {
  151.         return mass;
  152.     }

  153.     /** Set the initial mass.
  154.      * @param mass the mass (kg)
  155.      */
  156.     public void setMass(final double mass) {
  157.         this.mass = mass;
  158.     }

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

  185.         for (final ParameterDriver driver : model.getParametersDrivers()) {
  186.             addSupportedParameter(driver);
  187.         }
  188.     }

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

  191.         setParameters(normalizedParameters);
  192.         final EquinoctialOrbit orbit    = (EquinoctialOrbit) OrbitType.EQUINOCTIAL.convertType(createInitialOrbit());
  193.         final Attitude         attitude = getAttitudeProvider().getAttitude(orbit, orbit.getDate(), getFrame());
  194.         final SpacecraftState  state    = new SpacecraftState(orbit, attitude, mass);

  195.         final DSSTPropagator propagator = new DSSTPropagator(
  196.                 builder.buildIntegrator(orbit, OrbitType.EQUINOCTIAL),
  197.                 propagationType,
  198.                 getAttitudeProvider());

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

  207.         propagator.setInitialState(state, stateType);

  208.         // Add additional equations to the propagator
  209.         for (AdditionalEquations equation: getAdditionalEquations()) {
  210.             propagator.addAdditionalEquations(equation);
  211.         }

  212.         return propagator;
  213.     }

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

  226.     /** {@inheritDoc} */
  227.     @Override
  228.     public DSSTKalmanModel buildKalmanModel(final List<OrbitDeterminationPropagatorBuilder> propagatorBuilders,
  229.                                             final List<CovarianceMatrixProvider> covarianceMatricesProviders,
  230.                                             final ParameterDriversList estimatedMeasurementsParameters,
  231.                                             final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  232.         return new DSSTKalmanModel(propagatorBuilders, covarianceMatricesProviders,
  233.                                    estimatedMeasurementsParameters, measurementProcessNoiseMatrix,
  234.                                    propagationType, stateType);
  235.     }

  236.     /** Check if Newtonian attraction force model is available.
  237.      * <p>
  238.      * Newtonian attraction is always the last force model in the list.
  239.      * </p>
  240.      * @return true if Newtonian attraction force model is available
  241.      */
  242.     private boolean hasNewtonianAttraction() {
  243.         final int last = forceModels.size() - 1;
  244.         return last >= 0 && forceModels.get(last) instanceof DSSTNewtonianAttraction;
  245.     }

  246. }