NumericalPropagatorBuilder.java

  1. /* Copyright 2002-2025 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.PropagationType;
  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 AbstractIntegratedPropagatorBuilder<NumericalPropagator> {

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

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

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

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

  101.     /** Copy constructor.
  102.      *
  103.      * @param builder builder to copy
  104.      */
  105.     private NumericalPropagatorBuilder(final NumericalPropagatorBuilder builder) {
  106.         this(builder.createInitialOrbit(),
  107.              builder.getIntegratorBuilder(),
  108.              builder.getPositionAngleType(),
  109.              builder.getPositionScale(),
  110.              builder.getAttitudeProvider());
  111.     }

  112.     /** {@inheritDoc}. */
  113.     @Override
  114.     public NumericalPropagatorBuilder clone() {
  115.         // Call to super clone() method to avoid warning
  116.         final NumericalPropagatorBuilder clonedBuilder = (NumericalPropagatorBuilder) super.clone();

  117.         // Use copy constructor to unlink orbital drivers
  118.         final NumericalPropagatorBuilder builder =  new NumericalPropagatorBuilder(clonedBuilder);

  119.         // Set mass and force models
  120.         builder.setMass(getMass());
  121.         for (ForceModel model : forceModels) {
  122.             builder.addForceModel(model);
  123.         }

  124.         // Add impulse maneuvers
  125.         impulseManeuvers.forEach(builder::addImpulseManeuver);

  126.         return builder;
  127.     }


  128.     /**
  129.      * Add impulse maneuver.
  130.      * @param impulseManeuver impulse maneuver
  131.      * @since 12.2
  132.      */
  133.     public void addImpulseManeuver(final ImpulseManeuver impulseManeuver) {
  134.         impulseManeuvers.add(impulseManeuver);
  135.     }

  136.     /**
  137.      * Remove all impulse maneuvers.
  138.      * @since 12.2
  139.      */
  140.     public void clearImpulseManeuvers() {
  141.         impulseManeuvers.clear();
  142.     }

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

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

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

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

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

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

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

  200.         propagator.resetInitialState(state);

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

  205.         return propagator;

  206.     }

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

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

  225. }