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 * http://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 package org.apache.commons.math4.legacy.ode.sampling; 19 20 import org.apache.commons.math4.legacy.core.RealFieldElement; 21 import org.apache.commons.math4.legacy.exception.MaxCountExceededException; 22 import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; 23 24 /** 25 * This interface represents a handler that should be called after 26 * each successful step. 27 * 28 * <p>The ODE integrators compute the evolution of the state vector at 29 * some grid points that depend on their own internal algorithm. Once 30 * they have found a new grid point (possibly after having computed 31 * several evaluation of the derivative at intermediate points), they 32 * provide it to objects implementing this interface. These objects 33 * typically either ignore the intermediate steps and wait for the 34 * last one, store the points in an ephemeris, or forward them to 35 * specialized processing or output methods.</p> 36 * 37 * @see org.apache.commons.math4.legacy.ode.FirstOrderFieldIntegrator 38 * @see FieldStepInterpolator 39 * @param <T> the type of the field elements 40 * @since 3.6 41 */ 42 43 public interface FieldStepHandler<T extends RealFieldElement<T>> { 44 45 /** Initialize step handler at the start of an ODE integration. 46 * <p> 47 * This method is called once at the start of the integration. It 48 * may be used by the step handler to initialize some internal data 49 * if needed. 50 * </p> 51 * @param initialState initial time, state vector and derivative 52 * @param finalTime target time for the integration 53 */ 54 void init(FieldODEStateAndDerivative<T> initialState, T finalTime); 55 56 /** 57 * Handle the last accepted step. 58 * @param interpolator interpolator for the last accepted step. For 59 * efficiency purposes, the various integrators reuse the same 60 * object on each call, so if the instance wants to keep it across 61 * all calls (for example to provide at the end of the integration a 62 * continuous model valid throughout the integration range, as the 63 * {@link org.apache.commons.math4.legacy.ode.ContinuousOutputModel 64 * ContinuousOutputModel} class does), it should build a local copy 65 * using the clone method of the interpolator and store this copy. 66 * Keeping only a reference to the interpolator and reusing it will 67 * result in unpredictable behavior (potentially crashing the application). 68 * @param isLast true if the step is the last one 69 * @exception MaxCountExceededException if the interpolator throws one because 70 * the number of functions evaluations is exceeded 71 */ 72 void handleStep(FieldStepInterpolator<T> interpolator, boolean isLast) 73 throws MaxCountExceededException; 74 }