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.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.util.MathArrays;
30  
31  /**
32   * This class implements a simple Euler integrator for Ordinary
33   * Differential Equations.
34   *
35   * <p>The Euler algorithm is the simplest one that can be used to
36   * integrate ordinary differential equations. It is a simple inversion
37   * of the forward difference expression :
38   * <code>f'=(f(t+h)-f(t))/h</code> which leads to
39   * <code>f(t+h)=f(t)+hf'</code>. The interpolation scheme used for
40   * dense output is the linear scheme already used for integration.</p>
41   *
42   * <p>This algorithm looks cheap because it needs only one function
43   * evaluation per step. However, as it uses linear estimates, it needs
44   * very small steps to achieve high accuracy, and small steps lead to
45   * numerical errors and instabilities.</p>
46   *
47   * <p>This algorithm is almost never used and has been included in
48   * this package only as a comparison reference for more useful
49   * integrators.</p>
50   *
51   * @see MidpointFieldIntegrator
52   * @see ClassicalRungeKuttaFieldIntegrator
53   * @see GillFieldIntegrator
54   * @see ThreeEighthesFieldIntegrator
55   * @see LutherFieldIntegrator
56   * @param <T> the type of the field elements
57   */
58  
59  public class EulerFieldIntegrator<T extends CalculusFieldElement<T>> extends RungeKuttaFieldIntegrator<T> {
60  
61      /** Name of integration scheme. */
62      public static final String METHOD_NAME = EulerIntegrator.METHOD_NAME;
63  
64      /** Simple constructor.
65       * Build an Euler integrator with the given step.
66       * @param field field to which the time and state vector elements belong
67       * @param step integration step
68       */
69      public EulerFieldIntegrator(final Field<T> field, final T step) {
70          super(field, METHOD_NAME, step);
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public T[] getC() {
76          return MathArrays.buildArray(getField(), 0);
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public T[][] getA() {
82          return MathArrays.buildArray(getField(), 0, 0);
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public T[] getB() {
88          final T[] b = MathArrays.buildArray(getField(), 1);
89          b[0] = getField().getOne();
90          return b;
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      protected EulerFieldStateInterpolator<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 EulerFieldStateInterpolator<T>(getField(), forward, yDotK,
101                                                  globalPreviousState, globalCurrentState,
102                                                  globalPreviousState, globalCurrentState,
103                                                  mapper);
104     }
105 
106 }