Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for SciMLOperators #768

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/DiffEqBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ using ForwardDiff

@reexport using SciMLBase

using SciMLBase: @def, DEIntegrator, DEProblem, AbstractDiffEqOperator,
AbstractDiffEqLinearOperator, AbstractDiffEqInterpolation,
using SciMLBase: @def, DEIntegrator, DEProblem, AbstractDiffEqInterpolation,
DECallback, AbstractDEOptions, DECache, AbstractContinuousCallback,
AbstractDiscreteCallback, AbstractLinearProblem, AbstractNonlinearProblem,
AbstractOptimizationProblem, AbstractSteadyStateProblem, AbstractJumpProblem,
Expand Down Expand Up @@ -81,6 +80,8 @@ import SciMLBase: solve, init, solve!, __init, __solve, update_coefficients!,
update_coefficients, isadaptive, wrapfun_oop, wrapfun_iip,
unwrap_fw, promote_tspan, set_u!, set_t!, set_ut!

import SciMLOperators: MatrixOperator, AbstractSciMLOperator, AbstractSciMLLinearOperator

SciMLBase.isfunctionwrapper(x::FunctionWrapper) = true

"""
Expand Down
2 changes: 1 addition & 1 deletion src/nlsolve/newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ end
@.. broadcast=false ztmp = (dt*k - ztmp) * invγdt
end

if W isa AbstractDiffEqLinearOperator
if W isa AbstractSciMLLinearOperator
update_coefficients!(W,dz,p,tstep)
end
nlsolver.linsolve(vecdz,W,vecztmp,iter == 1 && new_W; Pl=ScaleVector(weight, true), Pr=ScaleVector(weight, false), tol=lintol)
Expand Down
4 changes: 2 additions & 2 deletions src/nlsolve/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ DiffEqBase.@def oopnlsolve begin
if islinear(f) || DiffEqBase.has_jac(f)
# get the operator
J = islinear(f) ? nf.f : f.jac(uprev, p, t)
if !isa(J, DiffEqBase.AbstractDiffEqLinearOperator)
J = DiffEqArrayOperator(J)
if !isa(J, SciMLOperators.AbstractSciMLLinearOperator)
J = MatrixOperator(J)
end
W = WOperator(f.mass_matrix, dt, J, false)
else
Expand Down
18 changes: 9 additions & 9 deletions test/affine_operators_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ using DiffEqBase
using Test
using Random

mutable struct TestDiffEqOperator{T} <: DiffEqBase.AbstractDiffEqLinearOperator{T}
mutable struct TestSciMLOperator{T} <: DiffEqBase.AbstractSciMLLinearOperator{T}
m::Int
n::Int
end

TestDiffEqOperator(A::AbstractMatrix{T}) where {T} =
TestDiffEqOperator{T}(size(A)...)
TestSciMLOperator(A::AbstractMatrix{T}) where {T} =
TestSciMLOperator{T}(size(A)...)

Base.size(A::TestDiffEqOperator) = (A.m, A.n)
Base.size(A::TestSciMLOperator) = (A.m, A.n)


A = TestDiffEqOperator([0 0; 0 1])
B = TestDiffEqOperator([0 0 0; 0 1 0; 0 0 2])
A = TestSciMLOperator([0 0; 0 1])
B = TestSciMLOperator([0 0 0; 0 1 0; 0 0 2])

@test_throws ErrorException AffineDiffEqOperator{Int64}((A,B),())
@test_throws ErrorException AffineSciMLOperator{Int64}((A,B),())

@testset "DiffEq linear operators" begin
Random.seed!(0)
M = rand(2,2); A = DiffEqArrayOperator(M)
M = rand(2,2); A = MatrixOperator(M)
b = rand(2)
u = rand(2)
p = rand(1)
t = rand()
As_list = [(A,), (A, A)]#, (A, α)]
bs_list = [(), (b,), (2b,), (b, 2b)]
@testset "combinations of A's and b's" for As in As_list, bs in bs_list
L = AffineDiffEqOperator{Float64}(As, bs, zeros(2))
L = AffineSciMLOperator{Float64}(As, bs, zeros(2))
mysum = sum(A*u for A in As)
for b in bs; mysum .+= b; end
@test L(u,p,t) == mysum
Expand Down
4 changes: 2 additions & 2 deletions test/basic_operators_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

@testset "Array Operators" begin
Random.seed!(0); A = rand(2,2); u = rand(2); du = zeros(2)
L = DiffEqArrayOperator(A)
L = MatrixOperator(A)
@test Matrix(L) == A
@test size(L) == size(A)
@test L * u == A * u
Expand All @@ -44,7 +44,7 @@ end
@testset "Mutable Array Operators" begin
Random.seed!(0); A = rand(2,2); u = rand(2); du = zeros(2)
update_func = (_A,u,p,t) -> _A .= t * A
Lt = DiffEqArrayOperator(zeros(2,2); update_func=update_func)
Lt = MatrixOperator(zeros(2,2); update_func=update_func)
t = 5.0
@test isconstant(Lt) == false
@test Lt(u,nothing,t) ≈ (t*A) * u
Expand Down