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