From d852ada2b6a4baae9bb0296b2ac9353ce0798536 Mon Sep 17 00:00:00 2001 From: Oriol Colomes Date: Mon, 25 Oct 2021 21:51:05 +0200 Subject: [PATCH 1/2] Replacing fill_entries! to fillstored! --- Project.toml | 2 +- src/DiffEqsWrappers/DiffEqsWrappers.jl | 8 +++----- src/ODETools/AffineNewmark.jl | 2 +- src/ODETools/AffineThetaMethod.jl | 6 +++--- src/ODETools/ConstantMatrixNewmark.jl | 2 +- src/ODETools/ConstantNewmark.jl | 6 +++--- src/ODETools/ForwardEuler.jl | 2 +- src/ODETools/Newmark.jl | 2 +- src/ODETools/ODETools.jl | 2 +- src/ODETools/RungeKutta.jl | 2 +- src/ODETools/ThetaMethod.jl | 2 +- test/ODEsTests/ODESolverMocks.jl | 3 +-- 12 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Project.toml b/Project.toml index 2239129..aaa6873 100644 --- a/Project.toml +++ b/Project.toml @@ -13,7 +13,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] ForwardDiff = "0.10" -Gridap = "0.16" +Gridap = "0.17" LineSearches = "7.1" Sundials = "4.5" julia = "1.6" diff --git a/src/DiffEqsWrappers/DiffEqsWrappers.jl b/src/DiffEqsWrappers/DiffEqsWrappers.jl index b976c2c..c35d72d 100644 --- a/src/DiffEqsWrappers/DiffEqsWrappers.jl +++ b/src/DiffEqsWrappers/DiffEqsWrappers.jl @@ -14,8 +14,6 @@ using Gridap.Algebra: allocate_jacobian using Gridap.FESpaces: get_algebraic_operator -using Gridap.Algebra: fill_entries! - export prototype_jacobian export prototype_mass export prototype_stiffness @@ -51,21 +49,21 @@ function diffeq_wrappers(op) function _jacobian!(jac, du, u, p, gamma, t) ode_cache = update_cache!(ode_cache, ode_op, t) z = zero(eltype(jac)) - fill_entries!(jac, z) + fillstored!(jac, z) jacobians!(jac, ode_op, t, (u, du), (1.0, gamma), ode_cache) end function _mass!(mass, du, u, p, t) ode_cache = update_cache!(ode_cache, ode_op, t) z = zero(eltype(mass)) - fill_entries!(mass, z) + fillstored!(mass, z) jacobian!(mass, ode_op, t, (u, du), 2, 1.0, ode_cache) end function _stiffness!(stif, du, u, p, t) ode_cache = update_cache!(ode_cache, ode_op, t) z = zero(eltype(stif)) - fill_entries!(stif, z) + fillstored!(stif, z) jacobian!(stif, ode_op, t, (u, du), 1, 1.0, ode_cache) end diff --git a/src/ODETools/AffineNewmark.jl b/src/ODETools/AffineNewmark.jl index b9c30b9..7e229e7 100644 --- a/src/ODETools/AffineNewmark.jl +++ b/src/ODETools/AffineNewmark.jl @@ -97,7 +97,7 @@ function jacobian!(A::AbstractMatrix,op::NewmarkAffineOperator,x::AbstractVector a1 = 1.0/(op.β*op.dt^2)*(u1-u0) - 1.0/(op.β*op.dt)*v0 - (1-2*op.β)/(2*op.β)*a0 v1 = op.γ/(op.β*op.dt)*(u1-u0) + (1-op.γ/op.β)*v0 + op.dt*(1-op.γ/(2*op.β))*a0 z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,op.odeop,op.t1,(u1,v1,a1),(1.0,op.γ/(op.β*op.dt),1.0/(op.β*op.dt^2)),cache) end diff --git a/src/ODETools/AffineThetaMethod.jl b/src/ODETools/AffineThetaMethod.jl index 6396c3d..0896482 100644 --- a/src/ODETools/AffineThetaMethod.jl +++ b/src/ODETools/AffineThetaMethod.jl @@ -103,13 +103,13 @@ end function _matrix!(A,odeop,tθ,dtθ,u0,ode_cache,vθ) z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,odeop,tθ,(vθ,vθ),(1.0,1/dtθ),ode_cache) end function _mass_matrix!(A,odeop,tθ,dtθ,u0,ode_cache,vθ) z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobian!(A,odeop,tθ,(vθ,vθ),2,(1/dtθ),ode_cache) end @@ -140,7 +140,7 @@ function ThetaMethodConstantOperator(odeop::ConstantODEOperator,tθ::Float64,dt residual!(b,odeop,tθ,(u0,vθ),ode_cache) b = -1*b z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,odeop,tθ,(vθ,vθ),(1.0,1/dtθ),ode_cache) return A, b end diff --git a/src/ODETools/ConstantMatrixNewmark.jl b/src/ODETools/ConstantMatrixNewmark.jl index 559f1ee..06699bc 100644 --- a/src/ODETools/ConstantMatrixNewmark.jl +++ b/src/ODETools/ConstantMatrixNewmark.jl @@ -92,7 +92,7 @@ function jacobian!(A::AbstractMatrix,op::NewmarkConstantMatrixOperator,x::Abstra a1 = 1.0/(op.β*op.dt^2)*(u1-u0) - 1.0/(op.β*op.dt)*v0 - (1-2*op.β)/(2*op.β)*a0 v1 = op.γ/(op.β*op.dt)*(u1-u0) + (1-op.γ/op.β)*v0 + op.dt*(1-op.γ/(2*op.β))*a0 z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,op.odeop,op.t1,(u1,v1,a1),(1.0,op.γ/(op.β*op.dt),1.0/(op.β*op.dt^2)),cache) end diff --git a/src/ODETools/ConstantNewmark.jl b/src/ODETools/ConstantNewmark.jl index a568377..685a117 100644 --- a/src/ODETools/ConstantNewmark.jl +++ b/src/ODETools/ConstantNewmark.jl @@ -125,7 +125,7 @@ function jacobian!(A::AbstractMatrix,op::NewmarkConstantOperator,x::AbstractVect a1 = 1.0/(op.β*op.dt^2)*(u1-u0) - 1.0/(op.β*op.dt)*v0 - (1-2*op.β)/(2*op.β)*a0 v1 = op.γ/(op.β*op.dt)*(u1-u0) + (1-op.γ/op.β)*v0 + op.dt*(1-op.γ/(2*op.β))*a0 z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,op.odeop,op.t1,(u1,v1,a1),(1.0,op.γ/(op.β*op.dt),1.0/(op.β*op.dt^2)),cache) end @@ -136,7 +136,7 @@ function _mass_matrix!(A::AbstractMatrix,op::NewmarkConstantOperator,x::Abstract a1 = 1.0/(op.β*op.dt^2)*(u1-u0) - 1.0/(op.β*op.dt)*v0 - (1-2*op.β)/(2*op.β)*a0 v1 = op.γ/(op.β*op.dt)*(u1-u0) + (1-op.γ/op.β)*v0 + op.dt*(1-op.γ/(2*op.β))*a0 z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobian!(A,op.odeop,op.t1,(u1,v1,a1),3,1.0,cache) end @@ -147,6 +147,6 @@ function _damping_matrix!(A::AbstractMatrix,op::NewmarkConstantOperator,x::Abstr a1 = 1.0/(op.β*op.dt^2)*(u1-u0) - 1.0/(op.β*op.dt)*v0 - (1-2*op.β)/(2*op.β)*a0 v1 = op.γ/(op.β*op.dt)*(u1-u0) + (1-op.γ/op.β)*v0 + op.dt*(1-op.γ/(2*op.β))*a0 z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobian!(A,op.odeop,op.t1,(u1,v1,a1),2,1.0,cache) end diff --git a/src/ODETools/ForwardEuler.jl b/src/ODETools/ForwardEuler.jl index cc80741..67b67da 100644 --- a/src/ODETools/ForwardEuler.jl +++ b/src/ODETools/ForwardEuler.jl @@ -60,7 +60,7 @@ function jacobian!(A::AbstractMatrix,op::ForwardEulerNonlinearOperator,x::Abstra vf = op.vf vf = (x-op.u0)/op.dt z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobian!(A,op.odeop,op.tf,(op.u0,vf),1,(1/op.dt),op.ode_cache) end diff --git a/src/ODETools/Newmark.jl b/src/ODETools/Newmark.jl index 4577f43..eda2fe9 100644 --- a/src/ODETools/Newmark.jl +++ b/src/ODETools/Newmark.jl @@ -75,7 +75,7 @@ function jacobian!(A::AbstractMatrix,op::NewmarkNonlinearOperator,x::AbstractVec a1 = 1.0/(op.β*op.dt^2)*(u1-u0) - 1.0/(op.β*op.dt)*v0 - (1-2*op.β)/(2*op.β)*a0 v1 = op.γ/(op.β*op.dt)*(u1-u0) + (1-op.γ/op.β)*v0 + op.dt*(1-op.γ/(2*op.β))*a0 z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,op.odeop,op.t1,(u1,v1,a1),(1.0,op.γ/(op.β*op.dt),1.0/(op.β*op.dt^2)),cache) end diff --git a/src/ODETools/ODETools.jl b/src/ODETools/ODETools.jl index 804018d..5c5dd62 100644 --- a/src/ODETools/ODETools.jl +++ b/src/ODETools/ODETools.jl @@ -3,6 +3,7 @@ module ODETools using Test using ForwardDiff +using LinearAlgebra: fillstored! const ϵ = 100*eps() export ∂t @@ -59,7 +60,6 @@ export MidPoint export ThetaMethod export RungeKutta export Newmark -import Gridap.Algebra: fill_entries! export ODESolution export test_ode_solution diff --git a/src/ODETools/RungeKutta.jl b/src/ODETools/RungeKutta.jl index 41c8fb5..7882d10 100644 --- a/src/ODETools/RungeKutta.jl +++ b/src/ODETools/RungeKutta.jl @@ -175,7 +175,7 @@ function jacobian!(A::AbstractMatrix,op::RungeKuttaNonlinearOperator,x::Abstract vi = op.vi vi = (x-op.u0)/(op.a[op.i,op.i]*op.dt) z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,op.odeop,op.ti,(ui,vi),(1/(op.a[op.i,op.i]*op.dt)),op.ode_cache) end diff --git a/src/ODETools/ThetaMethod.jl b/src/ODETools/ThetaMethod.jl index e67bcb9..dae23eb 100644 --- a/src/ODETools/ThetaMethod.jl +++ b/src/ODETools/ThetaMethod.jl @@ -79,7 +79,7 @@ function jacobian!(A::AbstractMatrix,op::ThetaMethodNonlinearOperator,x::Abstrac vθ = op.vθ vθ = (x-op.u0)/op.dtθ z = zero(eltype(A)) - fill_entries!(A,z) + fillstored!(A,z) jacobians!(A,op.odeop,op.tθ,(uF,vθ),(1.0,1/op.dtθ),op.ode_cache) end diff --git a/test/ODEsTests/ODESolverMocks.jl b/test/ODEsTests/ODESolverMocks.jl index d018aae..5ea5b53 100644 --- a/test/ODEsTests/ODESolverMocks.jl +++ b/test/ODEsTests/ODESolverMocks.jl @@ -1,6 +1,5 @@ using Gridap.Algebra: residual using Gridap.Algebra: jacobian -using Gridap.Algebra: fill_entries! import Gridap.Algebra: NonlinearSolver import Gridap.Algebra: NonlinearOperator import Gridap.Algebra: solve! @@ -35,7 +34,7 @@ end function jacobian!(A::AbstractMatrix,op::OperatorMock,x::AbstractVector) uf = x uf_t = (x-op.u0)/op.dt - fill_entries!(A,0.0) + fillstored!(A,0.0) jacobian!(A,op.odeop,op.tf,uf,uf_t,op.cache) jacobian_t!(A,op.odeop,op.tf,uf,uf_t,(1/op.dt),op.cache) end From 5842f23dd28f237e4f3eee5e5f206a571b1f62c5 Mon Sep 17 00:00:00 2001 From: Oriol Colomes Date: Mon, 25 Oct 2021 21:56:34 +0200 Subject: [PATCH 2/2] fix DiffEqsWrappers --- src/DiffEqsWrappers/DiffEqsWrappers.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DiffEqsWrappers/DiffEqsWrappers.jl b/src/DiffEqsWrappers/DiffEqsWrappers.jl index c35d72d..0e00258 100644 --- a/src/DiffEqsWrappers/DiffEqsWrappers.jl +++ b/src/DiffEqsWrappers/DiffEqsWrappers.jl @@ -13,6 +13,7 @@ using GridapODEs.ODETools: jacobian! using Gridap.Algebra: allocate_jacobian using Gridap.FESpaces: get_algebraic_operator +using LinearAlgebra: fillstored! export prototype_jacobian export prototype_mass