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.nonstiff;
24
25 import org.hipparchus.CalculusFieldElement;
26 import org.hipparchus.Field;
27 import org.hipparchus.ode.FieldEquationsMapper;
28 import org.hipparchus.ode.FieldODEStateAndDerivative;
29 import org.hipparchus.ode.nonstiff.interpolators.MidpointFieldStateInterpolator;
30 import org.hipparchus.util.MathArrays;
31
32 /**
33 * This class implements a second order Runge-Kutta integrator for
34 * Ordinary Differential Equations.
35 *
36 * <p>This method is an explicit Runge-Kutta method, its Butcher-array
37 * is the following one :</p>
38 * <pre>
39 * 0 | 0 0
40 * 1/2 | 1/2 0
41 * |----------
42 * | 0 1
43 * </pre>
44 *
45 * @see EulerFieldIntegrator
46 * @see ClassicalRungeKuttaFieldIntegrator
47 * @see GillFieldIntegrator
48 * @see ThreeEighthesFieldIntegrator
49 * @see LutherFieldIntegrator
50 *
51 * @param <T> the type of the field elements
52 */
53
54 public class MidpointFieldIntegrator<T extends CalculusFieldElement<T>> extends FixedStepRungeKuttaFieldIntegrator<T> {
55
56 /** Name of integration scheme. */
57 public static final String METHOD_NAME = MidpointIntegrator.METHOD_NAME;
58
59 /** Simple constructor.
60 * Build a midpoint integrator with the given step.
61 * @param field field to which the time and state vector elements belong
62 * @param step integration step
63 */
64 public MidpointFieldIntegrator(final Field<T> field, final T step) {
65 super(field, METHOD_NAME, step);
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public T[] getC() {
71 final T[] c = MathArrays.buildArray(getField(), 1);
72 c[0] = getField().getOne().newInstance(0.5);
73 return c;
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 public T[][] getA() {
79 final T[][] a = MathArrays.buildArray(getField(), 1, 1);
80 a[0][0] = FieldExplicitRungeKuttaIntegrator.fraction(getField(), 1, 2);
81 return a;
82 }
83
84 /** {@inheritDoc} */
85 @Override
86 public T[] getB() {
87 final T[] b = MathArrays.buildArray(getField(), 2);
88 b[0] = getField().getZero();
89 b[1] = getField().getOne();
90 return b;
91 }
92
93 /** {@inheritDoc} */
94 @Override
95 protected MidpointFieldStateInterpolator<T>
96 createInterpolator(final boolean forward, T[][] yDotK,
97 final FieldODEStateAndDerivative<T> globalPreviousState,
98 final FieldODEStateAndDerivative<T> globalCurrentState,
99 final FieldEquationsMapper<T> mapper) {
100 return new MidpointFieldStateInterpolator<>(getField(), forward, yDotK, globalPreviousState, globalCurrentState,
101 globalPreviousState, globalCurrentState, mapper);
102 }
103
104 }