ConstantGrid.java

  1. /* Copyright 2022-2025 Thales Alenia Space
  2.  * Licensed to CS Communication & Systèmes (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.models.earth.troposphere.iturp834;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.analysis.interpolation.GridAxis;
  20. import org.orekit.bodies.FieldGeodeticPoint;
  21. import org.orekit.bodies.GeodeticPoint;
  22. import org.orekit.utils.units.Unit;

  23. /** Constant (with respect to time) grid data.
  24.  * @author Luc Maisonobe
  25.  * @since 13.0
  26.  */
  27. class ConstantGrid extends AbstractGrid {

  28.     /** Constant data. */
  29.     private final double[][] data;

  30.     /** Build a grid by parsing a resource file.
  31.      * @param unit unit of values in resource file
  32.      * @param name name of the resource holding the data
  33.      */
  34.     ConstantGrid(final Unit unit, final String name) {
  35.         data = parse(unit, name);
  36.     }

  37.     /** Build a grid by parsing a resource file.
  38.      * @param data constant data
  39.      */
  40.     private ConstantGrid(final double[][] data) {
  41.         this.data = data;
  42.     }

  43.     /** Create a grid by applying a function to all nodes.
  44.      * @param function function to apply to all nodes
  45.      * @return new grid
  46.      */
  47.     public ConstantGrid apply(final Function function) {
  48.         final GridAxis latitudeAxis  = getLatitudeAxis();
  49.         final GridAxis longitudeAxis = getLongitudeAxis();
  50.         final double[][] values = new double[latitudeAxis.size()][longitudeAxis.size()];
  51.         for (int i = 0; i < latitudeAxis.size(); ++i) {
  52.             final double latitude = latitudeAxis.node(i);
  53.             for (int j = 0; j < longitudeAxis.size(); ++j) {
  54.                 values[i][j] = function.apply(latitude, longitudeAxis.node(j), data[i][j]);
  55.             }
  56.         }
  57.         return new ConstantGrid(values);
  58.     }

  59.     /** {@inheritDoc} */
  60.     @Override
  61.     public GridCell getCell(final GeodeticPoint location, final double ignored) {
  62.         return getRawCell(location, data);
  63.     }

  64.     /** {@inheritDoc} */
  65.     @Override
  66.     public <T extends CalculusFieldElement<T>> FieldGridCell<T> getCell(final FieldGeodeticPoint<T> location,
  67.                                                                         final T ignored) {
  68.         return getRawCell(location, data);
  69.     }

  70.     /** Interface for transforming nodes data. */
  71.     @FunctionalInterface
  72.     public interface Function {
  73.         /** Compute a new node data.
  74.          * @param latitude node latitude
  75.          * @param longitude node longitude
  76.          * @param data node value
  77.          * @return value for new node
  78.          */
  79.         double apply(double latitude, double longitude, double data);
  80.     }

  81. }