NumericalPropagatorBuilder.java

  1. /* Copyright 2002-2022 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.BatchLSModel;
  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.KalmanModel;
  29. import org.orekit.forces.ForceModel;
  30. import org.orekit.forces.gravity.NewtonianAttraction;
  31. import org.orekit.orbits.Orbit;
  32. import org.orekit.orbits.PositionAngle;
  33. import org.orekit.propagation.Propagator;
  34. import org.orekit.propagation.SpacecraftState;
  35. import org.orekit.propagation.integration.AdditionalDerivativesProvider;
  36. import org.orekit.propagation.numerical.NumericalPropagator;
  37. import org.orekit.utils.ParameterDriver;
  38. import org.orekit.utils.ParameterDriversList;

  39. /** Builder for numerical propagator.
  40.  * @author Pascal Parraud
  41.  * @since 6.0
  42.  */
  43. public class NumericalPropagatorBuilder extends AbstractPropagatorBuilder implements OrbitDeterminationPropagatorBuilder {

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

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

  48.     /** Current mass for initial state (kg). */
  49.     private double mass;

  50.     /** Build a new instance.
  51.      * <p>
  52.      * The reference orbit is used as a model to {@link
  53.      * #createInitialOrbit() create initial orbit}. It defines the
  54.      * inertial frame, the central attraction coefficient, and is also used together
  55.      * with the {@code positionScale} to convert from the {@link
  56.      * ParameterDriver#setNormalizedValue(double) normalized} parameters used by the
  57.      * callers of this builder to the real orbital parameters.
  58.      * </p>
  59.      *
  60.      * @param referenceOrbit reference orbit from which real orbits will be built
  61.      * @param builder first order integrator builder
  62.      * @param positionAngle position angle type to use
  63.      * @param positionScale scaling factor used for orbital parameters normalization
  64.      * (typically set to the expected standard deviation of the position)
  65.      * @since 8.0
  66.      * @see #NumericalPropagatorBuilder(Orbit, ODEIntegratorBuilder, PositionAngle,
  67.      * double, AttitudeProvider)
  68.      */
  69.     public NumericalPropagatorBuilder(final Orbit referenceOrbit,
  70.                                       final ODEIntegratorBuilder builder,
  71.                                       final PositionAngle positionAngle,
  72.                                       final double positionScale) {
  73.         this(referenceOrbit, builder, positionAngle, positionScale,
  74.                 InertialProvider.of(referenceOrbit.getFrame()));
  75.     }

  76.     /** Build a new instance.
  77.      * <p>
  78.      * The reference orbit is used as a model to {@link
  79.      * #createInitialOrbit() create initial orbit}. It defines the
  80.      * inertial frame, the central attraction coefficient, and is also used together
  81.      * with the {@code positionScale} to convert from the {@link
  82.      * ParameterDriver#setNormalizedValue(double) normalized} parameters used by the
  83.      * callers of this builder to the real orbital parameters.
  84.      * </p>
  85.      * @param referenceOrbit reference orbit from which real orbits will be built
  86.      * @param builder first order integrator builder
  87.      * @param positionAngle position angle type to use
  88.      * @param positionScale scaling factor used for orbital parameters normalization
  89.      * (typically set to the expected standard deviation of the position)
  90.      * @param attitudeProvider attitude law.
  91.      * @since 10.1
  92.      */
  93.     public NumericalPropagatorBuilder(final Orbit referenceOrbit,
  94.                                       final ODEIntegratorBuilder builder,
  95.                                       final PositionAngle positionAngle,
  96.                                       final double positionScale,
  97.                                       final AttitudeProvider attitudeProvider) {
  98.         super(referenceOrbit, positionAngle, positionScale, true, attitudeProvider);
  99.         this.builder     = builder;
  100.         this.forceModels = new ArrayList<ForceModel>();
  101.         this.mass        = Propagator.DEFAULT_MASS;
  102.     }

  103.     /** Create a copy of a NumericalPropagatorBuilder object.
  104.      * @return Copied version of the NumericalPropagatorBuilder
  105.      */
  106.     public NumericalPropagatorBuilder copy() {
  107.         final NumericalPropagatorBuilder copyBuilder =
  108.                         new NumericalPropagatorBuilder(createInitialOrbit(),
  109.                                                        builder,
  110.                                                        getPositionAngle(),
  111.                                                        getPositionScale(),
  112.                                                        getAttitudeProvider());
  113.         copyBuilder.setMass(mass);
  114.         for (ForceModel model : forceModels) {
  115.             copyBuilder.addForceModel(model);
  116.         }
  117.         return copyBuilder;
  118.     }

  119.     /** Get the integrator builder.
  120.      * @return the integrator builder
  121.      * @since 9.2
  122.      */
  123.     public ODEIntegratorBuilder getIntegratorBuilder()
  124.     {
  125.         return builder;
  126.     }

  127.     /** Get the list of all force models.
  128.      * @return the list of all force models
  129.      * @since 9.2
  130.      */
  131.     public List<ForceModel> getAllForceModels()
  132.     {
  133.         return Collections.unmodifiableList(forceModels);
  134.     }

  135.     /** Add a force model to the global perturbation model.
  136.      * <p>If this method is not called at all, the integrated orbit will follow
  137.      * a Keplerian evolution only.</p>
  138.      * @param model perturbing {@link ForceModel} to add
  139.      */
  140.     public void addForceModel(final ForceModel model) {
  141.         if (model instanceof NewtonianAttraction) {
  142.             // we want to add the central attraction force model
  143.             if (hasNewtonianAttraction()) {
  144.                 // there is already a central attraction model, replace it
  145.                 forceModels.set(forceModels.size() - 1, model);
  146.             } else {
  147.                 // there are no central attraction model yet, add it at the end of the list
  148.                 forceModels.add(model);
  149.             }
  150.         } else {
  151.             // we want to add a perturbing force model
  152.             if (hasNewtonianAttraction()) {
  153.                 // insert the new force model before Newtonian attraction,
  154.                 // which should always be the last one in the list
  155.                 forceModels.add(forceModels.size() - 1, model);
  156.             } else {
  157.                 // we only have perturbing force models up to now, just append at the end of the list
  158.                 forceModels.add(model);
  159.             }
  160.         }

  161.         for (final ParameterDriver driver : model.getParametersDrivers()) {
  162.             addSupportedParameter(driver);
  163.         }
  164.     }

  165.     /** Get the mass.
  166.      * @return the mass
  167.      * @since 9.2
  168.      */
  169.     public double getMass()
  170.     {
  171.         return mass;
  172.     }

  173.     /** Set the initial mass.
  174.      * @param mass the mass (kg)
  175.      */
  176.     public void setMass(final double mass) {
  177.         this.mass = mass;
  178.     }

  179.     /** {@inheritDoc} */
  180.     @SuppressWarnings("deprecation")
  181.     public NumericalPropagator buildPropagator(final double[] normalizedParameters) {

  182.         setParameters(normalizedParameters);
  183.         final Orbit           orbit    = createInitialOrbit();
  184.         final Attitude        attitude =
  185.                 getAttitudeProvider().getAttitude(orbit, orbit.getDate(), getFrame());
  186.         final SpacecraftState state    = new SpacecraftState(orbit, attitude, mass);

  187.         final NumericalPropagator propagator = new NumericalPropagator(
  188.                 builder.buildIntegrator(orbit, getOrbitType()),
  189.                 getAttitudeProvider());
  190.         propagator.setOrbitType(getOrbitType());
  191.         propagator.setPositionAngleType(getPositionAngle());

  192.         // Configure force models
  193.         if (!hasNewtonianAttraction()) {
  194.             // There are no central attraction model yet, add it at the end of the list
  195.             addForceModel(new NewtonianAttraction(orbit.getMu()));
  196.         }
  197.         for (ForceModel model : forceModels) {
  198.             propagator.addForceModel(model);
  199.         }

  200.         propagator.resetInitialState(state);

  201.         // Add additional derivatives providers to the propagator
  202.         for (AdditionalDerivativesProvider provider: getAdditionalDerivativesProviders()) {
  203.             propagator.addAdditionalDerivativesProvider(provider);
  204.         }

  205.         // FIXME: remove in 12.0 when AdditionalEquations is removed
  206.         for (org.orekit.propagation.integration.AdditionalEquations equations : getAdditionalEquations()) {
  207.             propagator.addAdditionalDerivativesProvider(new org.orekit.propagation.integration.AdditionalEquationsAdapter(equations, propagator::getInitialState));
  208.         }

  209.         return propagator;
  210.     }

  211.     /** {@inheritDoc} */
  212.     public BatchLSModel buildLSModel(final OrbitDeterminationPropagatorBuilder[] builders,
  213.                             final List<ObservedMeasurement<?>> measurements,
  214.                             final ParameterDriversList estimatedMeasurementsParameters,
  215.                             final ModelObserver observer) {
  216.         return new BatchLSModel(builders, measurements, estimatedMeasurementsParameters, observer);
  217.     }

  218.     /** {@inheritDoc} */
  219.     @Override
  220.     public KalmanModel buildKalmanModel(final List<OrbitDeterminationPropagatorBuilder> propagatorBuilders,
  221.                                         final List<CovarianceMatrixProvider> covarianceMatricesProviders,
  222.                                         final ParameterDriversList estimatedMeasurementsParameters,
  223.                                         final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  224.         return new KalmanModel(propagatorBuilders, covarianceMatricesProviders,
  225.                                estimatedMeasurementsParameters, measurementProcessNoiseMatrix);
  226.     }

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

  237. }