ComplexODEStateAndDerivative.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. /** Container for time, main and secondary state vectors as well as their derivatives.

  20.  * @see ComplexOrdinaryDifferentialEquation
  21.  * @see ComplexSecondaryODE
  22.  * @see ODEIntegrator
  23.  */

  24. public class ComplexODEStateAndDerivative extends ComplexODEState {

  25.     /** Serializable UID. */
  26.     private static final long serialVersionUID = 20180902L;

  27.     /** Derivative of the primary state at time. */
  28.     private final Complex[] primaryDerivative;

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

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

  43.     /** Simple constructor.
  44.      * @param time time
  45.      * @param primaryState primary state at time
  46.      * @param primaryDerivative derivative of the primary 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 ComplexODEStateAndDerivative(double time, Complex[] primaryState, Complex[] primaryDerivative,
  51.                                         Complex[][] secondaryState, Complex[][] secondaryDerivative) {
  52.         super(time, primaryState, secondaryState);
  53.         this.primaryDerivative   = primaryDerivative.clone();
  54.         this.secondaryDerivative = copy(secondaryDerivative);
  55.     }

  56.     /** Get derivative of the primary state at time.
  57.      * @return derivative of the primary state at time
  58.      * @see #getSecondaryDerivative(int)
  59.      * @see #getCompleteDerivative()
  60.      */
  61.     public Complex[] getPrimaryDerivative() {
  62.         return primaryDerivative.clone();
  63.     }

  64.     /** Get derivative of the secondary state at time.
  65.      * @param index index of the secondary set as returned
  66.      * by {@link ExpandableODE#addSecondaryEquations(SecondaryODE)}
  67.      * (beware index 0 corresponds to primary state, secondary states start at 1)
  68.      * @return derivative of the secondary state at time
  69.      * @see #getPrimaryDerivative()
  70.      * @see #getCompleteDerivative()
  71.      */
  72.     public Complex[] getSecondaryDerivative(final int index) {
  73.         return index == 0 ? primaryDerivative.clone() : secondaryDerivative[index - 1].clone();
  74.     }

  75.     /** Get complete derivative at time.
  76.      * @return complete derivative at time, starting with
  77.      * {@link #getPrimaryDerivative() primary derivative}, followed
  78.      * by all {@link #getSecondaryDerivative(int) secondary derivatives} in
  79.      * increasing index order
  80.      * @see #getPrimaryDerivative()
  81.      * @see #getSecondaryDerivative(int)
  82.      */
  83.     public Complex[] getCompleteDerivative() {
  84.         final Complex[] completeDerivative = new Complex[getCompleteStateDimension()];
  85.         System.arraycopy(primaryDerivative, 0, completeDerivative, 0, primaryDerivative.length);
  86.         int offset = primaryDerivative.length;
  87.         if (secondaryDerivative != null) {
  88.             for (int index = 0; index < secondaryDerivative.length; ++index) {
  89.                 System.arraycopy(secondaryDerivative[index], 0,
  90.                                  completeDerivative, offset,
  91.                                  secondaryDerivative[index].length);
  92.                 offset += secondaryDerivative[index].length;
  93.             }
  94.         }
  95.         return completeDerivative;
  96.     }

  97. }