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