Skip to content

Commit e1c03d7

Browse files
fix: simplify CheckInit
1 parent 77b72e3 commit e1c03d7

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

src/initialization.jl

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ function Base.showerror(io::IO, e::OverrideInitNoTolerance)
7878
end
7979

8080
"""
81-
Utility function to evaluate the RHS of the ODE, using the integrator's `tmp_cache` if
81+
Utility function to evaluate the RHS, using the integrator's `tmp_cache` if
8282
it is in-place or simply calling the function if not.
8383
"""
84-
function _evaluate_f_ode(integrator, f, isinplace::Val{true}, args...)
84+
function _evaluate_f(integrator, f, isinplace::Val{true}, args...)
8585
tmp = first(get_tmp_cache(integrator))
8686
f(tmp, args...)
8787
return tmp
8888
end
8989

90-
function _evaluate_f_ode(integrator, f, isinplace::Val{false}, args...)
90+
function _evaluate_f(integrator, f, isinplace::Val{false}, args...)
9191
return f(args...)
9292
end
9393

@@ -126,7 +126,7 @@ function get_initial_values(
126126
algebraic_eqs = [all(iszero, x) for x in eachrow(M)]
127127
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return u0, p, true
128128
update_coefficients!(M, u0, p, t)
129-
tmp = _evaluate_f_ode(integrator, f, isinplace, u0, p, t)
129+
tmp = _evaluate_f(integrator, f, isinplace, u0, p, t)
130130
tmp .= ArrayInterface.restructure(tmp, algebraic_eqs .* _vec(tmp))
131131

132132
normresid = isdefined(integrator.opts, :internalnorm) ?
@@ -137,34 +137,17 @@ function get_initial_values(
137137
return u0, p, true
138138
end
139139

140-
"""
141-
Utility function to evaluate the RHS of the DAE, using the integrator's `tmp_cache` if
142-
it is in-place or simply calling the function if not.
143-
"""
144-
function _evaluate_f_dae(integrator, f, isinplace::Val{true}, args...)
145-
tmp = get_tmp_cache(integrator)[2]
146-
f(tmp, args...)
147-
return tmp
148-
end
149-
150-
function _evaluate_f_dae(integrator, f, isinplace::Val{false}, args...)
151-
return f(args...)
152-
end
153-
154140
function get_initial_values(
155141
prob::AbstractDAEProblem, integrator::DEIntegrator, f, alg::CheckInit,
156-
isinplace::Union{Val{true}, Val{false}}; abstol = nothing, kwargs...)
142+
isinplace::Union{Val{true}, Val{false}}; abstol, kwargs...)
157143
u0 = state_values(integrator)
158144
p = parameter_values(integrator)
159145
t = current_time(integrator)
160146

161-
resid = _evaluate_f_dae(integrator, f, isinplace, integrator.du, u0, p, t)
147+
resid = _evaluate_f(integrator, f, isinplace, integrator.du, u0, p, t)
162148
normresid = isdefined(integrator.opts, :internalnorm) ?
163149
integrator.opts.internalnorm(resid, t) : norm(resid)
164150

165-
if abstol === nothing
166-
abstol = cache_get_abstol(integrator)
167-
end
168151
if normresid > abstol
169152
throw(CheckInitFailureError(normresid, abstol))
170153
end

0 commit comments

Comments
 (0)