LinearKeplerianCovarianceHandler.java

  1. /* Copyright 2022-2025 Romain Serra
  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.propagation;

  18. import org.hipparchus.util.Pair;
  19. import org.orekit.orbits.Orbit;
  20. import org.orekit.propagation.sampling.OrekitFixedStepHandler;
  21. import org.orekit.propagation.sampling.OrekitStepHandler;
  22. import org.orekit.propagation.sampling.OrekitStepInterpolator;
  23. import org.orekit.time.AbsoluteDate;

  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.stream.Collectors;

  27. /**
  28.  * Class implementing step handlers to propagate orbital covariance using linearized Keplerian motion, no matter the propagation model.
  29.  * Although less precise than using the same perturbations than the propagator, it is more computationally performant.
  30.  *
  31.  * @author Romain Serra
  32.  * @since 13.1
  33.  * @see StateCovarianceMatrixProvider
  34.  */
  35. public class LinearKeplerianCovarianceHandler implements OrekitFixedStepHandler {

  36.     /** Initial orbital covariance. */
  37.     private final StateCovariance initialCovariance;

  38.     /** Logged states and covariances. */
  39.     private final List<Pair<SpacecraftState, StateCovariance>> statesWithCovariances = new ArrayList<>();

  40.     /**
  41.      * Constructor.
  42.      * @param initialCovariance initial orbital covariance
  43.      */
  44.     public LinearKeplerianCovarianceHandler(final StateCovariance initialCovariance) {
  45.         this.initialCovariance = initialCovariance;
  46.     }

  47.     /**
  48.      * Gets a copy of the covariances.
  49.      * @return state covariances
  50.      */
  51.     public List<StateCovariance> getStatesCovariances() {
  52.         return statesWithCovariances.stream().map(Pair::getValue).collect(Collectors.toList());
  53.     }

  54.     @Override
  55.     public void init(final SpacecraftState s0, final AbsoluteDate t, final double dt) {
  56.         OrekitFixedStepHandler.super.init(s0, t, dt);
  57.         statesWithCovariances.clear();
  58.         statesWithCovariances.add(new Pair<>(s0, initialCovariance));
  59.     }

  60.     @Override
  61.     public void handleStep(final SpacecraftState currentState) {
  62.         final Pair<SpacecraftState, StateCovariance> lastPair = statesWithCovariances.get(statesWithCovariances.size() - 1);
  63.         final Orbit lastOrbit = lastPair.getKey().getOrbit();
  64.         final LinearKeplerianCovarianceMapper covarianceHandler = new LinearKeplerianCovarianceMapper(lastOrbit,
  65.                 lastPair.getValue());
  66.         final StateCovariance currentCovariance = covarianceHandler.map(currentState.getOrbit());
  67.         statesWithCovariances.add(new Pair<>(currentState, currentCovariance));
  68.     }

  69.     /**
  70.      * Convert into a non-fixed step handler, based on the instance (so do not use it elsewhere for something else).
  71.      * @return fixed-step handler
  72.      * @see OrekitStepHandler
  73.      */
  74.     public OrekitStepHandler toOrekitStepHandler() {
  75.         final LinearKeplerianCovarianceHandler handler = new LinearKeplerianCovarianceHandler(initialCovariance);

  76.         return new OrekitStepHandler() {
  77.             @Override
  78.             public void init(final SpacecraftState s0, final AbsoluteDate t) {
  79.                 OrekitStepHandler.super.init(s0, t);
  80.                 handler.init(s0, t, 0.);
  81.                 statesWithCovariances.clear();
  82.             }

  83.             @Override
  84.             public void handleStep(final OrekitStepInterpolator interpolator) {
  85.                 handler.handleStep(interpolator.getCurrentState());
  86.             }

  87.             @Override
  88.             public void finish(final SpacecraftState finalState) {
  89.                 OrekitStepHandler.super.finish(finalState);
  90.                 statesWithCovariances.addAll(handler.statesWithCovariances);
  91.             }
  92.         };
  93.     }
  94. }