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.linear.Array2DRowRealMatrix; 021 import org.apache.commons.math.ode.DerivativeException; 022 import org.apache.commons.math.ode.FirstOrderDifferentialEquations; 023 import org.apache.commons.math.ode.IntegratorException; 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 $Revision: 790368 $ $Date: 2009-07-01 16:31:50 -0400 (Wed, 01 Jul 2009) $ 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 prameters. 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 (must be positive even for backward 043 * integration), the last step can be smaller than this 044 * @param maxStep maximal step (must be positive even for backward 045 * integration) 046 * @param scalAbsoluteTolerance allowed absolute error 047 * @param scalRelativeTolerance allowed relative error 048 * @exception IllegalArgumentException if order is 1 or less 049 */ 050 public AdamsIntegrator(final String name, final int nSteps, final int order, 051 final double minStep, final double maxStep, 052 final double scalAbsoluteTolerance, 053 final double scalRelativeTolerance) 054 throws IllegalArgumentException { 055 super(name, nSteps, order, minStep, maxStep, 056 scalAbsoluteTolerance, scalRelativeTolerance); 057 transformer = AdamsNordsieckTransformer.getInstance(nSteps); 058 } 059 060 /** 061 * Build an Adams integrator with the given order and step control parameters. 062 * @param name name of the method 063 * @param nSteps number of steps of the method excluding the one being computed 064 * @param order order of the method 065 * @param minStep minimal step (must be positive even for backward 066 * integration), the last step can be smaller than this 067 * @param maxStep maximal step (must be positive even for backward 068 * integration) 069 * @param vecAbsoluteTolerance allowed absolute error 070 * @param vecRelativeTolerance allowed relative error 071 * @exception IllegalArgumentException if order is 1 or less 072 */ 073 public AdamsIntegrator(final String name, final int nSteps, final int order, 074 final double minStep, final double maxStep, 075 final double[] vecAbsoluteTolerance, 076 final double[] vecRelativeTolerance) 077 throws IllegalArgumentException { 078 super(name, nSteps, order, minStep, maxStep, 079 vecAbsoluteTolerance, vecRelativeTolerance); 080 transformer = AdamsNordsieckTransformer.getInstance(nSteps); 081 } 082 083 /** {@inheritDoc} */ 084 @Override 085 public abstract double integrate(final FirstOrderDifferentialEquations equations, 086 final double t0, final double[] y0, 087 final double t, final double[] y) 088 throws DerivativeException, IntegratorException; 089 090 /** {@inheritDoc} */ 091 @Override 092 protected Array2DRowRealMatrix initializeHighOrderDerivatives(final double[] first, 093 final double[][] multistep) { 094 return transformer.initializeHighOrderDerivatives(first, multistep); 095 } 096 097 /** Update the high order scaled derivatives for Adams integrators (phase 1). 098 * <p>The complete update of high order derivatives has a form similar to: 099 * <pre> 100 * 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> 101 * </pre> 102 * this method computes the P<sup>-1</sup> A P r<sub>n</sub> part.</p> 103 * @param highOrder high order scaled derivatives 104 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) 105 * @return updated high order derivatives 106 * @see #updateHighOrderDerivativesPhase2(double[], double[], Array2DRowRealMatrix) 107 */ 108 public Array2DRowRealMatrix updateHighOrderDerivativesPhase1(final Array2DRowRealMatrix highOrder) { 109 return transformer.updateHighOrderDerivativesPhase1(highOrder); 110 } 111 112 /** Update the high order scaled derivatives Adams integrators (phase 2). 113 * <p>The complete update of high order derivatives has a form similar to: 114 * <pre> 115 * 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> 116 * </pre> 117 * this method computes the (s<sub>1</sub>(n) - s<sub>1</sub>(n+1)) P<sup>-1</sup> u part.</p> 118 * <p>Phase 1 of the update must already have been performed.</p> 119 * @param start first order scaled derivatives at step start 120 * @param end first order scaled derivatives at step end 121 * @param highOrder high order scaled derivatives, will be modified 122 * (h<sup>2</sup>/2 y'', ... h<sup>k</sup>/k! y(k)) 123 * @see #updateHighOrderDerivativesPhase1(Array2DRowRealMatrix) 124 */ 125 public void updateHighOrderDerivativesPhase2(final double[] start, 126 final double[] end, 127 final Array2DRowRealMatrix highOrder) { 128 transformer.updateHighOrderDerivativesPhase2(start, end, highOrder); 129 } 130 131 }