EulerFieldIntegrator.java

  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.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.ode.nonstiff;

  22. import org.hipparchus.CalculusFieldElement;
  23. import org.hipparchus.Field;
  24. import org.hipparchus.ode.FieldEquationsMapper;
  25. import org.hipparchus.ode.FieldODEStateAndDerivative;
  26. import org.hipparchus.ode.nonstiff.interpolators.EulerFieldStateInterpolator;
  27. import org.hipparchus.util.MathArrays;

  28. /**
  29.  * This class implements a simple Euler integrator for Ordinary
  30.  * Differential Equations.
  31.  *
  32.  * <p>The Euler algorithm is the simplest one that can be used to
  33.  * integrate ordinary differential equations. It is a simple inversion
  34.  * of the forward difference expression :
  35.  * <code>f'=(f(t+h)-f(t))/h</code> which leads to
  36.  * <code>f(t+h)=f(t)+hf'</code>. The interpolation scheme used for
  37.  * dense output is the linear scheme already used for integration.</p>
  38.  *
  39.  * <p>This algorithm looks cheap because it needs only one function
  40.  * evaluation per step. However, as it uses linear estimates, it needs
  41.  * very small steps to achieve high accuracy, and small steps lead to
  42.  * numerical errors and instabilities.</p>
  43.  *
  44.  * <p>This algorithm is almost never used and has been included in
  45.  * this package only as a comparison reference for more useful
  46.  * integrators.</p>
  47.  *
  48.  * @see MidpointFieldIntegrator
  49.  * @see ClassicalRungeKuttaFieldIntegrator
  50.  * @see GillFieldIntegrator
  51.  * @see ThreeEighthesFieldIntegrator
  52.  * @see LutherFieldIntegrator
  53.  * @param <T> the type of the field elements
  54.  */

  55. public class EulerFieldIntegrator<T extends CalculusFieldElement<T>> extends FixedStepRungeKuttaFieldIntegrator<T> {

  56.     /** Name of integration scheme. */
  57.     public static final String METHOD_NAME = EulerIntegrator.METHOD_NAME;

  58.     /** Simple constructor.
  59.      * Build an Euler integrator with the given step.
  60.      * @param field field to which the time and state vector elements belong
  61.      * @param step integration step
  62.      */
  63.     public EulerFieldIntegrator(final Field<T> field, final T step) {
  64.         super(field, METHOD_NAME, step);
  65.     }

  66.     /** {@inheritDoc} */
  67.     @Override
  68.     public T[] getC() {
  69.         return MathArrays.buildArray(getField(), 0);
  70.     }

  71.     /** {@inheritDoc} */
  72.     @Override
  73.     public T[][] getA() {
  74.         return MathArrays.buildArray(getField(), 0, 0);
  75.     }

  76.     /** {@inheritDoc} */
  77.     @Override
  78.     public T[] getB() {
  79.         final T[] b = MathArrays.buildArray(getField(), 1);
  80.         b[0] = getField().getOne();
  81.         return b;
  82.     }

  83.     /** {@inheritDoc} */
  84.     @Override
  85.     protected EulerFieldStateInterpolator<T>
  86.         createInterpolator(final boolean forward, T[][] yDotK,
  87.                            final FieldODEStateAndDerivative<T> globalPreviousState,
  88.                            final FieldODEStateAndDerivative<T> globalCurrentState,
  89.                            final FieldEquationsMapper<T> mapper) {
  90.         return new EulerFieldStateInterpolator<>(getField(), forward, yDotK,
  91.                                                  globalPreviousState, globalCurrentState,
  92.                                                  globalPreviousState, globalCurrentState,
  93.                                                  mapper);
  94.     }

  95. }