NumericalPropagatorBuilder.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.BatchLSModel;
  25. import org.orekit.estimation.leastsquares.ModelObserver;
  26. import org.orekit.estimation.measurements.ObservedMeasurement;
  27. import org.orekit.forces.ForceModel;
  28. import org.orekit.forces.gravity.NewtonianAttraction;
  29. import org.orekit.forces.maneuvers.ImpulseManeuver;
  30. import org.orekit.orbits.Orbit;
  31. import org.orekit.orbits.PositionAngleType;
  32. import org.orekit.propagation.Propagator;
  33. import org.orekit.propagation.SpacecraftState;
  34. import org.orekit.propagation.integration.AdditionalDerivativesProvider;
  35. import org.orekit.propagation.numerical.NumericalPropagator;
  36. import org.orekit.utils.ParameterDriver;
  37. import org.orekit.utils.ParameterDriversList;

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

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

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

  47.     /** Impulse maneuvers. */
  48.     private final List<ImpulseManeuver> impulseManeuvers;

  49.     /** Build a new instance.
  50.      * <p>
  51.      * The reference orbit is used as a model to {@link
  52.      * #createInitialOrbit() create initial orbit}. It defines the
  53.      * inertial frame, the central attraction coefficient, and is also used together
  54.      * with the {@code positionScale} to convert from the {@link
  55.      * ParameterDriver#setNormalizedValue(double) normalized} parameters used by the
  56.      * callers of this builder to the real orbital parameters.
  57.      * The default attitude provider is aligned with the orbit's inertial frame.
  58.      * </p>
  59.      *
  60.      * @param referenceOrbit reference orbit from which real orbits will be built
  61.      * @param builder first order integrator builder
  62.      * @param positionAngleType 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, PositionAngleType,
  67.      * double, AttitudeProvider)
  68.      */
  69.     public NumericalPropagatorBuilder(final Orbit referenceOrbit,
  70.                                       final ODEIntegratorBuilder builder,
  71.                                       final PositionAngleType positionAngleType,
  72.                                       final double positionScale) {
  73.         this(referenceOrbit, builder, positionAngleType, positionScale,
  74.              FrameAlignedProvider.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 positionAngleType 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 PositionAngleType positionAngleType,
  96.                                       final double positionScale,
  97.                                       final AttitudeProvider attitudeProvider) {
  98.         super(referenceOrbit, positionAngleType, positionScale, true, attitudeProvider, Propagator.DEFAULT_MASS);
  99.         this.builder     = builder;
  100.         this.forceModels = new ArrayList<>();
  101.         this.impulseManeuvers = new ArrayList<>();
  102.     }

  103.     /**
  104.      * Add impulse maneuver.
  105.      * @param impulseManeuver impulse maneuver
  106.      * @since 12.2
  107.      */
  108.     public void addImpulseManeuver(final ImpulseManeuver impulseManeuver) {
  109.         impulseManeuvers.add(impulseManeuver);
  110.     }

  111.     /**
  112.      * Remove all impulse maneuvers.
  113.      * @since 12.2
  114.      */
  115.     public void clearImpulseManeuvers() {
  116.         impulseManeuvers.clear();
  117.     }

  118.     /** Create a copy of a NumericalPropagatorBuilder object.
  119.      * @return Copied version of the NumericalPropagatorBuilder
  120.      */
  121.     @Deprecated
  122.     public NumericalPropagatorBuilder copy() {
  123.         final NumericalPropagatorBuilder copyBuilder =
  124.                         new NumericalPropagatorBuilder(createInitialOrbit(),
  125.                                                        builder,
  126.                                                        getPositionAngleType(),
  127.                                                        getPositionScale(),
  128.                                                        getAttitudeProvider());
  129.         copyBuilder.setMass(getMass());
  130.         for (ForceModel model : forceModels) {
  131.             copyBuilder.addForceModel(model);
  132.         }
  133.         impulseManeuvers.forEach(copyBuilder::addImpulseManeuver);
  134.         return copyBuilder;
  135.     }

  136.     /** Get the integrator builder.
  137.      * @return the integrator builder
  138.      * @since 9.2
  139.      */
  140.     public ODEIntegratorBuilder getIntegratorBuilder()
  141.     {
  142.         return builder;
  143.     }

  144.     /** Get the list of all force models.
  145.      * @return the list of all force models
  146.      * @since 9.2
  147.      */
  148.     public List<ForceModel> getAllForceModels()
  149.     {
  150.         return Collections.unmodifiableList(forceModels);
  151.     }

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

  178.         addSupportedParameters(model.getParametersDrivers());
  179.     }

  180.     /** {@inheritDoc} */
  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, getMass());

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

  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.         impulseManeuvers.forEach(propagator::addEventDetector);

  201.         propagator.resetInitialState(state);

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

  206.         return propagator;

  207.     }

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

  216.     /** Check if Newtonian attraction force model is available.
  217.      * <p>
  218.      * Newtonian attraction is always the last force model in the list.
  219.      * </p>
  220.      * @return true if Newtonian attraction force model is available
  221.      */
  222.     private boolean hasNewtonianAttraction() {
  223.         final int last = forceModels.size() - 1;
  224.         return last >= 0 && forceModels.get(last) instanceof NewtonianAttraction;
  225.     }

  226. }