DSSTPropagatorBuilder.java

  1. /* Copyright 2002-2024 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 org.orekit.attitudes.Attitude;
  19. import org.orekit.attitudes.AttitudeProvider;
  20. import org.orekit.attitudes.FrameAlignedProvider;
  21. import org.orekit.estimation.leastsquares.DSSTBatchLSModel;
  22. import org.orekit.estimation.leastsquares.ModelObserver;
  23. import org.orekit.estimation.measurements.ObservedMeasurement;
  24. import org.orekit.orbits.EquinoctialOrbit;
  25. import org.orekit.orbits.Orbit;
  26. import org.orekit.orbits.OrbitType;
  27. import org.orekit.orbits.PositionAngleType;
  28. import org.orekit.propagation.PropagationType;
  29. import org.orekit.propagation.Propagator;
  30. import org.orekit.propagation.SpacecraftState;
  31. import org.orekit.propagation.integration.AdditionalDerivativesProvider;
  32. import org.orekit.propagation.semianalytical.dsst.DSSTPropagator;
  33. import org.orekit.propagation.semianalytical.dsst.forces.DSSTForceModel;
  34. import org.orekit.propagation.semianalytical.dsst.forces.DSSTNewtonianAttraction;
  35. import org.orekit.utils.ParameterDriver;
  36. import org.orekit.utils.ParameterDriversList;

  37. import java.util.ArrayList;
  38. import java.util.Collections;
  39. import java.util.List;

  40. /** Builder for DSST propagator.
  41.  * @author Bryan Cazabonne
  42.  * @since 10.0
  43.  */
  44. public class DSSTPropagatorBuilder extends AbstractPropagatorBuilder {

  45.     /** First order integrator builder for propagation. */
  46.     private final ODEIntegratorBuilder builder;

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

  49.     /** Type of the orbit used for the propagation.*/
  50.     private PropagationType propagationType;

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

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

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

  111.     /** Get the type of the orbit used for the propagation (mean or osculating).
  112.      * @return the type of the orbit used for the propagation
  113.      */
  114.     public PropagationType getPropagationType() {
  115.         return propagationType;
  116.     }

  117.     /** Get the type of the elements used to define the orbital state (mean or osculating).
  118.      * @return the type of the elements used to define the orbital state
  119.      */
  120.     public PropagationType getStateType() {
  121.         return stateType;
  122.     }

  123.     /** Create a copy of a DSSTPropagatorBuilder object.
  124.      * @return Copied version of the DSSTPropagatorBuilder
  125.      */
  126.     @Deprecated
  127.     public DSSTPropagatorBuilder copy() {
  128.         final DSSTPropagatorBuilder copyBuilder =
  129.                         new DSSTPropagatorBuilder(createInitialOrbit(),
  130.                                                   builder,
  131.                                                   getPositionScale(),
  132.                                                   propagationType,
  133.                                                   stateType,
  134.                                                   getAttitudeProvider());
  135.         copyBuilder.setMass(getMass());
  136.         for (DSSTForceModel model : forceModels) {
  137.             copyBuilder.addForceModel(model);
  138.         }
  139.         return copyBuilder;
  140.     }

  141.     /** Get the integrator builder.
  142.      * @return the integrator builder
  143.      */
  144.     public ODEIntegratorBuilder getIntegratorBuilder()
  145.     {
  146.         return builder;
  147.     }

  148.     /** Get the list of all force models.
  149.      * @return the list of all force models
  150.      */
  151.     public List<DSSTForceModel> getAllForceModels()
  152.     {
  153.         return Collections.unmodifiableList(forceModels);
  154.     }

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

  181.         addSupportedParameters(model.getParametersDrivers());
  182.     }

  183.     /** Reset the orbit in the propagator builder.
  184.      * @param newOrbit newOrbit New orbit to set in the propagator builder
  185.      * @param orbitType orbit type (MEAN or OSCULATING)
  186.      */
  187.     public void resetOrbit(final Orbit newOrbit, final PropagationType orbitType) {
  188.         this.stateType = orbitType;
  189.         super.resetOrbit(newOrbit);
  190.     }

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

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

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

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

  209.         propagator.setInitialState(state, stateType);

  210.         // Add additional derivatives providers to the propagator
  211.         for (AdditionalDerivativesProvider provider: getAdditionalDerivativesProviders()) {
  212.             propagator.addAdditionalDerivativesProvider(provider);
  213.         }

  214.         return propagator;

  215.     }

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

  228.     /** Check if Newtonian attraction force model is available.
  229.      * <p>
  230.      * Newtonian attraction is always the last force model in the list.
  231.      * </p>
  232.      * @return true if Newtonian attraction force model is available
  233.      */
  234.     private boolean hasNewtonianAttraction() {
  235.         final int last = forceModels.size() - 1;
  236.         return last >= 0 && forceModels.get(last) instanceof DSSTNewtonianAttraction;
  237.     }

  238. }