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.estimation.measurements.modifiers;
18  
19  import org.hipparchus.geometry.euclidean.threed.Vector3D;
20  import org.hipparchus.util.FastMath;
21  import org.orekit.estimation.measurements.EstimatedMeasurementBase;
22  import org.orekit.estimation.measurements.EstimationModifier;
23  import org.orekit.estimation.measurements.ObservedMeasurement;
24  import org.orekit.utils.Constants;
25  import org.orekit.utils.TimeStampedPVCoordinates;
26  
27  /** Class modifying theoretical range measurement with Shapiro time delay.
28   * <p>
29   * Shapiro time delay is a relativistic effect due to gravity.
30   * </p>
31   * @author Luc Maisonobe
32   * @since 10.0
33   */
34  public class AbstractShapiroBaseModifier {
35  
36      /** Shapiro effect scale factor. */
37      private final double s;
38  
39      /** Simple constructor.
40       * @param gm gravitational constant for main body in signal path vicinity.
41       */
42      public AbstractShapiroBaseModifier(final double gm) {
43          this.s = 2 * gm / (Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT);
44      }
45  
46      /** Modify measurement.
47       * @param <T> type of the measurements
48       * @param modifier applied modifier
49       * @param estimated measurement to modify
50       * @since 12.1
51       */
52      protected <T extends ObservedMeasurement<T>> void doModify(final EstimationModifier<T> modifier,
53                                                                 final EstimatedMeasurementBase<T> estimated) {
54  
55          // compute correction, for one way or two way measurements
56          final TimeStampedPVCoordinates[] pv = estimated.getParticipants();
57          final double correction = pv.length < 3 ?
58                                    shapiroCorrection(pv[0], pv[1]) :
59                                    0.5 * (shapiroCorrection(pv[0], pv[1]) + shapiroCorrection(pv[1], pv[2]));
60  
61          // update estimated value taking into account the Shapiro time delay.
62          final double[] newValue = estimated.getEstimatedValue().clone();
63          newValue[0] = newValue[0] + correction;
64          estimated.modifyEstimatedValue(modifier, newValue);
65  
66      }
67  
68      /** Compute Shapiro path dilation between two points in a gravity field.
69       * @param pvEmitter coordinates of emitter in body-centered frame
70       * @param pvReceiver coordinates of receiver in body-centered frame
71       * @return path dilation to add to raw measurement
72       */
73      protected double shapiroCorrection(final TimeStampedPVCoordinates pvEmitter, final TimeStampedPVCoordinates pvReceiver) {
74          final Vector3D pEmitter  = pvEmitter.getPosition();
75          final Vector3D pReceiver = pvReceiver.getPosition();
76          final double   rEpR      = pEmitter.getNorm() + pReceiver.getNorm();
77          final double   d         = Vector3D.distance(pEmitter, pReceiver);
78          return s * FastMath.log((rEpR + d) / (rEpR - d));
79      }
80  
81  }