Skip to content

Commit 94cbba0

Browse files
Merge pull request #886 from Ickaser/dae_init_error
Make CheckInit more informative
2 parents dae2c41 + 3ae7b69 commit 94cbba0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/SciMLBase.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ export ODEFunction, DiscreteFunction, ImplicitDiscreteFunction, SplitFunction, D
835835

836836
export OptimizationFunction, MultiObjectiveOptimizationFunction
837837

838+
export CheckInit
839+
838840
export EnsembleThreads, EnsembleDistributed, EnsembleSplitThreads, EnsembleSerial
839841

840842
export EnsembleAnalysis, EnsembleSummary

src/initialization.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,27 @@ function get_initial_values end
5555
struct CheckInitFailureError <: Exception
5656
normresid::Any
5757
abstol::Any
58+
isdae::Bool
5859
end
5960

6061
function Base.showerror(io::IO, e::CheckInitFailureError)
6162
print(io,
62-
"CheckInit specified but initialization not satisfied. normresid = $(e.normresid) > abstol = $(e.abstol)")
63+
"DAE initialization failed: your u0 did not satisfy the initialization requirements,
64+
normresid = $(e.normresid) > abstol = $(e.abstol)."
65+
)
66+
67+
if isdae
68+
print(io, " If you wish for the system to
69+
automatically change the algebraic variables to satisfy the algebraic constraints,
70+
please pass `initializealg = BrownBasicInit()` to solve (this option will require
71+
`using OrdinaryDiffEqNonlinearSolve`). If you wish to perform an initialization on the
72+
complete u0, please pass initializealg = ShampineCollocationInit() to solve. Note that
73+
initialization can be a very difficult process for DAEs and in many cases can be
74+
numerically intractable without symbolic manipulation of the system. For an automated
75+
system that will generate numerically stable initializations, see ModelingToolkit.jl
76+
structural simplification for more details."
77+
)
78+
end
6379
end
6480

6581
struct OverrideInitMissingAlgorithm <: Exception end
@@ -134,7 +150,7 @@ function get_initial_values(
134150
normresid = isdefined(integrator.opts, :internalnorm) ?
135151
integrator.opts.internalnorm(tmp, t) : norm(tmp)
136152
if normresid > abstol
137-
throw(CheckInitFailureError(normresid, abstol))
153+
throw(CheckInitFailureError(normresid, abstol, true))
138154
end
139155
return u0, p, true
140156
end
@@ -151,7 +167,7 @@ function get_initial_values(
151167
integrator.opts.internalnorm(resid, t) : norm(resid)
152168

153169
if normresid > abstol
154-
throw(CheckInitFailureError(normresid, abstol))
170+
throw(CheckInitFailureError(normresid, abstol, false))
155171
end
156172
return u0, p, true
157173
end

0 commit comments

Comments
 (0)