From d852ada2b6a4baae9bb0296b2ac9353ce0798536 Mon Sep 17 00:00:00 2001 From: Oriol Colomes Date: Mon, 25 Oct 2021 21:51:05 +0200 Subject: [PATCH 1/6] 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/6] 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 From 704338771dea0c2c3df445b4eb5ee525d57577e7 Mon Sep 17 00:00:00 2001 From: Oriol Colomes Date: Sun, 7 Nov 2021 20:50:58 +0100 Subject: [PATCH 3/6] Removed TransientFESolver --- src/TransientFETools/TransientFESolutions.jl | 27 ++++++++++++++----- src/TransientFETools/TransientFESolvers.jl | 21 --------------- src/TransientFETools/TransientFETools.jl | 3 --- .../AffineFEOperatorsTests.jl | 3 +-- .../BoundaryHeatEquationTests.jl | 3 +-- .../ConstantFEOperatorsTests.jl | 3 +-- test/TransientFEsTests/DGHeatEquationTests.jl | 3 +-- .../ForwardEulerHeatEquationTests.jl | 3 +-- .../HeatEquationAutoDiffTests.jl | 3 +-- test/TransientFEsTests/HeatEquationTests.jl | 3 +-- .../HeatVectorEquationTests.jl | 3 +-- .../StokesEquationAutoDiffTests.jl | 3 +-- test/TransientFEsTests/StokesEquationTests.jl | 3 +-- .../Transient2ndOrderFEOperatorsTests.jl | 9 +++---- .../TransientFEOperatorsTests.jl | 3 +-- test/TransientFEsTests/TransientFETests.jl | 6 ++--- .../VectorHeatEquationTests.jl | 3 +-- 17 files changed, 39 insertions(+), 63 deletions(-) delete mode 100644 src/TransientFETools/TransientFESolvers.jl diff --git a/src/TransientFETools/TransientFESolutions.jl b/src/TransientFETools/TransientFESolutions.jl index 2e1f3b3..1e2001c 100644 --- a/src/TransientFETools/TransientFESolutions.jl +++ b/src/TransientFETools/TransientFESolutions.jl @@ -11,36 +11,51 @@ end function TransientFESolution( - solver::TransientFESolver, op::TransientFEOperator, uh0, t0::Real, tF::Real) + solver::ODESolver, op::TransientFEOperator, uh0, t0::Real, tF::Real) - ode_solver = solver.odes ode_op = get_algebraic_operator(op) u0 = get_free_dof_values(uh0) - ode_sol = solve(ode_solver,ode_op,u0,t0,tF) + ode_sol = solve(solver,ode_op,u0,t0,tF) trial = get_trial(op) TransientFESolution(ode_sol, trial) end function TransientFESolution( - solver::TransientFESolver, + solver::ODESolver, op::TransientFEOperator, xh0::Tuple{Vararg{Any}}, t0::Real, tF::Real) - ode_solver = solver.odes ode_op = get_algebraic_operator(op) x0 = () for xhi in xh0 x0 = (x0...,get_free_dof_values(xhi)) end - ode_sol = solve(ode_solver,ode_op,x0,t0,tF) + ode_sol = solve(solver,ode_op,x0,t0,tF) trial = get_trial(op) TransientFESolution(ode_sol, trial) end +# Solve functions + +function solve( + solver::ODESolver,op::TransientFEOperator,u0,t0::Real,tf::Real) + TransientFESolution(solver,op,u0,t0,tf) +end + +function solve( + solver::ODESolver,op::TransientFEOperator,u0,v0,a0,t0::Real,tf::Real) + TransientFESolution(solver,op,u0,v0,a0,t0,tf) +end + +function test_transient_fe_solver(solver::ODESolver,op::TransientFEOperator,u0,t0,tf) + solution = solve(solver,op,u0,t0,tf) + test_transient_fe_solution(solution) +end + #@fverdugo this is a general implementation of iterate for TransientFESolution # We could also implement another one for the very common case that the # underlying ode_op is a ODEOpFromFEOp object diff --git a/src/TransientFETools/TransientFESolvers.jl b/src/TransientFETools/TransientFESolvers.jl deleted file mode 100644 index 17397ca..0000000 --- a/src/TransientFETools/TransientFESolvers.jl +++ /dev/null @@ -1,21 +0,0 @@ -""" -A general TransientFESolver -""" -struct TransientFESolver - odes::ODESolver -end - -function solve( - solver::TransientFESolver,op::TransientFEOperator,u0,t0::Real,tf::Real) - TransientFESolution(solver,op,u0,t0,tf) -end - -function solve( - solver::TransientFESolver,op::TransientFEOperator,u0,v0,a0,t0::Real,tf::Real) - TransientFESolution(solver,op,u0,v0,a0,t0,tf) -end - -function test_transient_fe_solver(solver::TransientFESolver,op::TransientFEOperator,u0,t0,tf) - solution = solve(solver,op,u0,t0,tf) - test_transient_fe_solution(solution) -end diff --git a/src/TransientFETools/TransientFETools.jl b/src/TransientFETools/TransientFETools.jl index e6b1f9e..434b3f7 100644 --- a/src/TransientFETools/TransientFETools.jl +++ b/src/TransientFETools/TransientFETools.jl @@ -67,7 +67,6 @@ import Gridap.FESpaces: get_test using GridapODEs.ODETools: test_ode_operator export test_transient_fe_operator -export TransientFESolver import Gridap.FESpaces: FESolver import GridapODEs.ODETools: ODESolver import Gridap: solve @@ -94,8 +93,6 @@ include("TransientFEOperators.jl") include("ODEOperatorInterfaces.jl") -include("TransientFESolvers.jl") - include("TransientFESolutions.jl") export FETerm diff --git a/test/TransientFEsTests/AffineFEOperatorsTests.jl b/test/TransientFEsTests/AffineFEOperatorsTests.jl index 3fd5f85..3d36ad8 100644 --- a/test/TransientFEsTests/AffineFEOperatorsTests.jl +++ b/test/TransientFEsTests/AffineFEOperatorsTests.jl @@ -55,8 +55,7 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/BoundaryHeatEquationTests.jl b/test/TransientFEsTests/BoundaryHeatEquationTests.jl index f07f76f..70f5749 100644 --- a/test/TransientFEsTests/BoundaryHeatEquationTests.jl +++ b/test/TransientFEsTests/BoundaryHeatEquationTests.jl @@ -71,9 +71,8 @@ ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver # nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) # Juno.@enter Base.iterate(sol_t) diff --git a/test/TransientFEsTests/ConstantFEOperatorsTests.jl b/test/TransientFEsTests/ConstantFEOperatorsTests.jl index 8f33a7c..8ecaf4f 100644 --- a/test/TransientFEsTests/ConstantFEOperatorsTests.jl +++ b/test/TransientFEsTests/ConstantFEOperatorsTests.jl @@ -55,8 +55,7 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/DGHeatEquationTests.jl b/test/TransientFEsTests/DGHeatEquationTests.jl index 3cfaf1a..05eb2c5 100644 --- a/test/TransientFEsTests/DGHeatEquationTests.jl +++ b/test/TransientFEsTests/DGHeatEquationTests.jl @@ -70,9 +70,8 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl b/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl index 63427bc..e82fb1a 100644 --- a/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl +++ b/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl @@ -61,9 +61,8 @@ ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/HeatEquationAutoDiffTests.jl b/test/TransientFEsTests/HeatEquationAutoDiffTests.jl index 3ec19eb..b4d5313 100644 --- a/test/TransientFEsTests/HeatEquationAutoDiffTests.jl +++ b/test/TransientFEsTests/HeatEquationAutoDiffTests.jl @@ -72,9 +72,8 @@ ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) # Juno.@enter Base.iterate(sol_t) diff --git a/test/TransientFEsTests/HeatEquationTests.jl b/test/TransientFEsTests/HeatEquationTests.jl index 70545a6..992c08a 100644 --- a/test/TransientFEsTests/HeatEquationTests.jl +++ b/test/TransientFEsTests/HeatEquationTests.jl @@ -57,9 +57,8 @@ ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) # Juno.@enter Base.iterate(sol_t) diff --git a/test/TransientFEsTests/HeatVectorEquationTests.jl b/test/TransientFEsTests/HeatVectorEquationTests.jl index 96475e6..4262c34 100644 --- a/test/TransientFEsTests/HeatVectorEquationTests.jl +++ b/test/TransientFEsTests/HeatVectorEquationTests.jl @@ -58,9 +58,8 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) l2(w) = w⋅w diff --git a/test/TransientFEsTests/StokesEquationAutoDiffTests.jl b/test/TransientFEsTests/StokesEquationAutoDiffTests.jl index b4d9fa0..640f039 100644 --- a/test/TransientFEsTests/StokesEquationAutoDiffTests.jl +++ b/test/TransientFEsTests/StokesEquationAutoDiffTests.jl @@ -100,9 +100,8 @@ dt = 0.1 ls = LUSolver() odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,xh0,t0,tF) +sol_t = solve(odes,op,xh0,t0,tF) l2(w) = w⋅w diff --git a/test/TransientFEsTests/StokesEquationTests.jl b/test/TransientFEsTests/StokesEquationTests.jl index d198cac..ddba6ea 100644 --- a/test/TransientFEsTests/StokesEquationTests.jl +++ b/test/TransientFEsTests/StokesEquationTests.jl @@ -85,9 +85,8 @@ dt = 0.1 ls = LUSolver() odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,xh0,t0,tF) +sol_t = solve(odes,op,xh0,t0,tF) l2(w) = w⋅w diff --git a/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl b/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl index ba83eea..914e478 100644 --- a/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl +++ b/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl @@ -69,12 +69,11 @@ ah0_const = interpolate_everywhere(a_const(0.0),U0) ls = LUSolver() odes = Newmark(ls,dt,γ,β) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,(uh0,vh0,ah0),t0,tF) -sol_affine_t = solve(solver,op_affine,(uh0,vh0,ah0),t0,tF) -sol_const_t = solve(solver,op_const,(uh0,vh0_const,ah0_const),t0,tF) -sol_const_mat_t = solve(solver,op_const_mat,(uh0,vh0,ah0),t0,tF) +sol_t = solve(odes,op,(uh0,vh0,ah0),t0,tF) +sol_affine_t = solve(odes,op_affine,(uh0,vh0,ah0),t0,tF) +sol_const_t = solve(odes,op_const,(uh0,vh0_const,ah0_const),t0,tF) +sol_const_mat_t = solve(odes,op_const_mat,(uh0,vh0,ah0),t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/TransientFEOperatorsTests.jl b/test/TransientFEsTests/TransientFEOperatorsTests.jl index ed12332..062aa18 100644 --- a/test/TransientFEsTests/TransientFEOperatorsTests.jl +++ b/test/TransientFEsTests/TransientFEOperatorsTests.jl @@ -61,9 +61,8 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/TransientFETests.jl b/test/TransientFEsTests/TransientFETests.jl index fd8fadd..779d03a 100644 --- a/test/TransientFEsTests/TransientFETests.jl +++ b/test/TransientFEsTests/TransientFETests.jl @@ -113,8 +113,7 @@ maxiters = 20 using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) odes = ThetaMethod(nls,dt,1.0) -solver = TransientFESolver(odes) # Return a specialization of TransientFESolver -@test test_transient_fe_solver(solver,op,uh0,t0,tF) +@test test_transient_fe_solver(odes,op,uh0,t0,tF) residual!(r,op,0.1,(uh,uh),cache) jacobian!(J,op,1.0,(uh,uh10),1,1.0,cache) @@ -218,8 +217,7 @@ for (u_n, t_n) in sol_ode_t @test all(u_n .≈ t_n) end -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +sol_t = solve(odes,op,uh0,t0,tF) @test test_transient_fe_solution(sol_t) _t_n = 0.0 diff --git a/test/TransientFEsTests/VectorHeatEquationTests.jl b/test/TransientFEsTests/VectorHeatEquationTests.jl index b85be08..9bf2892 100644 --- a/test/TransientFEsTests/VectorHeatEquationTests.jl +++ b/test/TransientFEsTests/VectorHeatEquationTests.jl @@ -68,9 +68,8 @@ ls = LUSolver() # using Gridap.Algebra: NewtonRaphsonSolver # nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,xh0,t0,tF) +sol_t = solve(odes,op,xh0,t0,tF) l2(w) = w⋅w From 0d38d3c6c96488a4acdefb7f58b7a231bd74d247 Mon Sep 17 00:00:00 2001 From: Santiago Badia Date: Mon, 8 Nov 2021 08:04:57 +1100 Subject: [PATCH 4/6] some renaming and updated readme --- README.md | 5 ++--- test/TransientFEsTests/AffineFEOperatorsTests.jl | 4 ++-- .../BoundaryHeatEquationTests.jl | 4 ++-- .../TransientFEsTests/ConstantFEOperatorsTests.jl | 4 ++-- test/TransientFEsTests/DGHeatEquationTests.jl | 4 ++-- .../ForwardEulerHeatEquationTests.jl | 4 ++-- .../HeatEquationAutoDiffTests.jl | 4 ++-- test/TransientFEsTests/HeatEquationTests.jl | 4 ++-- test/TransientFEsTests/HeatVectorEquationTests.jl | 8 ++++---- .../StokesEquationAutoDiffTests.jl | 4 ++-- test/TransientFEsTests/StokesEquationTests.jl | 4 ++-- .../Transient2ndOrderFEOperatorsTests.jl | 10 +++++----- .../TransientFEOperatorsTests.jl | 8 ++++---- test/TransientFEsTests/TransientFETests.jl | 15 +++++++-------- test/TransientFEsTests/VectorHeatEquationTests.jl | 4 ++-- 15 files changed, 42 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index f94512e..942874f 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,8 @@ U0 = U(0.0) uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) -solver = TransientFESolver(odes) -sol_t = solve(solver,op,uh0,t0,tF) +ode_solver = ThetaMethod(ls,dt,θ) +sol_t = solve(ode_solver,op,uh0,t0,tF) for (uh_tn, tn) in sol_t # Here we have the solution uh_tn at tn diff --git a/test/TransientFEsTests/AffineFEOperatorsTests.jl b/test/TransientFEsTests/AffineFEOperatorsTests.jl index 3d36ad8..b68078b 100644 --- a/test/TransientFEsTests/AffineFEOperatorsTests.jl +++ b/test/TransientFEsTests/AffineFEOperatorsTests.jl @@ -54,8 +54,8 @@ U0 = U(0.0) uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +ode_solver = ThetaMethod(ls,dt,θ) +sol_t = solve(ode_solver,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/BoundaryHeatEquationTests.jl b/test/TransientFEsTests/BoundaryHeatEquationTests.jl index 70f5749..b5bdc0c 100644 --- a/test/TransientFEsTests/BoundaryHeatEquationTests.jl +++ b/test/TransientFEsTests/BoundaryHeatEquationTests.jl @@ -70,9 +70,9 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver # nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) # Juno.@enter Base.iterate(sol_t) diff --git a/test/TransientFEsTests/ConstantFEOperatorsTests.jl b/test/TransientFEsTests/ConstantFEOperatorsTests.jl index 8ecaf4f..d1a852a 100644 --- a/test/TransientFEsTests/ConstantFEOperatorsTests.jl +++ b/test/TransientFEsTests/ConstantFEOperatorsTests.jl @@ -54,8 +54,8 @@ U0 = U(0.0) uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +ode_solver = ThetaMethod(ls,dt,θ) +sol_t = solve(ode_solver,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/DGHeatEquationTests.jl b/test/TransientFEsTests/DGHeatEquationTests.jl index 05eb2c5..05d0b65 100644 --- a/test/TransientFEsTests/DGHeatEquationTests.jl +++ b/test/TransientFEsTests/DGHeatEquationTests.jl @@ -69,9 +69,9 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl b/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl index e82fb1a..2de154d 100644 --- a/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl +++ b/test/TransientFEsTests/ForwardEulerHeatEquationTests.jl @@ -60,9 +60,9 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/HeatEquationAutoDiffTests.jl b/test/TransientFEsTests/HeatEquationAutoDiffTests.jl index b4d5313..9fb494c 100644 --- a/test/TransientFEsTests/HeatEquationAutoDiffTests.jl +++ b/test/TransientFEsTests/HeatEquationAutoDiffTests.jl @@ -71,9 +71,9 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) # Juno.@enter Base.iterate(sol_t) diff --git a/test/TransientFEsTests/HeatEquationTests.jl b/test/TransientFEsTests/HeatEquationTests.jl index 992c08a..68d5319 100644 --- a/test/TransientFEsTests/HeatEquationTests.jl +++ b/test/TransientFEsTests/HeatEquationTests.jl @@ -56,9 +56,9 @@ uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) # Juno.@enter Base.iterate(sol_t) diff --git a/test/TransientFEsTests/HeatVectorEquationTests.jl b/test/TransientFEsTests/HeatVectorEquationTests.jl index 4262c34..58c213a 100644 --- a/test/TransientFEsTests/HeatVectorEquationTests.jl +++ b/test/TransientFEsTests/HeatVectorEquationTests.jl @@ -57,9 +57,9 @@ U0 = U(0.0) uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) l2(w) = w⋅w @@ -89,14 +89,14 @@ ode_cache = allocate_cache(odeop) vθ = similar(u0) nl_cache = nothing -odes.θ == 0.0 ? dtθ = dt : dtθ = dt*odes.θ +ode_solver.θ == 0.0 ? dtθ = dt : dtθ = dt*ode_solver.θ tθ = t0+dtθ ode_cache = update_cache!(ode_cache,odeop,tθ) using GridapODEs.ODETools: ThetaMethodNonlinearOperator nlop = ThetaMethodNonlinearOperator(odeop,tθ,dtθ,u0,ode_cache,vθ) -nl_cache = solve!(uf,odes.nls,nlop,nl_cache) +nl_cache = solve!(uf,ode_solver.nls,nlop,nl_cache) uf K = nl_cache.A diff --git a/test/TransientFEsTests/StokesEquationAutoDiffTests.jl b/test/TransientFEsTests/StokesEquationAutoDiffTests.jl index 640f039..487d6d6 100644 --- a/test/TransientFEsTests/StokesEquationAutoDiffTests.jl +++ b/test/TransientFEsTests/StokesEquationAutoDiffTests.jl @@ -99,9 +99,9 @@ tF = 1.0 dt = 0.1 ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,xh0,t0,tF) +sol_t = solve(ode_solver,op,xh0,t0,tF) l2(w) = w⋅w diff --git a/test/TransientFEsTests/StokesEquationTests.jl b/test/TransientFEsTests/StokesEquationTests.jl index ddba6ea..b731e71 100644 --- a/test/TransientFEsTests/StokesEquationTests.jl +++ b/test/TransientFEsTests/StokesEquationTests.jl @@ -84,9 +84,9 @@ tF = 1.0 dt = 0.1 ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,xh0,t0,tF) +sol_t = solve(ode_solver,op,xh0,t0,tF) l2(w) = w⋅w diff --git a/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl b/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl index 914e478..6d3e507 100644 --- a/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl +++ b/test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl @@ -68,12 +68,12 @@ vh0_const = interpolate_everywhere(v_const(0.0),U0) ah0_const = interpolate_everywhere(a_const(0.0),U0) ls = LUSolver() -odes = Newmark(ls,dt,γ,β) +ode_solver = Newmark(ls,dt,γ,β) -sol_t = solve(odes,op,(uh0,vh0,ah0),t0,tF) -sol_affine_t = solve(odes,op_affine,(uh0,vh0,ah0),t0,tF) -sol_const_t = solve(odes,op_const,(uh0,vh0_const,ah0_const),t0,tF) -sol_const_mat_t = solve(odes,op_const_mat,(uh0,vh0,ah0),t0,tF) +sol_t = solve(ode_solver,op,(uh0,vh0,ah0),t0,tF) +sol_affine_t = solve(ode_solver,op_affine,(uh0,vh0,ah0),t0,tF) +sol_const_t = solve(ode_solver,op_const,(uh0,vh0_const,ah0_const),t0,tF) +sol_const_mat_t = solve(ode_solver,op_const_mat,(uh0,vh0,ah0),t0,tF) l2(w) = w*w diff --git a/test/TransientFEsTests/TransientFEOperatorsTests.jl b/test/TransientFEsTests/TransientFEOperatorsTests.jl index 062aa18..9483657 100644 --- a/test/TransientFEsTests/TransientFEOperatorsTests.jl +++ b/test/TransientFEsTests/TransientFEOperatorsTests.jl @@ -60,9 +60,9 @@ U0 = U(0.0) uh0 = interpolate_everywhere(u(0.0),U0) ls = LUSolver() -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) l2(w) = w*w @@ -91,14 +91,14 @@ nl_cache = nothing # tf = t0+dt -odes.θ == 0.0 ? dtθ = dt : dtθ = dt*odes.θ +ode_solver.θ == 0.0 ? dtθ = dt : dtθ = dt*ode_solver.θ tθ = t0+dtθ ode_cache = update_cache!(ode_cache,odeop,tθ) using GridapODEs.ODETools: ThetaMethodNonlinearOperator nlop = ThetaMethodNonlinearOperator(odeop,tθ,dtθ,u0,ode_cache,vθ) -nl_cache = solve!(uf,odes.nls,nlop,nl_cache) +nl_cache = solve!(uf,ode_solver.nls,nlop,nl_cache) K = nl_cache.A h = nl_cache.b diff --git a/test/TransientFEsTests/TransientFETests.jl b/test/TransientFEsTests/TransientFETests.jl index 779d03a..fb1a66e 100644 --- a/test/TransientFEsTests/TransientFETests.jl +++ b/test/TransientFEsTests/TransientFETests.jl @@ -112,16 +112,15 @@ tol = 1.0 maxiters = 20 using Gridap.Algebra: NewtonRaphsonSolver nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) -odes = ThetaMethod(nls,dt,1.0) -@test test_transient_fe_solver(odes,op,uh0,t0,tF) +ode_solver = ThetaMethod(nls,dt,1.0) +@test test_transient_fe_solver(ode_solver,op,uh0,t0,tF) residual!(r,op,0.1,(uh,uh),cache) jacobian!(J,op,1.0,(uh,uh10),1,1.0,cache) jacobian!(J,op,1.0,(uh,uh10),2,10.0,cache) u0 = get_free_dof_values(uh0) -odes -solver = odes +solver = ode_solver t0 = 0.0 ode_cache = allocate_cache(odeop) cache = nothing @@ -194,7 +193,7 @@ Gridap.Algebra.nlsolve(df,x;linsolve=linsolve!,nls.kwargs...) using Gridap.FESpaces: get_algebraic_operator odeop = get_algebraic_operator(op) -sol_ode_t = solve(odes,odeop,u0,t0,tF) +sol_ode_t = solve(ode_solver,odeop,u0,t0,tF) test_ode_solution(sol_ode_t) _t_n = t0 @@ -205,8 +204,8 @@ for (u_n, t_n) in sol_ode_t @test all(u_n .≈ t_n) end -odes = ThetaMethod(nls,dt,θ) -sol_ode_t = solve(odes,odeop,u0,t0,tF) +ode_solver = ThetaMethod(nls,dt,θ) +sol_ode_t = solve(ode_solver,odeop,u0,t0,tF) test_ode_solution(sol_ode_t) _t_n = t0 un, tn = Base.iterate(sol_ode_t) @@ -217,7 +216,7 @@ for (u_n, t_n) in sol_ode_t @test all(u_n .≈ t_n) end -sol_t = solve(odes,op,uh0,t0,tF) +sol_t = solve(ode_solver,op,uh0,t0,tF) @test test_transient_fe_solution(sol_t) _t_n = 0.0 diff --git a/test/TransientFEsTests/VectorHeatEquationTests.jl b/test/TransientFEsTests/VectorHeatEquationTests.jl index 9bf2892..7dc2660 100644 --- a/test/TransientFEsTests/VectorHeatEquationTests.jl +++ b/test/TransientFEsTests/VectorHeatEquationTests.jl @@ -67,9 +67,9 @@ xh0 = interpolate_everywhere([uh0,uh0],X0) ls = LUSolver() # using Gridap.Algebra: NewtonRaphsonSolver # nls = NLSolver(ls;show_trace=true,method=:newton) #linesearch=BackTracking()) -odes = ThetaMethod(ls,dt,θ) +ode_solver = ThetaMethod(ls,dt,θ) -sol_t = solve(odes,op,xh0,t0,tF) +sol_t = solve(ode_solver,op,xh0,t0,tF) l2(w) = w⋅w From 23e5950941aa969c5a5f74c6fc991b6e7711e8c8 Mon Sep 17 00:00:00 2001 From: Santiago Badia Date: Mon, 8 Nov 2021 08:54:33 +1100 Subject: [PATCH 5/6] Update NEWS.md --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index 400b545..48eeaad 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Hiding the creation of `TransientFESolver` from user code. Since PR [#59](https://github.com/gridap/GridapODEs.jl/pull/59). + ## [0.7.0] - 2021-09-21 ### Added From 0e0cf3b027c43eb8e9cbfe9fec71279bffe1389d Mon Sep 17 00:00:00 2001 From: Oriol Colomes Date: Tue, 16 Nov 2021 21:40:05 +0100 Subject: [PATCH 6/6] fixed example code in README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 942874f..6a2df6b 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ a(u,v) = ∫( ∇(v)⋅∇(u) )dΩ b(v,t) = ∫( v*f(t) )dΩ m(u,v) = ∫( v*u )dΩ -res(t,u,ut,v) = a(u,v) + m(ut,v) - b(v,t) -jac(t,u,ut,du,v) = a(du,v) -jac_t(t,u,ut,dut,v) = m(dut,v) +res(t,(u,ut),v) = a(u,v) + m(ut,v) - b(v,t) +jac(t,(u,ut),du,v) = a(du,v) +jac_t(t,(u,ut),dut,v) = m(dut,v) op = TransientFEOperator(res,jac,jac_t,U,V0)