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.  */
  29. public class FieldOrekitStepNormalizer <T extends CalculusFieldElement<T>> implements FieldOrekitStepHandler<T> {

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

  102.         }
  103.     }

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

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

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

  112.     }

  113. }