use crate::polynomial;
#[derive(Clone)]
pub struct RungeKuttaTable<const S: usize>
where
[(); S * (S - 1) / 2]:,
{
pub order: usize,
pub order_embedded: usize,
pub order_interpolant: usize,
pub a: [f64; S * (S - 1) / 2],
pub b: [f64; S],
pub b2: [f64; S],
pub c: [f64; S],
pub bi: [crate::polynomial::Differentiable<fn(f64) -> f64, fn(f64) -> f64>; S],
}
impl<const S: usize> RungeKuttaTable<S>
where
[(); S * (S - 1) / 2]:,
{
pub fn a_indexed(&self, i: usize, j: usize) -> f64 {
self.a[i * (i - 1) / 2 + j]
}
}
pub static EULER: RungeKuttaTable<1> = RungeKuttaTable {
order: 1,
order_embedded: 0,
order_interpolant: 1,
a: [],
b: [1.],
b2: [0.],
c: [0.],
bi: [polynomial![0., 1.]],
};
#[macro_export]
macro_rules! generic_rk_order2 {
($TypeName:ident, $alpha:expr) => {
pub static $TypeName: RungeKuttaTable<2> = RungeKuttaTable {
order: 2,
order_embedded: 1,
order_interpolant: 1,
a: [$alpha],
b: [1. - 0.5 / $alpha, 0.5 / $alpha],
b2: [1., 0.],
c: [0., $alpha],
bi: [
polynomial![0., 1. - 0.5 / $alpha],
polynomial![0., 0.5 / $alpha],
], };
};
}
generic_rk_order2!(MIDPOINT, 0.5);
generic_rk_order2!(HEUN2, 1.);
generic_rk_order2!(RALSTON2, 2. / 3.);
#[macro_export]
macro_rules! generic_rk_order3 {
($TypeName:ident, $alpha:expr, $beta:expr) => {
pub static $TypeName: RungeKuttaTable<3> = RungeKuttaTable {
order: 3,
order_embedded: 2,
order_interpolant: 1,
a: [
$alpha,
($beta / $alpha) * ($beta - 3. * $alpha * (1. - $alpha)) / (3. * $alpha - 2.),
($beta / $alpha) * ($alpha - $beta) / (3. * $alpha - 2.),
],
b: [
1. - (3. * $alpha + 3. * $beta - 2.) / (6. * $alpha * $beta),
(3. * $beta - 2.) / (6. * $alpha * ($beta - $alpha)),
(2. - 3. * $alpha) / (6. * $beta * ($beta - $alpha)),
],
b2: [1. - 0.5 / $alpha, 0.5 / $alpha, 0.],
c: [0., $alpha, $beta],
bi: [
polynomial![
0.,
1. - (3. * $alpha + 3. * $beta - 2.) / (6. * $alpha * $beta)
],
polynomial![0., (3. * $beta - 2.) / (6. * $alpha * ($beta - $alpha))],
polynomial![0., (2. - 3. * $alpha) / (6. * $beta * ($beta - $alpha))],
], };
};
}
generic_rk_order3!(KUTTA3, 0.5, 1.);
generic_rk_order3!(HEUN3, 1. / 3., 2. / 3.);
generic_rk_order3!(RALSTON3, 1. / 2., 3. / 4.); generic_rk_order3!(WRAY3, 8. / 15., 2. / 3.);
generic_rk_order3!(SSP3, 1., 1. / 2.);
pub static CLASSIC4: RungeKuttaTable<4> = RungeKuttaTable {
order: 4,
order_embedded: 2,
order_interpolant: 3,
a: [
0.5, 0., 0.5, 0.0, 0.0, 1.0,
],
b: [1. / 6., 1. / 3., 1. / 3., 1. / 6.],
b2: [0., 1., 0., 0.],
c: [0., 0.5, 0.5, 1.],
bi: [
polynomial![0., 1., -1.5, 2. / 3.],
polynomial![0., 0., 1., -2. / 3.],
polynomial![0., 0., 1., -2. / 3.],
polynomial![0., 0., -0.5, 2. / 3.],
],
};
pub static CLASSIC43: RungeKuttaTable<5> = RungeKuttaTable {
order: 4,
order_embedded: 3,
order_interpolant: 3,
a: [
0.5, 0.,
0.5, 0.0,
0.0,
1.0, 5. / 32.,
7. / 32.,
13. / 32.,
-1. / 32., ],
b: [1. / 6., 1. / 3., 1. / 3., 1. / 6., 0.],
b2: [-1. / 2., 7. / 3., 7. / 3., 13. / 6., -16. / 3.],
c: [0., 0.5, 0.5, 1., 0.75],
bi: [
polynomial![0., 1., -1.5, 2. / 3.],
polynomial![0., 0., 1., -2. / 3.],
polynomial![0., 0., 1., -2. / 3.],
polynomial![0., 0., -0.5, 2. / 3.],
polynomial![0.],
],
};
pub static DP544: RungeKuttaTable<7> = RungeKuttaTable {
order: 5,
order_embedded: 4,
order_interpolant: 4,
a: [
0.20000000000000000000000000000000000000000000000000,
0.07500000000000000000000000000000000000000000000000,
0.22500000000000000000000000000000000000000000000000,
0.97777777777777777777777777777777777777777777777778,
-3.73333333333333333333333333333333333333333333333330,
3.55555555555555555555555555555555555555555555555560,
2.95259868922420362749580856576741350403901844231060,
-11.59579332418838591678097850937357110196616369455900,
9.82289285169943606157597927145252248132906569120560,
-0.29080932784636488340192043895747599451303155006859,
2.84627525252525252525252525252525252525252525252530,
-10.75757575757575757575757575757575757575757575757600,
8.90642271774347246045359252906422717743472460453590,
0.27840909090909090909090909090909090909090909090909,
-0.27353130360205831903945111492281303602058319039451,
0.09114583333333333333333333333333333333333333333333,
0.00000000000000000000000000000000000000000000000000,
0.44923629829290206648697214734950584007187780772686,
0.65104166666666666666666666666666666666666666666667,
-0.32237617924528301886792452830188679245283018867925,
0.13095238095238095238095238095238095238095238095238,
],
b: [
0.09114583333333333333333333333333333333333333333333,
0.00000000000000000000000000000000000000000000000000,
0.44923629829290206648697214734950584007187780772686,
0.65104166666666666666666666666666666666666666666667,
-0.32237617924528301886792452830188679245283018867925,
0.13095238095238095238095238095238095238095238095238,
0.,
],
b2: [
0.08991319444444444444444444444444444444444444444444,
0.00000000000000000000000000000000000000000000000000,
0.45348906858340820604971548367774782869122491764001,
0.61406250000000000000000000000000000000000000000000,
-0.27151238207547169811320754716981132075471698113208,
0.08904761904761904761904761904761904761904761904762,
0.02500000000000000000000000000000000000000000000000,
],
c: [
0.00000000000000000000000000000000000000000000000000,
0.20000000000000000000000000000000000000000000000000,
0.30000000000000000000000000000000000000000000000000,
0.80000000000000000000000000000000000000000000000000,
0.88888888888888888888888888888888888888888888888889,
1.00000000000000000000000000000000000000000000000000,
1.00000000000000000000000000000000000000000000000000,
],
bi: [
polynomial![
0.00000000000000000000000000000000000000000000000000,
1.00000000000000000000000000000000000000000000000000,
-2.86053866903708863097943370885663105213518085381780,
3.09957787870912092268605753792811855250234711279230,
-1.16181058364030928576714728261967728193248499746470,
0.01391720730161032739385678688152311489865207182347
],
polynomial![0.],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
4.04714149964278557319049904942449527421302289187800,
-6.34535404693892573505342403022818979479695679525830,
2.79546508641400508297021164893042296731423395351700,
-0.04801624082496285462031452077722260665842224240982
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
7.84741007111265892938301126569893156405542561453250,
-13.50816969460696101391505947117688990840374671710300,
6.72931750920927857301441847859031845797454992394090,
-0.41751621904830982181570360644569344695956215470417
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
2.84194470158703464060417964659343605697434957168720,
-7.54767586295938599838505349903387310042704029578820,
4.95763672493125298061794541677800406766688093311860,
-0.57428174280418464170499609263945381666702039769687
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
2.39670292163108553124449083469142506413685252737370,
-4.74272536284904180356196142354156484858415188009150,
2.95010386556673177529521224777075926666250808282390,
-0.47312904339639455059678927796823852983425634915370
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
1.52360049411133393144135467348444915173617479911710,
-4.32946547433983506636374840484767697183937753380880,
3.08812946634566833840343278924200648847023067026640,
-0.28226448611716720348103905787877866836702793557465
],
],
};
pub static RKTP64: RungeKuttaTable<7> = RungeKuttaTable {
order: 6,
order_embedded: 4,
order_interpolant: 4,
a: [
0.14814814814814814814814814814814814814814814814815,
0.05555555555555555555555555555555555555555555555556,
0.16666666666666666666666666666666666666666666666667,
0.19241982507288629737609329446064139941690962099125,
-0.53134110787172011661807580174927113702623906705539,
0.76749271137026239067055393586005830903790087463557,
0.27138264973958333333333333333333333333333333333333,
-0.28179931640625000000000000000000000000000000000000,
0.10191932091346153846153846153846153846153846153846,
0.59599734575320512820512820512820512820512820512821,
-0.12140681348692272679528027730121494345436084170722,
0.47761410187445690404270285927090660818471469359043,
0.12192296968479080920271208457739825271063725338342,
0.00820786686248269381285345905535723094994297948894,
0.28289264429596155050624264362832208237829668447521,
0.32310946589106292966684294024325753569539925965098,
-0.61039132734003172924378635642517186673717609730301,
0.45846867541639319976612888047255080412929454343221,
0.57505740806711566278133278660922926335638856572569,
-0.57379234522267681781745625845989491691225880929347,
0.82754812318813675484693800756002918046835253778760,
],
b: [
0.07277777777777777777777777777777777777777777777778,
0.00000000000000000000000000000000000000000000000000,
0.28752127070690503526324421846809906511399048712482,
0.18974846220396832187710941882243328294496258901153,
0.10581736348682550735167973519824811036097403449285,
0.26909544328484081804764916719375922411975542905334,
0.07503968253968253968253968253968253968253968253968,
],
b2: [
0.10322666047518118524035683798997408464864086165861,
0.00000000000000000000000000000000000000000000000000,
0.15611542056134071025476537742246069068941506933613,
0.38634918851063907802720917783777796648011517818308,
-0.12073095208684351320487107578989528150071079171750,
0.40000000000000000000000000000000000000000000000000,
0.07503968253968253968253968253968253968253968253968,
],
c: [
0.00000000000000000000000000000000000000000000000000,
0.14814814814814814814814814814814814814814814814815,
0.22222222222222222222222222222222222222222222222222,
0.42857142857142857142857142857142857142857142857143,
0.68750000000000000000000000000000000000000000000000,
0.76923076923076923076923076923076923076923076923077,
1.00000000000000000000000000000000000000000000000000,
],
bi: [
polynomial![
0.00000000000000000000000000000000000000000000000000,
1.00000000000000000000000000000000000000000000000000,
-3.18888888888888888888888888888888888888888888888890,
3.62962962962962962962962962962962962962962962962960,
-1.36796296296296296296296296296296296296296296296300
],
polynomial![0.],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
3.13664097096932917828440216499917992455305888141710,
-4.87567656224372642283090044284074134820403477119900,
2.02655686198130227980974249630966048876496637690670
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
1.44306660772178013557323902151488358384910109048040,
-2.68732193732193732193732193732193732193732193732190,
1.43400379180412550824119233462948702103318343585310
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-1.84105678504031566306399039286326985760850917824670,
5.43416252072968490878938640132669983416252072968490,
-3.48728837220254373837371627326518186619303751694540
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.26909544328484081804764916719375922411975542905334
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.45023809523809523809523809523809523809523809523810,
-1.50079365079365079365079365079365079365079365079370,
1.12559523809523809523809523809523809523809523809520
],
],
};
pub static RK98: RungeKuttaTable<26> = RungeKuttaTable {
order: 9,
order_embedded: 8,
order_interpolant: 9,
a: [
0.02173913043478260869565217391304347826086956521739,
-0.11698050118114486205818241524969622410384223979750,
0.21327631165914552875931243204789548369469882662606,
0.03611092892925025001292375629932472234657122006071,
0.00000000000000000000000000000000000000000000000000,
0.10833278678775075003877126889797416703971366018213,
1.57329743908138605107331820072051125641643664351840,
0.00000000000000000000000000000000000000000000000000,
-5.98400943754042002888532938159655553518127689802840,
4.93277082198844574251789353381722074935307554862770,
0.05052046351120380909008334360006234635511181026904,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.17686653884807108146683657390397612041041458603582,
0.00103743376935980522339467349390418494016089864590,
0.10543148021953768958529340893598138847228076756097,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.16042415162569842979496486916719383758722635620698,
0.11643956912829316045688724281285250393566139141568,
0.48215663817720491194449759844838932144562487430754,
0.07148407148407148407148407148407148407148407148407,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.32971116090443908023196389566296464803047147789829,
0.24216141096813279233990867620960722454140109397428,
0.07162368881118881118881118881118881118881118881119,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.32859867301674234161492268975519694162614616072449,
0.11622213117906185418927311444060725417804964347131,
-0.03392701048951048951048951048951048951048951048951,
0.04861540768024729180628870095388582672433144665591,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.03998502200331629058445317782406268415701330226122,
0.10715724786209388876739304914053506956742307410965,
-0.02177735985419485163815426357369818120744539675290,
-0.10579849950964443770179884616296721742314060809206,
-0.02540141041535143673515871979014924329181062727138,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.03333333333333333333333333333333333333333333333333,
-0.16404854760069182073503553020238782592593403647268,
0.03410548898794737788891414566528526831566085030511,
0.15836825014108792658008718465091487655106285177706,
0.21425115805975734472868683695127609710041268915582,
0.00584833331460742801095934302256470549308679646338,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.53954170547283522916525526480339109942148038774928,
0.20128430845560909506500331018201158854604633245476,
0.04347222773254789483240207937678906296377158021513,
-0.00402998571475307250775349983910179275996883814082,
0.16541535721570612771420482097898952379873117545074,
0.79491862412512344573322086551518180067011337498503,
-0.39964965968794892497157706711861448695678584565418,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-3.79096577568393158554742638116249372887353065024400,
-0.40349325653530103387515807815498044092471404107174,
-2.82463879530435263378049668286220715075739684385580,
1.04226892772185985533374283289821416817127166596790,
1.12510956420436603974237036536924078456840460862590,
3.32746188718986816186934832571938138898823948848920,
2.77897957186355606325818219255783627737871451629350,
0.39545306350085237157098218205756922782986369303575,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
5.82534730759650564865380791881446903058807699346900,
-0.36527452339161313311889856846974452073623398661972,
1.18860324058346533283780076203192232785089866681400,
0.57970467638357921347110271762687972861039216753388,
-0.86824862589087693262676988867897834489078687404306,
-5.20227677296454721392873650976792184255513966123660,
-0.79895541420753382543211121058675915615228526471112,
0.14360623206363792632792463778889008006745916371712,
8.49173149061346398013352206978380938811254798993340,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
86.32213734729036800877634194386790750555422670274600,
1.02560575501091662034511526187393241359208569198630,
85.77427969817339941806831550695235092732332032750500,
-13.98699305104110611795532466113248067352882550543300,
-20.71537405501426352265946477613161883453956174939900,
-72.16597156619946800281180102605140463857857412313000,
-76.71211139107806345587696023064419687367770684849400,
4.22319427707298828839851258893735507229542133136690,
-1.25649850482823521641825667745565428655293381708110,
-0.42892119881959353241190195318730008417639822149654,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-9.16865700950084689999297912545025359698183674801910,
1.08317616770620939241547721530003920686134353927750,
-1.23501525358323653198215832293981810963597375606850,
-1.21438272617593906232943856422371019120407220077490,
1.37226168507232166621351243731869914944482408243940,
9.15723239697162418155377135344394113594434999702470,
1.30616301842220047563298585480401671671773488342750,
-0.25285618808937955976690569433069974710150241616240,
0.38099910799663987066763679926508552013153084035240,
0.,
0.01490902081978461022483617102382552714139242858034,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.20408044692054151258349120934134791804493401512634,
0.22901438600570447264772469337066476035313738023741,
0.12800558251147375669208211573729202273772361889244,
0.22380626846054143649770066956485937727843730877752,
0.39553165293700054420552389156421651666967336137950,
0.05416646758806981196568364538360743735174887121333,
0.12691439652445903685643385312168037657766579108702,
-0.00052539244262118876455834655383035812936087407348,
0.03225806451612903225806451612903225806451612903226,
0.01143264806162683148447352608770843130688351141325,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.25910015109834286167182847913811051830137442223646,
0.26112279003556667442851494524453052787002472281687,
0.13603667739783981942567006544587344590589804289156,
0.21092629039215214634081204784167201347024172152871,
0.38561044391652919964360639985117799502808490792199,
0.00000000000000000000000000000000000000000000000000,
-0.00661207532174157850691857234576611971973486711992,
0.00000000000000000000000000000000000000000000000000,
-0.02549161288435370222211805328157188244801688658368,
0.02751219795444402467679515824991164325730461483227,
0.01366553050159930930166731302454554940049222009174,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.30703861145677111921271332186217224799841379326854,
0.25209531563572099623089165079301458643067366819802,
0.13108277539906970515311706137497175525567091838414,
0.21767739046525384968495567501048448741046855719450,
0.44086627030905856048873271907826814086582814561606,
0.00000000000000000000000000000000000000000000000000,
0.03671380286728679808871157446816959412389047219748,
-0.00045263428475531956819180895665607423710403411430,
-0.00752193649177454591721507271076959964221495086879,
0.00381781692513482105657710979374559710571824486086,
0.07452014234905174240051667374295888702166343240036,
0.01426863149710284245309409940057111195308127443335,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.24769768181800691975188712358712398631268154510221,
0.23928330553460883713418088067890938883853043450243,
0.12957572153718905740865524351757452810319504278959,
0.22078879969474376788381528067483098071997409005309,
0.36428486485822390774749367125266645618774323905403,
0.00000000000000000000000000000000000000000000000000,
0.00783166659042742405456684521422197104086873705846,
0.00006696072309176359008965576062243656745153965412,
-0.01479434832379674567986088037176888215981416364508,
0.01339859945556782115718963777695706693487452717695,
-0.08561464270959380901174849009933592721195166560560,
0.00040934649811497276726885169474090131619386247796,
0.01315416784778302394778796429393391359821078814752,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.34064115650712902848454767806522148674988110973980,
0.22802117967789421808187939123391074518336948936375,
0.13228168138941728498745754543959845959659626758377,
0.21597957165624687772098521823642410479978633550578,
0.51134550887345867838216854890276241492637024855887,
0.00000000000000000000000000000000000000000000000000,
0.13917551936854006335051797420701256636234094494752,
-0.00312636012329300861796602288338736550448001732240,
0.02618510996527733154670238209897355649775068666869,
-0.03341753473396350345910565967207905894856919558461,
0.07081596525729571765935922085622248542225420029521,
-0.20353982182996909215211745048425036172008841918984,
-0.24770863310964368488502368393967138012952969325479,
0.02535507596578664932031351246091593949814494404530,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.05440996386349609121656663157070045464793254721685,
-0.04383375847722494049241141794100264855807886393200,
0.02004975742629538533433566091281326978879638368667,
-0.00024788254005617140123338195175924856793966108209,
-0.12631069893410859053275171105542159873073386248667,
-0.03185235193254086044315902079022722497630561986690,
-0.06704694264301271731581895794160923176097477168487,
0.00010020361409469529044674287425696551698927319203,
-0.02058006813631520532690069708211526721599611831714,
0.02589348708046929134179136762563794135533222732790,
-0.03046960070485182936594624634813505567055389582286,
0.12543272686714171665493501546618170172428163594695,
0.07618220610817938917076466998564450036117984749384,
0.03639614331221231394037218004020645910966506471776,
0.01539260500437667416207300294447936239290330334579,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.17131075511174303857639085783141963754266619245588,
-0.10295888800566485368063579215700773927269652716306,
0.12664807696330681131041807930982444346633998002093,
0.07679795618366181160227075596280714800652025849271,
-0.40129043104290115715583071856941395748061630637968,
-0.10720941030190793125136703649916815239268789397437,
-0.23585167882283796886405619950743294196730516370008,
0.00053603964667026801456954462757383400167752919925,
-0.07355830332551291707938141030886813931173955376693,
0.08929999738206475788365248983806601543063035448653,
-0.22492183865035113492267262337342014954667507893708,
0.46777943183166745833381467641314459026710282830244,
0.40340308656988142553355663504942481574534292202827,
-0.01490120806800580627232607108523829069098665393440,
0.,
0.01071645645556208366068447871756749021881341530816,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00476866951622914597617545886193301170210202532728,
0.05456214508825763866384150008974197336512377566682,
0.14024269581068762481098276983438197589332975761842,
0.15952085814564003505112938989838639036830038000667,
-0.04420507311538380106630368978105783816958186742337,
-0.03424147651765967914583555261920479467686750578868,
-0.07704109917810578081589227344848239459627482015309,
0.00016550636069467510956568194922373457156145674472,
-0.02731253325700488720531056682496175342328157519177,
0.03075348203033812099576256162277450412788622616876,
-0.16119574292884668418355853021029183020638494535382,
0.17261442376774077933444824219760876537715856676776,
0.21099684113845276069212183897857155064519894807246,
-0.14867848664993536521114464259952411853041717110365,
0.,
0.,
0.01342744097914822834128321180583387359552549317827,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.20269618321902974002608815996374743006563410443932,
0.21000896916637284961602851090133424181900673255636,
0.13162024802466914306236177500626855707419305548129,
0.21715643928543653933291605863637139386689057303851,
0.36462517253857302045212491601584115881775632324511,
0.03521672222647990534615876066236108725981718350082,
0.10528396876056607082203930674055411490474243885281,
-0.00086472498035414042056867534332376875095350849072,
0.02433439927532513336393432650296595361512044609573,
-0.03147112889314383399995254753506164931754599419100,
0.04128009853681170388878034298378887569405303342952,
-0.18660895580008713104043380243662278334072815775061,
-0.14076538129350526647787344409065518838603900815358,
0.06231005824988037488214656297123442035665263650397,
0.,
0.,
0.,
0.01357083270566387857292973690866785426852901850251,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.18826396989965643710198366919069846199615091894197,
0.20984824833129470820003563755797727368336860075026,
0.13125831350364132574277700600450500795944241346593,
0.21792562414762654127299315873682169487921407523603,
0.35193782408706948140854779794608538432492004553239,
0.04064507251481134501095703585389867825202032803688,
0.10365206152603605179461155270679763147132839024727,
-0.00059520608834339302764441244548211782242769981546,
0.02485165066169629179233950734800589271768859409037,
-0.03192901616498970576728528643879152627447844263430,
0.08020269461992571935199865797703134187143392172039,
-0.19320093985265285610107869719684266072646372253420,
-0.08904004772583535026893062601492935709591253468386,
0.05640958490643967184700532751968063721476065830048,
0.,
0.,
0.,
0.,
],
b: [
0.01490902081978461022483617102382552714139242858034,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.20408044692054151258349120934134791804493401512634,
0.22901438600570447264772469337066476035313738023741,
0.12800558251147375669208211573729202273772361889244,
0.22380626846054143649770066956485937727843730877752,
0.39553165293700054420552389156421651666967336137950,
0.05416646758806981196568364538360743735174887121333,
0.12691439652445903685643385312168037657766579108702,
-0.00052539244262118876455834655383035812936087407348,
0.03225806451612903225806451612903225806451612903226,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
],
b2: [
0.09869444095328251126975653714615581841769601424819,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
20.90221890362017811333684732139815594192483291983000,
-1.83366447782387888082811845516038903355309852953490,
-0.08273332108398198824168126595166413313192173558539,
0.67131540884240257028965403993665111519129165487313,
-20.98923903996976470585685864367570085897357630905900,
6.13887488578967922129465332603558335891060855328640,
-4.29642051701795891700057824542304185815469652317780,
0.35869565217391304347826086956521739130434782608696,
0.03225806451612903225806451612903225806451612903226,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0.,
],
c: [
0.00000000000000000000000000000000000000000000000000,
0.02173913043478260869565217391304347826086956521739,
0.09629581047800066670113001679819925959085658682856,
0.14444371571700100005169502519729888938628488024283,
0.52205882352941176470588235294117647058823529411765,
0.22842443612863469578031459099794265170568729495076,
0.54360353589933733219171338103002937626634067707721,
0.64335664335664335664335664335664335664335664335664,
0.48251748251748251748251748251748251748251748251748,
0.06818181818181818181818181818181818181818181818182,
0.25060827250608272506082725060827250608272506082725,
0.66736715965600568968278165443304378929030003367893,
0.85507246376811594202898550724637681159420289855072,
0.89795918367346938775510204081632653061224489795918,
1.00000000000000000000000000000000000000000000000000,
1.00000000000000000000000000000000000000000000000000,
1.00000000000000000000000000000000000000000000000000,
0.74143720845372055359900703795542553636931134546459,
0.85542586221887479770704957375656067573667288069152,
0.64180122353767291975285767191286604597746537284710,
0.50852519773191487807809775022422859333413052597967,
0.04347826086956521739130434782608695652173913043478,
0.19047619047619047619047619047619047619047619047619,
0.29166666666666666666666666666666666666666666666667,
0.64285714285714285714285714285714285714285714285714,
0.72727272727272727272727272727272727272727272727273,
],
bi: [
polynomial![
0.00000000000000000000000000000000000000000000000000,
1.00000000000000000000000000000000000000000000000000,
-19.28431428517097368937448650675238144038622663303100,
151.50966865631955852563787365059035036647682676876000,
-632.27428373253362347243851600696227401791536406338000,
1542.85742238107211782044268880242939034309902209830000,
-2273.63087663919479996721471618210931632583793630850000,
1991.19390808449810523204472370824292892796356622780000,
-953.48708786737463831820578486212510253311743393027000,
192.13047242320403847933305356771023020685893826895000
],
polynomial![0.],
polynomial![0.],
polynomial![0.],
polynomial![0.],
polynomial![0.],
polynomial![0.],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.66684463629785661077095148068171329751989078864775,
16.70472393362983127607986095209445949808337228329600,
-139.10888715273347437541225913387879324613131233020000,
564.09442799479747420745918288816172944205821621118000,
-1247.94109403348375638601985951113785310244162778860000,
1536.91997233751955605116210412790556879547812357690000,
-988.24709396008923289137399183751742498947307129714000,
258.04071506973691721629242278571267898190125611807000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.74831772101327833743169720155527758675521679995711,
-18.74565717971273243472757131634225184778433958541100,
156.10479524098621072631492864482958142013936930990000,
-633.01379934142311533965436354205058216526253492360000,
1400.41080727660262452548627329842741829460549123230000,
-1724.69626128280236474800525893171109270665186939450000,
1108.98817040179305014676757863969690291243831457170000,
-289.56735845045124674096555930103458873388651063018000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.41826562711906322971113082093348374900551021653942,
-10.47772067379971813863676704850949974423210412704800,
87.25340619937754280845441334662115912287262067660500,
-353.81751136141153271718016957477737790638615462383000,
782.74733857260639365293392935667004746685079460040000,
-964.00384897814640174111715181339934384500968775069000,
619.85921158280016938395255270895050172764207262900000,
-161.85113538603404272142585568075167854800532800209000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.73129989641221334052615495668257895959143407531669,
-18.31935389040390497890150577575764612818788196431700,
152.55474697913416987332096274912951438979835488690000,
-618.61815227234222480523244300666881063342095693601000,
1368.56344509547076769623801670699252095781070292630000,
-1685.47418001913749720009261293125043526554255210210000,
1083.76817942924355058400139000640253668983823777260000,
-282.98217894991653307336226203596539959260890134990000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
1.29242249920080836219719766495915592018836139780440,
-32.37569874539428556369693975377799151917108981683100,
269.60921001496086698933582461621378081561703716587000,
-1093.28063949313333446888463810394697409881620185540000,
2418.65505068819909843848405562365539529834317140840000,
-2978.72974242962934035440674533288942112749966812160000,
1915.33786054678344806687172302156345500088451297890000,
-500.11293142805026092569495384421318377287644979581000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.17699205839337255764014279367859467001617742856350,
-4.43372160915989723067116079003775296132048144939970,
36.92189595265222451792286125012003416251828139234900,
-149.72038238669446309082299571854897335189616859951000,
331.22507247401179276644855362683444978385532083577000,
-407.92504682964807615264145476129303839903018601500000,
262.29780947527590756785204325860727205546306349638000,
-68.48845266724279112376230601397697852225425821793500
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.41470011394215677762383985652541889048210675437547,
-10.38840314755761168019948514476269926926012343490200,
86.50961290305368946930131517260547763194861914343800,
-350.80138735507464174872542363207600967322922332102000,
776.07479421582464594648720739732327037547790303138000,
-955.78618010156502242690138466047710500816556153347000,
614.57521011715693063227420234525443619445619698824000,
-160.47143234925568793300383748127110876513225183696000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.00171675012280710796318168442037778234620247940699,
0.04300527484742104612851342634289132972007902754857,
-0.35812719500730116513676812423999310375477593714269,
1.45222608958995771679799309220834496156634805323880,
-3.21274688259032799316617847794221983050601116223020,
3.95670506687048302272991746770852543932681291263700,
-2.54418079950177432737926513532298243968840954192910,
0.66430980347172761922441108911198106755279825321106
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
0.10540508718263532226339947975369078482319500972848,
-2.64043944682736397659529292453708322274240096039130,
21.98830669107142384152008150557665400167416157868200,
-89.16383086190468284152776286736923818722598787453400,
197.25635126296277486930173294171055368580125406164000,
-242.93392322437492261359235757250509585405706418992000,
156.20770630345403067184070209558016755651619565518000,
-40.78731774704776624095243814208061650672483715135700
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-0.19622044709013311527342922674369029214871702127138,
4.92269110148526446302097195034653535633371579371380,
-41.13308082349339985770128925611577286920634678905200,
167.65105647129187587015796492134401760665078355299000,
-373.53088665207796835716826167490750618167869365328000,
464.36560599621076885473693561841464579104604220092000,
-302.23997728316879180130632673177735921058867932208000,
80.16081163684238394353343439943912979959189523806100
],
polynomial![0.],
polynomial![0.],
polynomial![0.],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-6.27640216452357471440928376950400360619601728334410,
154.08388402337706945396002965637563294761028661613000,
-1225.37941146671157870081974581559170151285995424400000,
4654.68100361788741720908615449232926214775933197920000,
-9495.63413446671177245111534134181509768697019460720000,
10697.12564491412093786907767047653365886015278812000000,
-6279.74433255469572743995039737070633812842214782940000,
1501.14374809725722877417091367237858697892590724830000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
23.61951613225919497382337818831331887943637613247200,
-241.51162399132469509165306495355654559114590220407000,
1099.29514160853129554908623943306793660892666928070000,
-2756.85270055555451303264243958724126534700821305640000,
4050.10903576237014746062815532484074720246106869000000,
-3463.81696511113428760974066637535227366924107287700000,
1591.97504813685351295589017036295372546531922580330000,
-302.81745198200065520539177239302564354874815176900000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-11.20475515854784100418270946640106507266024745007500,
250.89896556357148487610247376796691767983673030573000,
-1615.29338363322780095768012847547136404620805834440000,
5055.15865340212371017614665112527983892808365350230000,
-8825.76967735578837436594877032605744665946019359510000,
8802.76940711826219082295876409914238199531752348100000,
-4699.35798488310911669159305568686901006394743814760000,
1042.79877494671574714419677496240974723903803024820000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
7.97048473182780579722076520205266346265129682658640,
-186.59096883695250470048066223925279926133689940224000,
1327.90479372051203712899675803818176384355080780500000,
-4388.14975146668661603758504397518103912611505257470000,
7819.20982380416973948943106363205702845288210613920000,
-7771.54314539763952695061974956728570990607290286170000,
4062.28427654587650156064131096936382306966797720670000,
-871.08551310110743628760444205993573053522733313891000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
6.26637435693506643977366997412302738816141861498050,
-155.10678824895457834230355015698147784906616136513000,
1256.73904227140870906842831658649474082415783681430000,
-4895.92617826151671627923165950130639499506869249180000,
10276.21491905144278932741597934246244448360739867000000,
-11881.32809978846235839487057130263249121992222876000000,
7120.79705310680167355768387077365720022577488529180000,
-1727.65632248765458537689605571581704885764445677420000
],
polynomial![
0.00000000000000000000000000000000000000000000000000,
0.00000000000000000000000000000000000000000000000000,
-4.11352478253240889623733400407397879985379160054810,
102.42743721685666249693627669979896021618637351456000,
-841.33377757798099144349299453058074402512794634562000,
3343.44954339897928736139630418741408205521183085960000,
-7200.74722217381377465222183973700443621480055448000000,
8579.90614964505775633927783775084829719190793708580000,
-5310.46986829809949365796672255771180353276350232540000,
1330.88126257153296245230847219130962310923965329160000
],
],
};
#[cfg(test)]
mod tests {
use super::*;
fn interpolation_continuity_error<const S: usize>(rk: &RungeKuttaTable<S>) -> f64
where
[(); S * (S - 1) / 2]:,
{
let mut max = 0f64;
for i in 0..S {
max = max.max((rk.b[i] - rk.bi[i](1.)).abs());
max = max.max(rk.bi[i](0.).abs());
}
max
}
fn c_is_sum_of_a_error<const S: usize>(rk: &RungeKuttaTable<S>) -> f64
where
[(); S * (S - 1) / 2]:,
{
let mut max = 0f64;
for i in 0..S {
let sum = ((i * i - i) / 2..).take(i).map(|j| rk.a[j]).sum::<f64>();
let diff = (rk.c[i] - sum).abs();
max = f64::max(max, diff);
}
max
}
fn order_conditions_error<const ORDER: usize, const S: usize>(
rk: &RungeKuttaTable<S>,
_: [(); ORDER],
) -> f64
where
[(); S * (S - 1) / 2]:,
{
let mut max_error = 0.;
for order in 1..=ORDER {
let advance_tree = |tree: &mut [usize]| -> bool {
let mut i_of_increased = order - 1;
while i_of_increased > 0 && tree[i_of_increased] + 1 >= i_of_increased {
i_of_increased -= 1;
}
if i_of_increased > 0 {
tree[i_of_increased] += 1;
for i in (i_of_increased + 1)..order {
tree[i] = tree[i_of_increased];
}
return true;
} else {
return false;
}
};
let fix_indexes = |tree: &[usize], indexes: &mut [usize]| {
for i in (1..order).rev() {
indexes[tree[i]] = usize::max(indexes[tree[i]], indexes[i] + 1);
}
};
let advance_indexes = |tree: &[usize], indexes: &mut [usize]| -> bool {
let mut i_of_increased = order - 1;
while i_of_increased > 0
&& indexes[i_of_increased] + 1 >= indexes[tree[i_of_increased]]
{
i_of_increased -= 1;
}
indexes[i_of_increased] += 1;
for i in (i_of_increased + 1)..order {
indexes[i] = 0;
}
for i in ((i_of_increased + 1)..order).rev() {
indexes[tree[i]] = usize::max(indexes[tree[i]], indexes[i] + 1);
}
if i_of_increased > 0 {
return true;
} else {
return false;
}
};
let gamma = |tree: &[usize]| -> f64 {
let mut rho = vec![0f64; order];
for i in (1..order).rev() {
rho[i] += 1.;
rho[tree[i]] += rho[i];
}
rho[0] += 1.;
rho.iter().product()
};
let mut tree = [0usize; ORDER];
let mut indexes = [0usize; ORDER];
loop
{
fix_indexes(&tree, &mut indexes);
let mut b_phi_sum = 0.;
let mut b_phi_sum_embedded = 0.;
println!("{:?}", &tree[..order]);
for j in indexes[0]..S {
indexes.fill(0);
indexes[0] = j;
fix_indexes(&tree, &mut indexes);
let mut phi_j = 0.;
loop
{
phi_j += (1..order).fold(1., |acc, i| {
acc * rk.a_indexed(indexes[tree[i]], indexes[i])
});
if !advance_indexes(&tree, &mut indexes) {
indexes.fill(0);
break;
}
}
b_phi_sum += phi_j * rk.b[j];
b_phi_sum_embedded += phi_j * rk.b2[j];
}
let error = f64::abs(b_phi_sum - 1. / gamma(&tree));
let error_embedded = f64::abs(b_phi_sum_embedded - 1. / gamma(&tree));
max_error = f64::max(max_error, error);
if order <= rk.order_embedded {
max_error = f64::max(max_error, error_embedded);
}
println!("\t{:?}", error);
println!("\t{:?}", error_embedded);
if !advance_tree(&mut tree) {
break;
}
}
}
max_error
}
macro_rules! test_rk {
($name:ident, $RK:path, $tolerance:expr) => {
#[test]
fn $name() {
assert!(interpolation_continuity_error(&$RK) < $tolerance);
assert!(c_is_sum_of_a_error(&$RK) < $tolerance);
assert!(order_conditions_error(&$RK, [(); $RK.order]) < $tolerance);
}
};
}
test_rk!(rk1_euler, EULER, 1e-15);
test_rk!(rk2_heun, HEUN2, 1e-15);
test_rk!(rk2_ralston, RALSTON2, 1e-15);
test_rk!(rk2_midpoint, MIDPOINT, 1e-15);
test_rk!(rk3_ssp, SSP3, 1e-15);
test_rk!(rk3_heun, HEUN3, 1e-15);
test_rk!(rk3_wray, WRAY3, 1e-15);
test_rk!(rk3_kutta, KUTTA3, 1e-15);
test_rk!(rk3_ralston, RALSTON3, 1e-15);
test_rk!(rk4_classic, CLASSIC4, 1e-15);
test_rk!(rk4_classic_dense, CLASSIC43, 1e-15);
test_rk!(dormand_prince, DP544, 1e-11);
test_rk!(rktp64, RKTP64, 1e-15);
#[test]
fn rk98_exept_order_conditions() {
assert!(interpolation_continuity_error(&RK98) < 1e-9);
assert!(c_is_sum_of_a_error(&RK98) < 1e-9);
assert!(order_conditions_error(&RK98, [(); 5]) < 1e-7);
}
#[test]
#[ignore] fn rk98_order_conditions() {
assert!(order_conditions_error(&RK98, [(); RK98.order]) < 1e-15);
}
}