Skip to content

Commit

Permalink
Merge branch 'termi-official:main' into make-master-great-again
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdAlazezAhmed authored Aug 16, 2024
2 parents b425b9a + 5862065 commit 59c304e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
17 changes: 12 additions & 5 deletions src/solver/time/euler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Base.@kwdef struct BackwardEulerSolver{SolverType, SolutionVectorType, SystemMat
system_matrix_type::Type{SystemMatrixType} = ThreadedSparseMatrixCSR{Float64, Int64}
# mass operator info
# diffusion opeartor info
verbose = true # Temporary helper for benchmarks
end

# TODO decouple from heat problem via special ODEFunction (AffineODEFunction)
Expand All @@ -27,6 +28,8 @@ mutable struct BackwardEulerSolverCache{T, SolutionType <: AbstractVector{T}, Ma
inner_solver::SolverCacheType
# Last time step length as a check if we have to update K
Δt_last::T
# DO NOT USE THIS (will be replaced by proper logging system)
verbose::Bool
end

# Helper to get A into the right form
Expand Down Expand Up @@ -59,13 +62,16 @@ function perform_step!(f::TransientDiffusionFunction, cache::BackwardEulerSolver
# TODO How to remove these two lines here?
# Update source term
@timeit_debug "update source term" begin
implicit_euler_heat_update_source_term!(cache, t)
implicit_euler_heat_update_source_term!(cache, t + Δt)
add!(inner_solver.b, cache.source_term)
end
# Solve linear problem
@timeit_debug "inner solve" LinearSolve.solve!(inner_solver)
@info inner_solver.cacheval.stats
return true
@timeit_debug "inner solve" sol = LinearSolve.solve!(inner_solver)
solve_failed = !(DiffEqBase.SciMLBase.successful_retcode(sol.retcode) || sol.retcode == DiffEqBase.ReturnCode.Default)
if cache.verbose || solve_failed # The latter seems off...
@info inner_solver.cacheval.stats
end
return !solve_failed
end

function setup_solver_cache(f::TransientDiffusionFunction, solver::BackwardEulerSolver, t₀)
Expand Down Expand Up @@ -120,7 +126,8 @@ function setup_solver_cache(f::TransientDiffusionFunction, solver::BackwardEuler
diffusion_operator,
source_operator,
inner_cache,
T(0.0)
T(0.0),
solver.verbose,
)

@timeit_debug "initial assembly" begin
Expand Down
4 changes: 2 additions & 2 deletions src/solver/time/load_stepping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ end
function perform_step!(f::AbstractSemidiscreteFunction, solver_cache::LoadDrivenSolverCache, t, Δt)
solver_cache.uₙ₋₁ .= solver_cache.uₙ
@info t
update_constraints!(f, solver_cache, t)
if !nlsolve!(solver_cache.uₙ, f, solver_cache.inner_solver_cache, t) # TODO remove ,,t'' here. But how?
update_constraints!(f, solver_cache, t + Δt)
if !nlsolve!(solver_cache.uₙ, f, solver_cache.inner_solver_cache, t + Δt) # TODO remove ,,t'' here. But how?
@warn "Inner solver failed."
return false
end
Expand Down
14 changes: 8 additions & 6 deletions src/solver/time/time_integrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ function DiffEqBase.step!(integrator::ThunderboltTimeIntegrator, dt, stop_at_tdt
dt <= zero(dt) && error("dt must be positive")
tnext = integrator.t + dt
while !OS.reached_tstop(integrator, tnext, stop_at_tdt)
# Solve inner problem
perform_step!(integrator, integrator.cache) || error("Time integration failed at t=$(integrator.t).") # remove this
# Update integrator
integrator.tprev = integrator.t
integrator.t = integrator.t + integrator.dt
# Solve inner problem
perform_step!(integrator, integrator.cache)
# TODO check for solver failure
end

while !isempty(tstops) && OS.reached_tstop(integrator, first(tstops))
Expand Down Expand Up @@ -115,7 +114,7 @@ function OS.build_subintegrators_recursive(f, synchronizer, p::Any, cache::Abstr
dt,
cache,
synchronizer,
nothing, # sol
nothing, # FIXME sol
true, #dtchangeable
tstops,
_tstops,
Expand Down Expand Up @@ -211,7 +210,10 @@ end
# Compat with OrdinaryDiffEq
function perform_step!(integ::ThunderboltTimeIntegrator, cache::AbstractTimeSolverCache)
if !perform_step!(integ.f, cache, integ.t, integ.dt)
integ.sol = DiffEqBase.solution_new_retcode(integ.sol, DiffEqBase.ReturnCode.Failure)
error("Time step failed at t=$(integ.t).") # remove this
if integ.sol !== nothing # FIXME
integ.sol = DiffEqBase.solution_new_retcode(integ.sol, DiffEqBase.ReturnCode.Failure)
end
return false
end
return true
end

0 comments on commit 59c304e

Please sign in to comment.