CelestialBodyFactory.java

  1. /* Copyright 2002-2025 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.bodies;

  18. import org.orekit.annotation.DefaultDataContext;
  19. import org.orekit.data.DataContext;

  20. /** Factory class for bodies of the solar system.
  21.  * <p>The {@link #getSun() Sun}, the {@link #getMoon() Moon} and the planets
  22.  * (including the Pluto dwarf planet) are provided by this factory. In addition,
  23.  * two important points are provided for convenience: the {@link
  24.  * #getSolarSystemBarycenter() solar system barycenter} and the {@link
  25.  * #getEarthMoonBarycenter() Earth-Moon barycenter}.</p>
  26.  * <p>The underlying body-centered frames are either direct children of {@link
  27.  * org.orekit.frames.FramesFactory#getEME2000() EME2000} (for {@link #getMoon() Moon}
  28.  * and {@link #getEarthMoonBarycenter() Earth-Moon barycenter}) or children from other
  29.  * body-centered frames. For example, the path from EME2000 to
  30.  * Jupiter-centered frame is: EME2000, Earth-Moon barycenter centered,
  31.  * solar system barycenter centered, Jupiter-centered. The defining transforms
  32.  * of these frames are combinations of simple linear {@link
  33.  * org.orekit.frames.Transform#Transform(org.orekit.time.AbsoluteDate,
  34.  * org.hipparchus.geometry.euclidean.threed.Vector3D,
  35.  * org.hipparchus.geometry.euclidean.threed.Vector3D) translation/velocity} transforms
  36.  * without any rotation. The frame axes are therefore always parallel to
  37.  * {@link org.orekit.frames.FramesFactory#getEME2000() EME2000} frame axes.</p>
  38.  * <p>The position of the bodies provided by this class are interpolated using
  39.  * the JPL DE 405/DE 406 ephemerides.</p>
  40.  * @author Luc Maisonobe
  41.  */
  42. public class CelestialBodyFactory {

  43.     /** Predefined name for solar system barycenter.
  44.      * @see #getBody(String)
  45.      */
  46.     public static final String SOLAR_SYSTEM_BARYCENTER = "solar system barycenter";

  47.     /** Predefined name for Sun.
  48.      * @see #getBody(String)
  49.      */
  50.     public static final String SUN = "Sun";

  51.     /** Predefined name for Mercury.
  52.      * @see #getBody(String)
  53.      */
  54.     public static final String MERCURY = "Mercury";

  55.     /** Predefined name for Venus.
  56.      * @see #getBody(String)
  57.      */
  58.     public static final String VENUS = "Venus";

  59.     /** Predefined name for Earth-Moon barycenter.
  60.      * @see #getBody(String)
  61.      */
  62.     public static final String EARTH_MOON = "Earth-Moon barycenter";

  63.     /** Predefined name for Earth.
  64.      * @see #getBody(String)
  65.      */
  66.     public static final String EARTH = "Earth";

  67.     /** Predefined name for Moon.
  68.      * @see #getBody(String)
  69.      */
  70.     public static final String MOON = "Moon";

  71.     /** Predefined name for Mars.
  72.      * @see #getBody(String)
  73.      */
  74.     public static final String MARS = "Mars";

  75.     /** Predefined name for Jupiter.
  76.      * @see #getBody(String)
  77.      */
  78.     public static final String JUPITER = "Jupiter";

  79.     /** Predefined name for Saturn.
  80.      * @see #getBody(String)
  81.      */
  82.     public static final String SATURN = "Saturn";

  83.     /** Predefined name for Uranus.
  84.      * @see #getBody(String)
  85.      */
  86.     public static final String URANUS = "Uranus";

  87.     /** Predefined name for Neptune.
  88.      * @see #getBody(String)
  89.      */
  90.     public static final String NEPTUNE = "Neptune";

  91.     /** Predefined name for Pluto.
  92.      * @see #getBody(String)
  93.      */
  94.     public static final String PLUTO = "Pluto";

  95.     /** Private constructor.
  96.      * <p>This class is a utility class, it should neither have a public
  97.      * nor a default constructor. This private constructor prevents
  98.      * the compiler from generating one automatically.</p>
  99.      */
  100.     private CelestialBodyFactory() {
  101.     }

  102.     /**
  103.      * Get the instance of {@link CelestialBodies} that is called by the static methods in
  104.      * this class.
  105.      *
  106.      * @return the reference frames used by this factory.
  107.      */
  108.     @DefaultDataContext
  109.     public static LazyLoadedCelestialBodies getCelestialBodies() {
  110.         return DataContext.getDefault().getCelestialBodies();
  111.     }

  112.     /** Add a loader for celestial bodies.
  113.      * @param name name of the body (may be one of the predefined names or a user-defined name)
  114.      * @param loader custom loader to add for the body
  115.      * @see #addDefaultCelestialBodyLoader(String)
  116.      * @see #clearCelestialBodyLoaders(String)
  117.      * @see #clearCelestialBodyLoaders()
  118.      */
  119.     @DefaultDataContext
  120.     public static void addCelestialBodyLoader(final String name,
  121.                                               final CelestialBodyLoader loader) {
  122.         getCelestialBodies().addCelestialBodyLoader(name, loader);
  123.     }

  124.     /** Add the default loaders for all predefined celestial bodies.
  125.      * @param supportedNames regular expression for supported files names
  126.      * (may be null if the default JPL file names are used)
  127.      * <p>
  128.      * The default loaders look for DE405 or DE406 JPL ephemerides.
  129.      * </p>
  130.      * @see <a href="ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de405/">DE405 JPL ephemerides</a>
  131.      * @see <a href="ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de406/">DE406 JPL ephemerides</a>
  132.      * @see #addCelestialBodyLoader(String, CelestialBodyLoader)
  133.      * @see #addDefaultCelestialBodyLoader(String)
  134.      * @see #clearCelestialBodyLoaders(String)
  135.      * @see #clearCelestialBodyLoaders()
  136.      */
  137.     @DefaultDataContext
  138.     public static void addDefaultCelestialBodyLoader(final String supportedNames) {
  139.         getCelestialBodies().addDefaultCelestialBodyLoader(supportedNames);
  140.     }

  141.     /** Add the default loaders for celestial bodies.
  142.      * @param name name of the body (if not one of the predefined names, the method does nothing)
  143.      * @param supportedNames regular expression for supported files names
  144.      * (may be null if the default JPL file names are used)
  145.      * <p>
  146.      * The default loaders look for DE405 or DE406 JPL ephemerides.
  147.      * </p>
  148.      * @see <a href="ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de405/">DE405 JPL ephemerides</a>
  149.      * @see <a href="ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de406/">DE406 JPL ephemerides</a>
  150.      * @see #addCelestialBodyLoader(String, CelestialBodyLoader)
  151.      * @see #addDefaultCelestialBodyLoader(String)
  152.      * @see #clearCelestialBodyLoaders(String)
  153.      * @see #clearCelestialBodyLoaders()
  154.      */
  155.     @DefaultDataContext
  156.     public static void addDefaultCelestialBodyLoader(final String name,
  157.                                                      final String supportedNames) {
  158.         getCelestialBodies().addDefaultCelestialBodyLoader(name, supportedNames);
  159.     }

  160.     /** Clear loaders for one celestial body.
  161.      * <p>
  162.      * Calling this method also clears the celestial body that
  163.      * has been loaded via this {@link CelestialBodyLoader}.
  164.      * </p>
  165.      * @param name name of the body
  166.      * @see #addCelestialBodyLoader(String, CelestialBodyLoader)
  167.      * @see #clearCelestialBodyLoaders()
  168.      * @see #clearCelestialBodyCache(String)
  169.      */
  170.     @DefaultDataContext
  171.     public static void clearCelestialBodyLoaders(final String name) {
  172.         getCelestialBodies().clearCelestialBodyLoaders(name);
  173.     }

  174.     /** Clear loaders for all celestial bodies.
  175.      * <p>
  176.      * Calling this method also clears all loaded celestial bodies.
  177.      * </p>
  178.      * @see #addCelestialBodyLoader(String, CelestialBodyLoader)
  179.      * @see #clearCelestialBodyLoaders(String)
  180.      * @see #clearCelestialBodyCache()
  181.      */
  182.     @DefaultDataContext
  183.     public static void clearCelestialBodyLoaders() {
  184.         getCelestialBodies().clearCelestialBodyLoaders();
  185.     }

  186.     /** Clear the specified celestial body from the internal cache.
  187.      * @param name name of the body
  188.      */
  189.     @DefaultDataContext
  190.     public static void clearCelestialBodyCache(final String name) {
  191.         getCelestialBodies().clearCelestialBodyCache(name);
  192.     }

  193.     /** Clear all loaded celestial bodies.
  194.      * <p>
  195.      * Calling this method will remove all loaded bodies from the internal
  196.      * cache. Subsequent calls to {@link #getBody(String)} or similar methods
  197.      * will result in a reload of the requested body from the configured loader(s).
  198.      * </p>
  199.      */
  200.     @DefaultDataContext
  201.     public static void clearCelestialBodyCache() {
  202.         getCelestialBodies().clearCelestialBodyCache();
  203.     }

  204.     /** Get the solar system barycenter aggregated body.
  205.      * <p>
  206.      * Both the {@link CelestialBody#getInertiallyOrientedFrame() inertially
  207.      * oriented frame} and {@link CelestialBody#getBodyOrientedFrame() body
  208.      * oriented frame} for this aggregated body are aligned with
  209.      * {@link org.orekit.frames.FramesFactory#getICRF() ICRF} (and therefore also
  210.      * {@link org.orekit.frames.FramesFactory#getGCRF() GCRF})
  211.      * </p>
  212.      * @return solar system barycenter aggregated body
  213.      */
  214.     @DefaultDataContext
  215.     public static CelestialBody getSolarSystemBarycenter() {
  216.         return getCelestialBodies().getSolarSystemBarycenter();
  217.     }

  218.     /** Get the Sun singleton body.
  219.      * @return Sun body
  220.      */
  221.     @DefaultDataContext
  222.     public static CelestialBody getSun() {
  223.         return getCelestialBodies().getSun();
  224.     }

  225.     /** Get the Mercury singleton body.
  226.      * @return Sun body
  227.      */
  228.     @DefaultDataContext
  229.     public static CelestialBody getMercury() {
  230.         return getCelestialBodies().getMercury();
  231.     }

  232.     /** Get the Venus singleton body.
  233.      * @return Venus body
  234.      */
  235.     @DefaultDataContext
  236.     public static CelestialBody getVenus() {
  237.         return getCelestialBodies().getVenus();
  238.     }

  239.     /** Get the Earth-Moon barycenter singleton bodies pair.
  240.      * <p>
  241.      * Both the {@link CelestialBody#getInertiallyOrientedFrame() inertially
  242.      * oriented frame} and {@link CelestialBody#getBodyOrientedFrame() body
  243.      * oriented frame} for this bodies pair are aligned with
  244.      * {@link org.orekit.frames.FramesFactory#getICRF() ICRF} (and therefore also
  245.      * {@link org.orekit.frames.FramesFactory#getGCRF() GCRF})
  246.      * </p>
  247.      * @return Earth-Moon barycenter bodies pair
  248.      */
  249.     @DefaultDataContext
  250.     public static CelestialBody getEarthMoonBarycenter() {
  251.         return getCelestialBodies().getEarthMoonBarycenter();
  252.     }

  253.     /** Get the Earth singleton body.
  254.      * @return Earth body
  255.      */
  256.     @DefaultDataContext
  257.     public static CelestialBody getEarth() {
  258.         return getCelestialBodies().getEarth();
  259.     }

  260.     /** Get the Moon singleton body.
  261.      * @return Moon body
  262.      */
  263.     @DefaultDataContext
  264.     public static CelestialBody getMoon() {
  265.         return getCelestialBodies().getMoon();
  266.     }

  267.     /** Get the Mars singleton body.
  268.      * @return Mars body
  269.      */
  270.     @DefaultDataContext
  271.     public static CelestialBody getMars() {
  272.         return getCelestialBodies().getMars();
  273.     }

  274.     /** Get the Jupiter singleton body.
  275.      * @return Jupiter body
  276.      */
  277.     @DefaultDataContext
  278.     public static CelestialBody getJupiter() {
  279.         return getCelestialBodies().getJupiter();
  280.     }

  281.     /** Get the Saturn singleton body.
  282.      * @return Saturn body
  283.      */
  284.     @DefaultDataContext
  285.     public static CelestialBody getSaturn() {
  286.         return getCelestialBodies().getSaturn();
  287.     }

  288.     /** Get the Uranus singleton body.
  289.      * @return Uranus body
  290.      */
  291.     @DefaultDataContext
  292.     public static CelestialBody getUranus() {
  293.         return getCelestialBodies().getUranus();
  294.     }

  295.     /** Get the Neptune singleton body.
  296.      * @return Neptune body
  297.      */
  298.     @DefaultDataContext
  299.     public static CelestialBody getNeptune() {
  300.         return getCelestialBodies().getNeptune();
  301.     }

  302.     /** Get the Pluto singleton body.
  303.      * @return Pluto body
  304.      */
  305.     @DefaultDataContext
  306.     public static CelestialBody getPluto() {
  307.         return getCelestialBodies().getPluto();
  308.     }

  309.     /** Get a celestial body.
  310.      * <p>
  311.      * If no {@link CelestialBodyLoader} has been added by calling {@link
  312.      * #addCelestialBodyLoader(String, CelestialBodyLoader)
  313.      * addCelestialBodyLoader} or if {@link #clearCelestialBodyLoaders(String)
  314.      * clearCelestialBodyLoaders} has been called afterwards,
  315.      * the {@link #addDefaultCelestialBodyLoader(String, String)
  316.      * addDefaultCelestialBodyLoader} method will be called automatically,
  317.      * once with the default name for JPL DE ephemerides and once with the
  318.      * default name for IMCCE INPOP files.
  319.      * </p>
  320.      * @param name name of the celestial body
  321.      * @return celestial body
  322.      */
  323.     @DefaultDataContext
  324.     public static CelestialBody getBody(final String name) {
  325.         return getCelestialBodies().getBody(name);
  326.     }

  327. }