Skip to content

Commit 2913a1e

Browse files
make nonllinchem an ODEProblem with analytic
1 parent 97b28fe commit 2913a1e

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/ode/filament_prob.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function (f::FilamentCache)(dr, r, p, t)
158158
mul!(S1, A, r)
159159
S1 .+= F
160160
mul!(S2, P, S1)
161-
copy!(dr, S2)
161+
copyto!(dr, S2)
162162
return dr
163163
end
164164

@@ -183,10 +183,10 @@ end
183183
function projection!(f::FilamentCache)
184184
# implement P[:] = I - J'/(J*J')*J in an optimized way to avoid temporaries
185185
J, P, J_JT, J_JT_LDLT, P0 = f.P.J, f.P.P, f.P.J_JT, f.P.J_JT_LDLT, f.P.P0
186-
A_mul_Bt!(J_JT, J, J)
186+
mul!(J_JT, J, J')
187187
LDLt_inplace!(J_JT_LDLT, J_JT)
188-
A_ldiv_B!(P0, J_JT_LDLT, J)
189-
At_mul_B!(P, P0, J)
188+
ldiv!(P0, J_JT_LDLT, J)
189+
mul!(P', P0, J)
190190
subtract_from_identity!(P)
191191
nothing
192192
end
Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
1-
using DifferentialEquations
2-
using Plots
3-
using SpecialFunctions
4-
51
function nonLinChem(dy,y,p,t)
62
dy[1] = -y[1]
73
dy[2] = y[1]-(y[2])^2
84
dy[3] = (y[2])^2
95
end
106
y0 = [1.0;0.0;0.0]
117
tspan = (0.0,20)
12-
prob = ODEProblem(nonLinChem,y0,tspan)
13-
sol = solve(prob)
14-
15-
Analytical(t) = [exp(-t);
8+
nlc_analytic(u0,p,t) = [exp(-t);
169
(2sqrt(exp(-t))besselk(1,2sqrt(exp(-t)))-2besselk(1,2)/besseli(1,2)*sqrt(exp(-t))besseli(1,2sqrt(exp(-t))))/(2besselk(0,2sqrt(exp(-t)))+(2besselk(1,2)/besseli(1,2))besseli(0,2sqrt(exp(-t))));
1710
-exp(-t)+1+(-2sqrt(exp(-t))*besselk(1,2sqrt(exp(-t)))+sqrt(exp(-t))*besseli(1,2sqrt(exp(-t)))*2besselk(1,2)/besseli(1,2))/(2besselk(0,2sqrt(exp(-t)))+2besselk(1,2)/besseli(1,2)*besseli(0,2sqrt(exp(-t))))]
18-
19-
t=0:.1:20
20-
p = 1
21-
plot(sol,vars=(0,p))
22-
plot!(t,(x->Analytical(x)[p]).(t))
23-
p = 2
24-
plot!(sol,vars=(0,p))
25-
plot!(t,(x->Analytical(x)[p]).(t))
26-
p = 3
27-
plot!(sol,vars=(0,p))
28-
plot!(t,(x->Analytical(x)[p]).(t))
11+
nonLinChem_f = ODEFunction(nonLinChem,analytic = nlc_analytic)
12+
prob_ode_nonlinchem = ODEProblem(nonLinChem,y0,tspan)

src/ode/ode_premade_problems.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export prob_ode_linear, prob_ode_bigfloatlinear, prob_ode_2Dlinear,
1010
prob_ode_lorenz, prob_ode_rober, prob_ode_threebody, prob_ode_mm_linear, prob_ode_pleiades,
1111
prob_ode_brusselator_1d, prob_ode_brusselator_2d, prob_ode_orego,
1212
prob_ode_hires, prob_ode_pollution, prob_ode_filament,
13+
prob_ode_nonlinchem,
1314
SolverDiffEq, filament_prob
1415

1516
include("ode_linear_prob.jl")
1617
include("ode_simple_nonlinear_prob.jl")
1718
include("brusselator_prob.jl")
1819
include("pollution_prob.jl")
1920
include("filament_prob.jl")
21+
include("nonlinchem.jl")

0 commit comments

Comments
 (0)