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    *      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  
18  package org.apache.commons.math4.legacy.ode;
19  
20  import org.apache.commons.math4.legacy.core.RealFieldElement;
21  
22  /** Container for time, main and secondary state vectors as well as their derivatives.
23  
24   * @see FirstOrderFieldDifferentialEquations
25   * @see FieldSecondaryEquations
26   * @see FirstOrderFieldIntegrator
27   * @param <T> the type of the field elements
28   * @since 3.6
29   */
30  
31  public class FieldODEStateAndDerivative<T extends RealFieldElement<T>> extends FieldODEState<T> {
32  
33      /** Derivative of the main state at time. */
34      private final T[] derivative;
35  
36      /** Derivative of the secondary state at time. */
37      private final T[][] secondaryDerivative;
38  
39      /** Simple constructor.
40       * <p>Calling this constructor is equivalent to call {@link
41       * #FieldODEStateAndDerivative(RealFieldElement, RealFieldElement[], RealFieldElement[],
42       * RealFieldElement[][], RealFieldElement[][]) FieldODEStateAndDerivative(time, state,
43       * derivative, null, null)}.</p>
44       * @param time time
45       * @param state state at time
46       * @param derivative derivative of the state at time
47       */
48      public FieldODEStateAndDerivative(T time, T[] state, T[] derivative) {
49          this(time, state, derivative, null, null);
50      }
51  
52      /** Simple constructor.
53       * @param time time
54       * @param state state at time
55       * @param derivative derivative of the state at time
56       * @param secondaryState state at time (may be null)
57       * @param secondaryDerivative derivative of the state at time (may be null)
58       */
59      public FieldODEStateAndDerivative(T time, T[] state, T[] derivative, T[][] secondaryState, T[][] secondaryDerivative) {
60          super(time, state, secondaryState);
61          this.derivative          = derivative.clone();
62          this.secondaryDerivative = copy(time.getField(), secondaryDerivative);
63      }
64  
65      /** Get derivative of the main state at time.
66       * @return derivative of the main state at time
67       */
68      public T[] getDerivative() {
69          return derivative.clone();
70      }
71  
72      /** Get derivative of the secondary state at time.
73       * @param index index of the secondary set as returned
74       * by {@link FieldExpandableODE#addSecondaryEquations(FieldSecondaryEquations)}
75       * (beware index 0 corresponds to main state, additional states start at 1)
76       * @return derivative of the secondary state at time
77       */
78      public T[] getSecondaryDerivative(final int index) {
79          return index == 0 ? derivative.clone() : secondaryDerivative[index - 1].clone();
80      }
81  }