DateBasedManeuverTriggers.java

  1. /* Copyright 2002-2022 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.forces.maneuvers.trigger;

  18. import java.util.Arrays;
  19. import java.util.List;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.Field;
  22. import org.orekit.propagation.events.FieldAbstractDetector;
  23. import org.orekit.propagation.events.FieldEventDetector;
  24. import org.orekit.propagation.events.FieldParameterDrivenDateIntervalDetector;
  25. import org.orekit.propagation.events.ParameterDrivenDateIntervalDetector;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.ParameterDriver;

  28. /** Maneuver triggers based on a start and end date, with no parameter drivers.
  29.  * @author Maxime Journot
  30.  * @since 10.2
  31.  */
  32. public class DateBasedManeuverTriggers extends IntervalEventTrigger<ParameterDrivenDateIntervalDetector> {

  33.     /** Default name for trigger. */
  34.     public static final String DEFAULT_NAME = "";

  35.     /** Name of the trigger (used as prefix for start and stop parameters drivers). */
  36.     private final String name;

  37.     /** Simple constructor.
  38.      * @param date start (or end) data of the maneuver
  39.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  40.      * if negative, maneuver will be from date - duration to date)
  41.      */
  42.     public DateBasedManeuverTriggers(final AbsoluteDate date, final double duration) {
  43.         this(DEFAULT_NAME, date, duration);
  44.     }

  45.     /** Simple constructor.
  46.      * @param name name of the trigger (used as prefix for start and stop parameters drivers)
  47.      * @param date start (or end) data of the maneuver
  48.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  49.      * if negative, maneuver will be from date - duration to date)
  50.      * @since 11.1
  51.      */
  52.     public DateBasedManeuverTriggers(final String name, final AbsoluteDate date, final double duration) {
  53.         super(createDetector(name, date, duration));
  54.         this.name = name;
  55.     }

  56.     /** Create a date detector from one boundary and signed duration.
  57.      * @param prefix for start and stop parameters drivers
  58.      * @param date start (or end) data of the maneuver
  59.      * @param duration maneuver duration (if positive, maneuver is from date to date + duration,
  60.      * if negative, maneuver will be from date - duration to date)
  61.      * @return date detector
  62.      * @since 11.1
  63.      */
  64.     private static ParameterDrivenDateIntervalDetector createDetector(final String prefix, final AbsoluteDate date, final double duration) {
  65.         if (duration >= 0) {
  66.             return new ParameterDrivenDateIntervalDetector(prefix, date, date.shiftedBy(duration));
  67.         } else {
  68.             return new ParameterDrivenDateIntervalDetector(prefix, date.shiftedBy(duration), date);
  69.         }
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public String getName() {
  74.         return name;
  75.     }

  76.     /** Get the start date.
  77.      * @return the start date
  78.      */
  79.     public AbsoluteDate getStartDate() {
  80.         return getFiringIntervalDetector().getStartDriver().getDate();
  81.     }

  82.     /** Get the end date.
  83.      * @return the end date
  84.      */
  85.     public AbsoluteDate getEndDate() {
  86.         return getFiringIntervalDetector().getStopDriver().getDate();
  87.     }

  88.     /** Get the duration of the maneuver (s).
  89.      * duration = endDate - startDate
  90.      * @return the duration of the maneuver (s)
  91.      */
  92.     public double getDuration() {
  93.         return getEndDate().durationFrom(getStartDate());
  94.     }

  95.     /** {@inheritDoc} */
  96.     @Override
  97.     protected <D extends FieldEventDetector<S>, S extends CalculusFieldElement<S>>
  98.         FieldAbstractDetector<D, S> convertIntervalDetector(final Field<S> field, final ParameterDrivenDateIntervalDetector detector) {

  99.         final FieldParameterDrivenDateIntervalDetector<S> fd =
  100.                         new FieldParameterDrivenDateIntervalDetector<S>(field, "",
  101.                                                                         detector.getStartDriver().getBaseDate(),
  102.                                                                         detector.getStopDriver().getBaseDate());
  103.         fd.getStartDriver().setName(detector.getStartDriver().getName());
  104.         fd.getStopDriver().setName(detector.getStopDriver().getName());
  105.         fd.getMedianDriver().setName(detector.getMedianDriver().getName());
  106.         fd.getDurationDriver().setName(detector.getDurationDriver().getName());

  107.         @SuppressWarnings("unchecked")
  108.         final FieldAbstractDetector<D, S> converted = (FieldAbstractDetector<D, S>) fd;
  109.         return converted;

  110.     }

  111.     /** {@inheritDoc} */
  112.     @Override
  113.     public List<ParameterDriver> getParametersDrivers() {
  114.         return Arrays.asList(getFiringIntervalDetector().getStartDriver(),
  115.                              getFiringIntervalDetector().getStopDriver(),
  116.                              getFiringIntervalDetector().getMedianDriver(),
  117.                              getFiringIntervalDetector().getDurationDriver());
  118.     }

  119. }