FieldODEStateAndDerivative.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) 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 ASF 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.  *      http://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.apache.commons.math4.legacy.ode;

  18. import org.apache.commons.math4.legacy.core.RealFieldElement;

  19. /** Container for time, main and secondary state vectors as well as their derivatives.

  20.  * @see FirstOrderFieldDifferentialEquations
  21.  * @see FieldSecondaryEquations
  22.  * @see FirstOrderFieldIntegrator
  23.  * @param <T> the type of the field elements
  24.  * @since 3.6
  25.  */

  26. public class FieldODEStateAndDerivative<T extends RealFieldElement<T>> extends FieldODEState<T> {

  27.     /** Derivative of the main state at time. */
  28.     private final T[] derivative;

  29.     /** Derivative of the secondary state at time. */
  30.     private final T[][] secondaryDerivative;

  31.     /** Simple constructor.
  32.      * <p>Calling this constructor is equivalent to call {@link
  33.      * #FieldODEStateAndDerivative(RealFieldElement, RealFieldElement[], RealFieldElement[],
  34.      * RealFieldElement[][], RealFieldElement[][]) FieldODEStateAndDerivative(time, state,
  35.      * derivative, null, null)}.</p>
  36.      * @param time time
  37.      * @param state state at time
  38.      * @param derivative derivative of the state at time
  39.      */
  40.     public FieldODEStateAndDerivative(T time, T[] state, T[] derivative) {
  41.         this(time, state, derivative, null, null);
  42.     }

  43.     /** Simple constructor.
  44.      * @param time time
  45.      * @param state state at time
  46.      * @param derivative derivative of the state at time
  47.      * @param secondaryState state at time (may be null)
  48.      * @param secondaryDerivative derivative of the state at time (may be null)
  49.      */
  50.     public FieldODEStateAndDerivative(T time, T[] state, T[] derivative, T[][] secondaryState, T[][] secondaryDerivative) {
  51.         super(time, state, secondaryState);
  52.         this.derivative          = derivative.clone();
  53.         this.secondaryDerivative = copy(time.getField(), secondaryDerivative);
  54.     }

  55.     /** Get derivative of the main state at time.
  56.      * @return derivative of the main state at time
  57.      */
  58.     public T[] getDerivative() {
  59.         return derivative.clone();
  60.     }

  61.     /** Get derivative of the secondary state at time.
  62.      * @param index index of the secondary set as returned
  63.      * by {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
  64.      * (beware index 0 corresponds to main state, additional states start at 1)
  65.      * @return derivative of the secondary state at time
  66.      */
  67.     public T[] getSecondaryDerivative(final int index) {
  68.         return index == 0 ? derivative.clone() : secondaryDerivative[index - 1].clone();
  69.     }
  70. }