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