DateBasedManeuverTriggers.java

  1. /* Copyright 2002-2024 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.Collections;
  20. import java.util.List;

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

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

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

  36.     /** Minimum max check interval (avoids infinite loops if duration is zero).
  37.      * @since 11.2
  38.      */
  39.     private static final double MIN_MAX_CHECK = 1.0e-3;

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

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

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

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

  78.     /** {@inheritDoc} */
  79.     @Override
  80.     public String getName() {
  81.         return name;
  82.     }

  83.     /** Get the start date.
  84.      * @return the start date
  85.      */
  86.     public AbsoluteDate getStartDate() {
  87.         return getFiringIntervalDetector().getStartDriver().getDate();
  88.     }

  89.     /** Get the end date.
  90.      * @return the end date
  91.      */
  92.     public AbsoluteDate getEndDate() {
  93.         return getFiringIntervalDetector().getStopDriver().getDate();
  94.     }

  95.     /** Get the duration of the maneuver (s).
  96.      * duration = endDate - startDate
  97.      * @return the duration of the maneuver (s)
  98.      */
  99.     public double getDuration() {
  100.         return getEndDate().durationFrom(getStartDate());
  101.     }

  102.     /** {@inheritDoc} */
  103.     @Override
  104.     protected <D extends FieldAbstractDetector<D, S>, S extends CalculusFieldElement<S>> FieldAbstractDetector<D, S> convertIntervalDetector(final Field<S> field,
  105.                                                                                                                                              final ParameterDrivenDateIntervalDetector detector) {

  106.         final FieldParameterDrivenDateIntervalDetector<S> fd =
  107.                         new FieldParameterDrivenDateIntervalDetector<S>(field, "",
  108.                                         detector.getStartDriver().getBaseDate(),
  109.                                         detector.getStopDriver().getBaseDate());
  110.         fd.getStartDriver().setName(detector.getStartDriver().getName());
  111.         fd.getStopDriver().setName(detector.getStopDriver().getName());
  112.         fd.getMedianDriver().setName(detector.getMedianDriver().getName());
  113.         fd.getDurationDriver().setName(detector.getDurationDriver().getName());

  114.         @SuppressWarnings("unchecked")
  115.         final FieldAbstractDetector<D, S> converted = (FieldAbstractDetector<D, S>) fd;
  116.         return converted;

  117.     }

  118.     /** {@inheritDoc} */
  119.     @Override
  120.     public List<ParameterDriver> getParametersDrivers() {
  121.         return Collections.unmodifiableList(Arrays.asList(getFiringIntervalDetector().getStartDriver(),
  122.                                                           getFiringIntervalDetector().getStopDriver(),
  123.                                                           getFiringIntervalDetector().getMedianDriver(),
  124.                                                           getFiringIntervalDetector().getDurationDriver()));
  125.     }
  126. }