1   /* Copyright 2002-2026 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.propagation.relative;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.orekit.frames.FieldTransform;
21  import org.orekit.frames.Frame;
22  import org.orekit.frames.LOF;
23  import org.orekit.orbits.FieldOrbit;
24  import org.orekit.utils.TimeStampedFieldPVCoordinates;
25  
26  /**
27   * Abstraction class for Field RelativeProvider.
28   *
29   * @param <T> Any scalar field.
30   * @author Romain Cuvillon
31   * @since 14.0
32   */
33  public abstract class FieldAbstractRelativeProvider<T extends CalculusFieldElement<T>>
34                  implements FieldRelativeProvider<T> {
35  
36      /**
37       * Additional equations name.
38       */
39      private final String additionalEquationsName;
40  
41      /**
42       * Initial chaser PVT in the target's LOF.
43       */
44      private TimeStampedFieldPVCoordinates<T> initialChaserPVTLof;
45  
46      /**
47       * Target's orbit.
48       */
49      private FieldOrbit<T> targetOrbit;
50  
51      /**
52       * Local Orbital Frame.
53       */
54      private final LOF lof;
55  
56      /**
57       * Builds a new RelativeProvider object from the target orbit and an initial PVT of the chaser.
58       *
59       * @param targetOrbit             Target orbit
60       * @param initialChaserPVTLof     Chaser PVT in the target's  local orbital frame
61       * @param additionalEquationsName Additional equations name
62       * @param lof                     Local Orbital Frame
63       */
64      public FieldAbstractRelativeProvider(final FieldOrbit<T> targetOrbit,
65                                           final TimeStampedFieldPVCoordinates<T> initialChaserPVTLof,
66                                           final String additionalEquationsName,
67                                           final LOF lof) {
68          this.targetOrbit             = targetOrbit;
69          this.initialChaserPVTLof     = initialChaserPVTLof;
70          this.additionalEquationsName = additionalEquationsName;
71          this.lof                     = lof;
72      }
73  
74      /**
75       * Builds a new Relativeprovider object from the target orbit and an initial PVT of the chaser expressed in
76       * the given input frame.
77       *
78       * @param targetOrbit             Target orbit. Should be circular for better results
79       * @param initialChaserPVT        Chaser PVT in given frame
80       * @param inputPVTFrame           Input frame for the initial chaser PVT
81       * @param additionalEquationsName Additional equations name
82       * @param lof                     Local Orbital Frame
83       */
84      public FieldAbstractRelativeProvider(final FieldOrbit<T> targetOrbit,
85                                           final TimeStampedFieldPVCoordinates<T> initialChaserPVT,
86                                           final Frame inputPVTFrame,
87                                           final String additionalEquationsName,
88                                           final LOF lof) {
89          // Copy input parameters
90          this.targetOrbit             = targetOrbit;
91          this.additionalEquationsName = additionalEquationsName;
92          this.lof                     = lof;
93  
94          // Transform PV from input frame to inertial frame of target Orbit.
95          final FieldTransform<T> inputFrameToInertial = inputPVTFrame.getTransformTo(targetOrbit.getFrame(),
96                                                                                      targetOrbit.getDate());
97          final TimeStampedFieldPVCoordinates<T> pvInertial = inputFrameToInertial.transformPVCoordinates(initialChaserPVT);
98  
99          // Transform and set PV from inertial to target's LOF.
100         setInitialChaserPVTLof(getLof().transformFromInertial(targetOrbit.getDate(),
101                                                               targetOrbit.getPVCoordinates())
102                                        .transformPVCoordinates(pvInertial));
103     }
104 
105     /** {@inheritDoc}. */
106     @Override
107     public LOF getLof() {
108         return lof;
109     }
110 
111     /** {@inheritDoc}. */
112     @Override
113     public void setInitialChaserPVTLof(final TimeStampedFieldPVCoordinates<T> initialChaserPVTLof) {
114         this.initialChaserPVTLof = initialChaserPVTLof;
115     }
116 
117     /** {@inheritDoc}. */
118     @Override
119     public TimeStampedFieldPVCoordinates<T> getInitialChaserPVTLof() {
120         return initialChaserPVTLof;
121     }
122 
123     /** {@inheritDoc}. */
124     @Override
125     public String getName() {
126         return additionalEquationsName;
127     }
128 
129     /** {@inheritDoc}. */
130     @Override
131     public FieldOrbit<T> getTargetOrbit() {
132         return targetOrbit;
133     }
134 
135     /** {@inheritDoc}. */
136     @Override
137     public void setTargetOrbit(final FieldOrbit<T> targetOrbit) {
138         this.targetOrbit = targetOrbit;
139     }
140 }