OceanTides.java

  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.forces.gravity;

  18. import java.util.List;
  19. import java.util.stream.Stream;

  20. import org.hipparchus.CalculusFieldElement;
  21. import org.hipparchus.Field;
  22. import org.hipparchus.geometry.euclidean.threed.FieldVector3D;
  23. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  24. import org.orekit.annotation.DefaultDataContext;
  25. import org.orekit.data.DataContext;
  26. import org.orekit.forces.ForceModel;
  27. import org.orekit.forces.gravity.potential.CachedNormalizedSphericalHarmonicsProvider;
  28. import org.orekit.forces.gravity.potential.GravityFields;
  29. import org.orekit.forces.gravity.potential.NormalizedSphericalHarmonicsProvider;
  30. import org.orekit.forces.gravity.potential.OceanTidesWave;
  31. import org.orekit.frames.Frame;
  32. import org.orekit.propagation.FieldSpacecraftState;
  33. import org.orekit.propagation.SpacecraftState;
  34. import org.orekit.propagation.events.EventDetector;
  35. import org.orekit.propagation.events.FieldEventDetector;
  36. import org.orekit.time.TimeScales;
  37. import org.orekit.time.UT1Scale;
  38. import org.orekit.utils.Constants;
  39. import org.orekit.utils.IERSConventions;
  40. import org.orekit.utils.OrekitConfiguration;
  41. import org.orekit.utils.ParameterDriver;

  42. /** Ocean tides force model.
  43.  * @since 6.1
  44.  * @author Luc Maisonobe
  45.  */
  46. public class OceanTides implements ForceModel {

  47.     /** Default step for tides field sampling (seconds). */
  48.     public static final double DEFAULT_STEP = 600.0;

  49.     /** Default number of points tides field sampling. */
  50.     public static final int DEFAULT_POINTS = 12;

  51.     /** Underlying attraction model. */
  52.     private final ForceModel attractionModel;

  53.     /** Simple constructor.
  54.      * <p>
  55.      * This constructor uses pole tides, the default {@link #DEFAULT_STEP step} and default
  56.      * {@link #DEFAULT_POINTS number of points} for the tides field interpolation.
  57.      * </p>
  58.      *
  59.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  60.      *
  61.      * @param centralBodyFrame rotating body frame
  62.      * @param ae central body reference radius
  63.      * @param mu central body attraction coefficient
  64.      * @param degree degree of the tide model to load
  65.      * @param order order of the tide model to load
  66.      * @param conventions IERS conventions used for loading ocean pole tide
  67.      * @param ut1 UT1 time scale
  68.      * @see #DEFAULT_STEP
  69.      * @see #DEFAULT_POINTS
  70.      * @see #OceanTides(Frame, double, double, boolean, double, int, int, int, IERSConventions, UT1Scale)
  71.      * @see GravityFields#getOceanTidesWaves(int, int)
  72.      * @see #OceanTides(Frame, double, double, boolean, double, int, int, int,
  73.      * IERSConventions, UT1Scale, GravityFields)
  74.      */
  75.     @DefaultDataContext
  76.     public OceanTides(final Frame centralBodyFrame, final double ae, final double mu,
  77.                       final int degree, final int order,
  78.                       final IERSConventions conventions, final UT1Scale ut1) {
  79.         this(centralBodyFrame, ae, mu, true,
  80.              DEFAULT_STEP, DEFAULT_POINTS, degree, order,
  81.              conventions, ut1);
  82.     }

  83.     /** Simple constructor.
  84.      *
  85.      * <p>This constructor uses the {@link DataContext#getDefault() default data context}.
  86.      *
  87.      * @param centralBodyFrame rotating body frame
  88.      * @param ae central body reference radius
  89.      * @param mu central body attraction coefficient
  90.      * @param poleTide if true, pole tide is computed
  91.      * @param step time step between sample points for interpolation
  92.      * @param nbPoints number of points to use for interpolation, if less than 2
  93.      * then no interpolation is performed (thus greatly increasing computation cost)
  94.      * @param degree degree of the tide model to load
  95.      * @param order order of the tide model to load
  96.      * @param conventions IERS conventions used for loading ocean pole tide
  97.      * @param ut1 UT1 time scale
  98.      * @see GravityFields#getOceanTidesWaves(int, int)
  99.      * @see #OceanTides(Frame, double, double, boolean, double, int, int, int,
  100.      * IERSConventions, UT1Scale, GravityFields)
  101.      */
  102.     @DefaultDataContext
  103.     public OceanTides(final Frame centralBodyFrame, final double ae, final double mu,
  104.                       final boolean poleTide, final double step, final int nbPoints,
  105.                       final int degree, final int order,
  106.                       final IERSConventions conventions, final UT1Scale ut1) {
  107.         this(centralBodyFrame, ae, mu, poleTide, step, nbPoints, degree, order,
  108.                 conventions, ut1, DataContext.getDefault().getGravityFields());
  109.     }

  110.     /** Simple constructor.
  111.      * @param centralBodyFrame rotating body frame
  112.      * @param ae central body reference radius
  113.      * @param mu central body attraction coefficient
  114.      * @param poleTide if true, pole tide is computed
  115.      * @param step time step between sample points for interpolation
  116.      * @param nbPoints number of points to use for interpolation, if less than 2
  117.      * then no interpolation is performed (thus greatly increasing computation cost)
  118.      * @param degree degree of the tide model to load
  119.      * @param order order of the tide model to load
  120.      * @param conventions IERS conventions used for loading ocean pole tide
  121.      * @param ut1 UT1 time scale
  122.      * @param gravityFields used to compute ocean tides.
  123.      * @see GravityFields#getOceanTidesWaves(int, int)
  124.      * @since 10.1
  125.      */
  126.     public OceanTides(final Frame centralBodyFrame, final double ae, final double mu,
  127.                       final boolean poleTide, final double step, final int nbPoints,
  128.                       final int degree, final int order,
  129.                       final IERSConventions conventions, final UT1Scale ut1,
  130.                       final GravityFields gravityFields) {

  131.         // load the ocean tides model
  132.         final List<OceanTidesWave> waves = gravityFields.getOceanTidesWaves(degree, order);

  133.         final TimeScales timeScales = ut1.getEOPHistory().getTimeScales();
  134.         final OceanTidesField raw =
  135.                 new OceanTidesField(ae, mu, waves,
  136.                                     conventions.getNutationArguments(ut1, timeScales),
  137.                                     poleTide ? conventions.getOceanPoleTide(ut1.getEOPHistory()) : null);

  138.         final NormalizedSphericalHarmonicsProvider provider;
  139.         if (nbPoints < 2) {
  140.             provider = raw;
  141.         } else {
  142.             provider =
  143.                 new CachedNormalizedSphericalHarmonicsProvider(raw, step, nbPoints,
  144.                                                                OrekitConfiguration.getCacheSlotsNumber(),
  145.                                                                7 * Constants.JULIAN_DAY,
  146.                                                                0.5 * Constants.JULIAN_DAY);
  147.         }

  148.         attractionModel = new HolmesFeatherstoneAttractionModel(centralBodyFrame, provider);

  149.     }

  150.     /** {@inheritDoc} */
  151.     @Override
  152.     public boolean dependsOnPositionOnly() {
  153.         return attractionModel.dependsOnPositionOnly();
  154.     }

  155.     /** {@inheritDoc} */
  156.     @Override
  157.     public Vector3D acceleration(final SpacecraftState s, final double[] parameters) {
  158.         // delegate to underlying model
  159.         return attractionModel.acceleration(s, parameters);
  160.     }

  161.     /** {@inheritDoc} */
  162.     @Override
  163.     public <T extends CalculusFieldElement<T>> FieldVector3D<T> acceleration(final FieldSpacecraftState<T> s,
  164.                                                                          final T[] parameters) {
  165.         // delegate to underlying model
  166.         return attractionModel.acceleration(s, parameters);
  167.     }


  168.     /** {@inheritDoc} */
  169.     @Override
  170.     public Stream<EventDetector> getEventDetectors() {
  171.         // delegate to underlying attraction model
  172.         return attractionModel.getEventDetectors();
  173.     }

  174.     /** {@inheritDoc} */
  175.     @Override
  176.     public <T extends CalculusFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventDetectors(final Field<T> field) {
  177.         // delegate to underlying attraction model
  178.         return attractionModel.getFieldEventDetectors(field);
  179.     }

  180.     /** {@inheritDoc} */
  181.     @Override
  182.     public List<ParameterDriver> getParametersDrivers() {
  183.         // delegate to underlying attraction model
  184.         return attractionModel.getParametersDrivers();
  185.     }

  186. }