NumericalPropagatorBuilder.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (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.errors.OrekitException;
  24. import org.orekit.forces.ForceModel;
  25. import org.orekit.orbits.Orbit;
  26. import org.orekit.orbits.PositionAngle;
  27. import org.orekit.propagation.Propagator;
  28. import org.orekit.propagation.SpacecraftState;
  29. import org.orekit.propagation.numerical.NumericalPropagator;
  30. import org.orekit.utils.ParameterDriver;

  31. /** Builder for numerical propagator.
  32.  * @author Pascal Parraud
  33.  * @since 6.0
  34.  */
  35. public class NumericalPropagatorBuilder extends AbstractPropagatorBuilder {

  36.     /** First order integrator builder for propagation. */
  37.     private final ODEIntegratorBuilder builder;

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

  40.     /** Current mass for initial state (kg). */
  41.     private double mass;

  42.     /** Attitude provider. */
  43.     private AttitudeProvider attProvider;

  44.     /** Build a new instance.
  45.      * <p>
  46.      * The reference orbit is used as a model to {@link
  47.      * #createInitialOrbit() create initial orbit}. It defines the
  48.      * inertial frame, the central attraction coefficient, and is also used together
  49.      * with the {@code positionScale} to convert from the {@link
  50.      * ParameterDriver#setNormalizedValue(double) normalized} parameters used by the
  51.      * callers of this builder to the real orbital parameters.
  52.      * </p>
  53.      * @param referenceOrbit reference orbit from which real orbits will be built
  54.      * @param builder first order integrator builder
  55.      * @param positionAngle position angle type to use
  56.      * @param positionScale scaling factor used for orbital parameters normalization
  57.      * (typically set to the expected standard deviation of the position)
  58.      * @exception OrekitException if parameters drivers cannot be scaled
  59.      * @since 8.0
  60.      */
  61.     public NumericalPropagatorBuilder(final Orbit referenceOrbit,
  62.                                       final ODEIntegratorBuilder builder,
  63.                                       final PositionAngle positionAngle,
  64.                                       final double positionScale)
  65.         throws OrekitException {
  66.         super(referenceOrbit, positionAngle, positionScale, true);
  67.         this.builder     = builder;
  68.         this.forceModels = new ArrayList<ForceModel>();
  69.         this.mass        = Propagator.DEFAULT_MASS;
  70.         this.attProvider = Propagator.DEFAULT_LAW;
  71.     }

  72.     /** Create a copy of a NumericalPropagatorBuilder object.
  73.      * @return Copied version of the NumericalPropagatorBuilder
  74.      * @throws OrekitException if parameters drivers cannot be scaled
  75.      */
  76.     public NumericalPropagatorBuilder copy() throws OrekitException {
  77.         final NumericalPropagatorBuilder copyBuilder =
  78.                         new NumericalPropagatorBuilder(createInitialOrbit(),
  79.                                                        builder,
  80.                                                        getPositionAngle(),
  81.                                                        getPositionScale());
  82.         copyBuilder.setAttitudeProvider(attProvider);
  83.         copyBuilder.setMass(mass);
  84.         for (ForceModel model : forceModels) {
  85.             copyBuilder.addForceModel(model);
  86.         }
  87.         return copyBuilder;
  88.     }

  89.     /** Get the integrator builder.
  90.      * @return the integrator builder
  91.      * @since 9.2
  92.      */
  93.     public ODEIntegratorBuilder getIntegratorBuilder()
  94.     {
  95.         return builder;
  96.     }

  97.     /** Get the list of all force models.
  98.      * @return the list of all force models
  99.      * @since 9.2
  100.      */
  101.     public List<ForceModel> getAllForceModels()
  102.     {
  103.         return Collections.unmodifiableList(forceModels);
  104.     }

  105.     /** Add a force model to the global perturbation model.
  106.      * <p>If this method is not called at all, the integrated orbit will follow
  107.      * a Keplerian evolution only.</p>
  108.      * @param model perturbing {@link ForceModel} to add
  109.      * @exception OrekitException if model parameters cannot be set
  110.      */
  111.     public void addForceModel(final ForceModel model)
  112.         throws OrekitException {
  113.         forceModels.add(model);
  114.         for (final ParameterDriver driver : model.getParametersDrivers()) {
  115.             addSupportedParameter(driver);
  116.         }
  117.     }

  118.     /** Get the mass.
  119.      * @return the mass
  120.      * @since 9.2
  121.      */
  122.     public double getMass()
  123.     {
  124.         return mass;
  125.     }

  126.     /** Set the initial mass.
  127.      * @param mass the mass (kg)
  128.      */
  129.     public void setMass(final double mass) {
  130.         this.mass = mass;
  131.     }

  132.     /** Get the attitudeProvider.
  133.      * @return the attitude provider
  134.      * @since 9.2
  135.      */
  136.     public AttitudeProvider getAttitudeProvider()
  137.     {
  138.         return attProvider;
  139.     }

  140.     /** Set the attitude provider.
  141.      * @param attitudeProvider attitude provider
  142.      */
  143.     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
  144.         this.attProvider = attitudeProvider;
  145.     }

  146.     /** {@inheritDoc} */
  147.     public NumericalPropagator buildPropagator(final double[] normalizedParameters)
  148.         throws OrekitException {

  149.         setParameters(normalizedParameters);
  150.         final Orbit           orbit    = createInitialOrbit();
  151.         final Attitude        attitude = attProvider.getAttitude(orbit, orbit.getDate(), getFrame());
  152.         final SpacecraftState state    = new SpacecraftState(orbit, attitude, mass);

  153.         final NumericalPropagator propagator = new NumericalPropagator(builder.buildIntegrator(orbit, getOrbitType()));
  154.         propagator.setOrbitType(getOrbitType());
  155.         propagator.setPositionAngleType(getPositionAngle());
  156.         propagator.setAttitudeProvider(attProvider);
  157.         for (ForceModel model : forceModels) {
  158.             propagator.addForceModel(model);
  159.         }
  160.         propagator.resetInitialState(state);

  161.         return propagator;
  162.     }
  163. }