|
1 | 1 | using BoundaryValueDiffEqCore |
| 2 | +using SciMLBase |
2 | 3 | using Test |
3 | 4 |
|
4 | 5 | module ExternalBVPAlgorithmExtension |
5 | | - using BoundaryValueDiffEqCore |
| 6 | + using BoundaryValueDiffEqCore, SciMLBase |
6 | 7 |
|
7 | 8 | struct ExternalBVPAlgorithm <: BoundaryValueDiffEqCore.AbstractBoundaryValueDiffEqAlgorithm end |
8 | 9 | struct ExternalBVPCache{P} <: BoundaryValueDiffEqCore.AbstractBoundaryValueDiffEqCache |
9 | 10 | prob::P |
| 11 | + init_arg::Symbol |
| 12 | + adaptive::Bool |
10 | 13 | end |
| 14 | + |
| 15 | + SciMLBase.__init( |
| 16 | + prob::SciMLBase.AbstractBVProblem, ::ExternalBVPAlgorithm, init_arg::Symbol; |
| 17 | + adaptive = true, kwargs... |
| 18 | + ) = ExternalBVPCache(prob, init_arg, adaptive) |
| 19 | + |
| 20 | + SciMLBase.solve!(cache::ExternalBVPCache) = |
| 21 | + (; prob = cache.prob, init_arg = cache.init_arg, adaptive = cache.adaptive) |
| 22 | + |
| 23 | + struct ExternalCombinedErrorControl <: BoundaryValueDiffEqCore.AbstractErrorControl end |
| 24 | + |
| 25 | + BoundaryValueDiffEqCore.__use_both_error_control(::ExternalCombinedErrorControl) = true |
11 | 26 | end |
12 | 27 |
|
13 | 28 | @testset "AbstractBoundaryValueDiffEqAlgorithm extension interface" begin |
14 | 29 | @test ExternalBVPAlgorithmExtension.ExternalBVPAlgorithm <: |
15 | 30 | BoundaryValueDiffEqCore.AbstractBoundaryValueDiffEqAlgorithm |
16 | 31 | @test ExternalBVPAlgorithmExtension.ExternalBVPCache <: |
17 | 32 | BoundaryValueDiffEqCore.AbstractBoundaryValueDiffEqCache |
| 33 | + |
| 34 | + f(u, p, t) = u |
| 35 | + bc(u, p, t) = u |
| 36 | + prob = SciMLBase.BVProblem(f, bc, [1.0], (0.0, 1.0)) |
| 37 | + sol = SciMLBase.solve( |
| 38 | + prob, ExternalBVPAlgorithmExtension.ExternalBVPAlgorithm(), :from_solve; |
| 39 | + adaptive = false |
| 40 | + ) |
| 41 | + |
| 42 | + @test sol.prob === prob |
| 43 | + @test sol.init_arg === :from_solve |
| 44 | + @test !sol.adaptive |
| 45 | + @test !SciMLBase.isinplace( |
| 46 | + ExternalBVPAlgorithmExtension.ExternalBVPCache(prob, :test, true) |
| 47 | + ) |
| 48 | +end |
| 49 | + |
| 50 | +@testset "AbstractErrorControl extension interface" begin |
| 51 | + @test !BoundaryValueDiffEqCore.__use_both_error_control(DefectControl()) |
| 52 | + @test BoundaryValueDiffEqCore.__use_both_error_control( |
| 53 | + ExternalBVPAlgorithmExtension.ExternalCombinedErrorControl() |
| 54 | + ) |
18 | 55 | end |
19 | 56 |
|
20 | 57 | @testset "__extract_lcons_ucons length" begin |
|
0 commit comments