Skip to content

Commit 138f316

Browse files
committed
Refactor BVProblemLibrary with new constructor
Signed-off-by: ErikQQY <2283984853@qq.com>
1 parent 81da7ac commit 138f316

File tree

4 files changed

+280
-242
lines changed

4 files changed

+280
-242
lines changed

lib/BVProblemLibrary/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
name = "BVProblemLibrary"
22
uuid = "ded0fc24-dfea-4565-b1d9-79c027d14d84"
3-
version = "0.1.2"
3+
version = "0.1.3"
44

55
[deps]
66
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
77
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
8+
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
89

910
[compat]
1011
Aqua = "0.5"
1112
DiffEqBase = "6"
1213
julia = "1.6"
14+
SpecialFunctions = "2.3"
1315

1416
[extras]
1517
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

lib/BVProblemLibrary/src/BVProblemLibrary.jl

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module BVProblemLibrary
22

3-
using DiffEqBase, Markdown
3+
using DiffEqBase, Markdown, SpecialFunctions
44

55
include("linear.jl")
66
include("nonlinear.jl")
77

88
################### flat_moon ############################
9-
function flat_moon_function!(du, u, p, t)
9+
function flat_moon_f!(du, u, p, t)
1010
g = 1.62
1111
A = 3 * 1.62
1212
du[1] = u[3]
@@ -17,19 +17,19 @@ function flat_moon_function!(du, u, p, t)
1717
du[6] = (u[6])^2 * sin(u[5])
1818
du[7] = 0
1919
end
20-
21-
function flat_moon_bc!(res, u, p, t)
22-
Vc = 1627
23-
h = 185.2
24-
res[1] = u[1][1]
25-
res[2] = u[1][2]
26-
res[3] = u[1][3]
27-
res[4] = u[1][4]
28-
res[5] = u[end][2] - h
29-
res[6] = u[end][3] - Vc
30-
res[7] = u[end][4]
20+
function flat_moon_bca!(res_a, u_a, p)
21+
res_a[1] = u_a[1]
22+
res_a[2] = u_a[2]
23+
res_a[3] = u_a[3]
24+
res_a[4] = u_a[4]
25+
end
26+
function flat_moon_bcb!(res_b, u_b, p)
27+
res_b[1] = u_b[5] - h
28+
res_b[2] = u_b[6] - Vc
29+
res_b[3] = u_b[7]
3130
end
32-
tspan = (0, 700)
31+
flat_moon_tspan = (0, 700)
32+
flat_moon_function = BVPFunction(flat_moon_f!, (flat_moon_bca!, flat_moon_bcb!), bcresid_prototype = (zeros(4), zeros(3)), twopoint = Val(true))
3333
@doc raw"""
3434
flat_moon
3535
@@ -91,10 +91,10 @@ No analytical solution
9191
9292
[Reference](https://archimede.uniba.it/~bvpsolvers/testsetbvpsolvers/?page_id=534)
9393
"""
94-
flat_moon = BVProblem(flat_moon_function!, flat_moon_bc!, [0, 0, 0, 0, 0, 0, 0], tspan)
94+
flat_moon = BVProblem(flat_moon_function, [0, 0, 0, 0, 0, 0, 0], flat_moon_tspan)
9595

9696
################### flat_earth ############################
97-
function flat_earth_function!(du, u, p, t)
97+
function flat_earth_f!(du, u, p, t)
9898
Vc = sqrt(398600.4 / (6378.14 + 300)) * 1000
9999
h = 300000
100100
g = 9.80665
@@ -109,18 +109,19 @@ function flat_earth_function!(du, u, p, t)
109109
du[6] = (-u[5] * (Vc / h))
110110
du[7] = 0
111111
end
112-
113-
function flat_earth_bc!(res, u, p, t)
114-
res[1] = u[1][1]
115-
res[2] = u[1][2]
116-
res[3] = u[1][3]
117-
res[4] = u[1][4]
118-
res[5] = u[end][2] - 1
119-
res[6] = u[end][3] - 1
120-
res[7] = u[end][4]
112+
function flat_earth_bca!(res_a, u_a, p)
113+
res_a[1] = u_a[1]
114+
res_a[2] = u_a[2]
115+
res_a[3] = u_a[3]
116+
res_a[4] = u_a[4]
121117
end
122-
tspan = (0, 700)
123-
118+
function flat_earth_bcb!(res_b, u_b, p)
119+
res_b[1] = u_b[2] - 1
120+
res_b[2] = u_b[3] - 1
121+
res_b[3] = u_b[4]
122+
end
123+
flat_earth_function = BVPFunction(flat_earth_f!, (flat_earth_bca!, flat_earth_bcb!), bcresid_prototype = (zeros(4), zeros(3)), twopoint = Val(true))
124+
flat_earth_tspan = (0, 700)
124125
@doc raw"""
125126
flat_earth
126127
@@ -182,10 +183,10 @@ No analytical solution
182183
183184
[Reference](https://archimede.uniba.it/~bvpsolvers/testsetbvpsolvers/?page_id=538)
184185
"""
185-
flat_earth = BVProblem(flat_earth_function!, flat_earth_bc!, [0, 0, 0, 0, 0, 0, 0], tspan)
186+
flat_earth = BVProblem(flat_earth_function, [0, 0, 0, 0, 0, 0, 0], flat_earth_tspan)
186187

