View Javadoc
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  
18  package org.hipparchus.ode;
19  
20  import org.hipparchus.complex.Complex;
21  import org.hipparchus.exception.MathIllegalArgumentException;
22  import org.hipparchus.exception.MathIllegalStateException;
23  
24  /**
25   * This interface allows users to add secondary differential equations to a primary
26   * set of differential equations.
27   * <p>
28   * In some cases users may need to integrate some problem-specific equations along
29   * with a primary set of differential equations. One example is optimal control where
30   * adjoined parameters linked to the minimized hamiltonian must be integrated.
31   * </p>
32   * <p>
33   * This interface allows users to add such equations to a primary set of {@link
34   * OrdinaryDifferentialEquation first order differential equations}
35   * thanks to the {@link
36   * ExpandableODE#addSecondaryEquations(SecondaryODE)}
37   * method, after having converted the instance to {@link SecondaryODE}
38   * </p>
39   * @see ExpandableODE
40   * @see ComplexODEConverter
41   * @since 1.4
42   */
43  public interface ComplexSecondaryODE {
44  
45      /** Get the dimension of the secondary state parameters.
46       * @return dimension of the secondary state parameters
47       */
48      int getDimension();
49  
50      /** Initialize equations at the start of an ODE integration.
51       * <p>
52       * This method is called once at the start of the integration. It
53       * may be used by the equations to initialize some internal data
54       * if needed.
55       * </p>
56       * <p>
57       * The default implementation does nothing.
58       * </p>
59       * @param t0 value of the independent <I>time</I> variable at integration start
60       * @param primary0 array containing the value of the primary state vector at integration start
61       * @param secondary0 array containing the value of the secondary state vector at integration start
62       * @param finalTime target time for the integration
63       */
64      default void init(double t0, Complex[] primary0, Complex[] secondary0, double finalTime) {
65          // nothing by default
66      }
67  
68      /** Compute the derivatives related to the secondary state parameters.
69       * <p>
70       * In some cases, additional equations can require to change the derivatives
71       * of the primary state (i.e. the content of the {@code primaryDot} array).
72       * One use case is optimal control, when the secondary equations handle co-state,
73       * which changes control, and the control changes the primary state. In this
74       * case, the primary and secondary equations are not really independent from each
75       * other, so if possible it would be better to put state and co-state and their
76       * equations all in the primary equations. As this is not always possible, this
77       * method explicitly <em>allows</em> to modify the content of the {@code primaryDot}
78       * array. This array will be used to evolve the primary state only <em>after</em>
79       * all secondary equations have computed their derivatives, hence allowing this
80       * side effect.
81       * </p>
82       * @param t current value of the independent <I>time</I> variable
83       * @param primary array containing the current value of the primary state vector
84       * @param primaryDot array containing the derivative of the primary state vector
85       * (the method is allowed to change the derivatives here, when the additional
86       * equations do have an effect on the primary equations)
87       * @param secondary array containing the current value of the secondary state vector
88       * @return derivative of the secondary state vector
89       * @exception MathIllegalStateException if the number of functions evaluations is exceeded
90       * @exception MathIllegalArgumentException if arrays dimensions do not match equations settings
91       */
92      Complex[] computeDerivatives(double t, Complex[] primary, Complex[] primaryDot, Complex[] secondary)
93          throws MathIllegalArgumentException, MathIllegalStateException;
94  
95  }