NumericalPropagatorBuilder.java

  1. /* Copyright 2002-2016 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.Iterator;
  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.errors.OrekitIllegalArgumentException;
  25. import org.orekit.forces.ForceModel;
  26. import org.orekit.forces.gravity.NewtonianAttraction;
  27. import org.orekit.frames.Frame;
  28. import org.orekit.orbits.Orbit;
  29. import org.orekit.orbits.OrbitType;
  30. import org.orekit.orbits.PositionAngle;
  31. import org.orekit.propagation.Propagator;
  32. import org.orekit.propagation.SpacecraftState;
  33. import org.orekit.propagation.numerical.NumericalPropagator;
  34. import org.orekit.time.AbsoluteDate;

  35. /** Builder for numerical propagator.
  36.  * @author Pascal Parraud
  37.  * @since 6.0
  38.  */
  39. public class NumericalPropagatorBuilder extends AbstractPropagatorBuilder {

  40.     /** First order integrator builder for propagation. */
  41.     private final FirstOrderIntegratorBuilder builder;

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

  44.     /** Current mass for initial state (kg). */
  45.     private double mass;

  46.     /** Attitude provider. */
  47.     private AttitudeProvider attProvider;

  48.     /** Build a new instance.
  49.      * @param mu central attraction coefficient (m³/s²)
  50.      * @param frame the frame in which the orbit is propagated
  51.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  52.      * @param builder first order integrator builder
  53.      * @deprecated as of 7.1, replaced with {@link #NumericalPropagatorBuilder(double,
  54.      * Frame, FirstOrderIntegratorBuilder, OrbitType, PositionAngle)}
  55.      */
  56.     @Deprecated
  57.     public NumericalPropagatorBuilder(final double mu,
  58.                                       final Frame frame,
  59.                                       final FirstOrderIntegratorBuilder builder) {
  60.         this(mu, frame, builder, OrbitType.CARTESIAN, PositionAngle.TRUE);
  61.     }

  62.     /** Build a new instance.
  63.      * @param mu central attraction coefficient (m³/s²)
  64.      * @param frame the frame in which the orbit is propagated
  65.      * (<em>must</em> be a {@link Frame#isPseudoInertial pseudo-inertial frame})
  66.      * @param builder first order integrator builder
  67.      * @param orbitType orbit type to use
  68.      * @param positionAngle position angle type to use
  69.      * @since 7.1
  70.      */
  71.     public NumericalPropagatorBuilder(final double mu,
  72.                                       final Frame frame,
  73.                                       final FirstOrderIntegratorBuilder builder,
  74.                                       final OrbitType orbitType, final PositionAngle positionAngle) {
  75.         super(frame, mu, orbitType, positionAngle);
  76.         this.builder     = builder;
  77.         this.forceModels = new ArrayList<ForceModel>();
  78.         this.mass        = Propagator.DEFAULT_MASS;
  79.         this.attProvider = Propagator.DEFAULT_LAW;
  80.     }

  81.     /** Set the attitude provider.
  82.      * @param attitudeProvider attitude provider
  83.      */
  84.     public void setAttitudeProvider(final AttitudeProvider attitudeProvider) {
  85.         this.attProvider = attitudeProvider;
  86.     }

  87.     /** Set the initial mass.
  88.      * @param mass the mass (kg)
  89.      */
  90.     public void setMass(final double mass) {
  91.         this.mass = mass;
  92.     }

  93.     /** Add a force model to the global perturbation model.
  94.      * <p>If this method is not called at all, the integrated orbit will follow
  95.      * a keplerian evolution only.</p>
  96.      * @param model perturbing {@link ForceModel} to add
  97.      */
  98.     public void addForceModel(final ForceModel model) {
  99.         forceModels.add(model);
  100.         for (final String name : model.getParametersNames()) {
  101.             // add model parameters, taking care of
  102.             // Newtonian central attraction which is already supported by base class
  103.             if (NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT.equals(name)) {
  104.                 super.setParameter(name, model.getParameter(name));
  105.             } else {
  106.                 addSupportedParameter(name);
  107.             }
  108.         }
  109.     }

  110.     /** {@inheritDoc} */
  111.     public NumericalPropagator buildPropagator(final AbsoluteDate date, final double[] parameters)
  112.         throws OrekitException {

  113.         checkParameters(parameters);
  114.         final Orbit orb = createInitialOrbit(date, parameters);

  115.         final Attitude attitude = attProvider.getAttitude(orb, date, getFrame());

  116.         final SpacecraftState state = new SpacecraftState(orb, attitude, mass);

  117.         final Iterator<String> freeItr = getFreeParameters().iterator();
  118.         for (int i = 6; i < parameters.length; i++) {
  119.             final String free = freeItr.next();
  120.             for (String available : getSupportedParameters()) {
  121.                 if (free.equals(available)) {
  122.                     setParameter(free, parameters[i]);
  123.                 }
  124.             }
  125.         }

  126.         final NumericalPropagator propagator = new NumericalPropagator(builder.buildIntegrator(orb, getOrbitType()));
  127.         propagator.setOrbitType(getOrbitType());
  128.         propagator.setPositionAngleType(getPositionAngle());
  129.         propagator.setAttitudeProvider(attProvider);
  130.         for (ForceModel model : forceModels) {
  131.             propagator.addForceModel(model);
  132.         }
  133.         propagator.resetInitialState(state);

  134.         return propagator;
  135.     }

  136.     /** {@inheritDoc} */
  137.     @Override
  138.     public double getParameter(final String name)
  139.         throws OrekitIllegalArgumentException {
  140.         for (ForceModel model : forceModels) {
  141.             if (model.isSupported(name)) {
  142.                 return model.getParameter(name);
  143.             }
  144.         }
  145.         return super.getParameter(name);
  146.     }

  147.     /** {@inheritDoc} */
  148.     @Override
  149.     public void setParameter(final String name, final double value)
  150.         throws OrekitIllegalArgumentException {
  151.         for (ForceModel model : forceModels) {
  152.             if (model.isSupported(name)) {
  153.                 model.setParameter(name, value);
  154.                 if (NewtonianAttraction.CENTRAL_ATTRACTION_COEFFICIENT.equals(name)) {
  155.                     // the central attraction must be configured
  156.                     // in both the force model and the base class
  157.                     super.setParameter(name, value);
  158.                 }
  159.                 return;
  160.             }
  161.         }
  162.         super.setParameter(name, value);
  163.     }

  164. }