ComplexSecondaryODE.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.complex.Complex;
  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.  * OrdinaryDifferentialEquation first order differential equations}
  32.  * thanks to the {@link
  33.  * ExpandableODE#addSecondaryEquations(SecondaryODE)}
  34.  * method, after having converted the instance to {@link SecondaryODE}
  35.  * </p>
  36.  * @see ExpandableODE
  37.  * @see ComplexODEConverter
  38.  * @since 1.4
  39.  */
  40. public interface ComplexSecondaryODE {

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

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

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

  88. }