TLEPropagatorBuilder.java

  1. /* Copyright 2002-2013 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.Collection;

  20. import org.apache.commons.math3.exception.util.LocalizedFormats;
  21. import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
  22. import org.apache.commons.math3.ode.AbstractParameterizable;
  23. import org.apache.commons.math3.util.FastMath;
  24. import org.apache.commons.math3.util.MathUtils;
  25. import org.orekit.errors.OrekitException;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.frames.FramesFactory;
  28. import org.orekit.orbits.KeplerianOrbit;
  29. import org.orekit.propagation.Propagator;
  30. import org.orekit.propagation.analytical.tle.TLE;
  31. import org.orekit.propagation.analytical.tle.TLEPropagator;
  32. import org.orekit.time.AbsoluteDate;
  33. import org.orekit.utils.PVCoordinates;

  34. /** Builder for TLEPropagator.
  35.  * @author Pascal Parraud
  36.  * @since 6.0
  37.  */
  38. public class TLEPropagatorBuilder extends AbstractParameterizable
  39.                                   implements PropagatorBuilder {

  40.     /** Parameter name for B* coefficient. */
  41.     public static final String B_STAR = "BSTAR";

  42.     /** Satellite number. */
  43.     private final int satelliteNumber;

  44.     /** Classification (U for unclassified). */
  45.     private final char classification;

  46.     /** Launch year (all digits). */
  47.     private final int launchYear;

  48.     /** Launch number. */
  49.     private final int launchNumber;

  50.     /** Launch piece. */
  51.     private final String launchPiece;

  52.     /** Element number. */
  53.     private final int elementNumber;

  54.     /** Revolution number at epoch. */
  55.     private final int revolutionNumberAtEpoch;

  56.     /** Central attraction coefficient (m<sup>3</sup>/s<sup>2</sup>). */
  57.     private final double mu;

  58.     /** TEME frame. */
  59.     private final Frame frame;

  60.     /** List of the free parameters names. */
  61.     private Collection<String> freeParameters;

  62.     /** Ballistic coefficient. */
  63.     private double bStar;

  64.     /** Build a new instance.
  65.      * @param satelliteNumber satellite number
  66.      * @param classification classification (U for unclassified)
  67.      * @param launchYear launch year (all digits)
  68.      * @param launchNumber launch number
  69.      * @param launchPiece launch piece
  70.      * @param elementNumber element number
  71.      * @param revolutionNumberAtEpoch revolution number at epoch
  72.      * @throws OrekitException if the TEME frame cannot be set
  73.      */
  74.     public TLEPropagatorBuilder(final int satelliteNumber,
  75.                                 final char classification,
  76.                                 final int launchYear,
  77.                                 final int launchNumber,
  78.                                 final String launchPiece,
  79.                                 final int elementNumber,
  80.                                 final int revolutionNumberAtEpoch) throws OrekitException {
  81.         super(B_STAR);
  82.         this.satelliteNumber         = satelliteNumber;
  83.         this.classification          = classification;
  84.         this.launchYear              = launchYear;
  85.         this.launchNumber            = launchNumber;
  86.         this.launchPiece             = launchPiece;
  87.         this.elementNumber           = elementNumber;
  88.         this.revolutionNumberAtEpoch = revolutionNumberAtEpoch;
  89.         this.bStar                   = 0.0;
  90.         this.mu                      = TLEPropagator.getMU();
  91.         this.frame                   = FramesFactory.getTEME();
  92.     }

  93.     /** {@inheritDoc} */
  94.     public Propagator buildPropagator(final AbsoluteDate date, final double[] parameters)
  95.         throws OrekitException {

  96.         if (parameters.length != (freeParameters.size() + 6)) {
  97.             throw OrekitException.createIllegalArgumentException(LocalizedFormats.DIMENSIONS_MISMATCH);
  98.         }

  99.         final KeplerianOrbit orb = new KeplerianOrbit(new PVCoordinates(new Vector3D(parameters[0],
  100.                                                                                      parameters[1],
  101.                                                                                      parameters[2]),
  102.                                                                         new Vector3D(parameters[3],
  103.                                                                                      parameters[4],
  104.                                                                                      parameters[5])),
  105.                                                       frame, date, mu);

  106.         for (int i = 6; i < parameters.length; i++) {
  107.             for (String free : freeParameters) {
  108.                 for (String available : getParametersNames()) {
  109.                     if (free.equals(available)) {
  110.                         setParameter(free, parameters[i]);
  111.                     }
  112.                 }
  113.             }
  114.         }

  115.         final TLE tle = new TLE(satelliteNumber, classification, launchYear, launchNumber, launchPiece,
  116.                                 TLE.DEFAULT, elementNumber, date,
  117.                                 orb.getKeplerianMeanMotion(), 0.0, 0.0,
  118.                                 orb.getE(), MathUtils.normalizeAngle(orb.getI(), FastMath.PI),
  119.                                 MathUtils.normalizeAngle(orb.getPerigeeArgument(), FastMath.PI),
  120.                                 MathUtils.normalizeAngle(orb.getRightAscensionOfAscendingNode(), FastMath.PI),
  121.                                 MathUtils.normalizeAngle(orb.getMeanAnomaly(), FastMath.PI),
  122.                                 revolutionNumberAtEpoch, bStar);

  123.         return TLEPropagator.selectExtrapolator(tle);
  124.     }

  125.     /** {@inheritDoc} */
  126.     public Frame getFrame() {
  127.         return frame;
  128.     }

  129.     /** {@inheritDoc} */
  130.     public void setFreeParameters(final Collection<String> parameters)
  131.         throws IllegalArgumentException {
  132.         freeParameters = new ArrayList<String>();
  133.         for (String name : parameters) {
  134.             complainIfNotSupported(name);
  135.         }
  136.         freeParameters.addAll(parameters);
  137.     }

  138.     /** {@inheritDoc} */
  139.     public double getParameter(final String name)
  140.         throws IllegalArgumentException {
  141.         complainIfNotSupported(name);
  142.         return bStar;
  143.     }

  144.     /** {@inheritDoc} */
  145.     public void setParameter(final String name, final double value)
  146.         throws IllegalArgumentException {
  147.         complainIfNotSupported(name);
  148.         bStar = value * 1.e-4;
  149.     }

  150. }