Reduced coupling between integrators and step interpolators.
This commit is contained in:
parent
41bbbd468a
commit
1077ae03c0
|
@ -101,7 +101,7 @@ public class ClassicalRungeKuttaFieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected ClassicalRungeKuttaFieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new ClassicalRungeKuttaFieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new ClassicalRungeKuttaFieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -60,14 +60,13 @@ class ClassicalRungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
extends RungeKuttaFieldStepInterpolator<T> {
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
ClassicalRungeKuttaFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
ClassicalRungeKuttaFieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
@ -92,7 +91,7 @@ class ClassicalRungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
final T time, final T theta,
|
||||
final T oneMinusThetaH) {
|
||||
|
||||
final T one = time.getField().getOne();
|
||||
final T one = getField().getOne();
|
||||
final T oneMinusTheta = one.subtract(theta);
|
||||
final T oneMinus2Theta = one.subtract(theta.multiply(2));
|
||||
final T coeffDot1 = oneMinusTheta.multiply(oneMinus2Theta);
|
||||
|
|
|
@ -190,7 +190,7 @@ public class DormandPrince54FieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected DormandPrince54FieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new DormandPrince54FieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new DormandPrince54FieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -73,15 +73,14 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
private final T d6;
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
DormandPrince54FieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
DormandPrince54FieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
final T one = rkIntegrator.getField().getOne();
|
||||
super(field, forward, mapper);
|
||||
final T one = field.getOne();
|
||||
a70 = one.multiply( 35.0).divide( 384.0);
|
||||
a72 = one.multiply( 500.0).divide(1113.0);
|
||||
a73 = one.multiply( 125.0).divide( 192.0);
|
||||
|
@ -131,7 +130,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
final T oneMinusThetaH) {
|
||||
|
||||
// interpolate
|
||||
final T one = theta.getField().getOne();
|
||||
final T one = getField().getOne();
|
||||
final T eta = one.subtract(theta);
|
||||
final T twoTheta = theta.multiply(2);
|
||||
final T dot2 = one.subtract(twoTheta);
|
||||
|
@ -148,7 +147,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
subtract(f2.multiply(a70.subtract(1))).
|
||||
add(f3.multiply(a70.multiply(2).subtract(1))).
|
||||
add(f4.multiply(d0));
|
||||
final T coeff1 = theta.getField().getZero();
|
||||
final T coeff1 = getField().getZero();
|
||||
final T coeff2 = f1.multiply(a72).
|
||||
subtract(f2.multiply(a72)).
|
||||
add(f3.multiply(a72.multiply(2))).
|
||||
|
@ -170,7 +169,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
subtract(dot2.multiply(a70.subtract(1))).
|
||||
add(dot3.multiply(a70.multiply(2).subtract(1))).
|
||||
add(dot4.multiply(d0));
|
||||
final T coeffDot1 = theta.getField().getZero();
|
||||
final T coeffDot1 = getField().getZero();
|
||||
final T coeffDot2 = a72.
|
||||
subtract(dot2.multiply(a72)).
|
||||
add(dot3.multiply(a72.multiply(2))).
|
||||
|
@ -201,7 +200,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
subtract(f2.multiply(a70.subtract(1))).
|
||||
add(f3.multiply(a70.multiply(2).subtract(1))).
|
||||
add(f4.multiply(d0));
|
||||
final T coeff1 = theta.getField().getZero();
|
||||
final T coeff1 = getField().getZero();
|
||||
final T coeff2 = f1.multiply(a72).
|
||||
subtract(f2.multiply(a72)).
|
||||
add(f3.multiply(a72.multiply(2))).
|
||||
|
@ -223,7 +222,7 @@ class DormandPrince54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
subtract(dot2.multiply(a70.subtract(1))).
|
||||
add(dot3.multiply(a70.multiply(2).subtract(1))).
|
||||
add(dot4.multiply(d0));
|
||||
final T coeffDot1 = theta.getField().getZero();
|
||||
final T coeffDot1 = getField().getZero();
|
||||
final T coeffDot2 = a72.
|
||||
subtract(dot2.multiply(a72)).
|
||||
add(dot3.multiply(a72.multiply(2))).
|
||||
|
|
|
@ -396,7 +396,7 @@ public class DormandPrince853FieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected DormandPrince853FieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new DormandPrince853FieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new DormandPrince853FieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.exception.MaxCountExceededException;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
import org.apache.commons.math4.util.MathArrays;
|
||||
|
@ -43,24 +43,23 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
private final T[][] d;
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
DormandPrince853FieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
DormandPrince853FieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
|
||||
// interpolation weights
|
||||
d = MathArrays.buildArray(integrator.getField(), 4, 16);
|
||||
d = MathArrays.buildArray(getField(), 4, 16);
|
||||
|
||||
// this row is the same as the b array
|
||||
d[0][ 0] = fraction(104257, 1929240);
|
||||
d[0][ 1] = integrator.getField().getZero();
|
||||
d[0][ 2] = integrator.getField().getZero();
|
||||
d[0][ 3] = integrator.getField().getZero();
|
||||
d[0][ 4] = integrator.getField().getZero();
|
||||
d[0][ 1] = getField().getZero();
|
||||
d[0][ 2] = getField().getZero();
|
||||
d[0][ 3] = getField().getZero();
|
||||
d[0][ 4] = getField().getZero();
|
||||
d[0][ 5] = fraction( 3399327.0, 763840.0);
|
||||
d[0][ 6] = fraction( 66578432.0, 35198415.0);
|
||||
d[0][ 7] = fraction( -1674902723.0, 288716400.0);
|
||||
|
@ -68,10 +67,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
d[0][ 9] = fraction( -734375.0, 4826304.0);
|
||||
d[0][10] = fraction( 171414593.0, 851261400.0);
|
||||
d[0][11] = fraction( 137909.0, 3084480.0);
|
||||
d[0][12] = integrator.getField().getZero();
|
||||
d[0][13] = integrator.getField().getZero();
|
||||
d[0][14] = integrator.getField().getZero();
|
||||
d[0][15] = integrator.getField().getZero();
|
||||
d[0][12] = getField().getZero();
|
||||
d[0][13] = getField().getZero();
|
||||
d[0][14] = getField().getZero();
|
||||
d[0][15] = getField().getZero();
|
||||
|
||||
d[1][ 0] = d[0][ 0].negate().add(1);
|
||||
d[1][ 1] = d[0][ 1].negate();
|
||||
|
@ -108,10 +107,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
d[2][15] = d[0][15].multiply(2); // really 0
|
||||
|
||||
d[3][ 0] = fraction( -17751989329.0, 2106076560.0);
|
||||
d[3][ 1] = integrator.getField().getZero();
|
||||
d[3][ 2] = integrator.getField().getZero();
|
||||
d[3][ 3] = integrator.getField().getZero();
|
||||
d[3][ 4] = integrator.getField().getZero();
|
||||
d[3][ 1] = getField().getZero();
|
||||
d[3][ 2] = getField().getZero();
|
||||
d[3][ 3] = getField().getZero();
|
||||
d[3][ 4] = getField().getZero();
|
||||
d[3][ 5] = fraction( 4272954039.0, 7539864640.0);
|
||||
d[3][ 6] = fraction( -118476319744.0, 38604839385.0);
|
||||
d[3][ 7] = fraction( 755123450731.0, 316657731600.0);
|
||||
|
@ -125,10 +124,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
d[3][15] = fraction( -1944542619.0, 438351368.0);
|
||||
|
||||
d[4][ 0] = fraction( 32941697297.0, 3159114840.0);
|
||||
d[4][ 1] = integrator.getField().getZero();
|
||||
d[4][ 2] = integrator.getField().getZero();
|
||||
d[4][ 3] = integrator.getField().getZero();
|
||||
d[4][ 4] = integrator.getField().getZero();
|
||||
d[4][ 1] = getField().getZero();
|
||||
d[4][ 2] = getField().getZero();
|
||||
d[4][ 3] = getField().getZero();
|
||||
d[4][ 4] = getField().getZero();
|
||||
d[4][ 5] = fraction( 456696183123.0, 1884966160.0);
|
||||
d[4][ 6] = fraction( 19132610714624.0, 115814518155.0);
|
||||
d[4][ 7] = fraction( -177904688592943.0, 474986597400.0);
|
||||
|
@ -142,10 +141,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
d[4][15] = fraction( 15700361463.0, 438351368.0);
|
||||
|
||||
d[5][ 0] = fraction( 12627015655.0, 631822968.0);
|
||||
d[5][ 1] = integrator.getField().getZero();
|
||||
d[5][ 2] = integrator.getField().getZero();
|
||||
d[5][ 3] = integrator.getField().getZero();
|
||||
d[5][ 4] = integrator.getField().getZero();
|
||||
d[5][ 1] = getField().getZero();
|
||||
d[5][ 2] = getField().getZero();
|
||||
d[5][ 3] = getField().getZero();
|
||||
d[5][ 4] = getField().getZero();
|
||||
d[5][ 5] = fraction( -72955222965.0, 188496616.0);
|
||||
d[5][ 6] = fraction( -13145744952320.0, 69488710893.0);
|
||||
d[5][ 7] = fraction( 30084216194513.0, 56998391688.0);
|
||||
|
@ -159,10 +158,10 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
d[5][15] = fraction( 5256837225.0, 438351368.0);
|
||||
|
||||
d[6][ 0] = fraction( -450944925.0, 17550638.0);
|
||||
d[6][ 1] = integrator.getField().getZero();
|
||||
d[6][ 2] = integrator.getField().getZero();
|
||||
d[6][ 3] = integrator.getField().getZero();
|
||||
d[6][ 4] = integrator.getField().getZero();
|
||||
d[6][ 1] = getField().getZero();
|
||||
d[6][ 2] = getField().getZero();
|
||||
d[6][ 3] = getField().getZero();
|
||||
d[6][ 4] = getField().getZero();
|
||||
d[6][ 5] = fraction( -14532122925.0, 94248308.0);
|
||||
d[6][ 6] = fraction( -595876966400.0, 2573655959.0);
|
||||
d[6][ 7] = fraction( 188748653015.0, 527762886.0);
|
||||
|
@ -186,7 +185,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
|
||||
super(interpolator);
|
||||
|
||||
d = MathArrays.buildArray(integrator.getField(), 4, -1);
|
||||
d = MathArrays.buildArray(getField(), 4, -1);
|
||||
for (int i = 0; i < d.length; ++i) {
|
||||
d[i] = interpolator.d[i].clone();
|
||||
}
|
||||
|
@ -199,7 +198,7 @@ class DormandPrince853FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
* @return p/q computed in the instance field
|
||||
*/
|
||||
private T fraction(final double p, final double q) {
|
||||
return integrator.getField().getOne().multiply(p).divide(q);
|
||||
return getField().getOne().multiply(p).divide(q);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -86,7 +86,7 @@ public class EulerFieldIntegrator<T extends RealFieldElement<T>> extends RungeKu
|
|||
@Override
|
||||
protected EulerFieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new EulerFieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new EulerFieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -50,14 +50,13 @@ class EulerFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
extends RungeKuttaFieldStepInterpolator<T> {
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
EulerFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
EulerFieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
@ -83,12 +82,12 @@ class EulerFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
final T oneMinusThetaH) {
|
||||
final T[] interpolatedState;
|
||||
final T[] interpolatedDerivatives;
|
||||
if ((getGlobalPreviousState() != null) && (theta.getReal() <= 0.5)) {
|
||||
if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
|
||||
interpolatedState = previousStateLinearCombination(theta.multiply(h));
|
||||
interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
|
||||
interpolatedDerivatives = derivativeLinearCombination(getField().getOne());
|
||||
} else {
|
||||
interpolatedState = currentStateLinearCombination(oneMinusThetaH.negate());
|
||||
interpolatedDerivatives = derivativeLinearCombination(time.getField().getOne());
|
||||
interpolatedDerivatives = derivativeLinearCombination(getField().getOne());
|
||||
}
|
||||
|
||||
return new FieldODEStateAndDerivative<T>(time, interpolatedState, interpolatedDerivatives);
|
||||
|
|
|
@ -111,7 +111,7 @@ public class GillFieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected GillFieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new GillFieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new GillFieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
import org.apache.commons.math4.util.FastMath;
|
||||
|
@ -66,14 +66,13 @@ class GillFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
private static final double ONE_PLUS_INV_SQRT_2 = 1 + FastMath.sqrt(0.5);
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
GillFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
GillFieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
@ -99,7 +98,7 @@ class GillFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
final T time, final T theta,
|
||||
final T oneMinusThetaH) {
|
||||
|
||||
final T one = time.getField().getOne();
|
||||
final T one = getField().getOne();
|
||||
final T twoTheta = theta.multiply(2);
|
||||
final T fourTheta2 = twoTheta.multiply(twoTheta);
|
||||
final T coeffDot1 = theta.multiply(twoTheta.subtract(3)).add(1);
|
||||
|
|
|
@ -165,7 +165,7 @@ public class HighamHall54FieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected HighamHall54FieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new HighamHall54FieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new HighamHall54FieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -36,14 +36,13 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
extends RungeKuttaFieldStepInterpolator<T> {
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
HighamHall54FieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
HighamHall54FieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
@ -70,7 +69,7 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
final T oneMinusThetaH) {
|
||||
|
||||
final T bDot0 = theta.multiply(theta.multiply(theta.multiply( -10.0 ).add( 16.0 )).add(-15.0 / 2.0)).add(1);
|
||||
final T bDot1 = time.getField().getZero();
|
||||
final T bDot1 = getField().getZero();
|
||||
final T bDot2 = theta.multiply(theta.multiply(theta.multiply( 135.0 / 2.0).add(-729.0 / 8.0)).add(459.0 / 16.0));
|
||||
final T bDot3 = theta.multiply(theta.multiply(theta.multiply(-120.0 ).add( 152.0 )).add(-44.0 ));
|
||||
final T bDot4 = theta.multiply(theta.multiply(theta.multiply( 125.0 / 2.0).add(-625.0 / 8.0)).add(375.0 / 16.0));
|
||||
|
@ -81,7 +80,7 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
if (getGlobalPreviousState() != null && theta.getReal() <= 0.5) {
|
||||
final T hTheta = h.multiply(theta);
|
||||
final T b0 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply( -5.0 / 2.0).add( 16.0 / 3.0)).add(-15.0 / 4.0)).add(1));
|
||||
final T b1 = time.getField().getZero();
|
||||
final T b1 = getField().getZero();
|
||||
final T b2 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(135.0 / 8.0).add(-243.0 / 8.0)).add(459.0 / 32.0)));
|
||||
final T b3 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(-30.0 ).add( 152.0 / 3.0)).add(-22.0 )));
|
||||
final T b4 = hTheta.multiply(theta.multiply(theta.multiply(theta.multiply(125.0 / 8.0).add(-625.0 / 24.0)).add(375.0 / 32.0)));
|
||||
|
@ -91,7 +90,7 @@ class HighamHall54FieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
} else {
|
||||
final T theta2 = theta.multiply(theta);
|
||||
final T b0 = h.multiply( theta.multiply(theta.multiply(theta.multiply(theta.multiply(-5.0 / 2.0).add( 16.0 / 3.0)).add( -15.0 / 4.0)).add( 1.0 )).add( -1.0 / 12.0));
|
||||
final T b1 = time.getField().getZero();
|
||||
final T b1 = getField().getZero();
|
||||
final T b2 = h.multiply(theta2.multiply(theta.multiply(theta.multiply( 135.0 / 8.0 ).add(-243.0 / 8.0)).add(459.0 / 32.0)).add( -27.0 / 32.0));
|
||||
final T b3 = h.multiply(theta2.multiply(theta.multiply(theta.multiply( -30.0 ).add( 152.0 / 3.0)).add(-22.0 )).add( 4.0 / 3.0));
|
||||
final T b4 = h.multiply(theta2.multiply(theta.multiply(theta.multiply( 125.0 / 8.0 ).add(-625.0 / 24.0)).add(375.0 / 32.0)).add(-125.0 / 96.0));
|
||||
|
|
|
@ -138,7 +138,7 @@ public class LutherFieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected LutherFieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new LutherFieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new LutherFieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -81,15 +81,14 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
private final T d6c;
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
LutherFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
LutherFieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
final T q = rkIntegrator.getField().getOne().multiply(21).sqrt();
|
||||
super(field, forward, mapper);
|
||||
final T q = field.getOne().multiply(21).sqrt();
|
||||
c5a = q.multiply( -49).add( -49);
|
||||
c5b = q.multiply( 287).add( 392);
|
||||
c5c = q.multiply( -357).add( -637);
|
||||
|
@ -188,7 +187,7 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
// At the end, we get the b_i as polynomials in theta.
|
||||
|
||||
final T coeffDot1 = theta.multiply(theta.multiply(theta.multiply(theta.multiply( 21 ).add( -47 )).add( 36 )).add( -54 / 5.0)).add(1);
|
||||
final T coeffDot2 = theta.getField().getZero();
|
||||
final T coeffDot2 = getField().getZero();
|
||||
final T coeffDot3 = theta.multiply(theta.multiply(theta.multiply(theta.multiply( 112 ).add(-608 / 3.0)).add( 320 / 3.0 )).add(-208 / 15.0));
|
||||
final T coeffDot4 = theta.multiply(theta.multiply(theta.multiply(theta.multiply( -567 / 5.0).add( 972 / 5.0)).add( -486 / 5.0 )).add( 324 / 25.0));
|
||||
final T coeffDot5 = theta.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(5)).add(c5b.divide(15))).add(c5c.divide(30))).add(c5d.divide(150)));
|
||||
|
@ -201,7 +200,7 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
|
||||
final T s = theta.multiply(theta.multiply(h));
|
||||
final T coeff1 = s.multiply(theta.multiply(theta.multiply(theta.multiply( 21 / 5.0).add( -47 / 4.0)).add( 12 )).add( -27 / 5.0)).add(1);
|
||||
final T coeff2 = s.getField().getZero();
|
||||
final T coeff2 = getField().getZero();
|
||||
final T coeff3 = s.multiply(theta.multiply(theta.multiply(theta.multiply( 112 / 5.0).add(-152 / 3.0)).add( 320 / 9.0 )).add(-104 / 15.0));
|
||||
final T coeff4 = s.multiply(theta.multiply(theta.multiply(theta.multiply(-567 / 25.0).add( 243 / 5.0)).add( -162 / 5.0 )).add( 162 / 25.0));
|
||||
final T coeff5 = s.multiply(theta.multiply(theta.multiply(theta.multiply(c5a.divide(25)).add(c5b.divide(60))).add(c5c.divide(90))).add(c5d.divide(300)));
|
||||
|
@ -213,7 +212,7 @@ class LutherFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
|
||||
final T s = oneMinusThetaH.multiply(theta);
|
||||
final T coeff1 = s.multiply(theta.multiply(theta.multiply(theta.multiply( -21 / 5.0).add( 151 / 20.0)).add( -89 / 20.0)).add( 19 / 20.0)).add( -1 / 20.0);
|
||||
final T coeff2 = s.getField().getZero();
|
||||
final T coeff2 = getField().getZero();
|
||||
final T coeff3 = s.multiply(theta.multiply(theta.multiply(theta.multiply(-112 / 5.0).add( 424 / 15.0)).add( -328 / 45.0)).add( -16 / 45.0)).add(-16 / 45.0);
|
||||
final T coeff4 = s.multiply(theta.multiply(theta.multiply(theta.multiply( 567 / 25.0).add( -648 / 25.0)).add( 162 / 25.0)));
|
||||
final T coeff5 = s.multiply(theta.multiply(theta.multiply(theta.multiply(d5a.divide(25)).add(d5b.divide(300))).add(d5c.divide(900))).add( -49 / 180.0)).add(-49 / 180.0);
|
||||
|
|
|
@ -86,7 +86,7 @@ public class MidpointFieldIntegrator<T extends RealFieldElement<T>> extends Rung
|
|||
@Override
|
||||
protected MidpointFieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new MidpointFieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new MidpointFieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -52,14 +52,13 @@ class MidpointFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
extends RungeKuttaFieldStepInterpolator<T> {
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
MidpointFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
MidpointFieldStepInterpolator(Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
@ -86,7 +85,7 @@ class MidpointFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
final T oneMinusThetaH) {
|
||||
|
||||
final T coeffDot2 = theta.multiply(2);
|
||||
final T coeffDot1 = time.getField().getOne().subtract(coeffDot2);
|
||||
final T coeffDot1 = getField().getOne().subtract(coeffDot2);
|
||||
final T[] interpolatedState;
|
||||
final T[] interpolatedDerivatives;
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.sampling.AbstractFieldStepInterpolator;
|
||||
import org.apache.commons.math4.util.MathArrays;
|
||||
|
@ -36,36 +36,25 @@ import org.apache.commons.math4.util.MathArrays;
|
|||
abstract class RungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
|
||||
extends AbstractFieldStepInterpolator<T> {
|
||||
|
||||
/** Reference to the integrator. */
|
||||
protected AbstractFieldIntegrator<T> integrator;
|
||||
/** Field to which the time and state vector elements belong. */
|
||||
private final Field<T> field;
|
||||
|
||||
/** Slopes at the intermediate points. */
|
||||
private T[][] yDotK;
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
protected RungeKuttaFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
protected RungeKuttaFieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(forward, mapper);
|
||||
this.yDotK = null;
|
||||
this.integrator = rkIntegrator;
|
||||
this.field = field;
|
||||
this.yDotK = null;
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
||||
* <p>The copied interpolator should have been finalized before the
|
||||
* copy, otherwise the copy will not be able to perform correctly any
|
||||
* interpolation and will throw a {@link NullPointerException}
|
||||
* later. Since we don't want this constructor to throw the
|
||||
* exceptions finalization may involve and since we don't want this
|
||||
* method to modify the state of the copied interpolator,
|
||||
* finalization is <strong>not</strong> done automatically, it
|
||||
* remains under user control.</p>
|
||||
|
||||
* <p>The copy is a deep copy: its arrays are separated from the
|
||||
* original arrays of the instance.</p>
|
||||
|
||||
|
@ -75,10 +64,10 @@ abstract class RungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
RungeKuttaFieldStepInterpolator(final RungeKuttaFieldStepInterpolator<T> interpolator) {
|
||||
|
||||
super(interpolator);
|
||||
field = interpolator.field;
|
||||
|
||||
if (yDotK != null) {
|
||||
yDotK = MathArrays.buildArray(interpolator.integrator.getField(),
|
||||
interpolator.yDotK.length, -1);
|
||||
yDotK = MathArrays.buildArray(field, interpolator.yDotK.length, -1);
|
||||
for (int k = 0; k < yDotK.length; ++k) {
|
||||
yDotK[k] = interpolator.yDotK[k].clone();
|
||||
}
|
||||
|
@ -87,10 +76,13 @@ abstract class RungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
yDotK = null;
|
||||
}
|
||||
|
||||
// we cannot keep any reference to the equations in the copy
|
||||
// the interpolator should have been finalized before
|
||||
integrator = null;
|
||||
}
|
||||
|
||||
/** Get the field to which the time and state vector elements belong.
|
||||
* @return to which the time and state vector elements belong
|
||||
*/
|
||||
protected Field<T> getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
/** Store the slopes at the intermediate points.
|
||||
|
@ -126,8 +118,7 @@ abstract class RungeKuttaFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T[] derivativeLinearCombination(final T ... coefficients) {
|
||||
return combine(MathArrays.buildArray(integrator.getField(), yDotK[0].length),
|
||||
coefficients);
|
||||
return combine(MathArrays.buildArray(field, yDotK[0].length), coefficients);
|
||||
}
|
||||
|
||||
/** Linearly combine arrays.
|
||||
|
|
|
@ -100,7 +100,7 @@ public class ThreeEighthesFieldIntegrator<T extends RealFieldElement<T>>
|
|||
@Override
|
||||
protected ThreeEighthesFieldStepInterpolator<T>
|
||||
createInterpolator(final boolean forward, final FieldEquationsMapper<T> mapper) {
|
||||
return new ThreeEighthesFieldStepInterpolator<T>(this, forward, mapper);
|
||||
return new ThreeEighthesFieldStepInterpolator<T>(getField(), forward, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.apache.commons.math4.ode.nonstiff;
|
||||
|
||||
import org.apache.commons.math4.Field;
|
||||
import org.apache.commons.math4.RealFieldElement;
|
||||
import org.apache.commons.math4.ode.AbstractFieldIntegrator;
|
||||
import org.apache.commons.math4.ode.FieldEquationsMapper;
|
||||
import org.apache.commons.math4.ode.FieldODEStateAndDerivative;
|
||||
|
||||
|
@ -62,14 +62,13 @@ class ThreeEighthesFieldStepInterpolator<T extends RealFieldElement<T>>
|
|||
extends RungeKuttaFieldStepInterpolator<T> {
|
||||
|
||||
/** Simple constructor.
|
||||
* @param rkIntegrator integrator being used
|
||||
* @param field field to which the time and state vector elements belong
|
||||
* @param forward integration direction indicator
|
||||
* @param mapper equations mapper for the all equations
|
||||
*/
|
||||
ThreeEighthesFieldStepInterpolator(final AbstractFieldIntegrator<T> rkIntegrator,
|
||||
final boolean forward,
|
||||
ThreeEighthesFieldStepInterpolator(final Field<T> field, final boolean forward,
|
||||
final FieldEquationsMapper<T> mapper) {
|
||||
super(rkIntegrator, forward, mapper);
|
||||
super(field, forward, mapper);
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
|
|
@ -55,9 +55,6 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
|
|||
/** Soft current state. */
|
||||
private FieldODEStateAndDerivative<T> softCurrentState;
|
||||
|
||||
/** indicate if the step has been finalized or not. */
|
||||
private boolean finalized;
|
||||
|
||||
/** integration direction. */
|
||||
private boolean forward;
|
||||
|
||||
|
@ -75,27 +72,14 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
|
|||
softPreviousState = null;
|
||||
softCurrentState = null;
|
||||
h = null;
|
||||
finalized = false;
|
||||
this.forward = isForward;
|
||||
this.mapper = equationsMapper;
|
||||
}
|
||||
|
||||
/** Copy constructor.
|
||||
|
||||
* <p>The copied interpolator should have been finalized before the
|
||||
* copy, otherwise the copy will not be able to perform correctly
|
||||
* any derivative computation and will throw a {@link
|
||||
* NullPointerException} later. Since we don't want this constructor
|
||||
* to throw the exceptions finalization may involve and since we
|
||||
* don't want this method to modify the state of the copied
|
||||
* interpolator, finalization is <strong>not</strong> done
|
||||
* automatically, it remains under user control.</p>
|
||||
|
||||
* <p>The copy is a deep copy: its arrays are separated from the
|
||||
* original arrays of the instance.</p>
|
||||
|
||||
* @param interpolator interpolator to copy from.
|
||||
|
||||
*/
|
||||
protected AbstractFieldStepInterpolator(final AbstractFieldStepInterpolator<T> interpolator) {
|
||||
|
||||
|
@ -104,7 +88,6 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
|
|||
softPreviousState = interpolator.softPreviousState;
|
||||
softCurrentState = interpolator.softCurrentState;
|
||||
h = interpolator.h;
|
||||
finalized = interpolator.finalized;
|
||||
forward = interpolator.forward;
|
||||
mapper = interpolator.mapper;
|
||||
|
||||
|
@ -113,20 +96,13 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
|
|||
/** {@inheritDoc} */
|
||||
public FieldStepInterpolator<T> copy() throws MaxCountExceededException {
|
||||
|
||||
// finalize the step before performing copy
|
||||
finalizeStep();
|
||||
|
||||
// create the new independent instance
|
||||
return doCopy();
|
||||
|
||||
}
|
||||
|
||||
/** Really copy the finalized instance.
|
||||
* <p>This method is called by {@link #copy()} after the
|
||||
* step has been finalized. It must perform a deep copy
|
||||
* to have an new instance completely independent for the
|
||||
* original instance.
|
||||
* @return a copy of the finalized instance
|
||||
/** Really copy the instance.
|
||||
* @return a copy of the instance
|
||||
*/
|
||||
protected abstract FieldStepInterpolator<T> doCopy();
|
||||
|
||||
|
@ -144,16 +120,11 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
|
|||
* @param state current state
|
||||
*/
|
||||
public void storeState(final FieldODEStateAndDerivative<T> state) {
|
||||
|
||||
globalCurrentState = state;
|
||||
softCurrentState = globalCurrentState;
|
||||
if (globalPreviousState != null) {
|
||||
h = globalCurrentState.getTime().subtract(globalPreviousState.getTime());
|
||||
}
|
||||
|
||||
// the step is not finalized anymore
|
||||
finalized = false;
|
||||
|
||||
}
|
||||
|
||||
/** Restrict step range to a limited part of the global step.
|
||||
|
@ -240,60 +211,4 @@ public abstract class AbstractFieldStepInterpolator<T extends RealFieldElement<T
|
|||
T time, T theta, T oneMinusThetaH)
|
||||
throws MaxCountExceededException;
|
||||
|
||||
/**
|
||||
* Finalize the step.
|
||||
|
||||
* <p>Some embedded Runge-Kutta integrators need fewer functions
|
||||
* evaluations than their counterpart step interpolators. These
|
||||
* interpolators should perform the last evaluations they need by
|
||||
* themselves only if they need them. This method triggers these
|
||||
* extra evaluations. It can be called directly by the user step
|
||||
* handler and it is called automatically if {@link
|
||||
* #setInterpolatedTime} is called.</p>
|
||||
|
||||
* <p>Once this method has been called, <strong>no</strong> other
|
||||
* evaluation will be performed on this step. If there is a need to
|
||||
* have some side effects between the step handler and the
|
||||
* differential equations (for example update some data in the
|
||||
* equations once the step has been done), it is advised to call
|
||||
* this method explicitly from the step handler before these side
|
||||
* effects are set up. If the step handler induces no side effect,
|
||||
* then this method can safely be ignored, it will be called
|
||||
* transparently as needed.</p>
|
||||
|
||||
* <p><strong>Warning</strong>: since the step interpolator provided
|
||||
* to the step handler as a parameter of the {@link
|
||||
* StepHandler#handleStep handleStep} is valid only for the duration
|
||||
* of the {@link StepHandler#handleStep handleStep} call, one cannot
|
||||
* simply store a reference and reuse it later. One should first
|
||||
* finalize the instance, then copy this finalized instance into a
|
||||
* new object that can be kept.</p>
|
||||
|
||||
* <p>This method calls the protected <code>doFinalize</code> method
|
||||
* if it has never been called during this step and set a flag
|
||||
* indicating that it has been called once. It is the <code>
|
||||
* doFinalize</code> method which should perform the evaluations.
|
||||
* This wrapping prevents from calling <code>doFinalize</code> several
|
||||
* times and hence evaluating the differential equations too often.
|
||||
* Therefore, subclasses are not allowed not reimplement it, they
|
||||
* should rather reimplement <code>doFinalize</code>.</p>
|
||||
|
||||
* @exception MaxCountExceededException if the number of functions evaluations is exceeded
|
||||
|
||||
*/
|
||||
public final void finalizeStep() throws MaxCountExceededException {
|
||||
if (! finalized) {
|
||||
doFinalize();
|
||||
finalized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Really finalize the step.
|
||||
* The default implementation of this method does nothing.
|
||||
* @exception MaxCountExceededException if the number of functions evaluations is exceeded
|
||||
*/
|
||||
protected void doFinalize() throws MaxCountExceededException {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue