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      /** Simple constructor.
62       * Build an Euler integrator with the given step.
63       * @param field field to which the time and state vector elements belong
64       * @param step integration step
65       */
66      public EulerFieldIntegrator(final Field<T> field, final T step) {
67          super(field, "Euler", step);
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public T[] getC() {
73          return MathArrays.buildArray(getField(), 0);
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public T[][] getA() {
79          return MathArrays.buildArray(getField(), 0, 0);
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public T[] getB() {
85          final T[] b = MathArrays.buildArray(getField(), 1);
86          b[0] = getField().getOne();
87          return b;
88      }
89  
90      /** {@inheritDoc} */
91      @Override
92      protected EulerFieldStateInterpolator<T>
93          createInterpolator(final boolean forward, T[][] yDotK,
94                             final FieldODEStateAndDerivative<T> globalPreviousState,
95                             final FieldODEStateAndDerivative<T> globalCurrentState,
96                             final FieldEquationsMapper<T> mapper) {
97          return new EulerFieldStateInterpolator<T>(getField(), forward, yDotK,
98                                                   globalPreviousState, globalCurrentState,
99                                                   globalPreviousState, globalCurrentState,
100                                                  mapper);
101     }
102 
103 }