View Javadoc
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.nonstiff;
19  
20  import org.hipparchus.ode.EquationsMapper;
21  import org.hipparchus.ode.ODEStateAndDerivative;
22  import org.hipparchus.ode.nonstiff.interpolators.MidpointStateInterpolator;
23  
24  /**
25   * This class implements a second order Runge-Kutta integrator for
26   * Ordinary Differential Equations.
27   *
28   * <p>This method is an explicit Runge-Kutta method, its Butcher-array
29   * is the following one :</p>
30   * <pre>
31   *    0  |  0    0
32   *   1/2 | 1/2   0
33   *       |----------
34   *       |  0    1
35   * </pre>
36   *
37   * @see EulerIntegrator
38   * @see ClassicalRungeKuttaIntegrator
39   * @see GillIntegrator
40   * @see ThreeEighthesIntegrator
41   * @see LutherIntegrator
42   *
43   */
44  
45  public class MidpointIntegrator extends FixedStepRungeKuttaIntegrator {
46  
47      /** Name of integration scheme. */
48      public static final String METHOD_NAME = "midpoint";
49  
50      /** Simple constructor.
51       * Build a midpoint integrator with the given step.
52       * @param step integration step
53       */
54      public MidpointIntegrator(final double step) {
55          super(METHOD_NAME, step);
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public double[] getC() {
61          return new double[] {
62              1.0 / 2.0
63          };
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public double[][] getA() {
69          return new double[][] {
70              { 1.0 / 2.0 }
71          };
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public double[] getB() {
77          return new double[] {
78              0.0, 1.0
79          };
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      protected MidpointStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
85                                                             final ODEStateAndDerivative globalPreviousState,
86                                                             final ODEStateAndDerivative globalCurrentState,
87                                                             final EquationsMapper mapper) {
88          return new MidpointStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
89                                              globalPreviousState, globalCurrentState, mapper);
90      }
91  
92  }