View Javadoc
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    *      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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.ode;
24  
25  import org.hipparchus.CalculusFieldElement;
26  import org.hipparchus.util.MathArrays;
27  
28  /** Container for time, main and secondary state vectors as well as their derivatives.
29  
30   * @see FieldOrdinaryDifferentialEquation
31   * @see FieldSecondaryODE
32   * @see FieldODEIntegrator
33   * @param <T> the type of the field elements
34   */
35  
36  public class FieldODEStateAndDerivative<T extends CalculusFieldElement<T>> extends FieldODEState<T> {
37  
38      /** Derivative of the primary state at time. */
39      private final T[] primaryDerivative;
40  
41      /** Derivative of the secondary state at time. */
42      private final T[][] secondaryDerivative;
43  
44      /** Simple constructor.
45       * <p>Calling this constructor is equivalent to call {@link
46       * #FieldODEStateAndDerivative(CalculusFieldElement, CalculusFieldElement[], CalculusFieldElement[],
47       * CalculusFieldElement[][], CalculusFieldElement[][]) FieldODEStateAndDerivative(time, state,
48       * derivative, null, null)}.</p>
49       * @param time time
50       * @param primaryState primary state at time
51       * @param primaryDerivative derivative of the primary state at time
52       */
53      public FieldODEStateAndDerivative(T time, T[] primaryState, T[] primaryDerivative) {
54          this(time, primaryState, primaryDerivative, null, null);
55      }
56  
57      /** Simple constructor.
58       * @param time time
59       * @param primaryState primary state at time
60       * @param primaryDerivative derivative of the primary state at time
61       * @param secondaryState state at time (may be null)
62       * @param secondaryDerivative derivative of the state at time (may be null)
63       */
64      public FieldODEStateAndDerivative(T time, T[] primaryState, T[] primaryDerivative,
65                                        T[][] secondaryState, T[][] secondaryDerivative) {
66          super(time, primaryState, secondaryState);
67          this.primaryDerivative   = primaryDerivative.clone();
68          this.secondaryDerivative = copy(secondaryDerivative);
69      }
70  
71      /** Get derivative of the primary state at time.
72       * @return derivative of the primary state at time
73       * @see #getSecondaryDerivative(int)
74       * @see #getCompleteDerivative()
75       */
76      public T[] getPrimaryDerivative() {
77          return primaryDerivative.clone();
78      }
79  
80      /** Get derivative of the secondary state at time.
81       * @param index index of the secondary set as returned
82       * by {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryODE)}
83       * (beware index 0 corresponds to primary state, secondary states start at 1)
84       * @return derivative of the secondary state at time
85       * @see #getPrimaryDerivative()
86       * @see #getCompleteDerivative()
87       */
88      public T[] getSecondaryDerivative(final int index) {
89          return index == 0 ? primaryDerivative.clone() : secondaryDerivative[index - 1].clone();
90      }
91  
92      /** Get complete derivative at time.
93       * @return complete derivative at time, starting with
94       * {@link #getPrimaryDerivative() primary derivative}, followed
95       * by all {@link #getSecondaryDerivative(int) secondary derivatives} in
96       * increasing index order
97       * @see #getPrimaryDerivative()
98       * @see #getSecondaryDerivative(int)
99       */
100     public T[] getCompleteDerivative() {
101         final T[] completeDerivative = MathArrays.buildArray(getTime().getField(), getCompleteStateDimension());
102         System.arraycopy(primaryDerivative, 0, completeDerivative, 0, primaryDerivative.length);
103         int offset = primaryDerivative.length;
104         if (secondaryDerivative != null) {
105             for (int index = 0; index < secondaryDerivative.length; ++index) {
106                 System.arraycopy(secondaryDerivative[index], 0,
107                                  completeDerivative, offset,
108                                  secondaryDerivative[index].length);
109                 offset += secondaryDerivative[index].length;
110             }
111         }
112         return completeDerivative;
113     }
114 
115 }