001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.math4.legacy.ode.nonstiff; 019 020import org.apache.commons.math4.legacy.core.Field; 021import org.apache.commons.math4.legacy.core.RealFieldElement; 022import org.apache.commons.math4.legacy.exception.DimensionMismatchException; 023import org.apache.commons.math4.legacy.exception.MaxCountExceededException; 024import org.apache.commons.math4.legacy.exception.NoBracketingException; 025import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; 026import org.apache.commons.math4.legacy.linear.Array2DRowFieldMatrix; 027import org.apache.commons.math4.legacy.ode.FieldExpandableODE; 028import org.apache.commons.math4.legacy.ode.FieldODEState; 029import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; 030import org.apache.commons.math4.legacy.ode.MultistepFieldIntegrator; 031 032 033/** Base class for {@link AdamsBashforthFieldIntegrator Adams-Bashforth} and 034 * {@link AdamsMoultonFieldIntegrator Adams-Moulton} integrators. 035 * @param <T> the type of the field elements 036 * @since 3.6 037 */ 038public abstract class AdamsFieldIntegrator<T extends RealFieldElement<T>> extends MultistepFieldIntegrator<T> { 039 040 /** Transformer. */ 041 private final AdamsNordsieckFieldTransformer<T> transformer; 042 043 /** 044 * Build an Adams integrator with the given order and step control parameters. 045 * @param field field to which the time and state vector elements belong 046 * @param name name of the method 047 * @param nSteps number of steps of the method excluding the one being computed 048 * @param order order of the method 049 * @param minStep minimal step (sign is irrelevant, regardless of 050 * integration direction, forward or backward), the last step can 051 * be smaller than this 052 * @param maxStep maximal step (sign is irrelevant, regardless of 053 * integration direction, forward or backward), the last step can 054 * be smaller than this 055 * @param scalAbsoluteTolerance allowed absolute error 056 * @param scalRelativeTolerance allowed relative error 057 * @exception NumberIsTooSmallException if order is 1 or less 058 */ 059 public AdamsFieldIntegrator(final Field<T> field, final String name, 060 final int nSteps, final int order, 061 final double minStep, final double maxStep, 062 final double scalAbsoluteTolerance, 063 final double scalRelativeTolerance) 064 throws NumberIsTooSmallException { 065 super(field, name, nSteps, order, minStep, maxStep, 066 scalAbsoluteTolerance, scalRelativeTolerance); 067 transformer = AdamsNordsieckFieldTransformer.getInstance(field, nSteps); 068 } 069 070 /** 071 * Build an Adams integrator with the given order and step control parameters. 072 * @param field field to which the time and state vector elements belong 073 * @param name name of the method 074 * @param nSteps number of steps of the method excluding the one being computed 075 * @param order order of the method 076 * @param minStep minimal step (sign is irrelevant, regardless of 077 * integration direction, forward or backward), the last step can 078 * be smaller than this 079 * @param maxStep maximal step (sign is irrelevant, regardless of 080 * integration direction, forward or backward), the last step can 081 * be smaller than this 082 * @param vecAbsoluteTolerance allowed absolute error 083 * @param vecRelativeTolerance allowed relative error 084 * @exception IllegalArgumentException if order is 1 or less 085 */ 086 public AdamsFieldIntegrator(final Field<T> field, final String name, 087 final int nSteps, final int order, 088 final double minStep, final double maxStep, 089 final double[] vecAbsoluteTolerance, 090 final double[] vecRelativeTolerance) 091 throws IllegalArgumentException { 092 super(field, name, nSteps, order, minStep, maxStep, 093 vecAbsoluteTolerance, vecRelativeTolerance); 094 transformer = AdamsNordsieckFieldTransformer.getInstance(field, nSteps); 095 } 096 097 /** {@inheritDoc} */ 098 @Override 099 public abstract FieldODEStateAndDerivative<T> integrate(FieldExpandableODE<T> equations, 100 FieldODEState<T> initialState, 101 T finalTime) 102 throws NumberIsTooSmallException, DimensionMismatchException, 103 MaxCountExceededException, NoBracketingException; 104 105 /** {@inheritDoc} */ 106 @Override 107 protected Array2DRowFieldMatrix<T> initializeHighOrderDerivatives(final T h, final T[] t, 108 final T[][] y, 109 final T[][] yDot) { 110 return transformer.initializeHighOrderDerivatives(h, t, y, yDot); 111 } 112 113 /** Update the high order scaled derivatives for Adams integrators (phase 1). 114 * <p>The complete update of high order derivatives has a form similar to: 115 * <div style="white-space: pre"><code> 116 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub> 117 * </code></div> 118 * this method computes the P<sup>-1</sup> A P r<sub>n</sub> part. 119 * @param highOrder high order scaled derivatives 120 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) 121 * @return updated high order derivatives 122 * @see #updateHighOrderDerivativesPhase2(RealFieldElement[], RealFieldElement[], Array2DRowFieldMatrix) 123 */ 124 public Array2DRowFieldMatrix<T> updateHighOrderDerivativesPhase1(final Array2DRowFieldMatrix<T> highOrder) { 125 return transformer.updateHighOrderDerivativesPhase1(highOrder); 126 } 127 128 /** Update the high order scaled derivatives Adams integrators (phase 2). 129 * <p>The complete update of high order derivatives has a form similar to: 130 * <div style="white-space: pre"><code> 131 * r<sub>n+1</sub> = (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u + P<sup>-1</sup> A P r<sub>n</sub> 132 * </code></div> 133 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part. 134 * <p>Phase 1 of the update must already have been performed.</p> 135 * @param start first order scaled derivatives at step start 136 * @param end first order scaled derivatives at step end 137 * @param highOrder high order scaled derivatives, will be modified 138 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) 139 * @see #updateHighOrderDerivativesPhase1(Array2DRowFieldMatrix) 140 */ 141 public void updateHighOrderDerivativesPhase2(final T[] start, final T[] end, 142 final Array2DRowFieldMatrix<T> highOrder) { 143 transformer.updateHighOrderDerivativesPhase2(start, end, highOrder); 144 } 145}