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
018 package org.apache.commons.math.ode.nonstiff;
019
020 import org.apache.commons.math.exception.MathIllegalArgumentException;
021 import org.apache.commons.math.exception.MathIllegalStateException;
022 import org.apache.commons.math.linear.Array2DRowRealMatrix;
023 import org.apache.commons.math.ode.ExpandableStatefulODE;
024 import org.apache.commons.math.ode.MultistepIntegrator;
025
026
027 /** Base class for {@link AdamsBashforthIntegrator Adams-Bashforth} and
028 * {@link AdamsMoultonIntegrator Adams-Moulton} integrators.
029 * @version $Id: AdamsIntegrator.java 1176734 2011-09-28 05:56:42Z luc $
030 * @since 2.0
031 */
032 public abstract class AdamsIntegrator extends MultistepIntegrator {
033
034 /** Transformer. */
035 private final AdamsNordsieckTransformer transformer;
036
037 /**
038 * Build an Adams integrator with the given order and step control parameters.
039 * @param name name of the method
040 * @param nSteps number of steps of the method excluding the one being computed
041 * @param order order of the method
042 * @param minStep minimal step (sign is irrelevant, regardless of
043 * integration direction, forward or backward), the last step can
044 * be smaller than this
045 * @param maxStep maximal step (sign is irrelevant, regardless of
046 * integration direction, forward or backward), the last step can
047 * be smaller than this
048 * @param scalAbsoluteTolerance allowed absolute error
049 * @param scalRelativeTolerance allowed relative error
050 * @exception IllegalArgumentException if order is 1 or less
051 */
052 public AdamsIntegrator(final String name, final int nSteps, final int order,
053 final double minStep, final double maxStep,
054 final double scalAbsoluteTolerance,
055 final double scalRelativeTolerance)
056 throws IllegalArgumentException {
057 super(name, nSteps, order, minStep, maxStep,
058 scalAbsoluteTolerance, scalRelativeTolerance);
059 transformer = AdamsNordsieckTransformer.getInstance(nSteps);
060 }
061
062 /**
063 * Build an Adams integrator with the given order and step control parameters.
064 * @param name name of the method
065 * @param nSteps number of steps of the method excluding the one being computed
066 * @param order order of the method
067 * @param minStep minimal step (sign is irrelevant, regardless of
068 * integration direction, forward or backward), the last step can
069 * be smaller than this
070 * @param maxStep maximal step (sign is irrelevant, regardless of
071 * integration direction, forward or backward), the last step can
072 * be smaller than this
073 * @param vecAbsoluteTolerance allowed absolute error
074 * @param vecRelativeTolerance allowed relative error
075 * @exception IllegalArgumentException if order is 1 or less
076 */
077 public AdamsIntegrator(final String name, final int nSteps, final int order,
078 final double minStep, final double maxStep,
079 final double[] vecAbsoluteTolerance,
080 final double[] vecRelativeTolerance)
081 throws IllegalArgumentException {
082 super(name, nSteps, order, minStep, maxStep,
083 vecAbsoluteTolerance, vecRelativeTolerance);
084 transformer = AdamsNordsieckTransformer.getInstance(nSteps);
085 }
086
087 /** {@inheritDoc} */
088 @Override
089 public abstract void integrate(final ExpandableStatefulODE equations, final double t)
090 throws MathIllegalStateException, MathIllegalArgumentException;
091
092 /** {@inheritDoc} */
093 @Override
094 protected Array2DRowRealMatrix initializeHighOrderDerivatives(final double h, final double[] t,
095 final double[][] y,
096 final double[][] yDot) {
097 return transformer.initializeHighOrderDerivatives(h, t, y, yDot);
098 }
099
100 /** Update the high order scaled derivatives for Adams integrators (phase 1).
101 * <p>The complete update of high order derivatives has a form similar to:
102 * <pre>
103 * 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>
104 * </pre>
105 * this method computes the P<sup>-1</sup> A P r<sub>n</sub> part.</p>
106 * @param highOrder high order scaled derivatives
107 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
108 * @return updated high order derivatives
109 * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowRealMatrix)
110 */
111 public Array2DRowRealMatrix updateHighOrderDerivativesPhase1(final Array2DRowRealMatrix highOrder) {
112 return transformer.updateHighOrderDerivativesPhase1(highOrder);
113 }
114
115 /** Update the high order scaled derivatives Adams integrators (phase 2).
116 * <p>The complete update of high order derivatives has a form similar to:
117 * <pre>
118 * 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>
119 * </pre>
120 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p>
121 * <p>Phase 1 of the update must already have been performed.</p>
122 * @param start first order scaled derivatives at step start
123 * @param end first order scaled derivatives at step end
124 * @param highOrder high order scaled derivatives, will be modified
125 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k))
126 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix)
127 */
128 public void updateHighOrderDerivativesPhase2(final double[] start,
129 final double[] end,
130 final Array2DRowRealMatrix highOrder) {
131 transformer.updateHighOrderDerivativesPhase2(start, end, highOrder);
132 }
133
134 }