Skip to content

Commit

Permalink
Update initialization.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas authored Dec 3, 2024
1 parent 8636420 commit 3ae7b69
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,27 @@ function get_initial_values end
struct CheckInitFailureError <: Exception
normresid::Any
abstol::Any
isdae::Bool
end

function Base.showerror(io::IO, e::CheckInitFailureError)
print(io,
"DAE initialization failed: your u0 did not satisfy the initialization requirements,
normresid = $(e.normresid) > abstol = $(e.abstol). If you wish for the system to
automatically change the algebraic variables to satisfy the algebraic constraints,
please pass `initializealg = BrownBasicInit()` to solve (this option will require
`using OrdinaryDiffEqNonlinearSolve`). If you wish to perform an initialization on the
complete u0, please pass initializealg = ShampineCollocationInit() to solve. Note that
initialization can be a very difficult process for DAEs and in many cases can be
numerically intractable without symbolic manipulation of the system. For an automated
system that will generate numerically stable initializations, see ModelingToolkit.jl
structural simplification for more details."
normresid = $(e.normresid) > abstol = $(e.abstol)."
)

if isdae
print(io, " If you wish for the system to
automatically change the algebraic variables to satisfy the algebraic constraints,
please pass `initializealg = BrownBasicInit()` to solve (this option will require
`using OrdinaryDiffEqNonlinearSolve`). If you wish to perform an initialization on the
complete u0, please pass initializealg = ShampineCollocationInit() to solve. Note that
initialization can be a very difficult process for DAEs and in many cases can be
numerically intractable without symbolic manipulation of the system. For an automated
system that will generate numerically stable initializations, see ModelingToolkit.jl
structural simplification for more details."
)
end
end

struct OverrideInitMissingAlgorithm <: Exception end
Expand Down Expand Up @@ -144,7 +150,7 @@ function get_initial_values(
normresid = isdefined(integrator.opts, :internalnorm) ?
integrator.opts.internalnorm(tmp, t) : norm(tmp)
if normresid > abstol
throw(CheckInitFailureError(normresid, abstol))
throw(CheckInitFailureError(normresid, abstol, true))
end
return u0, p, true
end
Expand All @@ -161,7 +167,7 @@ function get_initial_values(
integrator.opts.internalnorm(resid, t) : norm(resid)

if normresid > abstol
throw(CheckInitFailureError(normresid, abstol))
throw(CheckInitFailureError(normresid, abstol, false))
end
return u0, p, true
end
Expand Down

0 comments on commit 3ae7b69

Please sign in to comment.