SecondaryODE.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.exception.MathIllegalArgumentException;
  19. import org.hipparchus.exception.MathIllegalStateException;

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

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

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

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

  85. }