NumericalPropagatorBuilder.java

  1. /* Copyright 2002-2019 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.forces.ForceModel;
  24. import org.orekit.orbits.Orbit;
  25. import org.orekit.orbits.PositionAngle;
  26. import org.orekit.propagation.Propagator;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.propagation.numerical.NumericalPropagator;
  29. import org.orekit.utils.ParameterDriver;

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

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

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

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

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

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

  69.     /** Create a copy of a NumericalPropagatorBuilder object.
  70.      * @return Copied version of the NumericalPropagatorBuilder
  71.      */
  72.     public NumericalPropagatorBuilder copy() {
  73.         final NumericalPropagatorBuilder copyBuilder =
  74.                         new NumericalPropagatorBuilder(createInitialOrbit(),
  75.                                                        builder,
  76.                                                        getPositionAngle(),
  77.                                                        getPositionScale());
  78.         copyBuilder.setAttitudeProvider(attProvider);
  79.         copyBuilder.setMass(mass);
  80.         for (ForceModel model : forceModels) {
  81.             copyBuilder.addForceModel(model);
  82.         }
  83.         return copyBuilder;
  84.     }

  85.     /** Get the integrator builder.
  86.      * @return the integrator builder
  87.      * @since 9.2
  88.      */
  89.     public ODEIntegratorBuilder getIntegratorBuilder()
  90.     {
  91.         return builder;
  92.     }

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

  101.     /** Add a force model to the global perturbation model.
  102.      * <p>If this method is not called at all, the integrated orbit will follow
  103.      * a Keplerian evolution only.</p>
  104.      * @param model perturbing {@link ForceModel} to add
  105.      */
  106.     public void addForceModel(final ForceModel model) {
  107.         forceModels.add(model);
  108.         for (final ParameterDriver driver : model.getParametersDrivers()) {
  109.             addSupportedParameter(driver);
  110.         }
  111.     }

  112.     /** Get the mass.
  113.      * @return the mass
  114.      * @since 9.2
  115.      */
  116.     public double getMass()
  117.     {
  118.         return mass;
  119.     }

  120.     /** Set the initial mass.
  121.      * @param mass the mass (kg)
  122.      */
  123.     public void setMass(final double mass) {
  124.         this.mass = mass;
  125.     }

  126.     /** Get the attitudeProvider.
  127.      * @return the attitude provider
  128.      * @since 9.2
  129.      */
  130.     public AttitudeProvider getAttitudeProvider()
  131.     {
  132.         return attProvider;
  133.     }

  134.     /** Set the attitude provider.
  135.      * @param attitudeProvider attitude provider
  136.      */
  137.     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
  138.         this.attProvider = attitudeProvider;
  139.     }

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

  142.         setParameters(normalizedParameters);
  143.         final Orbit           orbit    = createInitialOrbit();
  144.         final Attitude        attitude = attProvider.getAttitude(orbit, orbit.getDate(), getFrame());
  145.         final SpacecraftState state    = new SpacecraftState(orbit, attitude, mass);

  146.         final NumericalPropagator propagator = new NumericalPropagator(builder.buildIntegrator(orbit, getOrbitType()));
  147.         propagator.setOrbitType(getOrbitType());
  148.         propagator.setPositionAngleType(getPositionAngle());
  149.         propagator.setAttitudeProvider(attProvider);
  150.         for (ForceModel model : forceModels) {
  151.             propagator.addForceModel(model);
  152.         }
  153.         propagator.resetInitialState(state);

  154.         return propagator;
  155.     }
  156. }