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 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.FrameAlignedProvider;
  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.orbits.EquinoctialOrbit;
  28. import org.orekit.orbits.Orbit;
  29. import org.orekit.orbits.OrbitType;
  30. import org.orekit.orbits.PositionAngleType;
  31. import org.orekit.propagation.PropagationType;
  32. import org.orekit.propagation.Propagator;
  33. import org.orekit.propagation.SpacecraftState;
  34. import org.orekit.propagation.integration.AdditionalDerivativesProvider;
  35. import org.orekit.propagation.semianalytical.dsst.DSSTPropagator;
  36. import org.orekit.propagation.semianalytical.dsst.forces.DSSTForceModel;
  37. import org.orekit.propagation.semianalytical.dsst.forces.DSSTNewtonianAttraction;
  38. import org.orekit.utils.ParameterDriver;
  39. import org.orekit.utils.ParameterDriversList;

  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.     /** Current mass for initial state (kg). */
  50.     private double mass;

  51.     /** Type of the orbit used for the propagation.*/
  52.     private PropagationType propagationType;

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

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

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

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

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

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

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

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

  157.     /** Get the mass.
  158.      * @return the mass
  159.      */
  160.     public double getMass()
  161.     {
  162.         return mass;
  163.     }

  164.     /** Set the initial mass.
  165.      * @param mass the mass (kg)
  166.      */
  167.     public void setMass(final double mass) {
  168.         this.mass = mass;
  169.     }

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

  196.         addSupportedParameters(model.getParametersDrivers());
  197.     }

  198.     /** Reset the orbit in the propagator builder.
  199.      * @param newOrbit newOrbit New orbit to set in the propagator builder
  200.      * @param orbitType orbit type (MEAN or OSCULATING)
  201.      */
  202.     public void resetOrbit(final Orbit newOrbit, final PropagationType orbitType) {
  203.         this.stateType = orbitType;
  204.         super.resetOrbit(newOrbit);
  205.     }

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

  208.         setParameters(normalizedParameters);
  209.         final EquinoctialOrbit orbit    = (EquinoctialOrbit) OrbitType.EQUINOCTIAL.convertType(createInitialOrbit());
  210.         final Attitude         attitude = getAttitudeProvider().getAttitude(orbit, orbit.getDate(), getFrame());
  211.         final SpacecraftState  state    = new SpacecraftState(orbit, attitude, mass);

  212.         final DSSTPropagator propagator = new DSSTPropagator(
  213.                 builder.buildIntegrator(orbit, OrbitType.EQUINOCTIAL),
  214.                 propagationType,
  215.                 getAttitudeProvider());

  216.         // Configure force models
  217.         if (!hasNewtonianAttraction()) {
  218.             // There are no central attraction model yet, add it at the end of the list
  219.             addForceModel(new DSSTNewtonianAttraction(orbit.getMu()));
  220.         }
  221.         for (DSSTForceModel model : forceModels) {
  222.             propagator.addForceModel(model);
  223.         }

  224.         propagator.setInitialState(state, stateType);

  225.         // Add additional derivatives providers to the propagator
  226.         for (AdditionalDerivativesProvider provider: getAdditionalDerivativesProviders()) {
  227.             propagator.addAdditionalDerivativesProvider(provider);
  228.         }

  229.         return propagator;

  230.     }

  231.     /** {@inheritDoc} */
  232.     @Override
  233.     public DSSTBatchLSModel buildLeastSquaresModel(final PropagatorBuilder[] builders,
  234.                                                    final List<ObservedMeasurement<?>> measurements,
  235.                                                    final ParameterDriversList estimatedMeasurementsParameters,
  236.                                                    final ModelObserver observer) {
  237.         return new DSSTBatchLSModel(builders,
  238.                                     measurements,
  239.                                     estimatedMeasurementsParameters,
  240.                                     observer,
  241.                                     propagationType);
  242.     }

  243.     /** Check if Newtonian attraction force model is available.
  244.      * <p>
  245.      * Newtonian attraction is always the last force model in the list.
  246.      * </p>
  247.      * @return true if Newtonian attraction force model is available
  248.      */
  249.     private boolean hasNewtonianAttraction() {
  250.         final int last = forceModels.size() - 1;
  251.         return last >= 0 && forceModels.get(last) instanceof DSSTNewtonianAttraction;
  252.     }

  253. }