A better display is then this integration example:
using ApproxFun, OrdinaryDiffEq
x = Fun(identity,-1..1)
f = exp(x)
g = f/sqrt(2-x^2)
h = @. f + 0.1g
function ff(u,p,t)
2u - u^2
end
prob = ODEProblem(ff,h,(0.0,1.0))
OrdinaryDiffEq.recursive_bottom_eltype(a::ApproxFun.Fun) = eltype(a.coefficients)
OrdinaryDiffEq.recursive_unitless_bottom_eltype(a::ApproxFun.Fun) = eltype(a.coefficients)
OrdinaryDiffEq.recursive_unitless_eltype(a::ApproxFun.Fun) = eltype(a.coefficients)
isnan(h) # :(
Base.isnan(a::ApproxFun.Fun) = any(isnan,a.coefficients)
sol = DiffEqBase.__solve(prob,Tsit5(),adaptive=false,dt=0.1)
@show sol[end].coefficients
sol = DiffEqBase.__solve(prob,Tsit5())
@show sol[end].coefficients
So just a few reasonable overloads (could be added via Requires) and that’s probably the simplest adaptive time adaptive space semilinear PDE solver script you’ve ever seen . The coefficients lists look like:
x = Fun(Chebyshev(-1..1),[1.37369, 1.23314, 0.312644, 0.057217, 0.0102633, 0.00210412, 0.000680313, 0.000220778, 9.27862e-5, 3.23932e-5, 1.40827e-5, 4.98013e-6, 2.19425e-6, 7.81442e-7, 3.47373e-7, 1.24314e-7, 5.56183e-8, 1.99758e-8, 8.98101e-9, 3.23453e-9, 1.45984e-9, 5.26919e-10, 2.38555e-10, 8.62588e-11, 3.91528e-11, 1.41782e-11, 6.44926e-12, 2.33834e-12, 1.06549e-12, 3.86616e-13, 1.76285e-13,
6.3722e-14, 2.87327e-14, 1.01941e-14, 4.5861e-15, 1.61385e-15, 6.88532e-16, 2.68315e-16, 1.32806e-16])
(sol[end]).coefficients = [1.74261, 0.397775, -0.0454502, -0.00270729, 0.00176207, -0.000219944, 6.33866e-5, -1.62488e-5, 1.19699e-5, -3.06074e-6, 1.83144e-6, -4.60346e-7, 2.83213e-7, -7.24161e-8, 4.46337e-8, -1.15028e-8, 7.09702e-9, -1.8429e-9, 1.13747e-9, -2.97332e-10, 1.83457e-10,
-4.82406e-11, 2.97425e-11, -7.863e-12, 4.84288e-12, -1.28656e-12, 7.91322e-13, -2.11464e-13, 1.29487e-13, -3.47097e-14, 2.12311e-14, -5.75179e-15, 3.54605e-15, -1.21433e-15, 9.9087e-16, -6.27891e-16, 2.29117e-16, -2.48411e-16, 1.45315e-16, 4.15729e-16, -7.54313e-18, -1.87555e-18, -5.55151e-19, -1.89897e-19, -7.16383e-20, -2.71441e-20, -1.05819e-20, -4.04815e-21, -1.58455e-21, -6.07215e-22, -2.3798e-22, -9.11932e-23, -3.5739e-23, -1.36772e-23, -5.35425e-24, -2.04399e-24, -7.98466e-25, -3.03684e-25, -1.18248e-25, -4.47412e-26, -1.73416e-26, -6.51539e-27, -2.5094e-27, -9.33774e-28, -3.56495e-28, -1.309e-28, -4.93575e-29, -1.77803e-29, -6.58306e-30, -2.30334e-30, -8.28578e-31, -2.77257e-31, -9.58546e-32, -2.97471e-32, -9.46569e-33, -2.61974e-33, -6.36441e-34, 1.57045e-35, 5.02227e-36, 1.70695e-36, 6.18296e-37, 2.30489e-37, 8.70625e-38, 3.28727e-38, 1.24436e-38, 4.69274e-39, 1.77251e-39, 6.6648e-40, 2.50898e-40, 9.39579e-41, 3.52145e-41, 1.31187e-41, 4.88924e-42, 1.80954e-42, 6.69697e-43, 2.45846e-43, 9.01968e-44, 3.27759e-44, 1.18944e-44, 4.26708e-45, 1.52726e-45, 5.3895e-46, 1.89486e-46, 6.54383e-47, 2.24694e-47, 7.53617e-48, 2.50516e-48, 8.0617e-49, 2.55813e-49, 7.74247e-50, 2.28975e-50, 6.23784e-51, 1.61996e-51, 3.54841e-52, 5.93231e-53]
(sol[end]).coefficients = [1.74262, 0.397778, -0.0454475, -0.00270537, 0.00176325, -0.000219333, 6.35796e-5, -1.62111e-5, 1.19832e-5, -3.05395e-6, 1.83367e-6, -4.59648e-7, 2.83495e-7, -7.23072e-8, 4.46756e-8, -1.14851e-8, 7.10432e-9, -1.84003e-9, 1.13863e-9, -2.96853e-10, 1.83652e-10, -4.81613e-11, 2.97752e-11, -7.85006e-12, 4.84817e-12, -1.28459e-12, 7.92376e-13, -2.11071e-13, 1.29953e-13, -3.44992e-14, 2.15547e-14, -5.61981e-15, 3.54937e-15, -1.37966e-15, 2.62586e-16, 3.8377e-17, 1.03977e-16, -3.55172e-17, -4.26953e-16, -7.84177e-17, 1.85717e-16, -1.83744e-16, -5.06391e-19, -1.732e-19, -6.53278e-20, -2.4752e-20, -9.64887e-21, -3.69133e-21, -1.44485e-21, -5.53705e-22, -2.17004e-22, -8.31592e-23, -3.25898e-23, -1.24727e-23, -4.8826e-24, -1.86403e-24, -7.28156e-25, -2.76957e-25, -1.07839e-25, -4.08055e-26, -1.58159e-26, -5.94256e-27, -2.28874e-27, -8.51733e-28, -3.2517e-28, -1.19409e-28, -4.50246e-29, -1.62213e-29, -6.00592e-30, -2.10174e-30, -7.56086e-31, -2.53061e-31, -8.74967e-32, -2.71649e-32, -8.64636e-33,
-2.39494e-33, -5.82687e-34, 1.3202e-35, 4.2246e-36, 1.43632e-36, 5.20266e-37, 1.93934e-37, 7.32492e-38, 2.76571e-38, 1.04692e-38, 3.94828e-39, 1.49132e-39, 5.60774e-40, 2.11105e-40, 7.90595e-41, 2.96308e-41, 1.1039e-41, 4.11417e-42, 1.52275e-42, 5.63557e-43, 2.06892e-43, 7.59046e-44,
2.75837e-44, 1.00101e-44, 3.59124e-45, 1.28535e-45, 4.53604e-46, 1.59476e-46, 5.5077e-47, 1.89109e-47, 6.34292e-48, 2.10837e-48, 6.78502e-49, 2.15277e-49, 6.51563e-50, 1.9265e-50, 5.24791e-51, 1.36221e-51, 2.98239e-52, 4.97929e-53]
and that’s what I mean by the cutoff issue, since the ODE solver tolerance is just a relative tolerance of 1e-3 and abstol of 1e-6, so it should really look like:
(sol[end]).coefficients = [1.74262, 0.397778, -0.0454475, -0.00270537, 0.00176325, -0.000219333, 6.35796e-5, -1.62111e-5, 1.19832e-5, -3.05395e-6, 1.83367e-6]
so if there was a constructor that could autochop:
function ff(u,p,t)
chop!(u,1e-6)
2u - u^2
end
prob = ODEProblem(ff,h,(0.0,1.0))
sol = DiffEqBase.__solve(prob,Tsit5())
@show sol[end].coefficients
this would have an efficient solution
(sol[end]).coefficients = [1.74262, 0.397778, -0.0454475, -0.00270537, 0.00176325, -0.000219333, 6.35794e-5, -1.62109e-5, 1.19852e-5, -3.06974e-6, 1.88027e-6, -4.7376e-7,
3.15883e-7]