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.ode.FieldEquationsMapper; 023import org.apache.commons.math4.legacy.ode.FieldODEStateAndDerivative; 024import org.apache.commons.math4.legacy.core.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 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 @Override 075 public T[] getC() { 076 final T q = getField().getZero().add(21).sqrt(); 077 final T[] c = MathArrays.buildArray(getField(), 6); 078 c[0] = getField().getOne(); 079 c[1] = fraction(1, 2); 080 c[2] = fraction(2, 3); 081 c[3] = q.subtract(7).divide(-14); 082 c[4] = q.add(7).divide(14); 083 c[5] = getField().getOne(); 084 return c; 085 } 086 087 /** {@inheritDoc} */ 088 @Override 089 public T[][] getA() { 090 final T q = getField().getZero().add(21).sqrt(); 091 final T[][] a = MathArrays.buildArray(getField(), 6, -1); 092 for (int i = 0; i < a.length; ++i) { 093 a[i] = MathArrays.buildArray(getField(), i + 1); 094 } 095 a[0][0] = getField().getOne(); 096 a[1][0] = fraction(3, 8); 097 a[1][1] = fraction(1, 8); 098 a[2][0] = fraction(8, 27); 099 a[2][1] = fraction(2, 27); 100 a[2][2] = a[2][0]; 101 a[3][0] = q.multiply( 9).add( -21).divide( 392); 102 a[3][1] = q.multiply( 8).add( -56).divide( 392); 103 a[3][2] = q.multiply( -48).add( 336).divide( 392); 104 a[3][3] = q.multiply( 3).add( -63).divide( 392); 105 a[4][0] = q.multiply(-255).add(-1155).divide(1960); 106 a[4][1] = q.multiply( -40).add( -280).divide(1960); 107 a[4][2] = q.multiply(-320) .divide(1960); 108 a[4][3] = q.multiply( 363).add( 63).divide(1960); 109 a[4][4] = q.multiply( 392).add( 2352).divide(1960); 110 a[5][0] = q.multiply( 105).add( 330).divide( 180); 111 a[5][1] = fraction(2, 3); 112 a[5][2] = q.multiply( 280).add( -200).divide( 180); 113 a[5][3] = q.multiply(-189).add( 126).divide( 180); 114 a[5][4] = q.multiply(-126).add( -686).divide( 180); 115 a[5][5] = q.multiply( -70).add( 490).divide( 180); 116 return a; 117 } 118 119 /** {@inheritDoc} */ 120 @Override 121 public T[] getB() { 122 123 final T[] b = MathArrays.buildArray(getField(), 7); 124 b[0] = fraction( 1, 20); 125 b[1] = getField().getZero(); 126 b[2] = fraction(16, 45); 127 b[3] = getField().getZero(); 128 b[4] = fraction(49, 180); 129 b[5] = b[4]; 130 b[6] = b[0]; 131 132 return b; 133 } 134 135 /** {@inheritDoc} */ 136 @Override 137 protected LutherFieldStepInterpolator<T> 138 createInterpolator(final boolean forward, T[][] yDotK, 139 final FieldODEStateAndDerivative<T> globalPreviousState, 140 final FieldODEStateAndDerivative<T> globalCurrentState, 141 final FieldEquationsMapper<T> mapper) { 142 return new LutherFieldStepInterpolator<>(getField(), forward, yDotK, 143 globalPreviousState, globalCurrentState, 144 globalPreviousState, globalCurrentState, 145 mapper); 146 } 147}