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.math3.ode.nonstiff; 019 020import org.apache.commons.math3.Field; 021import org.apache.commons.math3.RealFieldElement; 022import org.apache.commons.math3.ode.FieldEquationsMapper; 023import org.apache.commons.math3.ode.FieldODEStateAndDerivative; 024import org.apache.commons.math3.util.MathArrays; 025 026 027/** 028 * This class implements the Luther sixth order Runge-Kutta 029 * integrator for Ordinary Differential Equations. 030 031 * <p> 032 * This method is described in H. A. Luther 1968 paper <a 033 * href="http://www.ams.org/journals/mcom/1968-22-102/S0025-5718-68-99876-1/S0025-5718-68-99876-1.pdf"> 034 * An explicit Sixth-Order Runge-Kutta Formula</a>. 035 * </p> 036 037 * <p>This method is an explicit Runge-Kutta method, its Butcher-array 038 * is the following one : 039 * <pre> 040 * 0 | 0 0 0 0 0 0 041 * 1 | 1 0 0 0 0 0 042 * 1/2 | 3/8 1/8 0 0 0 0 043 * 2/3 | 8/27 2/27 8/27 0 0 0 044 * (7-q)/14 | ( -21 + 9q)/392 ( -56 + 8q)/392 ( 336 - 48q)/392 ( -63 + 3q)/392 0 0 045 * (7+q)/14 | (-1155 - 255q)/1960 ( -280 - 40q)/1960 ( 0 - 320q)/1960 ( 63 + 363q)/1960 ( 2352 + 392q)/1960 0 046 * 1 | ( 330 + 105q)/180 ( 120 + 0q)/180 ( -200 + 280q)/180 ( 126 - 189q)/180 ( -686 - 126q)/180 ( 490 - 70q)/180 047 * |-------------------------------------------------------------------------------------------------------------------------------------------------- 048 * | 1/20 0 16/45 0 49/180 49/180 1/20 049 * </pre> 050 * where q = √21</p> 051 * 052 * @see EulerFieldIntegrator 053 * @see ClassicalRungeKuttaFieldIntegrator 054 * @see GillFieldIntegrator 055 * @see MidpointFieldIntegrator 056 * @see ThreeEighthesFieldIntegrator 057 * @param <T> the type of the field elements 058 * @since 3.6 059 */ 060 061public class LutherFieldIntegrator<T extends RealFieldElement<T>> 062 extends RungeKuttaFieldIntegrator<T> { 063 064 /** Simple constructor. 065 * Build a fourth-order Luther integrator with the given step. 066 * @param field field to which the time and state vector elements belong 067 * @param step integration step 068 */ 069 public LutherFieldIntegrator(final Field<T> field, final T step) { 070 super(field, "Luther", step); 071 } 072 073 /** {@inheritDoc} */ 074 public T[] getC() { 075 final T q = getField().getZero().add(21).sqrt(); 076 final T[] c = MathArrays.buildArray(getField(), 6); 077 c[0] = getField().getOne(); 078 c[1] = fraction(1, 2); 079 c[2] = fraction(2, 3); 080 c[3] = q.subtract(7).divide(-14); 081 c[4] = q.add(7).divide(14); 082 c[5] = getField().getOne(); 083 return c; 084 } 085 086 /** {@inheritDoc} */ 087 public T[][] getA() { 088 final T q = getField().getZero().add(21).sqrt(); 089 final T[][] a = MathArrays.buildArray(getField(), 6, -1); 090 for (int i = 0; i < a.length; ++i) { 091 a[i] = MathArrays.buildArray(getField(), i + 1); 092 } 093 a[0][0] = getField().getOne(); 094 a[1][0] = fraction(3, 8); 095 a[1][1] = fraction(1, 8); 096 a[2][0] = fraction(8, 27); 097 a[2][1] = fraction(2, 27); 098 a[2][2] = a[2][0]; 099 a[3][0] = q.multiply( 9).add( -21).divide( 392); 100 a[3][1] = q.multiply( 8).add( -56).divide( 392); 101 a[3][2] = q.multiply( -48).add( 336).divide( 392); 102 a[3][3] = q.multiply( 3).add( -63).divide( 392); 103 a[4][0] = q.multiply(-255).add(-1155).divide(1960); 104 a[4][1] = q.multiply( -40).add( -280).divide(1960); 105 a[4][2] = q.multiply(-320) .divide(1960); 106 a[4][3] = q.multiply( 363).add( 63).divide(1960); 107 a[4][4] = q.multiply( 392).add( 2352).divide(1960); 108 a[5][0] = q.multiply( 105).add( 330).divide( 180); 109 a[5][1] = fraction(2, 3); 110 a[5][2] = q.multiply( 280).add( -200).divide( 180); 111 a[5][3] = q.multiply(-189).add( 126).divide( 180); 112 a[5][4] = q.multiply(-126).add( -686).divide( 180); 113 a[5][5] = q.multiply( -70).add( 490).divide( 180); 114 return a; 115 } 116 117 /** {@inheritDoc} */ 118 public T[] getB() { 119 120 final T[] b = MathArrays.buildArray(getField(), 7); 121 b[0] = fraction( 1, 20); 122 b[1] = getField().getZero(); 123 b[2] = fraction(16, 45); 124 b[3] = getField().getZero(); 125 b[4] = fraction(49, 180); 126 b[5] = b[4]; 127 b[6] = b[0]; 128 129 return b; 130 131 } 132 133 /** {@inheritDoc} */ 134 @Override 135 protected LutherFieldStepInterpolator<T> 136 createInterpolator(final boolean forward, T[][] yDotK, 137 final FieldODEStateAndDerivative<T> globalPreviousState, 138 final FieldODEStateAndDerivative<T> globalCurrentState, 139 final FieldEquationsMapper<T> mapper) { 140 return new LutherFieldStepInterpolator<T>(getField(), forward, yDotK, 141 globalPreviousState, globalCurrentState, 142 globalPreviousState, globalCurrentState, 143 mapper); 144 } 145 146}