Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #59 from gridap/remove_TransientFESolver
Browse files Browse the repository at this point in the history
Removed TransientFESolver
  • Loading branch information
santiagobadia authored Nov 7, 2021
2 parents 710f76f + 0d38d3c commit 4a5d41b
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 89 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions src/TransientFETools/TransientFESolutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions src/TransientFETools/TransientFESolvers.jl

This file was deleted.

3 changes: 0 additions & 3 deletions src/TransientFETools/TransientFETools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -94,8 +93,6 @@ include("TransientFEOperators.jl")

include("ODEOperatorInterfaces.jl")

include("TransientFESolvers.jl")

include("TransientFESolutions.jl")

export FETerm
Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/AffineFEOperatorsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,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)

l2(w) = w*w

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/BoundaryHeatEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +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,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

# Juno.@enter Base.iterate(sol_t)

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/ConstantFEOperatorsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,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)

l2(w) = w*w

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/DGHeatEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ uh0 = interpolate_everywhere(u(0.0),U0)

ls = LUSolver()
using Gridap.Algebra: NewtonRaphsonSolver
odes = ThetaMethod(ls,dt,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

l2(w) = w*w

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/ForwardEulerHeatEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +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,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

l2(w) = w*w

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/HeatEquationAutoDiffTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +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,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

# Juno.@enter Base.iterate(sol_t)

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/HeatEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +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,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

# Juno.@enter Base.iterate(sol_t)

Expand Down
9 changes: 4 additions & 5 deletions test/TransientFEsTests/HeatVectorEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ U0 = U(0.0)
uh0 = interpolate_everywhere(u(0.0),U0)

ls = LUSolver()
odes = ThetaMethod(ls,dt,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

l2(w) = ww

Expand Down Expand Up @@ -90,14 +89,14 @@ ode_cache = allocate_cache(odeop)
= similar(u0)
nl_cache = nothing

odes.θ == 0.0 ? dtθ = dt : dtθ = dt*odes.θ
ode_solver.θ == 0.0 ? dtθ = dt : dtθ = dt*ode_solver.θ
= 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
Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/StokesEquationAutoDiffTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ tF = 1.0
dt = 0.1

ls = LUSolver()
odes = ThetaMethod(ls,dt,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,xh0,t0,tF)
sol_t = solve(ode_solver,op,xh0,t0,tF)

l2(w) = ww

Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/StokesEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ tF = 1.0
dt = 0.1

ls = LUSolver()
odes = ThetaMethod(ls,dt,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,xh0,t0,tF)
sol_t = solve(ode_solver,op,xh0,t0,tF)

l2(w) = ww

Expand Down
11 changes: 5 additions & 6 deletions test/TransientFEsTests/Transient2ndOrderFEOperatorsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +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,γ,β)
solver = TransientFESolver(odes)
ode_solver = Newmark(ls,dt,γ,β)

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(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

Expand Down
9 changes: 4 additions & 5 deletions test/TransientFEsTests/TransientFEOperatorsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ U0 = U(0.0)
uh0 = interpolate_everywhere(u(0.0),U0)

ls = LUSolver()
odes = ThetaMethod(ls,dt,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,uh0,t0,tF)
sol_t = solve(ode_solver,op,uh0,t0,tF)

l2(w) = w*w

Expand Down Expand Up @@ -92,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.θ
= 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
Expand Down
17 changes: 7 additions & 10 deletions test/TransientFEsTests/TransientFETests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +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)
solver = TransientFESolver(odes) # Return a specialization of TransientFESolver
@test test_transient_fe_solver(solver,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
Expand Down Expand Up @@ -195,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
Expand All @@ -206,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)
Expand All @@ -218,8 +216,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(ode_solver,op,uh0,t0,tF)
@test test_transient_fe_solution(sol_t)

_t_n = 0.0
Expand Down
5 changes: 2 additions & 3 deletions test/TransientFEsTests/VectorHeatEquationTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +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,θ)
solver = TransientFESolver(odes)
ode_solver = ThetaMethod(ls,dt,θ)

sol_t = solve(solver,op,xh0,t0,tF)
sol_t = solve(ode_solver,op,xh0,t0,tF)

l2(w) = ww

Expand Down

0 comments on commit 4a5d41b

Please sign in to comment.