NumericalPropagatorBuilder.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.BatchLSModel;
  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.KalmanModel;
  30. import org.orekit.forces.ForceModel;
  31. import org.orekit.forces.gravity.NewtonianAttraction;
  32. import org.orekit.orbits.Orbit;
  33. import org.orekit.orbits.PositionAngle;
  34. import org.orekit.propagation.Propagator;
  35. import org.orekit.propagation.SpacecraftState;
  36. import org.orekit.propagation.integration.AdditionalEquations;
  37. import org.orekit.propagation.numerical.NumericalPropagator;
  38. import org.orekit.utils.ParameterDriver;
  39. import org.orekit.utils.ParameterDriversList;

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

  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<ForceModel> forceModels;

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

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

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

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

  123.     /** Get the integrator builder.
  124.      * @return the integrator builder
  125.      * @since 9.2
  126.      */
  127.     public ODEIntegratorBuilder getIntegratorBuilder()
  128.     {
  129.         return builder;
  130.     }

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

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

  165.         for (final ParameterDriver driver : model.getParametersDrivers()) {
  166.             addSupportedParameter(driver);
  167.         }
  168.     }

  169.     /** Get the mass.
  170.      * @return the mass
  171.      * @since 9.2
  172.      */
  173.     public double getMass()
  174.     {
  175.         return mass;
  176.     }

  177.     /** Set the initial mass.
  178.      * @param mass the mass (kg)
  179.      */
  180.     public void setMass(final double mass) {
  181.         this.mass = mass;
  182.     }

  183.     /** {@inheritDoc} */
  184.     public NumericalPropagator buildPropagator(final double[] normalizedParameters) {

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

  190.         final NumericalPropagator propagator = new NumericalPropagator(
  191.                 builder.buildIntegrator(orbit, getOrbitType()),
  192.                 getAttitudeProvider());
  193.         propagator.setOrbitType(getOrbitType());
  194.         propagator.setPositionAngleType(getPositionAngle());

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

  203.         propagator.resetInitialState(state);

  204.         // Add additional equations to the propagator
  205.         for (AdditionalEquations equation: getAdditionalEquations()) {
  206.             propagator.addAdditionalEquations(equation);
  207.         }

  208.         return propagator;
  209.     }

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

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

  225.     /** {@inheritDoc} */
  226.     @Override
  227.     public KalmanModel buildKalmanModel(final List<IntegratedPropagatorBuilder> propagatorBuilders,
  228.                                   final List<CovarianceMatrixProvider> covarianceMatricesProviders,
  229.                                   final ParameterDriversList estimatedMeasurementsParameters,
  230.                                   final CovarianceMatrixProvider measurementProcessNoiseMatrix) {
  231.         return new KalmanModel(propagatorBuilders, covarianceMatricesProviders,
  232.                                estimatedMeasurementsParameters, measurementProcessNoiseMatrix);
  233.     }

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

  244. }