001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.apache.commons.math3.ode;
019
020import org.apache.commons.math3.RealFieldElement;
021import org.apache.commons.math3.exception.DimensionMismatchException;
022import org.apache.commons.math3.exception.MaxCountExceededException;
023
024/**
025 * This interface allows users to add secondary differential equations to a primary
026 * set of differential equations.
027 * <p>
028 * In some cases users may need to integrate some problem-specific equations along
029 * with a primary set of differential equations. One example is optimal control where
030 * adjoined parameters linked to the minimized Hamiltonian must be integrated.
031 * </p>
032 * <p>
033 * This interface allows users to add such equations to a primary set of {@link
034 * FirstOrderFieldDifferentialEquations first order differential equations}
035 * thanks to the {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
036 * method.
037 * </p>
038 * @see FirstOrderFieldDifferentialEquations
039 * @see FieldExpandableODE
040 * @param <T> the type of the field elements
041 * @since 3.6
042 */
043public interface FieldSecondaryEquations<T extends RealFieldElement<T>> {
044
045    /** Get the dimension of the secondary state parameters.
046     * @return dimension of the secondary state parameters
047     */
048    int getDimension();
049
050    /** Initialize equations at the start of an ODE integration.
051     * <p>
052     * This method is called once at the start of the integration. It
053     * may be used by the equations to initialize some internal data
054     * if needed.
055     * </p>
056     * @param t0 value of the independent <I>time</I> variable at integration start
057     * @param primary0 array containing the value of the primary state vector at integration start
058     * @param secondary0 array containing the value of the secondary state vector at integration start
059     * @param finalTime target time for the integration
060     */
061    void init(T t0, T[] primary0, T[] secondary0, T finalTime);
062
063    /** Compute the derivatives related to the secondary state parameters.
064     * @param t current value of the independent <I>time</I> variable
065     * @param primary array containing the current value of the primary state vector
066     * @param primaryDot array containing the derivative of the primary state vector
067     * @param secondary array containing the current value of the secondary state vector
068     * @return derivative of the secondary state vector
069     * @exception MaxCountExceededException if the number of functions evaluations is exceeded
070     * @exception DimensionMismatchException if arrays dimensions do not match equations settings
071     */
072    T[] computeDerivatives(T t, T[] primary, T[] primaryDot, T[] secondary)
073        throws MaxCountExceededException, DimensionMismatchException;
074
075}