FieldSecondaryODE.java

  1. /*
  2.  * Licensed to the Hipparchus project under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The Hipparchus project 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.  *      https://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.hipparchus.ode;

  18. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.exception.MathIllegalArgumentException;
  20. import org.hipparchus.exception.MathIllegalStateException;

  21. /**
  22.  * This interface allows users to add secondary differential equations to a primary
  23.  * set of differential equations.
  24.  * <p>
  25.  * In some cases users may need to integrate some problem-specific equations along
  26.  * with a primary set of differential equations. One example is optimal control where
  27.  * adjoined parameters linked to the minimized Hamiltonian must be integrated.
  28.  * </p>
  29.  * <p>
  30.  * This interface allows users to add such equations to a primary set of {@link
  31.  * FieldOrdinaryDifferentialEquation first order differential equations}
  32.  * thanks to the {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryODE)}
  33.  * method.
  34.  * </p>
  35.  * @see FieldOrdinaryDifferentialEquation
  36.  * @see FieldExpandableODE
  37.  * @param <T> the type of the field elements
  38.  */
  39. public interface FieldSecondaryODE<T extends CalculusFieldElement<T>> {

  40.     /** Get the dimension of the secondary state parameters.
  41.      * @return dimension of the secondary state parameters
  42.      */
  43.     int getDimension();

  44.     /** Initialize equations at the start of an ODE integration.
  45.      * <p>
  46.      * This method is called once at the start of the integration. It
  47.      * may be used by the equations to initialize some internal data
  48.      * if needed.
  49.      * </p>
  50.      * <p>
  51.      * The default implementation does nothing.
  52.      * </p>
  53.      * @param t0 value of the independent <I>time</I> variable at integration start
  54.      * @param primary0 array containing the value of the primary state vector at integration start
  55.      * @param secondary0 array containing the value of the secondary state vector at integration start
  56.      * @param finalTime target time for the integration
  57.      */
  58.     default void init(T t0, T[] primary0, T[] secondary0, T finalTime) {
  59.         // nothing by default
  60.     }

  61.     /** Compute the derivatives related to the secondary state parameters.
  62.      * <p>
  63.      * In some cases, additional equations can require to change the derivatives
  64.      * of the primary state (i.e. the content of the {@code primaryDot} array).
  65.      * One use case is optimal control, when the secondary equations handle co-state,
  66.      * which changes control, and the control changes the primary state. In this
  67.      * case, the primary and secondary equations are not really independent from each
  68.      * other, so if possible it would be better to put state and co-state and their
  69.      * equations all in the primary equations. As this is not always possible, this
  70.      * method explicitly <em>allows</em> to modify the content of the {@code primaryDot}
  71.      * array. This array will be used to evolve the primary state only <em>after</em>
  72.      * all secondary equations have computed their derivatives, hence allowing this
  73.      * side effect.
  74.      * </p>
  75.      * @param t current value of the independent <I>time</I> variable
  76.      * @param primary array containing the current value of the primary state vector
  77.      * @param primaryDot array containing the derivative of the primary state vector
  78.      * (the method is allowed to change the derivatives here, when the additional
  79.      * equations do have an effect on the primary equations)
  80.      * @param secondary array containing the current value of the secondary state vector
  81.      * @return derivative of the secondary state vector
  82.      * @exception MathIllegalStateException if the number of functions evaluations is exceeded
  83.      * @exception MathIllegalArgumentException if arrays dimensions do not match equations settings
  84.      */
  85.     T[] computeDerivatives(T t, T[] primary, T[] primaryDot, T[] secondary)
  86.         throws MathIllegalArgumentException, MathIllegalStateException;

  87. }