187188
################### flat_earth_drag ############################
188-
function flat_earth_drag_function!(du, u, p, t)
189+
function flat_earth_drag_f!(du, u, p, t)
189190
fr = 2100000
190191
h = 180000
191192
m = 60880
@@ -223,27 +224,29 @@ function flat_earth_drag_function!(du, u, p, t)
223224
du[7] = lambda_4_bar
224225
du[8] = 0
225226
end
226-
227-
function flat_earth_drag_bc!(res, u, p, t)
227+
function flat_earth_drag_bca!(res_a, u_a, p)
228+
res_a[1] = u_a[1]
229+
res_a[2] = u_a[2]
230+
res_a[3] = u_a[3]
231+
res_a[4] = u_a[4]
232+
end
233+
function flat_earth_drag_bcb!(res_b, u_b, p)
228234
fr = 2100000
229235
h = 180000
230236
m = 60880
231237
g_accel = 9.80665
232238
vc = 1000 * sqrt((398600.4) / (6378.14 + (h / 1000.0)))
233239
beta = 180000 / 840
234240
eta = 1.225 * 0.5 * 7.069 / 2
235-
res[1] = u[1][1]
236-
res[2] = u[1][2]
237-
res[3] = u[1][3]
238-
res[4] = u[1][4]
239-
res[5] = u[end][2] - 1
240-
res[6] = u[end][3] - 1
241-
res[7] = u[end][4]
242-
res[8] = (-sqrt(u[6]^2.0 + u[7]^2.0) * fr / m / vc -
243-
(u[6] * u[3]) * eta * exp(-beta) * sqrt(u[3]^2.0) * vc / m -
244-
u[7] * g_accel / vc) * u[8] + 1.0
241+
res_b[1] = u_b[2] - 1
242+
res_b[2] = u_b[3] - 1
243+
res_b[3] = u_b[4]
244+
res_b[4] = (-sqrt(u_b[6]^2.0 + u_b[7]^2.0) * fr / m / vc -
245+
(u_b[6] * u_b[3]) * eta * exp(-beta) * sqrt(u_b[3]^2.0) * vc / m -
246+
u_b[7] * g_accel / vc) * u_b[8] + 1.0
245247
end
246-
tspan = (0, 100)
248+
flat_earth_drag_function = BVPFunction(flat_earth_drag_f!, (flat_earth_drag_bca!, flat_earth_drag_bcb!), bcresid_prototype = (zeros(4), zeros(4)), twopoint = Val(true))
249+
flat_earth_drag_tspan = (0, 100)
247250
@doc raw"""
248251
flat_earth_drag
249252
@@ -305,13 +308,12 @@ No analytical solution
305308
306309
[Reference](https://archimede.uniba.it/~bvpsolvers/testsetbvpsolvers/?page_id=544)
307310
"""
308-
flat_earth_drag = BVProblem(flat_earth_drag_function!,
309-
flat_earth_drag_bc!,
311+
flat_earth_drag = BVProblem(flat_earth_drag_function,
310312
[0, 0, 0, 0, 0, 0, 0, 0],
311-
tspan)
313+
flat_earth_drag_tspan)
312314

313315
################### measles ############################
314-
function measles_function!(du, u, p, t)
316+
function measles_f!(du, u, p, t)
315317
mu = 0.02
316318
lambda = 0.0279
317319
eta = 0.01
@@ -328,8 +330,8 @@ function measles_bc!(res, u, p, t)
328330
res[2] = u[1][2] - u[end][2]
329331
res[3] = u[1][3] - u[end][3]
330332
end
331-
tspan = (0, 1)
332-
333+
measles_function = BVPFunction(measles_f!, measles_bc!)
334+
measles_tspan = (0, 1)
333335
@doc raw"""
334336
measles
335337
@@ -362,7 +364,7 @@ No analytical solution
362364
363365
[Reference](https://archimede.uniba.it/~bvpsolvers/testsetbvpsolvers/?page_id=555)
364366
"""
365-
measles = BVProblem(measles_function!, measles_bc!, [0, 0, 0], tspan)
367+
measles = BVProblem(measles_function, [0, 0, 0], measles_tspan)
366368

367369
# Linear BVP Example Problems
368370
export prob_bvp_linear_1, prob_bvp_linear_2, prob_bvp_linear_3, prob_bvp_linear_4,

0 commit comments

Comments
 (0)