FieldOrekitStepNormalizer.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF 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.sampling;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.orekit.propagation.FieldSpacecraftState;
  20. import org.orekit.time.FieldAbsoluteDate;

  21. /**
  22.  * This class wraps an object implementing {@link OrekitFixedStepHandler}
  23.  * into a {@link OrekitStepHandler}.

  24.  * <p>It mirrors the <code>StepNormalizer</code> interface from <a
  25.  * href="http://commons.apache.org/math/">commons-math</a> but
  26.  * provides a space-dynamics interface to the methods.</p>
  27.  * @author Luc Maisonobe
  28.  * @param <T> type of the field elements
  29.  */
  30. public class FieldOrekitStepNormalizer <T extends CalculusFieldElement<T>> implements FieldOrekitStepHandler<T> {

  31.     /** Fixed time step. */
  32.     private T h;

  33.     /** Underlying step handler. */
  34.     private FieldOrekitFixedStepHandler<T> handler;

  35.     /** Last State vector. */
  36.     private FieldSpacecraftState<T> lastState;

  37.     /** Integration direction indicator. */
  38.     private boolean forward;

  39.     /** Simple constructor.
  40.      * @param h fixed time step (sign is not used)
  41.      * @param handler fixed time step handler to wrap
  42.      */
  43.     public FieldOrekitStepNormalizer(final T h, final FieldOrekitFixedStepHandler<T> handler) {
  44.         this.h       = h.abs();
  45.         this.handler = handler;
  46.         lastState = null;
  47.         forward   = true;
  48.     }

  49.     /** Get the fixed time step.
  50.      * @return fixed time step
  51.      * @since 11.0
  52.      */
  53.     public T getFixedTimeStep() {
  54.         return h;
  55.     }

  56.     /** Get the underlying fixed step handler.
  57.      * @return underlying fixed step handler
  58.      * @since 11.0
  59.      */
  60.     public FieldOrekitFixedStepHandler<T> getFixedStepHandler() {
  61.         return handler;
  62.     }

  63.     /** Determines whether this handler needs dense output.
  64.      * This handler needs dense output in order to provide data at
  65.      * regularly spaced steps regardless of the steps the propagator
  66.      * uses, so this method always returns true.
  67.      * @return always true
  68.      */
  69.     public boolean requiresDenseOutput() {
  70.         return true;
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     public void init(final FieldSpacecraftState<T> s0, final FieldAbsoluteDate<T> t) {
  75.         lastState = null;
  76.         forward   = true;
  77.         handler.init(s0, t, h);
  78.     }

  79.     /** {@inheritDoc} */
  80.     @Override
  81.     public void handleStep(final FieldOrekitStepInterpolator<T> interpolator) {

  82.         if (lastState == null) {
  83.             // initialize lastState in the first step case
  84.             lastState = interpolator.getPreviousState();
  85.         }
  86.         // take the propagation direction into account
  87.         T step = h;
  88.         forward = interpolator.isForward();
  89.         if (!forward) {
  90.             step = h.multiply(-1);
  91.         }


  92.         // use the interpolator to push fixed steps events to the underlying handler
  93.         FieldAbsoluteDate<T> nextTime = lastState.getDate().shiftedBy(step);
  94.         boolean nextInStep = forward ^ nextTime.compareTo(interpolator.getCurrentState().getDate()) > 0;
  95.         while (nextInStep) {

  96.             // output the stored previous step
  97.             handler.handleStep(lastState);

  98.             // store the next step
  99.             lastState = interpolator.getInterpolatedState(nextTime);

  100.             // prepare next iteration
  101.             nextTime = nextTime.shiftedBy(step);
  102.             nextInStep = forward ^ nextTime.compareTo(interpolator.getCurrentState().getDate()) > 0;

  103.         }
  104.     }

  105.     /** {@inheritDoc} */
  106.     @Override
  107.     public void finish(final FieldSpacecraftState<T> finalState) {

  108.         // there will be no more steps,
  109.         // the stored one should be handled now
  110.         handler.handleStep(lastState);

  111.         // and the final state handled too
  112.         handler.finish(finalState);

  113.     }

  114. }