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 /** Container for time, main and secondary state vectors as well as their derivatives. 21 22 * @see OrdinaryDifferentialEquation 23 * @see SecondaryODE 24 * @see ODEIntegrator 25 */ 26 27 public class ODEStateAndDerivative extends ODEState { 28 29 /** Serializable UID. */ 30 private static final long serialVersionUID = 20160408L; 31 32 /** Derivative of the primary state at time. */ 33 private final double[] primaryDerivative; 34 35 /** Derivative of the secondary state at time. */ 36 private final double[][] secondaryDerivative; 37 38 /** Simple constructor. 39 * <p>Calling this constructor is equivalent to call {@link 40 * #ODEStateAndDerivative(double, double[], double[], 41 * double[][], double[][]) ODEStateAndDerivative(time, state, 42 * derivative, null, null)}.</p> 43 * @param time time 44 * @param primaryState primary state at time 45 * @param primaryDerivative derivative of the primary state at time 46 */ 47 public ODEStateAndDerivative(double time, double[] primaryState, double[] primaryDerivative) { 48 this(time, primaryState, primaryDerivative, null, null); 49 } 50 51 /** Simple constructor. 52 * @param time time 53 * @param primaryState primary state at time 54 * @param primaryDerivative derivative of the primary state at time 55 * @param secondaryState state at time (may be null) 56 * @param secondaryDerivative derivative of the state at time (may be null) 57 */ 58 public ODEStateAndDerivative(double time, double[] primaryState, double[] primaryDerivative, 59 double[][] secondaryState, double[][] secondaryDerivative) { 60 super(time, primaryState, secondaryState); 61 this.primaryDerivative = primaryDerivative.clone(); 62 this.secondaryDerivative = copy(secondaryDerivative); 63 } 64 65 /** Get derivative of the primary state at time. 66 * @return derivative of the primary state at time 67 * @see #getSecondaryDerivative(int) 68 * @see #getCompleteDerivative() 69 */ 70 public double[] getPrimaryDerivative() { 71 return primaryDerivative.clone(); 72 } 73 74 /** Get derivative of the secondary state at time. 75 * @param index index of the secondary set as returned 76 * by {@link ExpandableODE#addSecondaryEquations(SecondaryODE)} 77 * (beware index 0 corresponds to primary state, secondary states start at 1) 78 * @return derivative of the secondary state at time 79 * @see #getPrimaryDerivative() 80 * @see #getCompleteDerivative() 81 */ 82 public double[] getSecondaryDerivative(final int index) { 83 return index == 0 ? primaryDerivative.clone() : secondaryDerivative[index - 1].clone(); 84 } 85 86 /** Get complete derivative at time. 87 * @return complete derivative at time, starting with 88 * {@link #getPrimaryDerivative() primary derivative}, followed 89 * by all {@link #getSecondaryDerivative(int) secondary derivatives} in 90 * increasing index order 91 * @see #getPrimaryDerivative() 92 * @see #getSecondaryDerivative(int) 93 */ 94 public double[] getCompleteDerivative() { 95 final double[] completeDerivative = new double[getCompleteStateDimension()]; 96 System.arraycopy(primaryDerivative, 0, completeDerivative, 0, primaryDerivative.length); 97 int offset = primaryDerivative.length; 98 if (secondaryDerivative != null) { 99 for (int index = 0; index < secondaryDerivative.length; ++index) { 100 System.arraycopy(secondaryDerivative[index], 0, 101 completeDerivative, offset, 102 secondaryDerivative[index].length); 103 offset += secondaryDerivative[index].length; 104 } 105 } 106 return completeDerivative; 107 } 108 109 }